Skip to content

Commit

Permalink
Add beatmap menu option for copying beatmap links
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed May 8, 2017
1 parent 0973e73 commit 21ed09a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
24 changes: 12 additions & 12 deletions App/BeatmapListingActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using System.Collections.Generic;
using System.Diagnostics;
using App.Interfaces;
using App.Misc;
using CollectionManager.DataTypes;
using CollectionManager.Modules.CollectionsManager;
using CollectionManager.Modules.FileIO;
using CollectionManagerExtensionsDll.Enums;
using CollectionManagerExtensionsDll.Modules.CollectionListGenerator;
using CollectionManagerExtensionsDll.Modules.CollectionListGenerator.ListTypes;
using CollectionManagerExtensionsDll.Utils;
using Common;
using GuiComponents.Interfaces;
Expand All @@ -21,6 +23,7 @@ public class BeatmapListingActionsHandler
private readonly OsuFileIo _osuFileIo;
private readonly ListGenerator _listGenerator = new ListGenerator();
private readonly Dictionary<BeatmapListingAction, Action<object>> _beatmapOperationHandlers;
private readonly UserListGenerator UserUrlListGenerator = new UserListGenerator() { collectionBodyFormat = "{MapLink}" + UserListGenerator.NewLine };
public BeatmapListingActionsHandler(ICollectionEditor collectionEditor, IUserDialogs userDialogs, ILoginFormView loginForm, OsuFileIo osuFileIo)
{
_collectionEditor = collectionEditor;
Expand All @@ -31,6 +34,7 @@ public BeatmapListingActionsHandler(ICollectionEditor collectionEditor, IUserDia
_beatmapOperationHandlers = new Dictionary<BeatmapListingAction, Action<object>>
{
{BeatmapListingAction.CopyBeatmapsAsText, CopyBeatmapsAsText },
{BeatmapListingAction.CopyBeatmapsAsUrls, CopyBeatmapsAsUrls },
{BeatmapListingAction.DeleteBeatmapsFromCollection, DeleteBeatmapsFromCollection },
{BeatmapListingAction.DownloadBeatmapsManaged, DownloadBeatmapsManaged },
{BeatmapListingAction.DownloadBeatmaps, DownloadBeatmaps },
Expand Down Expand Up @@ -68,20 +72,16 @@ private void DeleteBeatmapsFromCollection(object sender)
_collectionEditor.EditCollection(CollectionEditArgs.RemoveBeatmaps(model.CurrentCollection.Name, model.SelectedBeatmaps));
}

private void CopyBeatmapsAsUrls(object sender)
{
var dummyCollection = ((IBeatmapListingModel)sender).AddSelectedBeatmapsToCollection(new Collection(_osuFileIo.LoadedMaps));
Helpers.SetClipboardText(_listGenerator.GetAllMapsList(new Collections() { dummyCollection }, UserUrlListGenerator));
}

private void CopyBeatmapsAsText(object sender)
{
var model = (IBeatmapListingModel)sender;
var dummyCollection = new Collection(_osuFileIo.LoadedMaps);
foreach (var beatmap in model.SelectedBeatmaps)
{
dummyCollection.AddBeatmap(beatmap);
}
var text = _listGenerator.GetAllMapsList(new Collections() { dummyCollection },CollectionListSaveType.BeatmapList);
try
{
System.Windows.Forms.Clipboard.SetText(text);
}
catch { }
var dummyCollection = ((IBeatmapListingModel)sender).AddSelectedBeatmapsToCollection(new Collection(_osuFileIo.LoadedMaps));
Helpers.SetClipboardText(_listGenerator.GetAllMapsList(new Collections() { dummyCollection }, CollectionListSaveType.BeatmapList));
}

private void DownloadBeatmaps(object sender)
Expand Down
19 changes: 19 additions & 0 deletions App/Misc/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using App.Interfaces;
using App.Models;
using App.Presenters.Forms;
using CollectionManager.DataTypes;
using CollectionManagerExtensionsDll.Modules.DownloadManager.API;
using GuiComponents.Interfaces;

Expand Down Expand Up @@ -58,5 +59,23 @@ public static string GetCollectionName(this ICollectionAddRenameForm form, Func<

return model.NewCollectionNameIsValid ? model.NewCollectionName : "";
}

public static Collection AddSelectedBeatmapsToCollection(this IBeatmapListingModel model,Collection collection)
{
foreach (var beatmap in model.SelectedBeatmaps)
{
collection.AddBeatmap(beatmap);
}
return collection;
}

public static void SetClipboardText(string text)
{
try
{
System.Windows.Forms.Clipboard.SetText(text);
}
catch { }
}
}
}
3 changes: 2 additions & 1 deletion Common/BeatmapListingAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum BeatmapListingAction
DownloadBeatmaps, // Open download links using (?)default browser
DownloadBeatmapsManaged, // Download selected beatmaps using internal downloader
OpenBeatmapPages, // Open beatmap pages in (?)default browser
CopyBeatmapsAsText //Copy text representation of selected beatmaps
CopyBeatmapsAsText, //Copy text representation of selected beatmaps
CopyBeatmapsAsUrls //Copy map links of selected beatmaps
}
}
14 changes: 12 additions & 2 deletions GuiComponents/Controls/BeatmapListingView.Designer.cs

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

2 changes: 2 additions & 0 deletions GuiComponents/Controls/BeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ private void MenuStripClick(object sender, EventArgs e)
BeatmapOperation?.Invoke(this, Common.BeatmapListingAction.OpenBeatmapPages);
else if (sender == copyAsTextMenuStrip)
BeatmapOperation?.Invoke(this, Common.BeatmapListingAction.CopyBeatmapsAsText);
else if (sender == copyUrlMenuStrip)
BeatmapOperation?.Invoke(this, Common.BeatmapListingAction.CopyBeatmapsAsUrls);
}
}

Expand Down

0 comments on commit 21ed09a

Please sign in to comment.