Skip to content

Commit

Permalink
Save settings at fixed location (#313)
Browse files Browse the repository at this point in the history
Closes #313
  • Loading branch information
srwi committed Sep 7, 2024
1 parent 222f805 commit 8f7a548
Show file tree
Hide file tree
Showing 32 changed files with 706 additions and 854 deletions.
7 changes: 3 additions & 4 deletions EverythingToolbar.Deskband/ToolbarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Windows.Input;
using EverythingToolbar.Behaviors;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using Microsoft.Xaml.Behaviors;
using NHotkey;

Expand All @@ -29,8 +28,8 @@ public ToolbarControl()
SearchWindow.Instance.Hiding += OnSearchWindowHiding;

if (!ShortcutManager.Instance.AddOrReplace("FocusSearchBox",
(Key)Settings.Default.shortcutKey,
(ModifierKeys)Settings.Default.shortcutModifiers,
(Key)ToolbarSettings.User.ShortcutKey,
(ModifierKeys)ToolbarSettings.User.ShortcutModifiers,
FocusSearchBox))
{
ShortcutManager.Instance.SetShortcut(Key.None, ModifierKeys.None);
Expand All @@ -41,7 +40,7 @@ public ToolbarControl()
}

ShortcutManager.Instance.SetFocusCallback(FocusSearchBox);
if (Settings.Default.isReplaceStartMenuSearch)
if (ToolbarSettings.User.IsReplaceStartMenuSearch)
ShortcutManager.Instance.HookStartMenu();
}

Expand Down
3 changes: 1 addition & 2 deletions EverythingToolbar.Deskband/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Windows.Forms;
using System.Windows.Interop;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using Microsoft.Xaml.Behaviors;
using Point = System.Drawing.Point;

Expand Down Expand Up @@ -95,7 +94,7 @@ private RECT CalculatePosition()

private Size GetTargetWindowSize()
{
var windowSize = Settings.Default.popupSize;
var windowSize = new Size(ToolbarSettings.User.PopupWidth, ToolbarSettings.User.PopupHeight);
windowSize.Width = Math.Max(windowSize.Width, AssociatedObject.MinWidth) / DpiScalingFactor;
windowSize.Height = Math.Max(windowSize.Height, AssociatedObject.MinHeight) / DpiScalingFactor;
return windowSize;
Expand Down
11 changes: 5 additions & 6 deletions EverythingToolbar.Launcher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Windows.Forms;
using System.Windows.Input;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using Microsoft.Xaml.Behaviors;
using NHotkey;
using Application = System.Windows.Application;
Expand Down Expand Up @@ -53,8 +52,8 @@ public LauncherWindow(NotifyIcon icon)
new SetupAssistant(icon).Show();

if (!ShortcutManager.Instance.AddOrReplace("FocusSearchBox",
(Key)Settings.Default.shortcutKey,
(ModifierKeys)Settings.Default.shortcutModifiers,
(Key)ToolbarSettings.User.ShortcutKey,
(ModifierKeys)ToolbarSettings.User.ShortcutModifiers,
FocusSearchBox))
{
ShortcutManager.Instance.SetShortcut(Key.None, ModifierKeys.None);
Expand All @@ -65,7 +64,7 @@ public LauncherWindow(NotifyIcon icon)
}

ShortcutManager.Instance.SetFocusCallback(FocusSearchBox);
if (Settings.Default.isReplaceStartMenuSearch)
if (ToolbarSettings.User.IsReplaceStartMenuSearch)
ShortcutManager.Instance.HookStartMenu();

SearchWindow.Instance.Hiding += OnSearchWindowHiding;
Expand Down Expand Up @@ -112,10 +111,10 @@ private static string GetIconPath()
{
var processPath = Process.GetCurrentProcess().MainModule?.FileName ?? string.Empty;

if (string.IsNullOrEmpty(Settings.Default.iconName))
if (string.IsNullOrEmpty(ToolbarSettings.User.IconName))
return Path.Combine(processPath, "..", "Icons", "Medium.ico");

return Path.Combine(processPath, "..", Settings.Default.iconName);
return Path.Combine(processPath, "..", ToolbarSettings.User.IconName);
}

[STAThread]
Expand Down
9 changes: 4 additions & 5 deletions EverythingToolbar.Launcher/SetupAssistant.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using NLog;
using MessageBox = System.Windows.MessageBox;
using RadioButton = System.Windows.Controls.RadioButton;
Expand Down Expand Up @@ -47,7 +46,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)

