From 438da62e77bc225cc6ce775697a9941c2f3b29ae Mon Sep 17 00:00:00 2001 From: Piotrekol <4990365+Piotrekol@users.noreply.github.com> Date: Mon, 18 Jul 2022 19:40:14 +0200 Subject: [PATCH] Add: Map set export action on collections --- App/BeatmapListingActionsHandler.cs | 29 ++++++++++--- App/GuiActionsHandler.cs | 6 +-- App/Misc/CollectionEditArgsExtension.cs | 26 ++++++++++++ .../Controls/CollectionListingPresenter.cs | 6 +++ CollectionManagerDll/Enums/CollectionEdit.cs | 2 + .../CollectionsManager/CollectionEditArgs.cs | 16 +++---- .../CollectionsManager/CollectionsManager.cs | 3 ++ .../CollectionListingView.Designer.cs | 42 ++++++++++++------- 8 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 App/Misc/CollectionEditArgsExtension.cs diff --git a/App/BeatmapListingActionsHandler.cs b/App/BeatmapListingActionsHandler.cs index 858817d..5f31db3 100644 --- a/App/BeatmapListingActionsHandler.cs +++ b/App/BeatmapListingActionsHandler.cs @@ -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().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 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; diff --git a/App/GuiActionsHandler.cs b/App/GuiActionsHandler.cs index 63cfbaa..ede4595 100644 --- a/App/GuiActionsHandler.cs +++ b/App/GuiActionsHandler.cs @@ -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; } @@ -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); } } } \ No newline at end of file diff --git a/App/Misc/CollectionEditArgsExtension.cs b/App/Misc/CollectionEditArgsExtension.cs new file mode 100644 index 0000000..4d6f4bf --- /dev/null +++ b/App/Misc/CollectionEditArgsExtension.cs @@ -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 + }; + } + } +} diff --git a/App/Presenters/Controls/CollectionListingPresenter.cs b/App/Presenters/Controls/CollectionListingPresenter.cs index 8d10d84..55dea2d 100644 --- a/App/Presenters/Controls/CollectionListingPresenter.cs +++ b/App/Presenters/Controls/CollectionListingPresenter.cs @@ -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; diff --git a/CollectionManagerDll/Enums/CollectionEdit.cs b/CollectionManagerDll/Enums/CollectionEdit.cs index 5ebe12b..0dd2710 100644 --- a/CollectionManagerDll/Enums/CollectionEdit.cs +++ b/CollectionManagerDll/Enums/CollectionEdit.cs @@ -15,5 +15,7 @@ public enum CollectionEdit Inverse=10, Difference=11, Reorder=12, + + ExportBeatmaps=100, } } \ No newline at end of file diff --git a/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs b/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs index 0653330..58bc41a 100644 --- a/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs +++ b/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs @@ -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 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 CollectionNames { get; protected set; } + public bool PlaceCollectionsBefore { get; protected set; } public CollectionEditArgs(CollectionEdit action) { Action = action; diff --git a/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs b/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs index 9861f13..d74f924 100644 --- a/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs +++ b/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs @@ -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 collectionNames = new List(); diff --git a/GuiComponents/Controls/CollectionListingView.Designer.cs b/GuiComponents/Controls/CollectionListingView.Designer.cs index b76e327..8c7eaf1 100644 --- a/GuiComponents/Controls/CollectionListingView.Designer.cs +++ b/GuiComponents/Controls/CollectionListingView.Designer.cs @@ -47,6 +47,7 @@ private void InitializeComponent() this.differenceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.inverseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CollectionContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.exportBeatmapSetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ListViewCollections)).BeginInit(); this.CollectionContextMenuStrip.SuspendLayout(); @@ -131,7 +132,7 @@ private void InitializeComponent() // CreateMenuStrip // this.CreateMenuStrip.Name = "CreateMenuStrip"; - this.CreateMenuStrip.Size = new System.Drawing.Size(180, 22); + this.CreateMenuStrip.Size = new System.Drawing.Size(181, 22); this.CreateMenuStrip.Tag = "Create"; this.CreateMenuStrip.Text = "Create"; this.CreateMenuStrip.ToolTipText = "Create new collection"; @@ -141,7 +142,7 @@ private void InitializeComponent() // this.renameCollectionMenuStrip.Name = "renameCollectionMenuStrip"; this.renameCollectionMenuStrip.ShortcutKeyDisplayString = "F2"; - this.renameCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); + this.renameCollectionMenuStrip.Size = new System.Drawing.Size(181, 22); this.renameCollectionMenuStrip.Tag = "Rename"; this.renameCollectionMenuStrip.Text = "Rename"; this.renameCollectionMenuStrip.ToolTipText = "Rename currently selected collection"; @@ -151,7 +152,7 @@ private void InitializeComponent() // this.deleteCollectionMenuStrip.Name = "deleteCollectionMenuStrip"; this.deleteCollectionMenuStrip.ShortcutKeyDisplayString = "Del"; - this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); + this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(181, 22); this.deleteCollectionMenuStrip.Tag = "Delete"; this.deleteCollectionMenuStrip.Text = "Delete"; this.deleteCollectionMenuStrip.ToolTipText = "Delete currently selected collections"; @@ -161,7 +162,7 @@ private void InitializeComponent() // this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; this.copyToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+C"; - this.copyToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.copyToolStripMenuItem.Size = new System.Drawing.Size(181, 22); this.copyToolStripMenuItem.Tag = "Copy"; this.copyToolStripMenuItem.Text = "Copy"; this.copyToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); @@ -170,7 +171,7 @@ private void InitializeComponent() // this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; this.pasteToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+V"; - this.pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.pasteToolStripMenuItem.Size = new System.Drawing.Size(181, 22); this.pasteToolStripMenuItem.Tag = "Paste"; this.pasteToolStripMenuItem.Text = "Paste"; this.pasteToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); @@ -178,7 +179,7 @@ private void InitializeComponent() // DuplicateMenuStrip // this.DuplicateMenuStrip.Name = "DuplicateMenuStrip"; - this.DuplicateMenuStrip.Size = new System.Drawing.Size(180, 22); + this.DuplicateMenuStrip.Size = new System.Drawing.Size(181, 22); this.DuplicateMenuStrip.Tag = "Duplicate"; this.DuplicateMenuStrip.Text = "Duplicate"; this.DuplicateMenuStrip.ToolTipText = "Create a copy of currently selected collection"; @@ -187,7 +188,7 @@ private void InitializeComponent() // mergeWithMenuStrip // this.mergeWithMenuStrip.Name = "mergeWithMenuStrip"; - this.mergeWithMenuStrip.Size = new System.Drawing.Size(180, 22); + this.mergeWithMenuStrip.Size = new System.Drawing.Size(181, 22); this.mergeWithMenuStrip.Tag = "Merge"; this.mergeWithMenuStrip.Text = "Merge selected"; this.mergeWithMenuStrip.ToolTipText = "Merge beatmaps from selected collections into new collection"; @@ -196,26 +197,27 @@ private void InitializeComponent() // intersectMenuItem // this.intersectMenuItem.Name = "intersectMenuItem"; - this.intersectMenuItem.Size = new System.Drawing.Size(180, 22); + this.intersectMenuItem.Size = new System.Drawing.Size(181, 22); this.intersectMenuItem.Tag = "Intersect"; this.intersectMenuItem.Text = "Intersection"; this.intersectMenuItem.ToolTipText = "Create a collection that contains beatmaps that exist in all selected collections" + ""; this.intersectMenuItem.Click += new System.EventHandler(this.MenuStripClick); // - // differenceToolStripMenuItem + // differenceMenuItem // - this.differenceMenuItem.Name = "differenceToolStripMenuItem"; - this.differenceMenuItem.Size = new System.Drawing.Size(180, 22); + this.differenceMenuItem.Name = "differenceMenuItem"; + this.differenceMenuItem.Size = new System.Drawing.Size(181, 22); this.differenceMenuItem.Tag = "Difference"; this.differenceMenuItem.Text = "Difference"; - this.differenceMenuItem.ToolTipText = "Create a collection that contains beatmaps that exist in only one of the selected collections"; + this.differenceMenuItem.ToolTipText = "Create a collection that contains beatmaps that exist in only one of the selected" + + " collections"; this.differenceMenuItem.Click += new System.EventHandler(this.MenuStripClick); // // inverseToolStripMenuItem // this.inverseToolStripMenuItem.Name = "inverseToolStripMenuItem"; - this.inverseToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.inverseToolStripMenuItem.Size = new System.Drawing.Size(181, 22); this.inverseToolStripMenuItem.Tag = "Inverse"; this.inverseToolStripMenuItem.Text = "Inverse"; this.inverseToolStripMenuItem.ToolTipText = "Create new collection that contains every beatmap not present in all selected col" + @@ -234,9 +236,18 @@ private void InitializeComponent() this.mergeWithMenuStrip, this.intersectMenuItem, this.differenceMenuItem, - this.inverseToolStripMenuItem}); + this.inverseToolStripMenuItem, + this.exportBeatmapSetsToolStripMenuItem}); this.CollectionContextMenuStrip.Name = "CollectionContextMenuStrip"; - this.CollectionContextMenuStrip.Size = new System.Drawing.Size(181, 246); + this.CollectionContextMenuStrip.Size = new System.Drawing.Size(182, 268); + // + // exportBeatmapSetsToolStripMenuItem + // + this.exportBeatmapSetsToolStripMenuItem.Name = "exportBeatmapSetsToolStripMenuItem"; + this.exportBeatmapSetsToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.exportBeatmapSetsToolStripMenuItem.Tag = "Export"; + this.exportBeatmapSetsToolStripMenuItem.Text = "Export beatmap sets"; + this.exportBeatmapSetsToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); // // CollectionListingView // @@ -273,5 +284,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem differenceMenuItem; private System.Windows.Forms.ToolStripMenuItem inverseToolStripMenuItem; private System.Windows.Forms.ContextMenuStrip CollectionContextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem exportBeatmapSetsToolStripMenuItem; } }