@@ -32,12 +32,11 @@ public partial class MainWindow : Window
3232 [ DllImport ( "user32" ) ]
3333 static extern bool OpenIcon ( IntPtr hWnd ) ;
3434
35- //Project[] projectsSource;
35+ // datagrid sources
3636 List < Project > projectsSource ;
37-
38-
3937 Updates [ ] updatesSource ;
4038 UnityInstallation [ ] unityInstallationsSource ;
39+
4140 public static Dictionary < string , string > unityInstalledVersions = new Dictionary < string , string > ( ) ;
4241 const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
4342 public static readonly string launcherArgumentsFile = "LauncherArguments.txt" ;
@@ -154,7 +153,8 @@ void HandleCommandLineLaunch()
154153 else
155154 {
156155 // try launching it
157- Tools . LaunchProject ( proj ) ;
156+ var proc = Tools . LaunchProject ( proj ) ;
157+ proj . Process = proc ;
158158 }
159159
160160 // quit after launch if enabled in settings
@@ -641,7 +641,9 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
641641
642642 private void BtnLaunchProject_Click ( object sender , RoutedEventArgs e )
643643 {
644- Tools . LaunchProject ( GetSelectedProject ( ) ) ;
644+ var proj = GetSelectedProject ( ) ;
645+ var proc = Tools . LaunchProject ( proj ) ;
646+ proj . Process = proc ;
645647 Tools . SetFocusToGrid ( gridRecent ) ;
646648 }
647649
@@ -741,7 +743,8 @@ private void TxtSearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
741743 {
742744 case Key . Return : // open selected project
743745 var proj = GetSelectedProject ( ) ;
744- if ( proj != null ) Tools . LaunchProject ( proj ) ;
746+ var proc = Tools . LaunchProject ( proj ) ;
747+ proj . Process = proc ;
745748 break ;
746749 case Key . Tab :
747750 case Key . Up :
@@ -832,7 +835,8 @@ private void GridRecent_PreviewKeyDown(object sender, KeyEventArgs e)
832835 if ( IsEditingCell ( gridRecent ) == true ) return ;
833836 e . Handled = true ;
834837 var proj = GetSelectedProject ( ) ;
835- Tools . LaunchProject ( proj ) ;
838+ var proc = Tools . LaunchProject ( proj ) ;
839+ proj . Process = proc ;
836840 break ;
837841 default :
838842 break ;
@@ -1090,6 +1094,7 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
10901094 TextBox t = e . EditingElement as TextBox ;
10911095 string newcellValue = t . Text . ToString ( ) ;
10921096
1097+
10931098 // check if we edited project name, or launcher arguments
10941099 if ( e . Column . DisplayIndex == 0 )
10951100 {
@@ -1150,7 +1155,7 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
11501155 }
11511156
11521157 }
1153- else // it was launcher arguments
1158+ else // edit launcher arguments
11541159 {
11551160
11561161 string projSettingsFolder = "ProjectSettings" ;
@@ -1199,7 +1204,9 @@ private void GridRecent_PreviewMouseDoubleClick(object sender, MouseButtonEventA
11991204 var currentColumnCell = gridRecent . CurrentCell . Column . DisplayIndex ;
12001205 if ( currentColumnCell == 4 ) return ;
12011206
1202- Tools . LaunchProject ( GetSelectedProject ( ) ) ;
1207+ var proj = GetSelectedProject ( ) ;
1208+ var proc = Tools . LaunchProject ( proj ) ;
1209+ proj . Process = proc ;
12031210 }
12041211
12051212 private void DataGridUnitys_PreviewMouseDoubleClick ( object sender , MouseButtonEventArgs e )
@@ -1426,6 +1433,41 @@ private void ChkEnableProjectRename_Checked(object sender, RoutedEventArgs e)
14261433 Properties . Settings . Default . enableProjectRename = ( bool ) chkEnableProjectRename . IsChecked ;
14271434 Properties . Settings . Default . Save ( ) ;
14281435 }
1436+
1437+ private void MenuItemKillProcess_Click ( object sender , RoutedEventArgs e )
1438+ {
1439+ if ( tabControl . SelectedIndex == 0 )
1440+ {
1441+ KillSelectedProcess ( null , null ) ;
1442+ }
1443+ }
1444+
1445+ void KillSelectedProcess ( object sender , ExecutedRoutedEventArgs e )
1446+ {
1447+ var proj = GetSelectedProject ( ) ;
1448+ if ( proj . Process != null )
1449+ {
1450+ proj . Process . Kill ( ) ;
1451+ proj . Process = null ;
1452+ }
1453+ }
1454+
1455+ private void GridRecent_ContextMenuOpening ( object sender , ContextMenuEventArgs e )
1456+ {
1457+ if ( tabControl . SelectedIndex == 0 )
1458+ {
1459+ var proj = GetSelectedProject ( ) ;
1460+ menuItemKillProcess . IsEnabled = proj . Process != null ;
1461+ }
1462+ }
1463+
1464+ // add alt+Q shortcut for killing process
1465+ // https://stackoverflow.com/a/29817712/5452781
1466+ public static readonly RoutedCommand KillProcessCommand = new RoutedUICommand ( "None" , "KillProcessCommand" , typeof ( MainWindow ) , new InputGestureCollection ( new InputGesture [ ]
1467+ {
1468+ new KeyGesture ( Key . Q , ModifierKeys . Alt )
1469+ } ) ) ;
1470+
14291471 } // class
14301472} //namespace
14311473
0 commit comments