From 3cc0e06599812cd129dc9d93706eb6b87520c50f Mon Sep 17 00:00:00 2001 From: kuuube Date: Tue, 15 Mar 2022 21:36:54 -0400 Subject: [PATCH] Add: Difference of collections --- App/CollectionEditor.cs | 2 +- .../Controls/CollectionListingPresenter.cs | 5 ++ CollectionManagerDll/Enums/CollectionEdit.cs | 1 + .../CollectionsManager/CollectionEditArgs.cs | 10 +++ .../CollectionsManager/CollectionsManager.cs | 20 +++++ .../CollectionListingView.Designer.cs | 78 +++++++++++-------- README.md | 4 + 7 files changed, 86 insertions(+), 34 deletions(-) diff --git a/App/CollectionEditor.cs b/App/CollectionEditor.cs index faea4df..18c9689 100644 --- a/App/CollectionEditor.cs +++ b/App/CollectionEditor.cs @@ -48,7 +48,7 @@ public void EditCollection(CollectionEditArgs e) break; } } - else if (e.Action == CollectionEdit.Intersect) + else if (e.Action == CollectionEdit.Intersect || e.Action == CollectionEdit.Difference) { if (e.Collections.Count < 2) return; diff --git a/App/Presenters/Controls/CollectionListingPresenter.cs b/App/Presenters/Controls/CollectionListingPresenter.cs index 08b6e9e..d8fb831 100644 --- a/App/Presenters/Controls/CollectionListingPresenter.cs +++ b/App/Presenters/Controls/CollectionListingPresenter.cs @@ -85,6 +85,11 @@ private void _view_RightClick(object sender, Gui.Misc.StringEventArgs e) return; args = CollectionEditArgs.InverseCollections(selectedCollections, selectedCollections[0].Name); break; + case "Difference": + if (selectedCollections == null) + return; + args = CollectionEditArgs.DifferenceCollections(selectedCollections, selectedCollections[0].Name); + break; case "Create": args = CollectionEditArgs.AddCollections(null); break; diff --git a/CollectionManagerDll/Enums/CollectionEdit.cs b/CollectionManagerDll/Enums/CollectionEdit.cs index 42379b0..192249e 100644 --- a/CollectionManagerDll/Enums/CollectionEdit.cs +++ b/CollectionManagerDll/Enums/CollectionEdit.cs @@ -13,5 +13,6 @@ public enum CollectionEdit Duplicate=8, Intersect=9, Inverse=10, + Difference=11, } } \ No newline at end of file diff --git a/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs b/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs index b7b510e..1b94db5 100644 --- a/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs +++ b/CollectionManagerDll/Modules/CollectionsManager/CollectionEditArgs.cs @@ -88,6 +88,16 @@ public static CollectionEditArgs InverseCollections(Collections collections, str }; } #endregion + #region Difference Collections + public static CollectionEditArgs DifferenceCollections(Collections collections, string newName) + { + return new CollectionEditArgs(CollectionEdit.Difference) + { + Collections = collections, + NewName = newName + }; + } + #endregion #region Clear Collections public static CollectionEditArgs ClearCollections() { diff --git a/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs b/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs index 80156a9..4419d9a 100644 --- a/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs +++ b/CollectionManagerDll/Modules/CollectionsManager/CollectionsManager.cs @@ -23,6 +23,7 @@ edit collection name merge x collections intersect x collections inverse map sum of x collections + difference x collections clear collections add beatmaps to collection remove beatmaps from collection @@ -121,6 +122,25 @@ private void EditCollection(CollectionEditArgs args, bool suspendRefresh = false EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); } + else if (action == CollectionEdit.Difference) + { + var targetCollection = args.Collections.Last(); + args.Collections.RemoveAt(args.Collections.Count - 1); + var mainCollection = args.Collections[0]; + args.Collections.RemoveAt(0); + var beatmaps = mainCollection.AllBeatmaps(); + foreach (var collection in args.Collections) + { + beatmaps = beatmaps.Except(collection.AllBeatmaps(), new CollectionBeatmapComparer()).Union(collection.AllBeatmaps().Except(beatmaps, new CollectionBeatmapComparer())); + } + + foreach (var beatmap in beatmaps) + { + targetCollection.AddBeatmap(beatmap); + } + + EditCollection(CollectionEditArgs.AddCollections(new Collections() { targetCollection }), true); + } else if (action == CollectionEdit.Clear) { LoadedCollections.Clear(); diff --git a/GuiComponents/Controls/CollectionListingView.Designer.cs b/GuiComponents/Controls/CollectionListingView.Designer.cs index 35d9e9a..7b06654 100644 --- a/GuiComponents/Controls/CollectionListingView.Designer.cs +++ b/GuiComponents/Controls/CollectionListingView.Designer.cs @@ -36,7 +36,6 @@ private void InitializeComponent() this.Total = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.olvColumn2 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.textBox_collectionNameSearch = new System.Windows.Forms.TextBox(); - this.CollectionContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.CreateMenuStrip = new System.Windows.Forms.ToolStripMenuItem(); this.renameCollectionMenuStrip = new System.Windows.Forms.ToolStripMenuItem(); this.deleteCollectionMenuStrip = new System.Windows.Forms.ToolStripMenuItem(); @@ -45,7 +44,9 @@ private void InitializeComponent() this.DuplicateMenuStrip = new System.Windows.Forms.ToolStripMenuItem(); this.mergeWithMenuStrip = new System.Windows.Forms.ToolStripMenuItem(); this.intersectMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.differenceMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.inverseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.CollectionContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ListViewCollections)).BeginInit(); this.CollectionContextMenuStrip.SuspendLayout(); @@ -126,25 +127,10 @@ private void InitializeComponent() this.textBox_collectionNameSearch.Size = new System.Drawing.Size(463, 20); this.textBox_collectionNameSearch.TabIndex = 1; // - // CollectionContextMenuStrip - // - this.CollectionContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.CreateMenuStrip, - this.renameCollectionMenuStrip, - this.deleteCollectionMenuStrip, - this.copyToolStripMenuItem, - this.pasteToolStripMenuItem, - this.DuplicateMenuStrip, - this.mergeWithMenuStrip, - this.intersectMenuItem, - this.inverseToolStripMenuItem}); - this.CollectionContextMenuStrip.Name = "CollectionContextMenuStrip"; - this.CollectionContextMenuStrip.Size = new System.Drawing.Size(155, 202); - // // CreateMenuStrip // this.CreateMenuStrip.Name = "CreateMenuStrip"; - this.CreateMenuStrip.Size = new System.Drawing.Size(154, 22); + this.CreateMenuStrip.Size = new System.Drawing.Size(180, 22); this.CreateMenuStrip.Tag = "Create"; this.CreateMenuStrip.Text = "Create"; this.CreateMenuStrip.ToolTipText = "Create new collection"; @@ -154,7 +140,7 @@ private void InitializeComponent() // this.renameCollectionMenuStrip.Name = "renameCollectionMenuStrip"; this.renameCollectionMenuStrip.ShortcutKeyDisplayString = "F2"; - this.renameCollectionMenuStrip.Size = new System.Drawing.Size(154, 22); + this.renameCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); this.renameCollectionMenuStrip.Tag = "Rename"; this.renameCollectionMenuStrip.Text = "Rename"; this.renameCollectionMenuStrip.ToolTipText = "Rename currently selected collection"; @@ -164,7 +150,7 @@ private void InitializeComponent() // this.deleteCollectionMenuStrip.Name = "deleteCollectionMenuStrip"; this.deleteCollectionMenuStrip.ShortcutKeyDisplayString = "Del"; - this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(154, 22); + this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); this.deleteCollectionMenuStrip.Tag = "Delete"; this.deleteCollectionMenuStrip.Text = "Delete"; this.deleteCollectionMenuStrip.ToolTipText = "Delete currently selected collections"; @@ -174,7 +160,7 @@ private void InitializeComponent() // this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; this.copyToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+C"; - this.copyToolStripMenuItem.Size = new System.Drawing.Size(154, 22); + this.copyToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.copyToolStripMenuItem.Tag = "Copy"; this.copyToolStripMenuItem.Text = "Copy"; this.copyToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); @@ -183,7 +169,7 @@ private void InitializeComponent() // this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; this.pasteToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+V"; - this.pasteToolStripMenuItem.Size = new System.Drawing.Size(154, 22); + this.pasteToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.pasteToolStripMenuItem.Tag = "Paste"; this.pasteToolStripMenuItem.Text = "Paste"; this.pasteToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); @@ -191,7 +177,7 @@ private void InitializeComponent() // DuplicateMenuStrip // this.DuplicateMenuStrip.Name = "DuplicateMenuStrip"; - this.DuplicateMenuStrip.Size = new System.Drawing.Size(154, 22); + this.DuplicateMenuStrip.Size = new System.Drawing.Size(180, 22); this.DuplicateMenuStrip.Tag = "Duplicate"; this.DuplicateMenuStrip.Text = "Duplicate"; this.DuplicateMenuStrip.ToolTipText = "Create a copy of currently selected collection"; @@ -200,7 +186,7 @@ private void InitializeComponent() // mergeWithMenuStrip // this.mergeWithMenuStrip.Name = "mergeWithMenuStrip"; - this.mergeWithMenuStrip.Size = new System.Drawing.Size(154, 22); + this.mergeWithMenuStrip.Size = new System.Drawing.Size(180, 22); this.mergeWithMenuStrip.Tag = "Merge"; this.mergeWithMenuStrip.Text = "Merge selected"; this.mergeWithMenuStrip.ToolTipText = "Merge beatmaps from selected collections into new collection"; @@ -209,23 +195,48 @@ private void InitializeComponent() // intersectMenuItem // this.intersectMenuItem.Name = "intersectMenuItem"; - this.intersectMenuItem.Size = new System.Drawing.Size(154, 22); + this.intersectMenuItem.Size = new System.Drawing.Size(180, 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 + // + this.differenceMenuItem.Name = "differenceToolStripMenuItem"; + this.differenceMenuItem.Size = new System.Drawing.Size(180, 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.Click += new System.EventHandler(this.MenuStripClick); + // // inverseToolStripMenuItem // this.inverseToolStripMenuItem.Name = "inverseToolStripMenuItem"; - this.inverseToolStripMenuItem.Size = new System.Drawing.Size(154, 22); + this.inverseToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.inverseToolStripMenuItem.Tag = "Inverse"; this.inverseToolStripMenuItem.Text = "Inverse"; - this.inverseToolStripMenuItem.ToolTipText = "Create new collection that contains every beatmap in the user\'s library that isn\'" + - "t in selected collections"; + this.inverseToolStripMenuItem.ToolTipText = "Create new collection that contains every beatmap not present in all selected col" + + "lections"; this.inverseToolStripMenuItem.Click += new System.EventHandler(this.MenuStripClick); // + // CollectionContextMenuStrip + // + this.CollectionContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.CreateMenuStrip, + this.renameCollectionMenuStrip, + this.deleteCollectionMenuStrip, + this.copyToolStripMenuItem, + this.pasteToolStripMenuItem, + this.DuplicateMenuStrip, + this.mergeWithMenuStrip, + this.intersectMenuItem, + this.differenceMenuItem, + this.inverseToolStripMenuItem}); + this.CollectionContextMenuStrip.Name = "CollectionContextMenuStrip"; + this.CollectionContextMenuStrip.Size = new System.Drawing.Size(181, 246); + // // CollectionListingView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -249,16 +260,17 @@ private void InitializeComponent() private BrightIdeasSoftware.OLVColumn olvColumn1; private BrightIdeasSoftware.OLVColumn olvColumn2; private System.Windows.Forms.TextBox textBox_collectionNameSearch; - private System.Windows.Forms.ContextMenuStrip CollectionContextMenuStrip; + private BrightIdeasSoftware.OLVColumn Total; + private System.Windows.Forms.ToolStripMenuItem CreateMenuStrip; private System.Windows.Forms.ToolStripMenuItem renameCollectionMenuStrip; private System.Windows.Forms.ToolStripMenuItem deleteCollectionMenuStrip; - private System.Windows.Forms.ToolStripMenuItem mergeWithMenuStrip; - private System.Windows.Forms.ToolStripMenuItem CreateMenuStrip; - private BrightIdeasSoftware.OLVColumn Total; + private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem pasteToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem DuplicateMenuStrip; + private System.Windows.Forms.ToolStripMenuItem mergeWithMenuStrip; private System.Windows.Forms.ToolStripMenuItem intersectMenuItem; + private System.Windows.Forms.ToolStripMenuItem differenceMenuItem; private System.Windows.Forms.ToolStripMenuItem inverseToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem pasteToolStripMenuItem; + private System.Windows.Forms.ContextMenuStrip CollectionContextMenuStrip; } } diff --git a/README.md b/README.md index 219ebc7..a6b4b13 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,10 @@ The following opinions are made available by right clicking in the left panel: The new collection is named using the selected collection closest to the top of the listing, with `_0` appended to its name. +- Difference: Differentiates all selected collections by making a new collection with only maps that are present in only one selected collection. + + The new collection is named using the selected collection closest to the top of the listing, with `_0` appended to its name. + - Inverse: Inverses all selected collections by making a new collection with only maps that are not present in any of the selected collections but are present in your osu! songs folder. The new collection is named using the selected collection closest to the top of the listing, with `_0` appended to its name.