-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNSCodeWindow.cs
219 lines (175 loc) · 8.25 KB
/
NSCodeWindow.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
using IServiceProvider = System.IServiceProvider;
namespace NimStudio.NimStudio {
class NSCodeWindow: IVsCodeWindowManager, IVsCodeWindowEvents {
private readonly IServiceProvider _serviceProvider;
private readonly IVsCodeWindow _window;
private readonly ITextBuffer _textBuffer;
private IWpfTextView _curView;
private static readonly HashSet<NSCodeWindow> _windows = new HashSet<NSCodeWindow>();
//private uint _cookieVsCodeWindowEvents;
private static IVsEditorAdaptersFactoryService _vsEditorAdaptersFactoryService = null;
public NSCodeWindow(IServiceProvider serviceProvider, IVsCodeWindow codeWindow, IWpfTextView textView) {
_serviceProvider = serviceProvider;
_window = codeWindow;
_textBuffer = textView.TextBuffer;
}
public int AddAdornments() {
_windows.Add(this);
IVsTextView textView;
if (ErrorHandler.Succeeded(_window.GetPrimaryView(out textView))) {
((IVsCodeWindowEvents)this).OnNewView(textView);
}
if (ErrorHandler.Succeeded(_window.GetSecondaryView(out textView))) {
((IVsCodeWindowEvents)this).OnNewView(textView);
}
return VSConstants.S_OK;
}
private int AddDropDownBar() {
return VSConstants.S_OK;
}
private int RemoveDropDownBar() {
return VSConstants.S_OK;
}
public int OnNewView(IVsTextView pView) {
return VSConstants.S_OK;
}
public int RemoveAdornments() {
return VSConstants.S_OK;
}
public static void ToggleNavigationBar(bool fEnable) {
}
int IVsCodeWindowEvents.OnNewView(IVsTextView vsTextView) {
var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
if (wpfTextView != null) {
var factory = ComponentModel.GetService<IEditorOperationsFactoryService>();
var editFilter = new EditFilter(wpfTextView, factory.GetEditorOperations(wpfTextView), ServiceProvider.GlobalProvider);
editFilter.AttachKeyboardFilter(vsTextView);
wpfTextView.GotAggregateFocus += OnTextViewGotAggregateFocus;
wpfTextView.LostAggregateFocus += OnTextViewLostAggregateFocus;
}
return VSConstants.S_OK;
}
int IVsCodeWindowEvents.OnCloseView(IVsTextView vsTextView) {
var wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
if (wpfTextView != null) {
wpfTextView.GotAggregateFocus -= OnTextViewGotAggregateFocus;
wpfTextView.LostAggregateFocus -= OnTextViewLostAggregateFocus;
}
return VSConstants.S_OK;
}
private void OnTextViewGotAggregateFocus(object sender, EventArgs e) {
var wpfTextView = sender as IWpfTextView;
if (wpfTextView != null) {
_curView = wpfTextView;
}
}
private void OnTextViewLostAggregateFocus(object sender, EventArgs e) {
var wpfTextView = sender as IWpfTextView;
if (wpfTextView != null) {
_curView = null;
}
}
private IComponentModel ComponentModel {
get {
return (IComponentModel)_serviceProvider.GetService(typeof(SComponentModel));
}
}
private IVsEditorAdaptersFactoryService VsEditorAdaptersFactoryService {
get {
if (_vsEditorAdaptersFactoryService == null) {
_vsEditorAdaptersFactoryService = ComponentModel.GetService<IVsEditorAdaptersFactoryService>();
}
return _vsEditorAdaptersFactoryService;
}
}
}
internal sealed class EditFilter : IOleCommandTarget {
private readonly ITextView _textView;
private readonly IEditorOperations _editorOps;
private readonly IServiceProvider _serviceProvider;
//private readonly IComponentModel _componentModel;
private IOleCommandTarget _next;
public EditFilter(ITextView textView, IEditorOperations editorOps, IServiceProvider serviceProvider) {
_textView = textView;
_textView.Properties[typeof(EditFilter)] = this;
_editorOps = editorOps;
_serviceProvider = serviceProvider;
//_componentModel = _serviceProvider.GetComponentModel();
//BraceMatcher.WatchBraceHighlights(textView, _componentModel);
}
internal void AttachKeyboardFilter(IVsTextView vsTextView) {
if (_next == null) {
ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
}
}
private int GotoDefinition() {
return VSConstants.S_OK;
}
private void GotoLocation() {
}
private IVsTextView GetViewAdapter() {
//var adapterFactory = _componentModel.GetService<IVsEditorAdaptersFactoryService>();
//var viewAdapter = adapterFactory.GetViewAdapter(_textView);
//return viewAdapter;
return null;
}
private int FindAllReferences() {
return VSConstants.S_OK;
}
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) {
// preprocessing
if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) {
switch ((VSConstants.VSStd97CmdID)nCmdID) {
case VSConstants.VSStd97CmdID.Paste:
case VSConstants.VSStd97CmdID.GotoDefn: return GotoDefinition();
case VSConstants.VSStd97CmdID.FindReferences: return FindAllReferences();
}
};
return _next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
}
private void ExtractMethod() {
}
private void FormatCode(SnapshotSpan span, bool selectResult) {
}
internal void RefactorRename() {
}
private const uint CommandDisabledAndHidden = (uint)(OLECMDF.OLECMDF_INVISIBLE | OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_DEFHIDEONCTXTMENU);
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText) {
if (pguidCmdGroup == VSConstants.GUID_VSStandardCommandSet97) {
for (int i = 0; i < cCmds; i++) {
switch ((VSConstants.VSStd97CmdID)prgCmds[i].cmdID) {
case VSConstants.VSStd97CmdID.GotoDefn:
prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);
return VSConstants.S_OK;
case VSConstants.VSStd97CmdID.FindReferences:
prgCmds[i].cmdf = (uint)(OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_SUPPORTED);
return VSConstants.S_OK;
}
}
}
return _next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
}
private void QueryStatusExtractMethod(OLECMD[] prgCmds, int i) {
//var activeView = CommonPackage.GetActiveTextView(_serviceProvider);
}
private void QueryStatusRename(OLECMD[] prgCmds, int i) {
//IWpfTextView activeView = CommonPackage.GetActiveTextView(_serviceProvider);
}
internal void DoIdle(IOleComponentManager compMgr) {
}
}
}