Skip to content

Commit

Permalink
Add: Remember collection collumns between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Jul 31, 2024
1 parent 6b1f9ec commit b1e57c0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
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
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
32 changes: 28 additions & 4 deletions GuiComponents/Controls/CollectionListingView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public Collections HighlightedCollections
public event EventHandler SelectedCollectionsChanged;
public event GuiHelpers.CollectionBeatmapsEventArgs BeatmapsDropped;
public event EventHandler<StringEventArgs> RightClick;
public event GuiHelpers.ColumnsToggledEventArgs ColumnsToggled;

private CollectionRenderer _collectionRenderer = new CollectionRenderer();
private RearrangingDropSink _dropsink = new RearrangingDropSink();
Expand All @@ -84,6 +85,16 @@ private void Bind()
OnSelectedCollectionsChanged();
};

ListViewCollections.ColumnWidthChanged += OnColumnReordered;
}

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

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

private void init()
Expand Down Expand Up @@ -176,6 +187,16 @@ public void SetFilter(IModelFilter filter)
ListViewCollections.AdditionalFilter = filter;
}

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

ListViewCollections.RebuildColumns();
}

public void FilteringStarted()
{
ListViewCollections.BeginUpdate();
Expand Down Expand Up @@ -208,8 +229,8 @@ private void ListViewCollections_ModelDropped(object sender, ModelDropEventArgs
foreach (var collection in e.SourceModels)
collections.Add((Collection)collection);

var sortOrder = ListViewCollections.LastSortOrder == SortOrder.Ascending
? CollectionManager.Enums.SortOrder.Ascending
var sortOrder = ListViewCollections.LastSortOrder == SortOrder.Ascending
? CollectionManager.Enums.SortOrder.Ascending
: CollectionManager.Enums.SortOrder.Descending;
OnCollectionReorder?.Invoke(this, collections, targetCollection, e.DropTargetLocation == DropTargetLocation.AboveItem, ListViewCollections.LastSortColumn.AspectName, sortOrder);

Expand All @@ -219,7 +240,8 @@ private void ListViewCollections_ModelDropped(object sender, ModelDropEventArgs
return;
}

if (targetCollection == null) return;
if (targetCollection == null)
return;
var beatmaps = new Beatmaps();
foreach (var b in e.SourceModels)
{
Expand Down Expand Up @@ -249,7 +271,8 @@ private void MenuStripClick(object sender, EventArgs e)
private void PasteCollectionFromClipboard()
{
var data = Clipboard.GetDataObject();
if (data == null) return;
if (data == null)
return;
DropFile(data);
return;
}
Expand Down Expand Up @@ -303,5 +326,6 @@ private void ListViewCollections_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = e.SuppressKeyPress = true;
}

}
}

0 comments on commit b1e57c0

Please sign in to comment.