foreach (RadioButton radio in IconRadioButtons.Children)
{
if ((string)radio.Tag == Settings.Default.iconName)
if ((string)radio.Tag == ToolbarSettings.User.IconName)
radio.IsChecked = true;
}

Expand Down Expand Up @@ -124,14 +123,14 @@ private void OnClosed(object sender, EventArgs e)
Properties.Resources.SetupAssistantRestartExplorerDialogTitle, MessageBoxButton.YesNo) ==
MessageBoxResult.Yes)
{
Utils.ChangeTaskbarPinIcon(Settings.Default.iconName);
Utils.ChangeTaskbarPinIcon(ToolbarSettings.User.IconName);
}
}

private void OnIconRadioButtonChecked(object sender, RoutedEventArgs e)
{
Settings.Default.iconName = ((RadioButton)sender).Tag as string;
Icon = new BitmapImage(new Uri("pack://application:,,,/" + Settings.Default.iconName));
ToolbarSettings.User.IconName = ((RadioButton)sender).Tag as string;
Icon = new BitmapImage(new Uri("pack://application:,,,/" + ToolbarSettings.User.IconName));
_iconHasChanged = true;

_unlockedPages = Math.Max(2, _unlockedPages);
Expand Down
3 changes: 1 addition & 2 deletions EverythingToolbar.Launcher/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics;
using System.IO;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using IWshRuntimeLibrary;
using Microsoft.Win32;
using NLog;
Expand Down Expand Up @@ -52,7 +51,7 @@ public static string GetTaskbarShortcutPath()

public static bool IsTaskbarCenterAligned()
{
if (Settings.Default.isForceCenterAlignment)
if (ToolbarSettings.User.IsForceCenterAlignment)
return true;

if (Helpers.Utils.GetWindowsVersion() < Helpers.Utils.WindowsVersion.Windows11)
Expand Down
3 changes: 1 addition & 2 deletions EverythingToolbar.Launcher/WindowPlacement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows.Forms;
using System.Windows.Interop;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using Microsoft.Xaml.Behaviors;
using Size = System.Windows.Size;

Expand Down Expand Up @@ -85,7 +84,7 @@ private RECT CalculatePosition(double scalingFactor)

private Size GetTargetWindowSize(double scalingFactor)
{
var windowSize = Settings.Default.popupSize;
var windowSize = new Size(ToolbarSettings.User.PopupWidth, ToolbarSettings.User.PopupHeight);
windowSize.Width = Math.Max(windowSize.Width, AssociatedObject.MinWidth) / scalingFactor;
windowSize.Height = Math.Max(windowSize.Height, AssociatedObject.MinHeight) / scalingFactor;
return windowSize;
Expand Down
7 changes: 3 additions & 4 deletions EverythingToolbar/Behaviors/ThemeAwareness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows.Media;
using Windows.UI.ViewManagement;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;
using Microsoft.Xaml.Behaviors;
using NLog;
using Color = Windows.UI.Color;
Expand Down Expand Up @@ -78,12 +77,12 @@ public ThemeAwareness()
Logger.Info("Could not apply accent color automatically.");
}

Settings.Default.PropertyChanged += OnSettingsChanged;
ToolbarSettings.User.PropertyChanged += OnSettingsChanged;
}

private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "itemTemplate")
if (e.PropertyName == nameof(ToolbarSettings.User.ItemTemplate))
{
AutoApplyTheme();
}
Expand Down Expand Up @@ -117,7 +116,7 @@ private void ApplyTheme(bool isLightTheme)
AddResource(Path.Combine(themeLocation, themeFileName));

// Apply ItemTemplate style
var dataTemplateLocation = Path.Combine(assemblyLocation, "ItemTemplates", Settings.Default.itemTemplate + ".xaml");
var dataTemplateLocation = Path.Combine(assemblyLocation, "ItemTemplates", ToolbarSettings.User.ItemTemplate + ".xaml");
AddResource(dataTemplateLocation, fallbackPath: Path.Combine(assemblyLocation, "ItemTemplates", "Normal.xaml"));

