Jelajahi Sumber

Add shortcut to launch new clock

Daniel Chalmers 2 tahun lalu
induk
melakukan
0083049f35
2 mengubah file dengan 18 tambahan dan 0 penghapusan
  1. 2 0
      DesktopClock/MainWindow.xaml
  2. 16 0
      DesktopClock/MainWindow.xaml.cs

+ 2 - 0
DesktopClock/MainWindow.xaml

@@ -98,6 +98,8 @@
 
 			<Separator />
 
+			<MenuItem Click="MenuItemNew_OnClick" Header="_New clock..." />
+
 			<MenuItem Click="MenuItemCountdown_OnClick" Header="_Countdown to..." />
 
 			<MenuItem Click="MenuItemSettings_OnClick" Header="Advanced _settings..." />

+ 16 - 0
DesktopClock/MainWindow.xaml.cs

@@ -50,6 +50,22 @@ public partial class MainWindow : Window
         CopyToClipboard();
     }
 
+    private void MenuItemNew_OnClick(object sender, RoutedEventArgs e)
+    {
+        var result = MessageBox.Show(this,
+            $"This will make a copy of the executable and start it with new settings.\n\n" +
+            $"Continue?",
+            Title, MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes);
+
+        if (result != MessageBoxResult.Yes)
+            return;
+
+        var exeFileInfo = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);
+        var newExePath = Path.Combine(exeFileInfo.DirectoryName, Guid.NewGuid().ToString() + exeFileInfo.Name);
+        File.Copy(exeFileInfo.FullName, newExePath);
+        Process.Start(newExePath);
+    }
+
     private void MenuItemCountdown_OnClick(object sender, RoutedEventArgs e)
     {
         var result = MessageBox.Show(this,