forked from cpmcgrath/codealignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandFilter.cs
More file actions
55 lines (44 loc) · 1.67 KB
/
Copy pathCommandFilter.cs
File metadata and controls
55 lines (44 loc) · 1.67 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
50
51
52
53
54
55
using System;
using System.Linq;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
namespace CMcG.CodeAlignment
{
public abstract class CommandFilter : IOleCommandTarget
{
protected abstract Guid CommandGuid { get; }
public IOleCommandTarget Next { get; set; }
public int Exec(ref Guid cmdGroup, uint cmdId, uint options, IntPtr inArg, IntPtr outArg)
{
if (cmdGroup != CommandGuid)
return Next.Exec(ref cmdGroup, cmdId, options, inArg, outArg);
Execute(cmdId);
return VSConstants.S_OK;
}
public int QueryStatus(ref Guid cmdGroup, uint cmdCount, OLECMD[] cmds, IntPtr cmdText)
{
if (cmdGroup != CommandGuid)
return Next.QueryStatus(ref cmdGroup, cmdCount, cmds, cmdText);
foreach (var cmd in cmds)
cmds[0].cmdf = (uint)CanExecuteResult(cmd.cmdID);
return VSConstants.S_OK;
}
public OLECMDF CanExecuteResult(uint cmdId)
{
return CanExecute(cmdId) ? (OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED)
: OLECMDF.OLECMDF_SUPPORTED;
}
public virtual bool CanExecute(uint cmdId)
{
return true;
}
public abstract void Execute(uint cmdId);
public static void Register(IVsTextView textViewAdapter, CommandFilter filter)
{
IOleCommandTarget next;
if (ErrorHandler.Succeeded(textViewAdapter.AddCommandFilter(filter, out next)))
filter.Next = next;
}
}
}