Skip to content

Commit

Permalink
Add back menu item for advanced settings
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Jul 30, 2024
1 parent 60f1778 commit d58add6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
1 change: 0 additions & 1 deletion DesktopClock/Data/TeachingTips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions DesktopClock/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />
Expand Down
46 changes: 45 additions & 1 deletion DesktopClock/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,55 @@ public void HideForNow()
/// 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.
Expand Down

0 comments on commit d58add6

Please sign in to comment.