-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathVisualCommander.vcmd
109 lines (91 loc) · 3.52 KB
/
VisualCommander.vcmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?xml version="1.0" encoding="utf-8"?>
<SerializableSnippets xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<commands>
<Snippet>
<id>1</id>
<name>Copy Avalonia URL</name>
<code>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 ;
}
}
</code>
<referencedAssemblies />
<type>Command</type>
<lang>CS</lang>
<langVersion>v4.0</langVersion>
<enabled>true</enabled>
<includeDebugInformation>false</includeDebugInformation>
</Snippet>
<Snippet>
<id>2</id>
<name>Copy WPF URL</name>
<code>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;
}
}
</code>
<referencedAssemblies />
<type>Command</type>
<lang>CS</lang>
<langVersion>v4.0</langVersion>
<enabled>true</enabled>
<includeDebugInformation>false</includeDebugInformation>
</Snippet>
</commands>
<extensions />
<commonCode />
</SerializableSnippets>