Skip to content

Commit

Permalink
Added multi row selection support
Browse files Browse the repository at this point in the history
  • Loading branch information
TekkaGB committed Sep 25, 2021
1 parent 8eca28c commit 806cda9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Unverum/UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@
EnableColumnVirtualization="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" AlternatingRowBackground="#2A2A2A"
dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" HeadersVisibility="Column"
SelectionMode="Single" RowBackground="#202020" Foreground="#f2f2f2" LoadingRow="ModGrid_LoadingRow" HorizontalScrollBarVisibility="Hidden"
HorizontalAlignment="Center" Background="#202020" Grid.Column="0" FontSize="12"
SelectionMode="Extended" RowBackground="#202020" Foreground="#f2f2f2" LoadingRow="ModGrid_LoadingRow" HorizontalScrollBarVisibility="Hidden"
HorizontalAlignment="Center" Background="#202020" Grid.Column="0" FontSize="12" PreviewKeyDown="ModGrid_PreviewKeyDown"
ContextMenuOpening="ModGrid_ContextMenuOpening" SelectionChanged="ModGrid_SelectionChanged">
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="#006ac1"/>
Expand Down
110 changes: 67 additions & 43 deletions Unverum/UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Security.Cryptography;
using Microsoft.Win32;
using xdelta3.net;
using System.Windows.Input;

namespace Unverum
{
Expand Down Expand Up @@ -505,24 +506,27 @@ private void ModGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)

private void DeleteItem_Click(object sender, RoutedEventArgs e)
{
Mod row = (Mod)ModGrid.SelectedItem;
if (row != null)
{
var dialogResult = MessageBox.Show($@"Are you sure you want to delete {row.name}?" + Environment.NewLine + "This cannot be undone.", $@"Deleting {row.name}: Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dialogResult == MessageBoxResult.Yes)
var selectedMods = ModGrid.SelectedItems;
var temp = new Mod[selectedMods.Count];
selectedMods.CopyTo(temp, 0);
foreach (var row in temp)
if (row != null)
{
try
{
Directory.Delete($@"{Global.assemblyLocation}{Global.s}Mods{Global.s}{Global.config.CurrentGame}{Global.s}{row.name}", true);
Global.logger.WriteLine($@"Deleting {row.name}.", LoggerType.Info);
ShowMetadata(null);
}
catch (Exception ex)
var dialogResult = MessageBox.Show($@"Are you sure you want to delete {row.name}?" + Environment.NewLine + "This cannot be undone.", $@"Deleting {row.name}: Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (dialogResult == MessageBoxResult.Yes)
{
Global.logger.WriteLine($@"Couldn't delete {row.name} ({ex.Message})", LoggerType.Error);
try
{
Directory.Delete($@"{Global.assemblyLocation}{Global.s}Mods{Global.s}{Global.config.CurrentGame}{Global.s}{row.name}", true);
Global.logger.WriteLine($@"Deleting {row.name}.", LoggerType.Info);
ShowMetadata(null);
}
catch (Exception ex)
{
Global.logger.WriteLine($@"Couldn't delete {row.name} ({ex.Message})", LoggerType.Error);
}
}
}
}
}

private async Task<bool> Build(string path)
Expand Down Expand Up @@ -583,43 +587,52 @@ private void Window_Closing(object sender, CancelEventArgs e)

private void OpenItem_Click(object sender, RoutedEventArgs e)
{
Mod row = (Mod)ModGrid.SelectedItem;
if (row != null)
{
var folderName = $@"{Global.assemblyLocation}{Global.s}Mods{Global.s}{Global.config.CurrentGame}{Global.s}{row.name}";
if (Directory.Exists(folderName))
var selectedMods = ModGrid.SelectedItems;
var temp = new Mod[selectedMods.Count];
selectedMods.CopyTo(temp, 0);
foreach (var row in temp)
if (row != null)
{
try
var folderName = $@"{Global.assemblyLocation}{Global.s}Mods{Global.s}{Global.config.CurrentGame}{Global.s}{row.name}";
if (Directory.Exists(folderName))
{
Process process = Process.Start("explorer.exe", folderName);
Global.logger.WriteLine($@"Opened {folderName}.", LoggerType.Info);
}
catch (Exception ex)
{
Global.logger.WriteLine($@"Couldn't open {folderName}. ({ex.Message})", LoggerType.Error);
try
{
Process process = Process.Start("explorer.exe", folderName);
Global.logger.WriteLine($@"Opened {folderName}.", LoggerType.Info);
}
catch (Exception ex)
{
Global.logger.WriteLine($@"Couldn't open {folderName}. ({ex.Message})", LoggerType.Error);
}
}
}
}
}
private void EditItem_Click(object sender, RoutedEventArgs e)
{
Mod row = (Mod)ModGrid.SelectedItem;
if (row != null)
{
EditWindow ew = new EditWindow(row);
ew.ShowDialog();
}
var selectedMods = ModGrid.SelectedItems;
var temp = new Mod[selectedMods.Count];
selectedMods.CopyTo(temp, 0);
foreach (var row in temp)
if (row != null)
{
EditWindow ew = new EditWindow(row);
ew.ShowDialog();
}
}
private void FetchItem_Click(object sender, RoutedEventArgs e)
{
Mod row = (Mod)ModGrid.SelectedItem;
if (row != null)
{
FetchWindow fw = new FetchWindow(row);
fw.ShowDialog();
if (fw.success)
ShowMetadata(row.name);
}
var selectedMods = ModGrid.SelectedItems;
var temp = new Mod[selectedMods.Count];
selectedMods.CopyTo(temp, 0);
foreach (var row in temp)
if (row != null)
{
FetchWindow fw = new FetchWindow(row);
fw.ShowDialog();
if (fw.success)
ShowMetadata(row.name);
}
}
private void Add_Enter(object sender, DragEventArgs e)
{
Expand Down Expand Up @@ -1682,9 +1695,9 @@ private void Search()
RefreshFilter();
}
}
private void SearchBar_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
private void SearchBar_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Enter)
if (e.Key == Key.Enter)
Search();
}
private static readonly List<string> FilterBoxList = new string[] { " Featured", " Recent", " Popular" }.ToList();
Expand All @@ -1694,5 +1707,16 @@ private void SearchButton_Click(object sender, RoutedEventArgs e)
{
Search();
}

private void ModGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space && ModGrid.CurrentColumn.Header.ToString() != "Enabled")
foreach (var item in ModGrid.SelectedItems)
{
var checkbox = ModGrid.Columns[0].GetCellContent(item) as CheckBox;
if (checkbox != null)
checkbox.IsChecked = !checkbox.IsChecked;
}
}
}
}
2 changes: 1 addition & 1 deletion Unverum/Unverum.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>Assets\unverum.ico</ApplicationIcon>
<AssemblyName>Unverum</AssemblyName>
<AssemblyVersion>1.3.3.0</AssemblyVersion>
<AssemblyVersion>1.3.4.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 806cda9

Please sign in to comment.