-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCommandExecutorService.cs
More file actions
49 lines (44 loc) · 1.24 KB
/
Copy pathCommandExecutorService.cs
File metadata and controls
49 lines (44 loc) · 1.24 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using EnvDTE;
using System.ComponentModel.Design;
using EnvDTE80;
namespace PeasyMotion
{
public class CommandExecutorService
{
readonly DTE _dte;
public CommandExecutorService()
{
ThreadHelper.ThrowIfNotOnUIThread();
_dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
}
public bool IsCommandAvailable(string commandName)
{
ThreadHelper.ThrowIfNotOnUIThread();
return FindCommand(_dte.Commands, commandName) != null;
}
public void Execute(string commandName)
{
ThreadHelper.ThrowIfNotOnUIThread();
_dte.ExecuteCommand(commandName);
}
private static dynamic FindCommand(Commands commands, string commandName)
{
foreach (var command in commands)
{
if (((dynamic)command).Name == commandName)
{
return command;
}
}
return null;
}
}
}