From 29311e499b1b1dd1c518aaffced3e1f725101aba Mon Sep 17 00:00:00 2001 From: Qiu Hao Date: Sat, 27 Sep 2025 21:14:14 +0800 Subject: [PATCH 01/16] tweaks --- .../CodeIndexSearchWindowCommand.cs | 31 +++++- .../Controls/CodeIndexSearchControl.xaml | 20 ++-- .../Models/CodeIndexSearchViewModel.cs | 9 +- .../Models/UserSettingsManager.cs | 76 ++++++++++++++ .../ExtensionResourceDictionary.xaml | 98 ++++++++++++++----- .../VisualStudioExtensionPackage.vsct | 7 ++ 6 files changed, 207 insertions(+), 34 deletions(-) create mode 100644 src/CodeIndex.VisualStudioExtension/Models/UserSettingsManager.cs diff --git a/src/CodeIndex.VisualStudioExtension/CodeIndexSearchWindowCommand.cs b/src/CodeIndex.VisualStudioExtension/CodeIndexSearchWindowCommand.cs index cba22a4..907173a 100644 --- a/src/CodeIndex.VisualStudioExtension/CodeIndexSearchWindowCommand.cs +++ b/src/CodeIndex.VisualStudioExtension/CodeIndexSearchWindowCommand.cs @@ -13,7 +13,8 @@ internal sealed class CodeIndexSearchWindowCommand /// /// Command ID. /// - public const int CommandId = 4129; + public const int CommandId = 4129; + public const int OpenSettingsCommandId = 4130; /// /// Command menu group (command set GUID). @@ -39,6 +40,10 @@ private CodeIndexSearchWindowCommand(AsyncPackage package, OleMenuCommandService var menuCommandID = new CommandID(CommandSet, CommandId); var menuItem = new MenuCommand(this.Execute, menuCommandID); commandService.AddCommand(menuItem); + + var openSettingsCommandID = new CommandID(CommandSet, OpenSettingsCommandId); + var openSettingsMenuItem = new MenuCommand(this.OpenSettingsExecute, openSettingsCommandID); + commandService.AddCommand(openSettingsMenuItem); } /// @@ -91,5 +96,29 @@ private void Execute(object sender, EventArgs e) } }); } + + private void OpenSettingsExecute(object sender, EventArgs e) + { + this.package.JoinableTaskFactory.RunAsync(async delegate + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + try + { + var settings = UserSettingsManager.Load(); // 确保已初始化目录 + var path = UserSettingsManager.SettingsFile; + if (!System.IO.File.Exists(path)) + { + UserSettingsManager.Save(settings); // 创建文件 + } + + var dte = (EnvDTE.DTE)await package.GetServiceAsync(typeof(EnvDTE.DTE)); + dte.ItemOperations.OpenFile(path); + } + catch (Exception ex) + { + System.Windows.MessageBox.Show("Open settings failed: " + ex.Message, "CodeIndex", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); + } + }); + } } } diff --git a/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml b/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml index 1167312..ce88238 100644 --- a/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml +++ b/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml @@ -3,10 +3,18 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0" mc:Ignorable="d" - d:DesignHeight="281.2" d:DesignWidth="987.2" Foreground="Black" Background="#FF2D2D30"> + d:DesignHeight="281.2" d:DesignWidth="987.2" + Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}" + Background="{DynamicResource {x:Static vsshell:VsBrushes.ToolWindowBackgroundKey}}"> - + + + + + + @@ -49,13 +57,13 @@ public const int CommandId = 4129; - public const int OpenSettingsCommandId = 4130; /// /// Command menu group (command set GUID). @@ -41,9 +40,6 @@ private CodeIndexSearchWindowCommand(AsyncPackage package, OleMenuCommandService var menuItem = new MenuCommand(this.Execute, menuCommandID); commandService.AddCommand(menuItem); - var openSettingsCommandID = new CommandID(CommandSet, OpenSettingsCommandId); - var openSettingsMenuItem = new MenuCommand(this.OpenSettingsExecute, openSettingsCommandID); - commandService.AddCommand(openSettingsMenuItem); } /// @@ -98,34 +94,5 @@ private void Execute(object sender, EventArgs e) }).FileAndForget("CodeIndex/ShowToolWindow"); } - private void OpenSettingsExecute(object sender, EventArgs e) - { - this.package.JoinableTaskFactory.RunAsync(async delegate - { - await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - try - { - var settings = UserSettingsManager.Load(); // 确保已初始化目录 - var path = UserSettingsManager.SettingsFile; - if (!System.IO.File.Exists(path)) - { - UserSettingsManager.Save(settings); // 创建文件 - } - - var dte = await package.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; - if (dte == null) - { - System.Windows.MessageBox.Show("Cannot get DTE service.", "CodeIndex", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Warning); - return; - } - - dte.ItemOperations.OpenFile(path); - } - catch (Exception ex) - { - System.Windows.MessageBox.Show("Open settings failed: " + ex.Message, "CodeIndex", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); - } - }).FileAndForget("CodeIndex/OpenSettings"); - } } } diff --git a/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml b/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml index ce88238..90401a0 100644 --- a/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml +++ b/src/CodeIndex.VisualStudioExtension/Controls/CodeIndexSearchControl.xaml @@ -54,6 +54,7 @@ +