Skip to content

Commit

Permalink
Added option to sort the prefixes in the custom control by a position…
Browse files Browse the repository at this point in the history
… field.
  • Loading branch information
HerrKnarz committed Oct 5, 2024
1 parent 0bdfe17 commit 8280eb0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Generic/MetadataUtilities/Models/PrefixItemList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PrefixItemList : ObservableObject
private string _icon;
private MetadataObjects _items;
private string _name;
private int _position;
private string _prefix;

public PrefixItemList(MetadataUtilities plugin, Game game, FieldType fieldType, string icon)
Expand All @@ -33,6 +34,7 @@ public PrefixItemList(MetadataUtilities plugin, Game game, PrefixItemList itemLi
_icon = itemList.Icon;
_name = itemList.Name;
_prefix = itemList.Prefix;
_position = itemList.Position;

PrepareData(plugin, game);
}
Expand Down Expand Up @@ -65,6 +67,12 @@ public string Name
set => SetValue(ref _name, value);
}

public int Position
{
get => _position;
set => SetValue(ref _position, value);
}

public string Prefix
{
get => _prefix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ public void RefreshData()

ItemLists.Clear();

foreach (var itemList in _plugin.Settings.Settings.PrefixItemTypes.Where(x => x.FieldType == _fieldType && x.Name != default))
foreach (var itemList in _plugin.Settings.Settings.PrefixItemTypes.Where(x =>
x.FieldType == _fieldType && x.Name != default))
{
ItemLists.Add(new PrefixItemList(_plugin, _game, itemList));
}

ItemLists.Add(new PrefixItemList(_plugin, _game, _fieldType, _defaultIcon));

ItemLists = ItemLists.Where(x => x.Items.Count > 0).ToObservable();
ItemLists = ItemLists.Where(x => x.Items.Count > 0).OrderBy(x => x.Position).ThenBy(x => x.Name)
.ToObservable();
}
}
}
4 changes: 4 additions & 0 deletions Generic/MetadataUtilities/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ public Settings Settings
}
}

public RelayCommand SortPrefixesCommand => new RelayCommand(() =>
Settings.PrefixItemTypes =
Settings.PrefixItemTypes.OrderBy(x => x.Position).ThenBy(x => x.Name).ToObservable());

public CollectionViewSource SourceObjectsViewSource
{
get => _sourceObjectsViewSource;
Expand Down
10 changes: 10 additions & 0 deletions Generic/MetadataUtilities/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@
<Button Content="&#xec53;" DockPanel.Dock="Left" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCRemoveTitle}" Margin="10,0,0,0"
Command="{Binding RemovePrefixCommand}"
CommandParameter="{Binding SelectedItems, ElementName=LvPrefixes}" />
<Button Content="&#xEFEE;" DockPanel.Dock="Left" FontFamily="{DynamicResource FontIcoFont}"
Command="{Binding SortPrefixesCommand}" />
<Button Content="&#xEFCA;" DockPanel.Dock="Right" FontFamily="{DynamicResource FontIcoFont}" ToolTip="{DynamicResource LOCMenuHelpTitle}"
Command="{Binding HelpPrefixesCommand}" Margin="10,0,0,0" />
</DockPanel>
Expand All @@ -316,6 +318,14 @@
VerticalContentAlignment="Stretch" VerticalAlignment="Stretch">
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="{DynamicResource LOCMetadataUtilitiesSettingsPosition}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Position, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" HorizontalContentAlignment="Right" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="200" Header="{DynamicResource LOCMetadataUtilitiesPrefixLabel}">
<GridViewColumn.CellTemplate>
<DataTemplate>
Expand Down

0 comments on commit 8280eb0

Please sign in to comment.