diff --git a/App/SidePanelActionsHandler.cs b/App/SidePanelActionsHandler.cs index a7e5bba..04c7289 100644 --- a/App/SidePanelActionsHandler.cs +++ b/App/SidePanelActionsHandler.cs @@ -82,10 +82,24 @@ private void BindMainFormActions() }; _mainForm.SidePanelView.SidePanelOperation += SidePanelViewOnSidePanelOperation; + _mainForm.OnLoadFile += OnLoadFile; + _mainForm.CombinedListingView.CollectionListingView.OnLoadFile += OnLoadFile; _mainFormPresenter.InfoTextModel.UpdateTextClicked += FormUpdateTextClicked; _mainForm.Closing += FormOnClosing; } + private void OnLoadFile(object sender, string[] filePaths) + { + foreach (var filePath in filePaths) + { + var lowercaseFilepath = filePath.ToLowerInvariant(); + if (lowercaseFilepath.EndsWith(".osdb") || lowercaseFilepath.EndsWith(".db")) + { + LoadCollectionFile(sender, filePath); + } + } + } + private async void RemoveWebCollection(object sender, object data = null) { var collectionList = (IList)data; @@ -389,9 +403,9 @@ private void FormOnClosing(object sender, EventArgs eventArgs) } private void LoadCollectionFile(object sender, object data = null) { - var fileLocation = _userDialogs.SelectFile("", "Collection database (*.db/*.osdb)|*.db;*.osdb", + string fileLocation = data?.ToString() ?? _userDialogs.SelectFile("", "Collection database (*.db/*.osdb)|*.db;*.osdb", "collection.db"); - if (fileLocation == string.Empty) return; + if (string.IsNullOrEmpty(fileLocation)) return; var loadedCollections = _osuFileIo.CollectionLoader.LoadCollection(fileLocation); _collectionEditor.EditCollection(CollectionEditArgs.AddCollections(loadedCollections)); } diff --git a/Common/GuiHelpers.cs b/Common/GuiHelpers.cs index df856ed..1799ada 100644 --- a/Common/GuiHelpers.cs +++ b/Common/GuiHelpers.cs @@ -8,7 +8,8 @@ public static class GuiHelpers public delegate void BeatmapsEventArgs(object sender, Beatmaps args); public delegate void CollectionBeatmapsEventArgs(object sender, Beatmaps args, string collectionName); public delegate void BeatmapListingActionArgs(object sender, BeatmapListingAction args); - public delegate void SidePanelActionsHandlerArgs(object sender, MainSidePanelActions args, object data=null); + public delegate void SidePanelActionsHandlerArgs(object sender, MainSidePanelActions args, object data = null); + public delegate void LoadFileArgs(object sender, string[] filePaths); } } \ No newline at end of file diff --git a/Common/Interfaces/Controls/ICollectionListingView.cs b/Common/Interfaces/Controls/ICollectionListingView.cs index fac3cb7..a8f9016 100644 --- a/Common/Interfaces/Controls/ICollectionListingView.cs +++ b/Common/Interfaces/Controls/ICollectionListingView.cs @@ -8,6 +8,8 @@ namespace GuiComponents.Interfaces { public interface ICollectionListingView { + event GuiHelpers.LoadFileArgs OnLoadFile; + string SearchText { get; } Collections Collections { set; } diff --git a/Common/Interfaces/Forms/IMainFormView.cs b/Common/Interfaces/Forms/IMainFormView.cs index 27bd62f..babbb21 100644 --- a/Common/Interfaces/Forms/IMainFormView.cs +++ b/Common/Interfaces/Forms/IMainFormView.cs @@ -1,7 +1,10 @@ -namespace GuiComponents.Interfaces +using Gui.Misc; + +namespace GuiComponents.Interfaces { public interface IMainFormView :IForm { + event GuiHelpers.LoadFileArgs OnLoadFile; ICombinedListingView CombinedListingView { get; } ICombinedBeatmapPreviewView CombinedBeatmapPreviewView { get; } IMainSidePanelView SidePanelView { get; } diff --git a/GuiComponents/Controls/CollectionListingView.Designer.cs b/GuiComponents/Controls/CollectionListingView.Designer.cs index 21f1f49..b0ecbf5 100644 --- a/GuiComponents/Controls/CollectionListingView.Designer.cs +++ b/GuiComponents/Controls/CollectionListingView.Designer.cs @@ -72,6 +72,7 @@ private void InitializeComponent() this.ListViewCollections.AllColumns.Add(this.olvColumn1); this.ListViewCollections.AllColumns.Add(this.Total); this.ListViewCollections.AllColumns.Add(this.olvColumn2); + this.ListViewCollections.AllowDrop = true; this.ListViewCollections.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); @@ -127,12 +128,12 @@ private void InitializeComponent() this.CreateMenuStrip, this.DuplicateMenuStrip}); this.CollectionContextMenuStrip.Name = "CollectionContextMenuStrip"; - this.CollectionContextMenuStrip.Size = new System.Drawing.Size(181, 136); + this.CollectionContextMenuStrip.Size = new System.Drawing.Size(155, 114); // // renameCollectionMenuStrip // this.renameCollectionMenuStrip.Name = "renameCollectionMenuStrip"; - this.renameCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); + this.renameCollectionMenuStrip.Size = new System.Drawing.Size(154, 22); this.renameCollectionMenuStrip.Tag = "Rename"; this.renameCollectionMenuStrip.Text = "Rename"; this.renameCollectionMenuStrip.Click += new System.EventHandler(this.MenuStripClick); @@ -140,7 +141,7 @@ private void InitializeComponent() // deleteCollectionMenuStrip // this.deleteCollectionMenuStrip.Name = "deleteCollectionMenuStrip"; - this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(180, 22); + this.deleteCollectionMenuStrip.Size = new System.Drawing.Size(154, 22); this.deleteCollectionMenuStrip.Tag = "Delete"; this.deleteCollectionMenuStrip.Text = "Delete"; this.deleteCollectionMenuStrip.Click += new System.EventHandler(this.MenuStripClick); @@ -148,7 +149,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(154, 22); this.mergeWithMenuStrip.Tag = "Merge"; this.mergeWithMenuStrip.Text = "Merge selected"; this.mergeWithMenuStrip.Click += new System.EventHandler(this.MenuStripClick); @@ -156,7 +157,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(154, 22); this.CreateMenuStrip.Tag = "Create"; this.CreateMenuStrip.Text = "Create"; this.CreateMenuStrip.Click += new System.EventHandler(this.MenuStripClick); @@ -164,7 +165,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(154, 22); this.DuplicateMenuStrip.Tag = "Duplicate"; this.DuplicateMenuStrip.Text = "Duplicate"; this.DuplicateMenuStrip.Click += new System.EventHandler(this.MenuStripClick); diff --git a/GuiComponents/Controls/CollectionListingView.cs b/GuiComponents/Controls/CollectionListingView.cs index 8e50388..1d06be5 100644 --- a/GuiComponents/Controls/CollectionListingView.cs +++ b/GuiComponents/Controls/CollectionListingView.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Linq; using System.Windows.Forms; using BrightIdeasSoftware; using CollectionManager.DataTypes; @@ -11,6 +12,7 @@ namespace GuiComponents.Controls { public partial class CollectionListingView : UserControl, ICollectionListingView { + public event GuiHelpers.LoadFileArgs OnLoadFile; public string SearchText => textBox_collectionNameSearch.Text; public Collections Collections { set { ListViewCollections.SetObjects(value); } } @@ -70,6 +72,26 @@ private void init() ListViewCollections.CellRightClick += ListViewCollectionsOnCellRightClick; dropsink.ModelCanDrop+=DropsinkOnModelCanDrop; + dropsink.CanDrop+=DropsinkOnCanDrop; + dropsink.Dropped+=DropsinkOnDropped; + } + + private void DropsinkOnDropped(object sender, OlvDropEventArgs e) + { + if (e.DataObject is DataObject dataObject && dataObject.GetFormats().Any(f => f == "FileDrop")) + { + var files = (string[])dataObject.GetData(DataFormats.FileDrop); + OnLoadFile?.Invoke(this, files); + } + } + + private void DropsinkOnCanDrop(object sender, OlvDropEventArgs e) + { + if (e.DataObject is DataObject dataObject && dataObject.GetFormats().Any(f => f == "FileDrop")) + { + e.Effect = DragDropEffects.Copy; + e.Handled = true; + } } private void DropsinkOnModelCanDrop(object sender, ModelDropEventArgs e) diff --git a/GuiComponents/Forms/MainFormView.cs b/GuiComponents/Forms/MainFormView.cs index 8c37196..b978a7a 100644 --- a/GuiComponents/Forms/MainFormView.cs +++ b/GuiComponents/Forms/MainFormView.cs @@ -1,5 +1,6 @@ - using System; +using System.Linq; using System.Windows.Forms; +using Gui.Misc; using GuiComponents.Interfaces; namespace GuiComponents.Forms @@ -10,12 +11,35 @@ public MainFormView() { InitializeComponent(); splitContainer1.Paint += Helpers.SplitterPaint; + AllowDrop = true; + DragEnter += Form1_DragEnter; + DragDrop += Form1_DragDrop; } + public event GuiHelpers.LoadFileArgs OnLoadFile; public ICombinedListingView CombinedListingView => combinedListingView1; public ICombinedBeatmapPreviewView CombinedBeatmapPreviewView => combinedBeatmapPreviewView1; public IMainSidePanelView SidePanelView => mainSidePanelView1; public ICollectionTextView CollectionTextView => collectionTextView1; public IInfoTextView InfoTextView => infoTextView1; + + private void Form1_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Data.GetFormats().Any(f => f == "FileDrop")) + { + e.Effect = DragDropEffects.Copy; + } + } + + private void Form1_DragDrop(object sender, DragEventArgs e) + { + if (e.Data.GetFormats().All(f => f != "FileDrop")) + { + return; + } + + var files = (string[]) e.Data.GetData(DataFormats.FileDrop); + OnLoadFile?.Invoke(this, files); + } } -} +} \ No newline at end of file diff --git a/InnoSetup/script.iss b/InnoSetup/script.iss index b12c5c9..f178967 100644 --- a/InnoSetup/script.iss +++ b/InnoSetup/script.iss @@ -46,7 +46,7 @@ Name: "english"; MessagesFile: "compiler:Default.isl" [Tasks] Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked -Name: osdbAssociation; Description: "Associate "".osdb"" extension"; GroupDescription: File extensions: +Name: osdbAssociation; Description: "Associate "".osdb"" extension (Collection files)"; GroupDescription: File extensions: Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1