Skip to content

Commit

Permalink
Add: Map set export action on collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jul 18, 2022
1 parent c3eab1c commit 438da62
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 32 deletions.
29 changes: 23 additions & 6 deletions App/BeatmapListingActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,50 @@ public BeatmapListingActionsHandler(ICollectionEditor collectionEditor, IUserDia
};
}

public void Bind(IBeatmapListingModel beatmapListingModel)
public void Bind(IBeatmapListingModel beatmapListingModel, ICollectionListingModel collectionListingModel = null)
{
beatmapListingModel.BeatmapOperation += BeatmapListingModel_BeatmapOperation;
if (collectionListingModel != null)
collectionListingModel.CollectionEditing += CollectionListingModel_CollectionEditing;
}


public void UnBind(IBeatmapListingModel beatmapListingModel)
public void UnBind(IBeatmapListingModel beatmapListingModel, ICollectionListingModel collectionListingModel = null)
{
beatmapListingModel.BeatmapOperation -= BeatmapListingModel_BeatmapOperation;
if (collectionListingModel != null)
collectionListingModel.CollectionEditing -= CollectionListingModel_CollectionEditing;
}

private void BeatmapListingModel_BeatmapOperation(object sender, BeatmapListingAction args)
{
_beatmapOperationHandlers[args](sender);
}
private void CollectionListingModel_CollectionEditing(object sender, CollectionEditArgs e)
{
if (e.Action != CollectionManager.Enums.CollectionEdit.ExportBeatmaps)
return;

ExportBeatmapSets(e.Collections.AllBeatmaps().Cast<Beatmap>().ToList());
}

private void ExportBeatmapSets(object sender)
{
var model = (IBeatmapListingModel)sender;
if (model.SelectedBeatmaps?.Count == 0)
if (sender is not IBeatmapListingModel beatmapListingModel)
return;

ExportBeatmapSets(beatmapListingModel.SelectedBeatmaps?.ToList());
}

private void ExportBeatmapSets(List<Beatmap> beatmaps)
{
if (beatmaps?.Count == 0)
{
_userDialogs.OkMessageBox("No beatmaps selected", "Info");
return;
}

var saveDirectory = _userDialogs.SelectDirectory("Select directory for exported maps", true);
var beatmapSets = model.SelectedBeatmaps.Select(b => (Beatmap: b, FileName: OsuDownloadManager.CreateOszFileName(b)))
var beatmapSets = beatmaps.Select(b => (Beatmap: b, FileName: OsuDownloadManager.CreateOszFileName(b)))
.GroupBy(e => e.FileName).Select(e => e.First()).ToList();
if (!Directory.Exists(saveDirectory))
return;
Expand Down
6 changes: 3 additions & 3 deletions App/GuiActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GuiActionsHandler(OsuFileIo osuFileIo, ICollectionEditor collectionEditor
SidePanelActionsHandler = new SidePanelActionsHandler(osuFileIo, collectionEditor, userDialogs, mainFormView, this, mainFormPresenter, loginForm);

_beatmapListingActionsHandler = new BeatmapListingActionsHandler(collectionEditor, userDialogs, loginForm, osuFileIo);
_beatmapListingActionsHandler.Bind(mainFormPresenter.BeatmapListingModel);
_beatmapListingActionsHandler.Bind(mainFormPresenter.BeatmapListingModel, mainFormPresenter.CollectionListingModel);

Initalizer.CollectionsManager.LoadedCollections.CollectionChanged += LoadedCollectionsOnCollectionChanged;
}
Expand All @@ -47,12 +47,12 @@ private void LoadedCollectionsOnCollectionChanged(object sender, NotifyCollectio

public void Bind(IBeatmapListingModel model)
{
_beatmapListingActionsHandler.Bind(model);
_beatmapListingActionsHandler.Bind(model, null);
}

public void UnBind(IBeatmapListingModel model)
{
_beatmapListingActionsHandler.UnBind(model);
_beatmapListingActionsHandler.UnBind(model, null);
}
}
}
26 changes: 26 additions & 0 deletions App/Misc/CollectionEditArgsExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CollectionManager.DataTypes;
using CollectionManager.Enums;
using CollectionManager.Modules.CollectionsManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App.Misc
{
internal class CollectionEditArgsExtension : CollectionEditArgs
{
public CollectionEditArgsExtension(CollectionEdit action) : base(action)
{
}

public static CollectionEditArgs ExportBeatmaps(Collections collections)
{
return new CollectionEditArgsExtension(CollectionEdit.ExportBeatmaps)
{
Collections = collections
};
}
}
}
6 changes: 6 additions & 0 deletions App/Presenters/Controls/CollectionListingPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ private void _view_RightClick(object sender, Gui.Misc.StringEventArgs e)

args = CollectionEditArgs.DuplicateCollection(_view.SelectedCollection);
break;
case "Export":
if (selectedCollections == null)
return;

args = CollectionEditArgsExtension.ExportBeatmaps(selectedCollections);
break;
case "Copy":
if (selectedCollections == null)
return;
Expand Down
2 changes: 2 additions & 0 deletions CollectionManagerDll/Enums/CollectionEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public enum CollectionEdit
Inverse=10,
Difference=11,
Reorder=12,

ExportBeatmaps=100,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace CollectionManager.Modules.CollectionsManager
{
public class CollectionEditArgs : EventArgs
{
public CollectionEdit Action { get; private set; }
public string OrginalName { get; private set; }
public string NewName { get; set; }
public Collections Collections { get; private set; }
public Collection TargetCollection { get; private set; }
public Beatmaps Beatmaps { get; private set; }
public IList<string> CollectionNames { get; private set; }
public bool PlaceCollectionsBefore { get; private set; }
public CollectionEdit Action { get; protected set; }
public string OrginalName { get; protected set; }
public string NewName { get; protected set; }
public Collections Collections { get; protected set; }
public Collection TargetCollection { get; protected set; }
public Beatmaps Beatmaps { get; protected set; }
public IList<string> CollectionNames { get; protected set; }
public bool PlaceCollectionsBefore { get; protected set; }
public CollectionEditArgs(CollectionEdit action)
{
Action = action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ remove beatmaps from collection
private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false)
{
var action = args.Action;
if ((int)action >= 100)
return;

if (action == CollectionEdit.Add)
{
List<string> collectionNames = new List<string>();
Expand Down
42 changes: 27 additions & 15 deletions GuiComponents/Controls/CollectionListingView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 438da62

Please sign in to comment.