Skip to content

Commit d2da947

Browse files
committed
recent projects: fix context menu crash, fix removing last items from grid list (by making right mouse button also select the row,) fixes #223
1 parent 360cb44 commit d2da947

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<Button Style="{StaticResource CustomButton}" ToolTip="Browse and add existing project to list" x:Name="btnAddProjectFolder" Content="Add Project.." Height="22" Width="78" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,38,0" Click="BtnAddProjectFolder_Click" TabIndex="10" Grid.Column="1" />
5757
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh list (F5)" x:Name="btnRefreshProjectList" Content="" Height="22" Width="26" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Margin="0,4,3,0" Padding="1,-2,1,1" Click="BtnRefreshProjectList_Click" TabIndex="11" Grid.Column="1"/>
5858

59-
<DataGrid x:Name="gridRecent" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" SelectionMode="Single" Margin="4,30,2,42" CanUserAddRows="False" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding" PreviewMouseDoubleClick="GridRecent_PreviewMouseDoubleClick" ContextMenuOpening="GridRecent_ContextMenuOpening" BeginningEdit="GridRecent_BeginningEdit" RowHeight="21" ColumnReordered="GridRecent_ColumnReordered" Sorting="gridRecent_Sorting" Grid.ColumnSpan="2" DragLeave="gridRecent_DragLeave" DragEnter="gridRecent_DragEnter" Drop="gridRecent_Drop" AllowDrop="True" >
59+
<DataGrid x:Name="gridRecent" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" SelectionMode="Single" Margin="4,30,2,42" CanUserAddRows="False" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding" PreviewMouseDoubleClick="GridRecent_PreviewMouseDoubleClick" ContextMenuOpening="GridRecent_ContextMenuOpening" BeginningEdit="GridRecent_BeginningEdit" RowHeight="21" ColumnReordered="GridRecent_ColumnReordered" Sorting="gridRecent_Sorting" Grid.ColumnSpan="2" DragLeave="gridRecent_DragLeave" DragEnter="gridRecent_DragEnter" Drop="gridRecent_Drop" AllowDrop="True" PreviewMouseRightButtonDown="gridRecent_PreviewMouseRightButtonDown" >
6060

6161
<DataGrid.CommandBindings>
6262
<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyRowFolderToClipBoard" CanExecute="CanExecute_Copy"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ private void RemoveProjectFromList(bool confirm = false)
12681268
projectsSource.Remove(proj);
12691269
gridRecent.Items.Refresh();
12701270
Tools.SetFocusToGrid(gridRecent);
1271-
gridRecent.SelectedIndex = 0;
1271+
if (gridRecent.Items.Count > 0) gridRecent.SelectedIndex = 0;
12721272
}
12731273

12741274
// NOTE this doesnt remove from settings list?
@@ -2332,8 +2332,15 @@ private void GridRecent_ContextMenuOpening(object sender, ContextMenuEventArgs e
23322332
if (tabControl.SelectedIndex == 0)
23332333
{
23342334
var proj = GetSelectedProject();
2335-
var proc = ProcessHandler.Get(proj.Path);
2336-
menuItemKillProcess.IsEnabled = proc != null;
2335+
if (proj != null)
2336+
{
2337+
var proc = ProcessHandler.Get(proj.Path);
2338+
menuItemKillProcess.IsEnabled = proc != null;
2339+
}
2340+
else
2341+
{
2342+
menuItemKillProcess.IsEnabled = false;
2343+
}
23372344
}
23382345
}
23392346

@@ -3161,6 +3168,8 @@ private void BtnThemeEditor_Click(object sender, RoutedEventArgs e)
31613168

31623169
private void MenuRemoveProject_Click(object sender, RoutedEventArgs e)
31633170
{
3171+
var proj = GetSelectedProject();
3172+
if (proj == null) return;
31643173
RemoveProjectFromList();
31653174
}
31663175

@@ -4324,6 +4333,24 @@ private void gridRecent_Drop(object sender, DragEventArgs e)
43244333
}
43254334
}
43264335

4336+
private void gridRecent_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
4337+
{
4338+
var dep = e.OriginalSource as DependencyObject;
4339+
if (dep == null) return;
4340+
4341+
while (dep != null && !(dep is DataGridRow))
4342+
{
4343+
dep = VisualTreeHelper.GetParent(dep);
4344+
}
4345+
4346+
var row = dep as DataGridRow;
4347+
if (row == null) return;
4348+
4349+
gridRecent.SelectedItem = row.Item;
4350+
gridRecent.SelectedIndex = row.GetIndex();
4351+
row.Focus();
4352+
}
4353+
43274354
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
43284355
//{
43294356
// var proj = GetSelectedProject();

0 commit comments

Comments
 (0)