ソースを参照

Add back menu item for advanced settings

Daniel Chalmers 1 年間 前
コミット
d58add6bf9

+ 0 - 1
DesktopClock/Data/TeachingTips.cs

@@ -10,7 +10,6 @@ public enum TeachingTips
     [Obsolete("Always asks now")]
     NewClock = 1 << 0,
 
-    [Obsolete("Settings were moved to a native window")]
     AdvancedSettings = 1 << 1,
 
     HideForNow = 1 << 2,

+ 8 - 4
DesktopClock/MainWindow.xaml

@@ -65,16 +65,20 @@
 
             <Separator />
 
-            <MenuItem Command="{Binding OpenSettingsCommand}" CommandParameter="0" Header="_Format" />
+            <MenuItem Command="{Binding OpenSettingsWindowCommand}" CommandParameter="0" Header="_Format" />
 
-            <MenuItem Command="{Binding OpenSettingsCommand}" CommandParameter="1" Header="_Appearance" />
+            <MenuItem Command="{Binding OpenSettingsWindowCommand}" CommandParameter="1" Header="_Appearance" />
 
-            <MenuItem Command="{Binding OpenSettingsCommand}" CommandParameter="2" Header="_Behavior" />
+            <MenuItem Command="{Binding OpenSettingsWindowCommand}" CommandParameter="2" Header="_Behavior" />
 
-            <MenuItem Command="{Binding OpenSettingsCommand}" CommandParameter="3" Header="H_elp" />
+            <MenuItem Command="{Binding OpenSettingsWindowCommand}" CommandParameter="3" Header="H_elp" />
 
             <Separator />
 
+            <MenuItem Command="{Binding OpenSettingsFileCommand}"
+			          Header="Advanced _settings"
+			          IsEnabled="{x:Static p:Settings.CanBeSaved}" />
+
             <MenuItem Command="{Binding NewClockCommand}"
                       Header="Create _new clock"
                       IsEnabled="{x:Static p:Settings.CanBeSaved}" />

+ 45 - 1
DesktopClock/MainWindow.xaml.cs

@@ -101,11 +101,55 @@ public partial class MainWindow : Window
     /// Opens a new settings window or activates the existing one.
     /// </summary>
     [RelayCommand]
-    public void OpenSettings(string tabIndex)
+    public void OpenSettingsWindow(string tabIndex)
     {
         Settings.Default.SettingsTabIndex = int.Parse(tabIndex);
         App.ShowSingletonWindow<SettingsWindow>(this);
     }
+    /// <summary>
+    /// Opens the settings file in Notepad.
+    /// </summary>
+    [RelayCommand]
+    public void OpenSettingsFile()
+    {
+        // Teach user how it works.
+        if (!Settings.Default.TipsShown.HasFlag(TeachingTips.AdvancedSettings))
+        {
+            MessageBox.Show(this,
+                "Settings are stored in JSON format and will be opened in Notepad. Simply save the file to see your changes appear on the clock. To start fresh, delete your '.settings' file.",
+                Title, MessageBoxButton.OK, MessageBoxImage.Information);
+
+            Settings.Default.TipsShown |= TeachingTips.AdvancedSettings;
+        }
+
+        // Save first if we can so it's up-to-date.
+        if (Settings.CanBeSaved)
+            Settings.Default.Save();
+
+        // If it doesn't even exist then it's probably somewhere that requires special access and we shouldn't even be at this point.
+        if (!Settings.Exists)
+        {
+            MessageBox.Show(this,
+                "Settings file doesn't exist and couldn't be created.",
+                Title, MessageBoxButton.OK, MessageBoxImage.Error);
+            return;
+        }
+
+        // Open settings file in notepad.
+        try
+        {
+            Process.Start("notepad", Settings.FilePath);
+        }
+        catch (Exception ex)
+        {
+            // Lazy scammers on the Microsoft Store may reupload without realizing it gets sandboxed, making it unable to start the Notepad process (#1, #12).
+            MessageBox.Show(this,
+                "Couldn't open settings file.\n\n" +
+                "This app may have be reuploaded without permission. If you paid for it, ask for a refund and download it for free from the original source: https://github.com/danielchalmers/DesktopClock.\n\n" +
+                $"If it still doesn't work, create a new Issue at that link with details on what happened and include this error: \"{ex.Message}\"",
+                Title, MessageBoxButton.OK, MessageBoxImage.Error);
+        }
+    }
 
     /// <summary>
     /// Asks the user then creates a new clock executable and starts it.