Skip to content

Commit

Permalink
Add: Ability to drag&drop .db and .osdb files into CM window
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jun 3, 2019
1 parent 7e6a8b6 commit dbae0af
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
18 changes: 16 additions & 2 deletions App/SidePanelActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebCollection>)data;
Expand Down Expand Up @@ -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));
}
Expand Down
3 changes: 2 additions & 1 deletion Common/GuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
2 changes: 2 additions & 0 deletions Common/Interfaces/Controls/ICollectionListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace GuiComponents.Interfaces
{
public interface ICollectionListingView
{
event GuiHelpers.LoadFileArgs OnLoadFile;

string SearchText { get; }

Collections Collections { set; }
Expand Down
5 changes: 4 additions & 1 deletion Common/Interfaces/Forms/IMainFormView.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
13 changes: 7 additions & 6 deletions GuiComponents/Controls/CollectionListingView.Designer.cs

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

22 changes: 22 additions & 0 deletions GuiComponents/Controls/CollectionListingView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Linq;
using System.Windows.Forms;
using BrightIdeasSoftware;
using CollectionManager.DataTypes;
Expand All @@ -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); } }

Expand Down Expand Up @@ -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)
Expand Down
28 changes: 26 additions & 2 deletions GuiComponents/Forms/MainFormView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
 using System;
using System.Linq;
using System.Windows.Forms;
using Gui.Misc;
using GuiComponents.Interfaces;

namespace GuiComponents.Forms
Expand All @@ -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);
}
}
}
}
2 changes: 1 addition & 1 deletion InnoSetup/script.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dbae0af

Please sign in to comment.