@@ -32,12 +32,11 @@ public partial class MainWindow : Window
32
32
[ DllImport ( "user32" ) ]
33
33
static extern bool OpenIcon ( IntPtr hWnd ) ;
34
34
35
- //Project[] projectsSource;
35
+ // datagrid sources
36
36
List < Project > projectsSource ;
37
-
38
-
39
37
Updates [ ] updatesSource ;
40
38
UnityInstallation [ ] unityInstallationsSource ;
39
+
41
40
public static Dictionary < string , string > unityInstalledVersions = new Dictionary < string , string > ( ) ;
42
41
const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
43
42
public static readonly string launcherArgumentsFile = "LauncherArguments.txt" ;
@@ -154,7 +153,8 @@ void HandleCommandLineLaunch()
154
153
else
155
154
{
156
155
// try launching it
157
- Tools . LaunchProject ( proj ) ;
156
+ var proc = Tools . LaunchProject ( proj ) ;
157
+ proj . Process = proc ;
158
158
}
159
159
160
160
// quit after launch if enabled in settings
@@ -641,7 +641,9 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
641
641
642
642
private void BtnLaunchProject_Click ( object sender , RoutedEventArgs e )
643
643
{
644
- Tools . LaunchProject ( GetSelectedProject ( ) ) ;
644
+ var proj = GetSelectedProject ( ) ;
645
+ var proc = Tools . LaunchProject ( proj ) ;
646
+ proj . Process = proc ;
645
647
Tools . SetFocusToGrid ( gridRecent ) ;
646
648
}
647
649
@@ -741,7 +743,8 @@ private void TxtSearchBox_PreviewKeyDown(object sender, KeyEventArgs e)
741
743
{
742
744
case Key . Return : // open selected project
743
745
var proj = GetSelectedProject ( ) ;
744
- if ( proj != null ) Tools . LaunchProject ( proj ) ;
746
+ var proc = Tools . LaunchProject ( proj ) ;
747
+ proj . Process = proc ;
745
748
break ;
746
749
case Key . Tab :
747
750
case Key . Up :
@@ -832,7 +835,8 @@ private void GridRecent_PreviewKeyDown(object sender, KeyEventArgs e)
832
835
if ( IsEditingCell ( gridRecent ) == true ) return ;
833
836
e . Handled = true ;
834
837
var proj = GetSelectedProject ( ) ;
835
- Tools . LaunchProject ( proj ) ;
838
+ var proc = Tools . LaunchProject ( proj ) ;
839
+ proj . Process = proc ;
836
840
break ;
837
841
default :
838
842
break ;
@@ -1090,6 +1094,7 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
1090
1094
TextBox t = e . EditingElement as TextBox ;
1091
1095
string newcellValue = t . Text . ToString ( ) ;
1092
1096
1097
+
1093
1098
// check if we edited project name, or launcher arguments
1094
1099
if ( e . Column . DisplayIndex == 0 )
1095
1100
{
@@ -1150,7 +1155,7 @@ private void GridRecent_CellEditEnding(object sender, DataGridCellEditEndingEven
1150
1155
}
1151
1156
1152
1157
}
1153
- else // it was launcher arguments
1158
+ else // edit launcher arguments
1154
1159
{
1155
1160
1156
1161
string projSettingsFolder = "ProjectSettings" ;
@@ -1199,7 +1204,9 @@ private void GridRecent_PreviewMouseDoubleClick(object sender, MouseButtonEventA
1199
1204
var currentColumnCell = gridRecent . CurrentCell . Column . DisplayIndex ;
1200
1205
if ( currentColumnCell == 4 ) return ;
1201
1206
1202
- Tools . LaunchProject ( GetSelectedProject ( ) ) ;
1207
+ var proj = GetSelectedProject ( ) ;
1208
+ var proc = Tools . LaunchProject ( proj ) ;
1209
+ proj . Process = proc ;
1203
1210
}
1204
1211
1205
1212
private void DataGridUnitys_PreviewMouseDoubleClick ( object sender , MouseButtonEventArgs e )
@@ -1426,6 +1433,41 @@ private void ChkEnableProjectRename_Checked(object sender, RoutedEventArgs e)
1426
1433
Properties . Settings . Default . enableProjectRename = ( bool ) chkEnableProjectRename . IsChecked ;
1427
1434
Properties . Settings . Default . Save ( ) ;
1428
1435
}
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
+
1429
1471
} // class
1430
1472
} //namespace
1431
1473
0 commit comments