diff --git a/Common.cs b/Common.cs index c355bbf..0643a13 100644 --- a/Common.cs +++ b/Common.cs @@ -79,6 +79,8 @@ public enum UUIDType public static void AddDatabase(Database db) { + static object PanelLabel(TabItem item) => ((Label)((StackPanel)item.Header).Children[0]).Content; + var template = (DataTemplate)Application.Current.MainWindow.TryFindResource("DatabaseContentTemplate"); var control = (TabControl)Application.Current.MainWindow.FindName("DatabasesPanel"); var tabs = control.Items.Cast(); @@ -86,14 +88,14 @@ public static void AddDatabase(Database db) if ((db.Name ?? string.Empty).Equals(string.Empty)) db.Name = DefaultDatabase; - if (tabs.Where(item => ((Label)((StackPanel)item.Header).Children[0]).Content.Equals(db.Name)).Any()) + if (tabs.Where(item => PanelLabel(item).Equals(db.Name)).Any()) { var index = 1; Match match; if ((match = IndexDigits().Match(db.Name ?? string.Empty)).Success) index = int.Parse(match.Groups[1].Value); - while (tabs.Where(item => ((Label)((StackPanel)item.Header).Children[0]).Content.Equals($"{db.Name} ({index})")).Any()) + while (tabs.Where(item => PanelLabel(item).Equals($"{db.Name} ({index})")).Any()) index++; db.Name = $"{db.Name} ({index})"; } @@ -127,6 +129,7 @@ public static void AddDatabase(Database db) public static SolidColorBrush? BrushFromBytes(string data) { var hex = NumberStyles.HexNumber; + if (data.Length == 6) data = "FF" + data; diff --git a/ContextSettings.cs b/ContextSettings.cs index ea5ddc2..c03e079 100644 --- a/ContextSettings.cs +++ b/ContextSettings.cs @@ -77,12 +77,9 @@ public void Load() if (!File.Exists(SettingsFile)) return; - string[] settings = File.ReadAllLines(SettingsFile); - - for (int i = 0; i < settings.Length; i++) + foreach (string setting in File.ReadAllLines(SettingsFile)) { - var setting = settings[i].Trim(); - var keyValue = setting.Split(':', 2); + var keyValue = setting.Trim().Split(':', 2); switch (keyValue[0]) { case "AccentBackground": @@ -141,25 +138,20 @@ public void Load() protected void OnPropertyChanged([CallerMemberName] string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); - public void Save() - { - string[] settings = [ - $"AccentBackground:{BytesFromBrush(AccentBackground)}", - $"AccentForeground:{BytesFromBrush(AccentForeground)}", - $"FontFamily:{MainFontFamily?.Source}", - $"FontSize:{MainFontSize}", - $"LastDatabases:{string.Join(';', DatabaseFiles.Distinct().Where(File.Exists))}", - $"ListBackground:{BytesFromBrush(ListBackground)}", - $"ListForeground:{BytesFromBrush(ListForeground)}", - $"MenuBackground:{BytesFromBrush(MenuBackground)}", - $"MenuForeground:{BytesFromBrush(MenuForeground)}", - $"RecentNotesSortMode:{(int)RecentEntriesSortMode}", - $"RibbonDisplayMode:{(int)RibbonTabContent}", - $"SearchResultsOnTop:{SearchResultsOnTop}", - $"SnapSearchResults:{SnapSearchResults}", - ]; - - File.WriteAllLines(SettingsFile, settings); - } + public void Save() => File.WriteAllLines(SettingsFile, [ + $"AccentBackground:{BytesFromBrush(AccentBackground)}", + $"AccentForeground:{BytesFromBrush(AccentForeground)}", + $"FontFamily:{MainFontFamily?.Source}", + $"FontSize:{MainFontSize}", + $"LastDatabases:{string.Join(';', DatabaseFiles.Distinct().Where(File.Exists))}", + $"ListBackground:{BytesFromBrush(ListBackground)}", + $"ListForeground:{BytesFromBrush(ListForeground)}", + $"MenuBackground:{BytesFromBrush(MenuBackground)}", + $"MenuForeground:{BytesFromBrush(MenuForeground)}", + $"RecentNotesSortMode:{(int)RecentEntriesSortMode}", + $"RibbonDisplayMode:{(int)RibbonTabContent}", + $"SearchResultsOnTop:{SearchResultsOnTop}", + $"SnapSearchResults:{SnapSearchResults}", + ]); } } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 56de3cb..a473865 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -233,7 +233,7 @@ private void MainWindow_Loaded(object sender, RoutedEventArgs e) Directory.CreateDirectory(folder.Value); if (FirstRun) - Database.Create(Path.Join(Subfolders["Databases"], $"{DefaultDatabase}", $"{DefaultDatabase}.sidb")); + Database.Create(Path.Join(Subfolders["Databases"], DefaultDatabase, $"{DefaultDatabase}.sidb")); DatabasesPanel.SelectedIndex = 0; @@ -276,17 +276,15 @@ protected override void OnClosed(EventArgs e) protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); - var helper = new WindowInteropHelper(this); - WindowSource = HwndSource.FromHwnd(helper.Handle); + WindowSource = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); WindowSource.AddHook(HwndHook); RegisterHotKey(); } private void RegisterHotKey() { - var helper = new WindowInteropHelper(this); - if (!RegisterHotKey(helper.Handle, HotKeyID, 2, (uint)KeyInterop.VirtualKeyFromKey(Key.N))) - MessageBox.Show("Failed to register hotkey.", "Sylver Ink: Error", MessageBoxButton.OK, MessageBoxImage.Error); + if (!RegisterHotKey(new WindowInteropHelper(this).Handle, HotKeyID, 2, (uint)KeyInterop.VirtualKeyFromKey(Key.N))) + MessageBox.Show("Failed to register new note hotkey.", "Sylver Ink: Error", MessageBoxButton.OK, MessageBoxImage.Error); } private void RenameClosed(object sender, EventArgs e) @@ -364,7 +362,7 @@ private void TabChanged(object sender, SelectionChangedEventArgs e) var control = (TabControl)sender; if (control.Name.Equals("DatabasesPanel")) { - var item = (TabItem)control.SelectedItem; + var item = (TabItem?)control.SelectedItem; if (item is null) return; @@ -380,10 +378,6 @@ private void TabChanged(object sender, SelectionChangedEventArgs e) DeferUpdateRecentNotes(true); } - private void UnregisterHotKey() - { - var helper = new WindowInteropHelper(this); - UnregisterHotKey(helper.Handle, HotKeyID); - } + private void UnregisterHotKey() => UnregisterHotKey(new WindowInteropHelper(this).Handle, HotKeyID); } } diff --git a/Sylver Ink.csproj b/Sylver Ink.csproj index 4177409..a8d2780 100644 --- a/Sylver Ink.csproj +++ b/Sylver Ink.csproj @@ -12,16 +12,17 @@ build$([System.DateTime]::UtcNow.ToString("yyyyMMdd")) 7.0 en-US - 1.1.2 + 1.1.3 False Sylver Ink - Taica + Taicanium,milesfarber,norvinsk.hunter glasses.png glasses.ico README.md https://github.com/Taicanium/Sylver-Ink true + https://github.com/Taicanium/Sylver-Ink