From fd01082a3d8333280622543e7fd7b7bbd99ce382 Mon Sep 17 00:00:00 2001 From: ema Date: Wed, 23 Apr 2025 22:35:31 +0800 Subject: [PATCH] Add VisualCommander --- VisualCommander.vcmd | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 VisualCommander.vcmd diff --git a/VisualCommander.vcmd b/VisualCommander.vcmd new file mode 100644 index 0000000..981ced5 --- /dev/null +++ b/VisualCommander.vcmd @@ -0,0 +1,109 @@ + + + + + 1 + Copy Avalonia URL + using EnvDTE; +using System; +using System.Collections; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +public class C : VisualCommanderExt.ICommand +{ + public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) + { + var toolWindow = DTE.ToolWindows; + var solutionExplorer = toolWindow.SolutionExplorer; + + var selectedItems = (solutionExplorer.SelectedItems as IEnumerable).OfType<UIHierarchyItem>().Select(i=>i.Object).OfType<ProjectItem>(); + var selectedItem = selectedItems.FirstOrDefault(); + + if (selectedItem == null) return; + + var project = selectedItem.ContainingProject; + var projectPath = project.FullName; + var projectName = Path.GetFileNameWithoutExtension(projectPath); + var projectDirPath = Path.GetDirectoryName(projectPath); + + var filePath = selectedItem.FileNames[0]; + var partPath = filePath.Substring(projectDirPath.Length); + + var url = GetAvaloniaURL(projectName, partPath); + + //Console.WriteLine(url); + Clipboard.SetText(url); + } + + string GetAvaloniaURL(string assemblyName, string relPath) + { + var relPathFixed = relPath.Replace('\\', '/'); + return "avares://" + assemblyName + relPathFixed ; + } +} + + + Command + CS + v4.0 + true + false + + + 2 + Copy WPF URL + using EnvDTE; +using System; +using System.Collections; +using System.IO; +using System.Linq; +using System.Windows.Forms; + +public class C : VisualCommanderExt.ICommand +{ + public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) + { + var toolWindow = DTE.ToolWindows; + + var solutionExplorer = toolWindow.SolutionExplorer; + + var selectedItems = (solutionExplorer.SelectedItems as IEnumerable).OfType<UIHierarchyItem>().Select(i=>i.Object).OfType<ProjectItem>(); + var selectedItem = selectedItems.FirstOrDefault(); + + if (selectedItem == null) return; + + var project = selectedItem.ContainingProject; + var projectPath = project.FullName; + var projectName = Path.GetFileNameWithoutExtension(projectPath); + var projectDirPath = Path.GetDirectoryName(projectPath); + + var filePath = selectedItem.FileNames[0]; + var partPath = filePath.Substring(projectDirPath.Length); + + var url = GetWPFURL(projectName, partPath); + + //Console.WriteLine(url); + Clipboard.SetText(url); + } + + string GetWPFURL(string assemblyName, string relPath) + { + var relPathFixed = relPath.Replace('\\', '/'); + return "pack://application:,,,/"+assemblyName+";component"+relPathFixed; + } + +} + + + Command + CS + v4.0 + true + false + + + + + \ No newline at end of file