// Apply accent color
Expand Down
2 changes: 1 addition & 1 deletion EverythingToolbar/Controls/FilterSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void SelectCurrentFilter()

private void OnCurrentFilterChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "CurrentFilter")
if (e.PropertyName == nameof(EverythingSearch.Instance.CurrentFilter))
{
SelectCurrentFilter();
}
Expand Down
21 changes: 11 additions & 10 deletions EverythingToolbar/Controls/SearchBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:c="clr-namespace:EverythingToolbar.Converters"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:properties="clr-namespace:EverythingToolbar.Properties"
xmlns:local="clr-namespace:EverythingToolbar"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeChanged="OnSizeChanged">

Expand All @@ -24,17 +25,17 @@

<MenuItem Header="{x:Static properties:Resources.SettingsRegularExpressions}"
IsCheckable="True"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isRegExEnabled, Mode=TwoWay}" />
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsRegExEnabled, Mode=TwoWay}" />
<MenuItem Header="{x:Static properties:Resources.SettingsMatchCase}"
IsCheckable="True"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchCase, Mode=TwoWay}" />
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchCase, Mode=TwoWay}" />
<MenuItem Header="{x:Static properties:Resources.SettingsMatchPath}"
IsCheckable="True"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchPath, Mode=TwoWay}" />
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchPath, Mode=TwoWay}" />
<MenuItem Header="{x:Static properties:Resources.SettingsMatchWholeWord}"
IsCheckable="True"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchWholeWord, Mode=TwoWay}"
IsEnabled="{Binding Source={x:Static properties:Settings.Default}, Path=isRegExEnabled, Mode=OneWay, TargetNullValue=True, Converter={c:NotConverter}}" />
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchWholeWord, Mode=TwoWay}"
IsEnabled="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsRegExEnabled, Mode=OneWay, TargetNullValue=True, Converter={c:NotConverter}}" />
<Separator />
<MenuItem Header="{x:Static properties:Resources.ContextMenuCut}"
Click="OnCutClicked"
Expand All @@ -58,13 +59,13 @@
Background="Transparent">
<ToggleButton Style="{DynamicResource QuickSettingsToggleButton}"
ToolTip="{x:Static properties:Resources.SettingsMatchCase}"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchCase}"
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchCase}"
Content="Aa"
Margin="1" />
<ToggleButton Style="{DynamicResource QuickSettingsToggleButton}"
ToolTip="{x:Static properties:Resources.SettingsMatchWholeWord}"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchWholeWord}"
IsEnabled="{Binding Source={x:Static properties:Settings.Default}, Path=isRegExEnabled, Mode=OneWay, TargetNullValue=True, Converter={c:NotConverter}}"
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchWholeWord}"
IsEnabled="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsRegExEnabled, Mode=OneWay, TargetNullValue=True, Converter={c:NotConverter}}"
Name="IsMatchWholeWordButton"
Margin="1">
<TextBlock TextDecorations="Underline,OverLine"
Expand All @@ -75,15 +76,15 @@
</ToggleButton>
<ToggleButton Style="{DynamicResource QuickSettingsToggleButton}"
ToolTip="{x:Static properties:Resources.SettingsMatchPath}"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isMatchPath}"
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsMatchPath}"
Margin="1">
<TextBlock Text="..\"
FontSize="12pt"
Margin="-1, -2, 0, 0" />
</ToggleButton>
<ToggleButton Style="{DynamicResource QuickSettingsToggleButton}"
ToolTip="{x:Static properties:Resources.SettingsRegularExpressions}"
IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=isRegExEnabled}"
IsChecked="{Binding Source={x:Static local:ToolbarSettings.User}, Path=IsRegExEnabled}"
TextBlock.FontWeight="Bold"
Content=".*"
Margin="1" />
Expand Down
9 changes: 4 additions & 5 deletions EverythingToolbar/Controls/SearchBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows.Input;
using System.Windows.Interop;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;

