Skip to content

Commit fd01082

Browse files
committed
Add VisualCommander
1 parent 2d085cb commit fd01082

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

VisualCommander.vcmd

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<SerializableSnippets xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
<commands>
4+
<Snippet>
5+
<id>1</id>
6+
<name>Copy Avalonia URL</name>
7+
<code>using EnvDTE;
8+
using System;
9+
using System.Collections;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Windows.Forms;
13+
14+
public class C : VisualCommanderExt.ICommand
15+
{
16+
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
17+
{
18+
var toolWindow = DTE.ToolWindows;
19+
var solutionExplorer = toolWindow.SolutionExplorer;
20+
21+
var selectedItems = (solutionExplorer.SelectedItems as IEnumerable).OfType&lt;UIHierarchyItem&gt;().Select(i=&gt;i.Object).OfType&lt;ProjectItem&gt;();
22+
var selectedItem = selectedItems.FirstOrDefault();
23+
24+
if (selectedItem == null) return;
25+
26+
var project = selectedItem.ContainingProject;
27+
var projectPath = project.FullName;
28+
var projectName = Path.GetFileNameWithoutExtension(projectPath);
29+
var projectDirPath = Path.GetDirectoryName(projectPath);
30+
31+
var filePath = selectedItem.FileNames[0];
32+
var partPath = filePath.Substring(projectDirPath.Length);
33+
34+
var url = GetAvaloniaURL(projectName, partPath);
35+
36+
//Console.WriteLine(url);
37+
Clipboard.SetText(url);
38+
}
39+
40+
string GetAvaloniaURL(string assemblyName, string relPath)
41+
{
42+
var relPathFixed = relPath.Replace('\\', '/');
43+
return "avares://" + assemblyName + relPathFixed ;
44+
}
45+
}
46+
</code>
47+
<referencedAssemblies />
48+
<type>Command</type>
49+
<lang>CS</lang>
50+
<langVersion>v4.0</langVersion>
51+
<enabled>true</enabled>
52+
<includeDebugInformation>false</includeDebugInformation>
53+
</Snippet>
54+
<Snippet>
55+
<id>2</id>
56+
<name>Copy WPF URL</name>
57+
<code>using EnvDTE;
58+
using System;
59+
using System.Collections;
60+
using System.IO;
61+
using System.Linq;
62+
using System.Windows.Forms;
63+
64+
public class C : VisualCommanderExt.ICommand
65+
{
66+
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
67+
{
68+
var toolWindow = DTE.ToolWindows;
69+
70+
var solutionExplorer = toolWindow.SolutionExplorer;
71+
72+
var selectedItems = (solutionExplorer.SelectedItems as IEnumerable).OfType&lt;UIHierarchyItem&gt;().Select(i=&gt;i.Object).OfType&lt;ProjectItem&gt;();
73+
var selectedItem = selectedItems.FirstOrDefault();
74+
75+
if (selectedItem == null) return;
76+
77+
var project = selectedItem.ContainingProject;
78+
var projectPath = project.FullName;
79+
var projectName = Path.GetFileNameWithoutExtension(projectPath);
80+
var projectDirPath = Path.GetDirectoryName(projectPath);
81+
82+
var filePath = selectedItem.FileNames[0];
83+
var partPath = filePath.Substring(projectDirPath.Length);
84+
85+
var url = GetWPFURL(projectName, partPath);
86+
87+
//Console.WriteLine(url);
88+
Clipboard.SetText(url);
89+
}
90+
91+
string GetWPFURL(string assemblyName, string relPath)
92+
{
93+
var relPathFixed = relPath.Replace('\\', '/');
94+
return "pack://application:,,,/"+assemblyName+";component"+relPathFixed;
95+
}
96+
97+
}
98+
</code>
99+
<referencedAssemblies />
100+
<type>Command</type>
101+
<lang>CS</lang>
102+
<langVersion>v4.0</langVersion>
103+
<enabled>true</enabled>
104+
<includeDebugInformation>false</includeDebugInformation>
105+
</Snippet>
106+
</commands>
107+
<extensions />
108+
<commonCode />
109+
</SerializableSnippets>

0 commit comments

Comments
 (0)