Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Settings for column visibility #82

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions App/Initalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using CollectionManager.DataTypes;
using CollectionManager.Modules.CollectionsManager;
using CollectionManager.Modules.FileIO;
using CollectionManagerApp.Properties;
using CollectionManagerExtensionsDll.Modules.API.osustats;
using GuiComponents.Interfaces;

Expand Down
3 changes: 2 additions & 1 deletion App/OsuDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Common.Interfaces;
using Newtonsoft.Json;
using System.Reflection;
using CollectionManagerApp.Properties;

namespace App
{
Expand Down Expand Up @@ -52,7 +53,7 @@ public bool AskUserForSaveDirectoryAndLogin(IUserDialogs userDialogs, ILoginForm
{
if (IsLoggedIn)
return true;

var downloaderSettings = JsonConvert.DeserializeObject<DownloaderSettings>(Settings.Default.DownloadManager_DownloaderSettings);
if (downloaderSettings.LoginData == null)
downloaderSettings.LoginData = new LoginData();
Expand Down
26 changes: 21 additions & 5 deletions App/Presenters/Controls/BeatmapListingPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using App.Interfaces;
using App.Misc;
using GuiComponents.Interfaces;
using CollectionManagerApp.Properties;
using Newtonsoft.Json;

namespace App.Presenters.Controls
{
public class BeatmapListingPresenter: IBeatmapListingPresenter
public class BeatmapListingPresenter : IBeatmapListingPresenter
{
readonly IBeatmapListingView _view;
readonly IBeatmapListingModel _model;
Expand All @@ -28,21 +30,35 @@ public Beatmaps Beatmaps
public BeatmapListingPresenter(IBeatmapListingView view, IBeatmapListingModel model)
{
_view = view;
_view.SearchTextChanged+=ViewOnSearchTextChanged;
_view.SearchTextChanged += ViewOnSearchTextChanged;
_view.SelectedBeatmapChanged += (s, a) => _model.SelectedBeatmap = _view.SelectedBeatmap;
_view.SelectedBeatmapsChanged += (s, a) => _model.SelectedBeatmaps = _view.SelectedBeatmaps;

_view.BeatmapsDropped += (s, a) => _model.EmitBeatmapsDropped(s, a);
_view.BeatmapOperation += (s, a) => _model.EmitBeatmapOperation(a);
_view.ColumnsToggled += (s, a) => OnColumnsToggled(a);

_model = model;
_model.BeatmapsChanged += _model_BeatmapsChanged;
_model.FilteringStarted+=ModelOnFilteringStarted;
_model.FilteringStarted += ModelOnFilteringStarted;
_model.FilteringFinished += _model_FilteringFinished;
_view.SetFilter(_model.GetFilter());

var visibleColumns = JsonConvert.DeserializeObject<string[]>(Settings.Default.BeatmapColumns);

if (visibleColumns.Length > 0)
{
_view.SetVisibleColumns(visibleColumns);
}

Beatmaps = _model.GetBeatmaps();
}


private void OnColumnsToggled(string[] visibleColumnAspectNames)
{
Settings.Default.BeatmapColumns = JsonConvert.SerializeObject(visibleColumnAspectNames);
}

private void _model_FilteringFinished(object sender, EventArgs e)
{
if (_model.GetFilter() is BeatmapListFilter filter)
Expand Down
1 change: 1 addition & 0 deletions App/Presenters/Controls/CollectionListingPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using App.Properties;
using CollectionManager.Enums;
using SortOrder = CollectionManager.Enums.SortOrder;
using CollectionManagerApp.Properties;

namespace App.Presenters.Controls
{
Expand Down
16 changes: 15 additions & 1 deletion App/Presenters/Controls/CombinedListingPresenter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using App.Interfaces;
using CollectionManager.DataTypes;
using CollectionManagerExtensionsDll.Modules.API.osustats;
using CollectionManagerApp.Properties;
using GuiComponents.Interfaces;
using Newtonsoft.Json;

namespace App.Presenters.Controls
{
Expand Down Expand Up @@ -34,6 +35,19 @@ public CombinedListingPresenter(ICombinedListingView view, ICollectionListingMod
BeatmapListingModel.SelectedBeatmapsChanged += BeatmapListingModelOnSelectedBeatmapsChanged;
_collectionsView.SelectedCollectionChanged += CollectionsViewOnSelectedCollectionChanged;
_collectionsView.SelectedCollectionsChanged += CollectionsViewOnSelectedCollectionsChanged;
_collectionsView.ColumnsToggled += OnColumnsToggled;

var visibleColumns = JsonConvert.DeserializeObject<string[]>(Settings.Default.CollectionColumns);

if (visibleColumns.Length > 0)
{
_collectionsView.SetVisibleColumns(visibleColumns);
}
}

private void OnColumnsToggled(object sender, string[] visibleCollumnAspectNames)
{
Settings.Default.CollectionColumns = JsonConvert.SerializeObject(visibleCollumnAspectNames);
}

private void BeatmapListingModelOnSelectedBeatmapsChanged(object sender, EventArgs e)
Expand Down
1 change: 1 addition & 0 deletions App/Presenters/Controls/MusicControlPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using MusicPlayer;
using Timer = System.Timers.Timer;
using System.Runtime.InteropServices;
using CollectionManagerApp.Properties;

namespace App.Presenters.Controls
{
Expand Down
2 changes: 1 addition & 1 deletion App/Presenters/Controls/StartupPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using App.Models;
using App.Properties;
using CollectionManager.Modules.CollectionsManager;
using CollectionManagerApp.Properties;
using CollectionManagerExtensionsDll.Utils;
using Common;
using GuiComponents.Interfaces;
Expand Down Expand Up @@ -216,7 +217,6 @@ private void LoadDatabase(CancellationToken cancellationToken)

private void SaveSettings()
{

Settings.Default.StartupSettings = JsonConvert.SerializeObject(_startupSettings);
Settings.Default.Save();
}
Expand Down
28 changes: 26 additions & 2 deletions App/Properties/Settings.Designer.cs

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

8 changes: 7 additions & 1 deletion App/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="App.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CollectionManagerApp.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="StartupSettings" Type="System.String" Scope="User">
Expand All @@ -23,5 +23,11 @@
<Setting Name="DontAskAboutReorderingCollections" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="CollectionColumns" Type="System.String" Scope="User">
<Value Profile="(Default)">[]</Value>
</Setting>
<Setting Name="BeatmapColumns" Type="System.String" Scope="User">
<Value Profile="(Default)">[]</Value>
</Setting>
</Settings>
</SettingsFile>
28 changes: 0 additions & 28 deletions App/Settings.cs

This file was deleted.

1 change: 1 addition & 0 deletions App/SidePanelActionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using System.Security.Cryptography;
using GuiComponents;
using System.Windows.Markup;
using CollectionManagerApp.Properties;

namespace App
{
Expand Down
30 changes: 30 additions & 0 deletions App/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="CollectionManagerApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="App.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup>
<userSettings>
<CollectionManagerApp.Properties.Settings>
<setting name="StartupSettings" serializeAs="String">
<value>{}</value>
</setting>
<setting name="Audio_autoPlay" serializeAs="String">
<value>False</value>
</setting>
<setting name="Audio_playerMode" serializeAs="String">
<value>False</value>
</setting>
<setting name="Audio_volume" serializeAs="String">
<value>0.25</value>
</setting>
<setting name="Osustats_apiKey" serializeAs="String">
<value />
</setting>
<setting name="DownloadManager_DownloaderSettings" serializeAs="String">
<value>{}</value>
</setting>
<setting name="DontAskAboutReorderingCollections" serializeAs="String">
<value>False</value>
</setting>
<setting name="CollectionColumns" serializeAs="String">
<value>[]</value>
</setting>
<setting name="BeatmapColumns" serializeAs="String">
<value>[]</value>
</setting>
</CollectionManagerApp.Properties.Settings>
<App.Properties.Settings>
<setting name="StartupSettings" serializeAs="String">
<value>{}</value>
Expand Down
1 change: 1 addition & 0 deletions Common/GuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public static class GuiHelpers
public delegate void LoadFileArgs(object sender, string[] filePaths);
public delegate void StartupCollectionEventArgs(object sender, StartupCollectionAction args);
public delegate void StartupDatabaseEventArgs(object sender, StartupDatabaseAction args);
public delegate void ColumnsToggledEventArgs(object sender, string[] visibleCollumnAspectNames);
}
}
2 changes: 2 additions & 0 deletions Common/Interfaces/Controls/IBeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public interface IBeatmapListingView
event EventHandler SelectedBeatmapsChanged;
event GuiHelpers.BeatmapListingActionArgs BeatmapOperation;
event GuiHelpers.BeatmapsEventArgs BeatmapsDropped;
event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

void SetCurrentPlayMode(PlayMode playMode);
void SetCurrentMods(Mods mods);
void SetBeatmaps(IEnumerable beatmaps);
void SetVisibleColumns(string[] visibleColumnsAspectNames);
void SetFilter(IModelFilter filter);
void FilteringStarted();
void FilteringFinished();
Expand Down
2 changes: 2 additions & 0 deletions Common/Interfaces/Controls/ICollectionListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public interface ICollectionListingView
event EventHandler SelectedCollectionsChanged;
event GuiHelpers.CollectionBeatmapsEventArgs BeatmapsDropped;
event EventHandler<StringEventArgs> RightClick;
event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

void SetFilter(IModelFilter filter);
void SetVisibleColumns(string[] visibleColumnsAspectNames);
void FilteringStarted();
void FilteringFinished();
//void OnCollectionEditing(CollectionEditArgs e);
Expand Down
30 changes: 28 additions & 2 deletions GuiComponents/Controls/BeatmapListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Common;
using GuiComponents.Interfaces;
using Gui.Misc;
using System.Linq;

namespace GuiComponents.Controls
{
Expand All @@ -22,6 +23,7 @@ public partial class BeatmapListingView : UserControl, IBeatmapListingView

public event GuiHelpers.BeatmapListingActionArgs BeatmapOperation;
public event GuiHelpers.BeatmapsEventArgs BeatmapsDropped;
public event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

public string SearchText => textBox_beatmapSearch.Text;
public string ResultText { get; set; }
Expand Down Expand Up @@ -54,6 +56,16 @@ public void SetBeatmaps(IEnumerable beatmaps)
UpdateResultsCount();
}

public void SetVisibleColumns(string[] visibleColumnsAspectNames)
{
foreach (var column in ListViewBeatmaps.AllColumns)
{
column.IsVisible = visibleColumnsAspectNames.Contains(column.AspectName);
}

ListViewBeatmaps.RebuildColumns();
}

public Beatmap SelectedBeatmap
{
get => (Beatmap)ListViewBeatmaps.SelectedObject;
Expand Down Expand Up @@ -99,7 +111,18 @@ private void Bind()
{
args.MenuStrip = BeatmapsContextMenuStrip;
};
ListViewBeatmaps.ColumnWidthChanged += OnColumnReordered;
}

private void OnColumnReordered(object sender, ColumnWidthChangedEventArgs e)
{
var visibleColumnAspectNames = ListViewBeatmaps.AllColumns
.Where(column => column.IsVisible)
.Select(column => column.AspectName);

ColumnsToggled?.Invoke(this, visibleColumnAspectNames.ToArray());
}

private void UpdateResultsCount()
{
int count = 0;
Expand Down Expand Up @@ -174,7 +197,8 @@ private void InitListView()
};
LastPlayed.AspectToStringConverter = delegate (object cellValue)
{
if (cellValue == null) return string.Empty;
if (cellValue == null)
return string.Empty;
var val = (DateTimeOffset)cellValue;
return val > d ? $"{val}" : "Never";
};
Expand All @@ -188,7 +212,8 @@ private void InitListView()
};
column_bpm.AspectToStringConverter = delegate (object cellValue)
{
if (cellValue == null) return string.Empty;
if (cellValue == null)
return string.Empty;
return $"{cellValue:0.##}";
};

Expand Down Expand Up @@ -312,6 +337,7 @@ private void ListViewBeatmaps_KeyUp(object sender, KeyEventArgs e)
MenuStripClick(DeleteMapMenuStrip, e);
}
}

}


Expand Down
Loading