namespace EverythingToolbar.Controls
{
Expand All @@ -24,7 +23,7 @@ public SearchBox()

// IsEnabled property of matchWholeWord button needs to be handled
// in code because DataTriggers are not compatible with DynamicResources as MenuItem styles
Settings.Default.PropertyChanged += OnSettingsChanged;
ToolbarSettings.User.PropertyChanged += OnSettingsChanged;
EverythingSearch.Instance.PropertyChanged += OnSettingsChanged;

EventDispatcher.Instance.SearchTermReplaced += (s, searchTerm) => { UpdateSearchTerm(searchTerm); };
Expand Down Expand Up @@ -53,7 +52,7 @@ private void OnPreviewKeyDown(object sender, KeyEventArgs e)
UpdateSearchTerm(HistoryManager.Instance.GetNextItem());
e.Handled = true;
}
else if ((e.Key == Key.Home || e.Key == Key.End) && Keyboard.Modifiers != ModifierKeys.Shift && Settings.Default.isAutoSelectFirstResult ||
else if ((e.Key == Key.Home || e.Key == Key.End) && Keyboard.Modifiers != ModifierKeys.Shift && ToolbarSettings.User.IsAutoSelectFirstResult ||
e.Key == Key.PageDown || e.Key == Key.PageUp ||
e.Key == Key.Up || e.Key == Key.Down ||
e.Key == Key.Escape || e.Key == Key.Enter ||
Expand All @@ -72,7 +71,7 @@ private void UpdateSearchTerm(string newSearchTerm)

private void OnSettingsChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "isShowQuickToggles")
if (e.PropertyName == nameof(ToolbarSettings.User.IsShowQuickToggles))
UpdateQuickTogglesVisibility();
}

Expand All @@ -83,7 +82,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e)

private void UpdateQuickTogglesVisibility()
{
if (Settings.Default.isShowQuickToggles && ActualWidth > 200)
if (ToolbarSettings.User.IsShowQuickToggles && ActualWidth > 200)
{
QuickToggleButtons.Visibility = Visibility.Visible;
TextBox.Padding = new Thickness(37, 0, 130, 0);
Expand Down
11 changes: 5 additions & 6 deletions EverythingToolbar/Controls/SearchResultsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using EverythingToolbar.Behaviors;
using EverythingToolbar.Data;
using EverythingToolbar.Helpers;
using EverythingToolbar.Properties;

namespace EverythingToolbar.Controls
{
Expand Down Expand Up @@ -105,7 +104,7 @@ private void OnKeyPressed(object sender, KeyEventArgs e)
}
else if (e.Key == Key.Up)
{
if (SearchResultsListView.SelectedIndex == 0 && !Settings.Default.isAutoSelectFirstResult)
if (SearchResultsListView.SelectedIndex == 0 && !ToolbarSettings.User.IsAutoSelectFirstResult)
{
SearchResultsListView.SelectedIndex = -1;
EventDispatcher.Instance.InvokeSearchBoxFocused(this, EventArgs.Empty);
Expand Down Expand Up @@ -146,7 +145,7 @@ private void OnKeyPressed(object sender, KeyEventArgs e)

private void AutoSelectFirstResult(object sender, NotifyCollectionChangedEventArgs e)
{
if (!Settings.Default.isAutoSelectFirstResult)
if (!ToolbarSettings.User.IsAutoSelectFirstResult)
return;

if (SearchResultsListView.SelectedItems.Count == 0 && !SearchResultsListView.Items.IsEmpty)
Expand Down Expand Up @@ -295,13 +294,13 @@ private void CopyFile(object sender, RoutedEventArgs e)

private void SingleClickSearchResult(object sender, MouseEventArgs e)
{
if (!Settings.Default.isDoubleClickToOpen)
if (!ToolbarSettings.User.IsDoubleClickToOpen)
Open();
}

private void DoubleClickSearchResult(object sender, MouseEventArgs e)
{
if (Settings.Default.isDoubleClickToOpen)
if (ToolbarSettings.User.IsDoubleClickToOpen)
Open();
}

Expand Down Expand Up @@ -424,7 +423,7 @@ private void OnContextMenuOpened(object sender, RoutedEventArgs e)

private void FocusSelectedItem()
{
if (Settings.Default.isAutoSelectFirstResult)
if (ToolbarSettings.User.IsAutoSelectFirstResult)
return;

var selectedItem = (ListViewItem)SearchResultsListView.ItemContainerGenerator.ContainerFromItem(SelectedItem);
Expand Down
Loading

0 comments on commit 8f7a548

Please sign in to comment.