Consolidate config actions into menu
This commit is contained in:
@@ -21,12 +21,24 @@
|
||||
BorderBrush="{DynamicResource AppBorderBrush}">
|
||||
<WrapPanel HorizontalAlignment="Right">
|
||||
<Button Content="Save" Click="Save_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Backup Config" Click="BackupConfig_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Restore Config" Click="RestoreConfig_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Export Config" Click="ExportConfig_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Import Config" Click="ImportConfig_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Reload Config" Click="ReloadConfig_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Open Config Folder" Click="OpenConfigFolder_Click" Margin="0,0,8,0"/>
|
||||
<Button x:Name="ConfigMenuButton"
|
||||
Content="Config..."
|
||||
Click="ConfigMenuButton_Click"
|
||||
Margin="0,0,8,0">
|
||||
<Button.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="Backup Config" Click="BackupConfig_Click"/>
|
||||
<MenuItem Header="Restore from Backup" Click="RestoreConfig_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Export Config" Click="ExportConfig_Click"/>
|
||||
<MenuItem Header="Import Config" Click="ImportConfig_Click"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Reset to Defaults" Click="ResetConfig_Click"/>
|
||||
<MenuItem Header="Reload Config" Click="ReloadConfig_Click"/>
|
||||
<MenuItem Header="Open Config Folder" Click="OpenConfigFolder_Click"/>
|
||||
</ContextMenu>
|
||||
</Button.ContextMenu>
|
||||
</Button>
|
||||
<Button Content="About" Click="About_Click" Margin="0,0,8,0"/>
|
||||
<Button Content="Close" Click="Close_Click"/>
|
||||
</WrapPanel>
|
||||
|
||||
@@ -721,6 +721,17 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigMenuButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ConfigMenuButton.ContextMenu is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigMenuButton.ContextMenu.PlacementTarget = ConfigMenuButton;
|
||||
ConfigMenuButton.ContextMenu.IsOpen = true;
|
||||
}
|
||||
|
||||
private void ExportConfig_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (controller is null)
|
||||
@@ -792,6 +803,33 @@ public partial class MainWindow : Window
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetConfig_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MessageBoxResult result = MessageBox.Show(
|
||||
"Reset launcher config to the default folders and apps?\n\nA local backup will be created first.",
|
||||
"Taskbar Launcher",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (result != MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string backupPath = ConfigService.Backup();
|
||||
ConfigService.ResetToDefaults();
|
||||
controller?.ReloadConfig();
|
||||
RefreshView();
|
||||
StatusText.Text = $"Reset config to defaults. Previous config backed up to {backupPath}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Could not reset config.\n\n{ex.Message}", "Taskbar Launcher");
|
||||
}
|
||||
}
|
||||
|
||||
private List<int>? FindItemPath(LauncherItem item)
|
||||
{
|
||||
if (controller is null)
|
||||
|
||||
@@ -87,6 +87,13 @@ public static class ConfigService
|
||||
return config;
|
||||
}
|
||||
|
||||
public static LauncherConfig ResetToDefaults()
|
||||
{
|
||||
LauncherConfig config = CreateDefaultConfig();
|
||||
Save(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
public static LauncherConfig Restore(string sourcePath)
|
||||
{
|
||||
LauncherConfig config = ReadConfigFile(sourcePath);
|
||||
|
||||
Reference in New Issue
Block a user