~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/RefactoryCommands.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
using System;
30
30
using System.Collections.Generic;
31
 
using System.Text;
32
 
using System.Threading;
33
31
 
34
32
using MonoDevelop.Core;
35
33
using MonoDevelop.Ide.Gui;
36
34
using MonoDevelop.Components.Commands;
37
 
using MonoDevelop.Projects;
38
 
using MonoDevelop.Projects.Text;
39
35
using MonoDevelop.Ide.Gui.Content;
40
 
using MonoDevelop.Ide.Gui.Dialogs;
41
36
using MonoDevelop.Ide.FindInFiles;
42
37
using MonoDevelop.Ide;
43
38
using System.Linq;
44
 
using MonoDevelop.Ide.CodeCompletion;
45
39
using ICSharpCode.NRefactory.CSharp.Resolver;
46
40
using ICSharpCode.NRefactory.TypeSystem;
47
 
using ICSharpCode.NRefactory.CSharp.Refactoring;
48
41
using Mono.TextEditor;
49
 
using ICSharpCode.NRefactory.CSharp;
50
42
using ICSharpCode.NRefactory.Semantics;
51
43
using MonoDevelop.CodeActions;
 
44
using MonoDevelop.SourceEditor.QuickTasks;
 
45
using MonoDevelop.Projects;
52
46
 
53
47
namespace MonoDevelop.Refactoring
54
48
{
57
51
                CurrentRefactoryOperations,
58
52
                GotoDeclaration, // in 'referenced' in IdeViMode.cs as string
59
53
                FindReferences,
 
54
                FindAllReferences,
60
55
                FindDerivedClasses,
61
56
                DeclareLocal,
62
57
                RemoveUnusedImports,
104
99
                        }
105
100
                        if (resolveResult is TypeResolveResult)
106
101
                                return resolveResult.Type;
 
102
                        if (resolveResult is NamespaceResolveResult)
 
103
                                return ((NamespaceResolveResult)resolveResult).Namespace;
107
104
                        return null;
108
105
                }
109
 
                
 
106
 
110
107
                class JumpTo
111
108
                {
112
 
                        INamedElement el;
 
109
                        object el;
113
110
                        
114
 
                        public JumpTo (INamedElement el)
 
111
                        public JumpTo (object el)
115
112
                        {
116
113
                                this.el = el;
117
114
                        }
123
120
                                        IdeApp.Workbench.OpenDocument (e.Region.FileName, e.Region.BeginLine, e.Region.BeginColumn);
124
121
                                        return;
125
122
                                } 
126
 
                                IdeApp.ProjectOperations.JumpToDeclaration (el);
 
123
                                if (el is IVariable)
 
124
                                        IdeApp.ProjectOperations.JumpToDeclaration ((IVariable)el);
 
125
                                if (el is INamedElement)
 
126
                                        IdeApp.ProjectOperations.JumpToDeclaration ((INamedElement)el);
127
127
                        }
128
128
                }
 
129
 
129
130
                
130
131
                class GotoBase 
131
132
                {
173
174
                class FindRefs 
174
175
                {
175
176
                        object obj;
176
 
                        
177
 
                        public FindRefs (object obj)
 
177
                        bool allOverloads;
 
178
                        public FindRefs (object obj, bool all)
178
179
                        {
179
180
                                this.obj = obj;
 
181
                                this.allOverloads = all;
180
182
                        }
181
183
                        
182
184
                        public void Run ()
183
185
                        {
184
 
                                FindReferencesHandler.FindRefs (obj);
 
186
                                if (allOverloads) {
 
187
                                        FindAllReferencesHandler.FindRefs (obj);
 
188
                                } else {
 
189
                                        FindReferencesHandler.FindRefs (obj);
 
190
                                }
185
191
                        }
186
192
                }
187
193
                
200
206
                        }
201
207
                }
202
208
 
 
209
                IEnumerable<MonoDevelop.CodeActions.CodeAction> validActions;
 
210
                MonoDevelop.Ide.TypeSystem.ParsedDocument lastDocument;
 
211
 
 
212
                DocumentLocation lastLocation;
 
213
 
 
214
                static bool HasOverloads (Solution solution, object item)
 
215
                {
 
216
                        var method = item as IMethod;
 
217
                        if (method == null)
 
218
                                return false;
 
219
                        return method.DeclaringType.GetMethods (m => m.Name == method.Name).Count () > 1;
 
220
                }
 
221
 
203
222
                protected override void Update (CommandArrayInfo ainfo)
204
223
                {
205
224
                        var doc = IdeApp.Workbench.ActiveDocument;
213
232
                        ResolveResult resolveResult;
214
233
                        object item = GetItem (doc, out resolveResult);
215
234
                        bool added = false;
216
 
                        
 
235
 
217
236
                        var options = new RefactoringOptions (doc) {
218
237
                                ResolveResult = resolveResult,
219
238
                                SelectedItem = item
221
240
                        
222
241
                        var ciset = new CommandInfoSet ();
223
242
                        ciset.Text = GettextCatalog.GetString ("Refactor");
224
 
                        
225
 
                        
 
243
 
226
244
                        bool canRename;
227
245
                        if (item is IVariable || item is IParameter) {
228
246
                                canRename = true; 
229
247
                        } else if (item is ITypeDefinition) { 
230
248
                                canRename = !((ITypeDefinition)item).Region.IsEmpty;
 
249
                        } else if (item is IType) { 
 
250
                                canRename = ((IType)item).Kind == TypeKind.TypeParameter;
231
251
                        } else if (item is IMember) {
232
252
                                canRename = !((IMember)item).Region.IsEmpty;
 
253
                        } else if (item is INamespace) {
 
254
                                canRename = true;
233
255
                        } else {
234
256
                                canRename = false;
235
257
                        }
236
258
                        if (canRename) {
237
 
                                ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.EditCommands.Rename), new System.Action (delegate {
 
259
                                ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (MonoDevelop.Ide.Commands.EditCommands.Rename), new Action (delegate {
238
260
                                        new MonoDevelop.Refactoring.Rename.RenameHandler ().Start (null);
239
261
                                }));
240
262
                                added = true;
244
266
                                if (refactoring.IsValid (options)) {
245
267
                                        CommandInfo info = new CommandInfo (refactoring.GetMenuDescription (options));
246
268
                                        info.AccelKey = refactoring.AccelKey;
247
 
                                        ciset.CommandInfos.Add (info, new System.Action (new RefactoringOperationWrapper (refactoring, options).Operation));
 
269
                                        ciset.CommandInfos.Add (info, new Action (new RefactoringOperationWrapper (refactoring, options).Operation));
248
270
                                }
249
271
                        }
250
272
 
251
273
                        var loc = doc.Editor.Caret.Location;
252
274
                        bool first = true;
253
 
                        foreach (var fix_ in RefactoringService.GetValidActions (doc, loc).Result) {
254
 
                                var fix = fix_;
255
 
                                if (first) {
256
 
                                        first = false;
257
 
                                        if (ciset.CommandInfos.Count > 0)
258
 
                                                ciset.CommandInfos.AddSeparator ();
259
 
                                }
260
 
                                ciset.CommandInfos.Add (fix.Title, new System.Action (() => fix.Run (doc, loc)));
 
275
                        if (lastDocument != doc.ParsedDocument || loc != lastLocation) {
 
276
 
 
277
                                if (QuickTaskStrip.EnableFancyFeatures) {
 
278
                                        var ext = doc.GetContent <CodeActionEditorExtension> ();
 
279
                                        validActions = ext != null ? ext.GetCurrentFixes () : null;
 
280
                                } else {
 
281
                                        validActions = RefactoringService.GetValidActions (doc, loc).Result;
 
282
                                }
 
283
 
 
284
                                lastLocation = loc;
 
285
                                lastDocument = doc.ParsedDocument;
 
286
                        }
 
287
                        if (validActions != null) {
 
288
                                foreach (var fix_ in validActions) {
 
289
                                        var fix = fix_;
 
290
                                        if (first) {
 
291
                                                first = false;
 
292
                                                if (ciset.CommandInfos.Count > 0)
 
293
                                                        ciset.CommandInfos.AddSeparator ();
 
294
                                        }
 
295
                                        ciset.CommandInfos.Add (fix.Title, new Action (() => fix.Run (doc, loc)));
 
296
                                }
261
297
                        }
262
298
 
263
299
                        if (ciset.CommandInfos.Count > 0) {
265
301
                                added = true;
266
302
                        }
267
303
                        
268
 
                        if (IdeApp.ProjectOperations.CanJumpToDeclaration (item as INamedElement)) {
269
 
                                var type = item as ICSharpCode.NRefactory.TypeSystem.IType;
 
304
                        if (IdeApp.ProjectOperations.CanJumpToDeclaration (item)) {
 
305
                                var type = item as IType;
270
306
                                if (type != null && type.GetDefinition ().Parts.Count > 1) {
271
307
                                        var declSet = new CommandInfoSet ();
272
308
                                        declSet.Text = GettextCatalog.GetString ("_Go to declaration");
275
311
                                                declSet.CommandInfos.Add (string.Format (GettextCatalog.GetString ("{0}, Line {1}"), FormatFileName (part.Region.FileName), part.Region.BeginLine), new System.Action (new JumpTo (part).Run));
276
312
                                        ainfo.Add (declSet);
277
313
                                } else {
278
 
                                        ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.GotoDeclaration), new System.Action (new JumpTo (item as INamedElement).Run));
 
314
                                        ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.GotoDeclaration), new System.Action (new JumpTo (item).Run));
279
315
                                }
280
316
                                added = true;
281
317
                        }
282
 
                        
283
 
                        if (item is IEntity || item is ITypeParameter || item is IVariable) {
284
 
                                ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new System.Action (new FindRefs (item).Run));
 
318
 
 
319
                        if (item is IEntity || item is ITypeParameter || item is IVariable || item is INamespace) {
 
320
                                ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new System.Action (new FindRefs (item, false).Run));
 
321
                                if (doc.HasProject && HasOverloads (doc.Project.ParentSolution, item))
 
322
                                        ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindAllReferences), new System.Action (new FindRefs (item, true).Run));
285
323
                                added = true;
286
324
                        }
287
325
                        
302
340
                                if ((cls.Kind == TypeKind.Class && !cls.IsSealed) || cls.Kind == TypeKind.Interface) {
303
341
                                        ainfo.Add (cls.Kind != TypeKind.Interface ? GettextCatalog.GetString ("Find _derived classes") : GettextCatalog.GetString ("Find _implementor classes"), new System.Action (new FindDerivedClasses (cls).Run));
304
342
                                }
305
 
//                              if (baseConstructor != null) {
306
 
//                                      Refactorer refactorer2 = new Refactorer (ctx, pinfo, baseConstructor.DeclaringType, baseConstructor, null);
307
 
//                                      ainfo.Add (GettextCatalog.GetString ("Go to _base"), new RefactoryOperation (refactorer2.GoToBase));
308
 
//                              }
309
343
                        }
310
 
                        
311
 
                        
312
 
                        
313
344
 
314
 
                        
315
 
                        if (resolveResult != null) {
316
 
//                              List<string> namespaces = QuickFixHandler.GetResolveableNamespaces (options, out resolveDirect);
317
 
//                      
318
 
//                              if (item == null || namespaces.Count > 1) {
319
 
//                                      if (item == null) {
320
 
//                                              foreach (string ns in namespaces) {
321
 
//                                                      // remove used namespaces for conflict resolving. 
322
 
//                                                      if (options.Document.CompilationUnit.IsNamespaceUsedAt (ns, options.ResolveResult.ResolvedExpression.Region.Start))
323
 
//                                                              continue;
324
 
//                                                      CommandInfo info = resolveMenu.CommandInfos.Add ("using " + ns + ";", new RefactoryOperation (new ResolveNameOperation (ctx, doc, resolveResult, ns).AddImport));
325
 
//                                                      info.Icon = MonoDevelop.Ide.Gui.Stock.AddNamespace;
326
 
//                                              }
327
 
//                                              // remove all unused namespaces (for resolving conflicts)
328
 
//                                              namespaces.RemoveAll (ns => !doc.CompilationUnit.IsNamespaceUsedAt (ns, resolveResult.ResolvedExpression.Region.Start));
329
 
//                                      }
330
 
//                                      
331
 
//                                      if (namespaces.Count > (item == null ? 0 : 1))
332
 
//                                              ainfo.Add (resolveMenu, null);
333
 
//                              }
334
 
                        }
335
 
                        
336
 
                        
337
 
//                              
338
 
//                              if (cls.GetSourceProject () != null && includeModifyCommands && ((cls.ClassType == ClassType.Class) || (cls.ClassType == ClassType.Struct))) {
339
 
//                                      ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Fields..."), new RefactoryOperation (refactorer.EncapsulateField));
340
 
//                                      ciset.CommandInfos.Add (GettextCatalog.GetString ("Override/Implement members..."), new RefactoryOperation (refactorer.OverrideOrImplementMembers));
341
 
//                              }
342
 
//                              
343
 
//                              ainfo.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new RefactoryOperation (refactorer.FindReferences));
344
 
//                              
345
 
//                              if (canRename && cls.ClassType == ClassType.Interface && eclass != null) {
346
 
//                                      // is now provided by the refactoring command infrastructure:
347
 
////                                    ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (explicit)"), new RefactoryOperation (refactorer.ImplementExplicitInterface));
348
 
////                                    ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (implicit)"), new RefactoryOperation (refactorer.ImplementImplicitInterface));
349
 
//                              } else if (canRename && includeModifyCommands && cls.BaseType != null && cls.ClassType != ClassType.Interface && cls == eclass) {
350
 
//                                      // Class might have interfaces... offer to implement them
351
 
//                                      CommandInfoSet impset = new CommandInfoSet ();
352
 
//                                      CommandInfoSet expset = new CommandInfoSet ();
353
 
//                                      CommandInfoSet abstactset = new CommandInfoSet ();
354
 
//                                      bool ifaceAdded = false;
355
 
//                                      bool abstractAdded = false;
356
 
//                                      
357
 
//                                      foreach (IReturnType rt in cls.BaseTypes) {
358
 
//                                              IType iface = ctx.GetType (rt);
359
 
//                                              if (iface == null)
360
 
//                                                      continue;
361
 
//                                              if (iface.ClassType == ClassType.Interface) {
362
 
//                                                      Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
363
 
//                                                      impset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementImplicitInterface));
364
 
//                                                      expset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementExplicitInterface));
365
 
//                                                      ifaceAdded = true;
366
 
//                                              } else if (ContainsAbstractMembers (iface)) {
367
 
//                                                      Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
368
 
//                                                      abstactset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementAbstractMembers));
369
 
//                                                      abstractAdded = true;
370
 
//                                              }
371
 
//                                      }
372
 
//                                      
373
 
//                                      if (ifaceAdded) {
374
 
//                                              impset.Text = GettextCatalog.GetString ("Implement Interface (implicit)");
375
 
//                                              ciset.CommandInfos.Add (impset, null);
376
 
//                                              
377
 
//                                              expset.Text = GettextCatalog.GetString ("Implement Interface (explicit)");
378
 
//                                              ciset.CommandInfos.Add (expset, null);
379
 
//                                      }
380
 
//                                      if (abstractAdded) {
381
 
//                                              abstactset.Text = GettextCatalog.GetString ("Implement abstract members");
382
 
//                                              ciset.CommandInfos.Add (abstactset, null);
383
 
//                                      }
384
 
//                              }
385
 
//                      } 
386
 
                        
387
 
                        
388
 
//                      IMember eitem = resolveResult != null ? (resolveResult.CallingMember ?? resolveResult.CallingType) : null;
389
 
//                      
390
 
//                      string itemName = null;
391
 
//                      if (item is IMember)
392
 
//                              itemName = ((IMember)item).Name;
393
 
//
394
 
//                      if (item != null && eitem != null && (eitem.Equals (item) || (eitem.Name == itemName && !(eitem is IProperty) && !(eitem is IMethod)))) {
395
 
//                              // If this occurs, then @item is either its own enclosing item, in
396
 
//                              // which case, we don't want to show it twice, or it is the base-class
397
 
//                              // version of @eitem, in which case we don't want to show the base-class
398
 
//                              // @item, we'd rather show the item the user /actually/ requested, @eitem.
399
 
//                              item = eitem;
400
 
//                              eitem = null;
401
 
//                      }
402
 
//
403
 
//                      IType eclass = null;
404
 
//
405
 
//                      if (item is IType) {
406
 
//                              if (((IType)item).ClassType == ClassType.Interface)
407
 
//                                      eclass = FindEnclosingClass (ctx, editor.Name, line, column); else
408
 
//                                      eclass = (IType)item;
409
 
//                              if (eitem is IMethod && ((IMethod)eitem).IsConstructor && eitem.DeclaringType.Equals (item)) {
410
 
//                                      item = eitem;
411
 
//                                      eitem = null;
412
 
//                              }
413
 
//                      }
414
 
//                      
415
 
//                      INode realItem = item;
416
 
//                      if (item is InstantiatedType)
417
 
//                              realItem = ((InstantiatedType)item).UninstantiatedType;
418
 
//                      if (realItem is CompoundType) {
419
 
//                              editor.GetLineColumnFromPosition (editor.CursorPosition, out line, out column);
420
 
//                              ((CompoundType)realItem).SetMainPart (doc.FileName, line, column);
421
 
//                              item = realItem;
422
 
//                      }
423
 
//                      
424
 
//                      
425
 
//                      
426
 
//                      var unit = doc.CompilationUnit;
427
 
//                      if (unit != null && unit.Usings != null && unit.Usings.Any (u => !u.IsFromNamespace && u.Region.Contains (line, column))) {
428
 
//                              CommandInfoSet organizeUsingsMenu = new CommandInfoSet ();
429
 
//                              organizeUsingsMenu.Text = GettextCatalog.GetString ("_Organize Usings");
430
 
//                              organizeUsingsMenu.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.RemoveUnusedImports), new RefactoryOperation (delegate {
431
 
//                                      new RemoveUnusedImportsHandler ().Start (options);
432
 
//                              }));
433
 
//                              organizeUsingsMenu.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (MonoDevelop.Refactoring.RefactoryCommands.SortImports), new RefactoryOperation (delegate {
434
 
//                                      new SortImportsHandler ().Start (options);
435
 
//                              }));
436
 
//                              organizeUsingsMenu.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (MonoDevelop.Refactoring.RefactoryCommands.RemoveSortImports), new RefactoryOperation (delegate {
437
 
//                                      new RemoveSortImportsHandler ().Start (options);
438
 
//                              }));
439
 
//                              ainfo.Add (organizeUsingsMenu, null);
440
 
//                              added = true;
441
 
//                      }
442
 
//                      
443
 
//                      IParsedFile pinfo = doc.CompilationUnit;
444
 
//                      if (pinfo == null)
445
 
//                              return;
446
 
//                      
447
 
//                      
448
 
//                      Refactorer refactorer = new Refactorer (ctx, pinfo, eclass, realItem, null);
449
 
//                      Ambience ambience = AmbienceService.GetAmbienceForFile (pinfo.FileName);
450
 
//                      bool includeModifyCommands = this.IsModifiable (item);
451
 
//                      
452
 
//                      
453
 
//                      // case: clicked on base in "constructor" - so pointing to the base constructor using argument count
454
 
//                      // not 100% correct, but it's the fastest thing to do.
455
 
//                      if (resolveResult is BaseResolveResult && eitem is IMethod && ((IMethod)eitem).IsConstructor) {
456
 
//                              IType type = item as IType;
457
 
//                              IMethod baseConstructor = null;
458
 
//                              int idx1 = resolveResult.ResolvedExpression.Expression.IndexOf ('(');
459
 
//                              int idx2 = resolveResult.ResolvedExpression.Expression.IndexOf (')');
460
 
//                              int paramCount = 0;
461
 
//                              if (idx1 > 0 && idx2 > 0) {
462
 
//                                      if (idx2 - idx1 > 1)
463
 
//                                              paramCount++;
464
 
//                                      for (int i=idx1; i < idx2; i++) {
465
 
//                                              if (resolveResult.ResolvedExpression.Expression[i] == ',') 
466
 
//                                                      paramCount++;
467
 
//                                      }
468
 
//                              }
469
 
//                              foreach (IMethod m in type.Methods) {
470
 
//                                      if (m.IsConstructor && m.Parameters.Count == paramCount)
471
 
//                                              baseConstructor = m;
472
 
//                              }
473
 
//                              Refactorer refactorer2 = new Refactorer (ctx, pinfo, baseConstructor.DeclaringType, baseConstructor, null);
474
 
//                              ainfo.Add (GettextCatalog.GetString ("Go to _base"), new RefactoryOperation (refactorer2.GoToBase));
475
 
//                      }
476
 
//                      
477
 
//                              else if (item is IField) {
478
 
//                              if (includeModifyCommands) {
479
 
//                                      if (canRename)
480
 
//                                              ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Field..."), new RefactoryOperation (refactorer.EncapsulateField));
481
 
//                              }
482
 
//                      } else 
483
 
                        
484
345
                        if (added)
485
346
                                ainfo.AddSeparator ();
486
 
                        /*
487
 
                        while (item != null) {
488
 
                                CommandInfo ci;
489
 
 
490
 
                                // case: clicked on base in "constructor" - so pointing to the base constructor using argument count
491
 
                                // not 100% correct, but it's the fastest thing to do.
492
 
                                if (resolveResult is BaseResolveResult && eitem is IMethod && ((IMethod)eitem).IsConstructor) {
493
 
                                        IType type = item as IType;
494
 
                                        IMethod baseConstructor = null;
495
 
                                        int idx1 = resolveResult.ResolvedExpression.Expression.IndexOf ('(');
496
 
                                        int idx2 = resolveResult.ResolvedExpression.Expression.IndexOf (')');
497
 
                                        int paramCount = 0;
498
 
                                        if (idx1 > 0 && idx2 > 0) {
499
 
                                                if (idx2 - idx1 > 1)
500
 
                                                        paramCount++;
501
 
                                                for (int i=idx1; i < idx2; i++) {
502
 
                                                        if (resolveResult.ResolvedExpression.Expression[i] == ',') 
503
 
                                                                paramCount++;
504
 
                                                }
505
 
                                        }
506
 
                                        foreach (IMethod m in type.Methods) {
507
 
                                                if (m.IsConstructor && m.Parameters.Count == paramCount)
508
 
                                                        baseConstructor = m;
509
 
                                        }
510
 
                                        if (baseConstructor != null && (ci = BuildRefactoryMenuForItem (ctx, doc.CompilationUnit, null, baseConstructor, true)) != null) {
511
 
                                                ainfo.Add (ci, null);
512
 
                                                added = true;
513
 
                                        }
514
 
                                }
515
 
                        
516
 
                                // Add the selected item
517
 
                                if ((ci = BuildRefactoryMenuForItem (ctx, doc.CompilationUnit, eclass, item, IsModifiable (item))) != null) {
518
 
                                        ainfo.Add (ci, null);
519
 
                                        added = true;
520
 
                                }
521
 
                                if (item is IParameter) {
522
 
                                        // Add the encompasing method for the previous item in the menu
523
 
                                        item = ((IParameter) item).DeclaringMember;
524
 
                                        if (item != null && (ci = BuildRefactoryMenuForItem (ctx, doc.CompilationUnit, null, item, true)) != null) {
525
 
                                                ainfo.Add (ci, null);
526
 
                                                added = true;
527
 
                                        }
528
 
                                }
529
 
                                
530
 
                                
531
 
                                if (item is IMember && !(eitem != null && eitem is IMember)) {
532
 
                                        // Add the encompasing class for the previous item in the menu
533
 
                                        item = ((IMember) item).DeclaringType;
534
 
                                        if (item != null && (ci = BuildRefactoryMenuForItem (ctx, doc.CompilationUnit, null, item, IsModifiable (item))) != null) {
535
 
                                                ainfo.Add (ci, null);
536
 
                                                added = true;
537
 
                                        }
538
 
                                }
539
 
                                
540
 
                                item = eitem;
541
 
                                eitem = null;
542
 
                                eclass = null;
543
 
                        }
544
 
                        
545
 
                        if (added)
546
 
                                ainfo.AddSeparator ();*/
547
347
                }
548
348
                
549
349
 
564
364
                        }
565
365
                }
566
366
 
567
 
/*              public class ResolveNameOperation
568
 
                {
569
 
                        ProjectDom ctx;
570
 
                        Document doc;
571
 
                        string ns;
572
 
                        ResolveResult resolveResult;
573
 
                        
574
 
                        public ResolveNameOperation (ProjectDom ctx, Document doc, ResolveResult resolveResult, string ns)
575
 
                        {
576
 
                                this.ctx = ctx;
577
 
                                this.doc = doc;
578
 
                                this.resolveResult = resolveResult;
579
 
                                this.ns = ns;
580
 
                        }
581
 
                        
582
 
                        public void AddImport ()
583
 
                        {
584
 
                                CodeRefactorer refactorer = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
585
 
                                
586
 
                                if (resolveResult is NamespaceResolveResult) {
587
 
                                        refactorer.AddLocalNamespaceImport (ctx, doc.FileName, ns, resolveResult.ResolvedExpression.Region.Start);
588
 
                                } else {
589
 
                                        refactorer.AddGlobalNamespaceImport (ctx, doc.FileName, ns);
590
 
                                }
591
 
                        }
592
 
                        
593
 
                        public void ResolveName ()
594
 
                        {
595
 
                                int pos = doc.Editor.Document.LocationToOffset (resolveResult.ResolvedExpression.Region.Start.Line, resolveResult.ResolvedExpression.Region.Start.Column);
596
 
                                if (pos < 0) {
597
 
                                        LoggingService.LogError ("Invalid expression position: " + resolveResult.ResolvedExpression);
598
 
                                        return;
599
 
                                }
600
 
                                doc.Editor.Insert (pos, ns + ".");
601
 
                                if (doc.Editor.Caret.Offset >= pos)
602
 
                                        doc.Editor.Caret.Offset += (ns + ".").Length;
603
 
                                doc.Editor.Document.CommitLineUpdate (resolveResult.ResolvedExpression.Region.Start.Line);
604
 
                        }
605
 
                }
606
 
*/
607
 
 
608
 
 
609
367
                bool IsModifiable (object member)
610
368
                {
611
369
                        IType t = member as IType;
615
373
                                return ((IMember)member).DeclaringTypeDefinition.Region.FileName == IdeApp.Workbench.ActiveDocument.FileName;
616
374
                        return false;
617
375
                }
618
 
                
619
 
//              // public class Funkadelic : IAwesomeSauce, IRockOn { ...
620
 
//              //        ----------------   -------------
621
 
//              // finds this ^ if you clicked on this ^
622
 
//              internal static IType FindEnclosingClass (ITypeResolveContext ctx, string fileName, int line, int col)
623
 
//              {
624
 
//                      IType klass = null;
625
 
//                      foreach (IType c in ctx.GetTypes (fileName)) {
626
 
//                              if (c.BodyRegion.Contains (line, col))
627
 
//                                      klass = c;
628
 
//                      }
629
 
//                      
630
 
//                      if (klass != null && klass.ClassType != ClassType.Interface)
631
 
//                              return klass;
632
 
//                      
633
 
//                      return null;
634
 
//              }
635
 
                
636
 
        /*      string EscapeName (string name)
637
 
                {
638
 
                        if (name.IndexOf ('_') == -1)
639
 
                                return name;
640
 
                        
641
 
                        StringBuilder sb = new StringBuilder ();
642
 
                        for (int i = 0; i < name.Length; i++) {
643
 
                                if (name[i] == '_')
644
 
                                        sb.Append ('_');
645
 
                                sb.Append (name[i]);
646
 
                        }
647
 
                        
648
 
                        return sb.ToString ();
649
 
                }*/
650
 
                
 
376
 
651
377
                static string FormatFileName (string fileName)
652
378
                {
653
379
                        if (fileName == null)
660
386
                                return "..." + fileName.Substring (idx);
661
387
                        return fileName;
662
388
                }
663
 
                /*
664
 
                CommandInfo BuildRefactoryMenuForItem (ITypeResolveContext ctx, IParsedFile pinfo, IType eclass, INode item, bool includeModifyCommands)
665
 
                {
666
 
                        INode realItem = item;
667
 
                        if (item is InstantiatedType)
668
 
                                realItem = ((InstantiatedType)item).UninstantiatedType;
669
 
                        Document doc = IdeApp.Workbench.ActiveDocument;
670
 
                        ITextBuffer editor = doc.GetContent<ITextBuffer> ();
671
 
                        
672
 
                        if (realItem is CompoundType) {
673
 
                                int line, column;
674
 
                                editor.GetLineColumnFromPosition (editor.CursorPosition, out line, out column);
675
 
                                ((CompoundType)realItem).SetMainPart (doc.FileName, line, column);
676
 
                                item = realItem;
677
 
                        }
678
 
                        
679
 
                        Refactorer refactorer = new Refactorer (ctx, pinfo, eclass, realItem, null);
680
 
                        CommandInfoSet ciset = new CommandInfoSet ();
681
 
                        Ambience ambience = AmbienceService.GetAmbienceForFile (pinfo.FileName);
682
 
                        OutputFlags flags = OutputFlags.IncludeMarkup;
683
 
                        if (item is IParameter) {
684
 
                                flags |= OutputFlags.IncludeParameterName;
685
 
                        } else {
686
 
                                flags |= OutputFlags.IncludeParameters;
687
 
                        }
688
 
                        
689
 
                        string itemName = EscapeName (ambience.GetString (item, flags));
690
 
                        bool canRename = false;
691
 
                        string txt;
692
 
                        if (IdeApp.ProjectOperations.CanJumpToDeclaration (item)) {
693
 
                                if (item is CompoundType) {
694
 
                                        CommandInfoSet declSet = new CommandInfoSet ();
695
 
                                        declSet.Text = GettextCatalog.GetString ("_Go to declaration");
696
 
                                        CompoundType ct = (CompoundType)item;
697
 
                                        foreach (IType part in ct.Parts) {
698
 
                                                Refactorer partRefactorer = new Refactorer (ctx, pinfo, eclass, part, null);
699
 
                                                declSet.CommandInfos.Add (string.Format (GettextCatalog.GetString ("{0}, Line {1}"), FormatFileName (part.GetDefinition ().Region.FileName), part.Location.Line), new RefactoryOperation (partRefactorer.GoToDeclaration));
700
 
                                        }
701
 
                                        ciset.CommandInfos.Add (declSet);
702
 
                                } else {
703
 
                                        ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.GotoDeclaration), new RefactoryOperation (refactorer.GoToDeclaration));
704
 
                                }
705
 
                        }
706
 
                        
707
 
 
708
 
                        if ((item is IMember || item is LocalVariable || item is IParameter) && !(item is IType))
709
 
                                ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new RefactoryOperation (refactorer.FindReferences));
710
 
                        
711
 
                        // We can rename local variables (always), method params (always), 
712
 
                        // or class/members (if they belong to a project)
713
 
                        if ((item is LocalVariable) || (item is IParameter)) {
714
 
                                canRename = true; 
715
 
                        } else if (item is IType) { 
716
 
                                canRename = ((IType)item).GetSourceProject () != null; 
717
 
                        } else if (item is IMember) {
718
 
                                IType cls = ((IMember)item).DeclaringType;
719
 
                                canRename = cls != null && cls.GetSourceProject () != null;
720
 
                        }
721
 
                        
722
 
                        RefactoringOptions options = new RefactoringOptions () {
723
 
                                Document = doc,
724
 
                                Dom = ctx,
725
 
                                ResolveResult = null,
726
 
                                SelectedItem = item is InstantiatedType ? ((InstantiatedType)item).UninstantiatedType : item
727
 
                        };
728
 
                        foreach (var refactoring in RefactoringService.Refactorings) {
729
 
                                if (refactoring.IsValid (options)) {
730
 
                                        CommandInfo info = new CommandInfo (refactoring.GetMenuDescription (options));
731
 
                                        info.AccelKey = refactoring.AccelKey;
732
 
                                        ciset.CommandInfos.Add (info, new RefactoryOperation (new RefactoringOperationWrapper (refactoring, options).Operation));
733
 
                                }
734
 
                        }
735
 
                        
736
 
//                      if (canRename && !(item is IType)) {
737
 
//                              // Defer adding this item for Classes until later
738
 
//                              ciset.CommandInfos.Add (GettextCatalog.GetString ("_Rename"), new RefactoryOperation (refactorer.Rename));
739
 
//                      }
740
 
                        if (item is IType) {
741
 
                                IType cls = (IType) item;
742
 
                                
743
 
                                if (cls.ClassType == ClassType.Enum)
744
 
                                        txt = GettextCatalog.GetString ("Enum <b>{0}</b>", itemName);
745
 
                                else if (cls.ClassType == ClassType.Struct)
746
 
                                        txt = GettextCatalog.GetString ("Struct <b>{0}</b>", itemName);
747
 
                                else if (cls.ClassType == ClassType.Interface)
748
 
                                        txt = GettextCatalog.GetString ("Interface <b>{0}</b>", itemName);
749
 
                                else if (cls.ClassType == ClassType.Delegate)
750
 
                                        txt = GettextCatalog.GetString ("Delegate <b>{0}</b>", itemName);
751
 
                                else
752
 
                                        txt = GettextCatalog.GetString ("Class <b>{0}</b>", itemName);
753
 
                                
754
 
                                if (cls.BaseType != null && cls.ClassType == ClassType.Class) {
755
 
                                        foreach (IReturnType rt in cls.BaseTypes) {
756
 
                                                IType bc = ctx.GetType (rt);
757
 
                                                if (bc != null && bc.ClassType != ClassType.Interface) {
758
 
                                                        ciset.CommandInfos.Add (GettextCatalog.GetString ("Go to _base"), new RefactoryOperation (refactorer.GoToBase));
759
 
                                                        break;
760
 
                                                }
761
 
                                        }
762
 
                                }
763
 
                                
764
 
                                if ((cls.ClassType == ClassType.Class && !cls.IsSealed) || cls.ClassType == ClassType.Interface) {
765
 
                                        ciset.CommandInfos.Add (cls.ClassType != ClassType.Interface ? GettextCatalog.GetString ("Find _derived classes") : GettextCatalog.GetString ("Find _implementor classes"), new RefactoryOperation (refactorer.FindDerivedClasses));
766
 
                                }
767
 
 
768
 
                                if (cls.GetSourceProject () != null && includeModifyCommands && ((cls.ClassType == ClassType.Class) || (cls.ClassType == ClassType.Struct))) {
769
 
                                        ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Fields..."), new RefactoryOperation (refactorer.EncapsulateField));
770
 
                                        ciset.CommandInfos.Add (GettextCatalog.GetString ("Override/Implement members..."), new RefactoryOperation (refactorer.OverrideOrImplementMembers));
771
 
                                }
772
 
                                
773
 
                                ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new RefactoryOperation (refactorer.FindReferences));
774
 
                                
775
 
//                              if (canRename)
776
 
//                                      ciset.CommandInfos.Add (GettextCatalog.GetString ("_Rename"), new RefactoryOperation (refactorer.Rename));
777
 
                                
778
 
                                if (canRename && cls.ClassType == ClassType.Interface && eclass != null) {
779
 
                                        // An interface is selected, so just need to provide these 2 submenu items
780
 
                                        ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (implicit)"), new RefactoryOperation (refactorer.ImplementImplicitInterface));
781
 
                                        ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (explicit)"), new RefactoryOperation (refactorer.ImplementExplicitInterface));
782
 
                                } else if (canRename && includeModifyCommands && cls.BaseType != null && cls.ClassType != ClassType.Interface && cls == eclass) {
783
 
                                        // Class might have interfaces... offer to implement them
784
 
                                        CommandInfoSet impset = new CommandInfoSet ();
785
 
                                        CommandInfoSet expset = new CommandInfoSet ();
786
 
                                        CommandInfoSet abstactset = new CommandInfoSet ();
787
 
                                        bool ifaceAdded = false;
788
 
                                        bool abstractAdded = false;
789
 
                                        
790
 
                                        foreach (IReturnType rt in cls.BaseTypes) {
791
 
                                                IType iface = ctx.GetType (rt);
792
 
                                                if (iface == null)
793
 
                                                        continue;
794
 
                                                if (iface.ClassType == ClassType.Interface) {
795
 
                                                        Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
796
 
                                                        impset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementImplicitInterface));
797
 
                                                        expset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementExplicitInterface));
798
 
                                                        ifaceAdded = true;
799
 
                                                } else if (ContainsAbstractMembers (iface)) {
800
 
                                                        Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
801
 
                                                        abstactset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementAbstractMembers));
802
 
                                                        abstractAdded = true;
803
 
                                                }
804
 
                                        }
805
 
                                        
806
 
                                        if (ifaceAdded) {
807
 
                                                impset.Text = GettextCatalog.GetString ("Implement Interface (implicit)");
808
 
                                                ciset.CommandInfos.Add (impset, null);
809
 
                                                
810
 
                                                expset.Text = GettextCatalog.GetString ("Implement Interface (explicit)");
811
 
                                                ciset.CommandInfos.Add (expset, null);
812
 
                                        }
813
 
                                        if (abstractAdded) {
814
 
                                                abstactset.Text = GettextCatalog.GetString ("Implement abstract members");
815
 
                                                ciset.CommandInfos.Add (abstactset, null);
816
 
                                        }
817
 
                                }
818
 
                        } else if (item is IField) {
819
 
                                txt = GettextCatalog.GetString ("Field <b>{0}</b>", itemName);
820
 
                                if (includeModifyCommands) {
821
 
                                        if (canRename)
822
 
                                                ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Field..."), new RefactoryOperation (refactorer.EncapsulateField));
823
 
                                        AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IField) item).ReturnType.FullName);
824
 
                                }
825
 
                        } else if (item is IProperty) {
826
 
                                if (((IProperty)item).IsIndexer) {                              
827
 
                                        txt = GettextCatalog.GetString ("Indexer <b>{0}</b>", itemName);                
828
 
                                } else {
829
 
                                        txt = GettextCatalog.GetString ("Property <b>{0}</b>", itemName);
830
 
                                }
831
 
                                AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IProperty) item).ReturnType.FullName);
832
 
                        } else if (item is IEvent) {
833
 
                                txt = GettextCatalog.GetString ("Event <b>{0}</b>", itemName);
834
 
                        } else if (item is IMethod) {
835
 
                                IMethod method = item as IMethod;
836
 
                                
837
 
                                if (method.IsConstructor) {
838
 
                                        txt = GettextCatalog.GetString ("Constructor <b>{0}</b>", EscapeName (method.DeclaringType.Name));
839
 
                                }Ā else {
840
 
                                        txt = GettextCatalog.GetString ("Method <b>{0}</b>", itemName);
841
 
                                        if (method.IsOverride) 
842
 
                                                ciset.CommandInfos.Add (GettextCatalog.GetString ("Go to _base"), new RefactoryOperation (refactorer.GoToBase));
843
 
                                }
844
 
                        } else if (item is IParameter) {
845
 
                                txt = GettextCatalog.GetString ("Parameter <b>{0}</b>", itemName);
846
 
                                AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IParameter) item).ReturnType.FullName);
847
 
                        } else if (item is LocalVariable) {
848
 
                                LocalVariable var = (LocalVariable) item;
849
 
                                AddRefactoryMenuForClass (ctx, pinfo, ciset, var.ReturnType.FullName);
850
 
                                txt = GettextCatalog.GetString ("Variable <b>{0}</b>", itemName);
851
 
                        } else {
852
 
                                return null;
853
 
                        }
854
 
                        
855
 
                        ciset.Text = txt;
856
 
                        ciset.UseMarkup = true;
857
 
                        return ciset;
858
 
                }
859
 
                */
860
 
                
 
389
 
861
390
                public static bool ContainsAbstractMembers (IType cls)
862
391
                {
863
392
                        if (cls == null)
864
393
                                return false;
865
394
                        return cls.GetMembers ().Any (m => m.IsAbstract);
866
395
                }
867
 
                
868
 
        /*      void AddRefactoryMenuForClass (ITypeResolveContext ctx, IParsedFile pinfo, CommandInfoSet ciset, string className)
869
 
                {
870
 
                        IType cls = ctx.GetType (className, null, true, true);
871
 
                        if (cls != null) {
872
 
                                CommandInfo ci = BuildRefactoryMenuForItem (ctx, pinfo, null, cls, false);
873
 
                                if (ci != null)
874
 
                                        ciset.CommandInfos.Add (ci, null);
875
 
                        }
876
 
                }*/
877
 
        }
878
 
        
879
 
        /*
880
 
        public class Refactorer
881
 
        {
882
 
                ISearchProgressMonitor monitor;
883
 
                ICompilationUnit pinfo;
884
 
                ProjectDom ctx;
885
 
                INode item;
886
 
                IType klass;
887
 
                IReturnType hintReturnType;
888
 
                
889
 
                public Refactorer (ProjectDom ctx, ICompilationUnit pinfo, IType klass, INode item, IReturnType hintReturnType)
890
 
                {
891
 
                        this.pinfo = pinfo;
892
 
                        this.klass = klass;
893
 
                        this.item = item;
894
 
                        this.ctx = ctx;
895
 
                        this.hintReturnType = hintReturnType;
896
 
                }
897
 
                
898
 
                public void GoToDeclaration ()
899
 
                {
900
 
                        IdeApp.ProjectOperations.JumpToDeclaration (item, true);
901
 
                }
902
 
                
903
 
                public void FindReferences ()
904
 
                {
905
 
                        monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
906
 
                        ThreadPool.QueueUserWorkItem (FindReferencesThread);
907
 
                }
908
 
                
909
 
                void FindReferencesThread (object state)
910
 
                {
911
 
                        try {
912
 
                                foreach (MemberReference mref in ReferenceFinder.FindReferences (IdeApp.ProjectOperations.CurrentSelectedSolution, item, monitor)) {
913
 
                                        monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (new FileProvider (mref.FileName), mref.Position, mref.Name.Length));
914
 
                                }
915
 
                        } catch (Exception ex) {
916
 
                                if (monitor != null)
917
 
                                        monitor.ReportError ("Error finding references", ex);
918
 
                                else
919
 
                                        LoggingService.LogError ("Error finding references", ex);
920
 
                        } finally {
921
 
                                if (monitor != null)
922
 
                                        monitor.Dispose ();
923
 
                        }
924
 
                }
925
 
                
926
 
                public void GoToBase ()
927
 
                {
928
 
                        IType cls = item as IType;
929
 
                        if (cls != null && cls.BaseTypes != null) {
930
 
                                foreach (IReturnType bc in cls.BaseTypes) {
931
 
                                        IType bcls = ctx.GetType (bc);
932
 
                                        if (bcls != null && bcls.ClassType != ClassType.Interface && !bcls.Location.IsEmpty) {
933
 
                                                IdeApp.Workbench.OpenDocument (bcls.CompilationUnit.FileName, bcls.Location.Line, bcls.Location.Column);
934
 
                                                return;
935
 
                                        }
936
 
                                }
937
 
                                return;
938
 
                        }
939
 
                        IMethod method = item as IMethod;
940
 
                        if (method != null) {
941
 
                                foreach (IReturnType bc in method.DeclaringType.BaseTypes) {
942
 
                                        IType bcls = ctx.GetType (bc);
943
 
                                        if (bcls != null && bcls.ClassType != ClassType.Interface && !bcls.Location.IsEmpty) {
944
 
                                                IMethod baseMethod = null;
945
 
                                                foreach (IMethod m in bcls.Methods) {
946
 
                                                        if (m.Name == method.Name && m.Parameters.Count == m.Parameters.Count) {
947
 
                                                                baseMethod = m;
948
 
                                                                break;
949
 
                                                        }
950
 
                                                }
951
 
                                                if (baseMethod != null)
952
 
                                                        IdeApp.Workbench.OpenDocument (bcls.CompilationUnit.FileName, baseMethod.Location.Line, baseMethod.Location.Column);
953
 
                                                return;
954
 
                                        }
955
 
                                }
956
 
                                return;
957
 
                        }
958
 
                }
959
 
                
960
 
                public void FindDerivedClasses ()
961
 
                {
962
 
                        ThreadPool.QueueUserWorkItem (FindDerivedThread);
963
 
                }
964
 
                
965
 
                void FindDerivedThread (object state)
966
 
                {
967
 
                        monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
968
 
                        using (monitor) {
969
 
                                IType cls = (IType) item;
970
 
                                if (cls == null) return;
971
 
                                
972
 
                                CodeRefactorer cr = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
973
 
                                foreach (IType sub in cr.FindDerivedClasses (cls)) {
974
 
                                        if (!sub.Location.IsEmpty) {
975
 
                                                IEditableTextFile textFile = cr.TextFileProvider.GetEditableTextFile (sub.CompilationUnit.FileName);
976
 
                                                if (textFile == null) 
977
 
                                                        textFile = new TextFile (sub.CompilationUnit.FileName);
978
 
                                                int position = textFile.GetPositionFromLineColumn (sub.Location.Line, sub.Location.Column);
979
 
                                                monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (new FileProvider (sub.CompilationUnit.FileName, sub.SourceProject as Project), position, 0));
980
 
                                        }
981
 
                                }
982
 
                        }
983
 
                }
984
 
                
985
 
                void ImplementInterface (bool explicitly)
986
 
                {
987
 
                        var doc = IdeApp.Workbench.ActiveDocument;
988
 
                        var editor = doc.Editor.Parent;
989
 
                        IType interfaceType = item as IType;
990
 
                        IType declaringType = klass;
991
 
                        
992
 
                        var mode = new Mono.TextEditor.InsertionCursorEditMode (editor, CodeGenerationService.GetInsertionPoints (doc, declaringType));
993
 
                        var helpWindow = new Mono.TextEditor.PopupWindow.ModeHelpWindow ();
994
 
                        helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
995
 
                        helpWindow.TitleText = GettextCatalog.GetString ("<b>Implement Interface -- Targeting</b>");
996
 
                        helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>")));
997
 
                        helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point.")));
998
 
                        helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point.")));
999
 
                        helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare interface implementation</b> at target point.")));
1000
 
                        helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring.")));
1001
 
                        mode.HelpWindow = helpWindow;
1002
 
                        mode.CurIndex = mode.InsertionPoints.Count - 1;
1003
 
                        mode.StartMode ();
1004
 
                        mode.Exited += delegate(object s, Mono.TextEditor.InsertionCursorEventArgs args) {
1005
 
                                if (args.Success) {
1006
 
                                        var generator = doc.CreateCodeGenerator ();
1007
 
                                        args.InsertionPoint.Insert (doc.Editor, generator.CreateInterfaceImplementation (declaringType, interfaceType, explicitly));
1008
 
                                }
1009
 
                        };
1010
 
                }
1011
 
                
1012
 
                public void ImplementImplicitInterface ()
1013
 
                {
1014
 
                        ImplementInterface (false);
1015
 
                }
1016
 
                
1017
 
                public void ImplementExplicitInterface ()
1018
 
                {
1019
 
                        ImplementInterface (true);
1020
 
                }
1021
 
                
1022
 
                public void ImplementAbstractMembers ()
1023
 
                {
1024
 
                        var doc = IdeApp.Workbench.ActiveDocument;
1025
 
                        IType interfaceType = item as IType;
1026
 
                        MonoDevelop.Refactoring.ImplementInterface.ImplementAbstractMembers.Implement (doc, interfaceType);
1027
 
                }
1028
 
                
1029
 
                public void EncapsulateField ()
1030
 
                {
1031
 
                        EncapsulateFieldDialog dialog;
1032
 
                        if (item is IField) {
1033
 
                                dialog = new EncapsulateFieldDialog (IdeApp.Workbench.ActiveDocument, ctx, (IField) item);
1034
 
                        } else {
1035
 
                                dialog = new EncapsulateFieldDialog (IdeApp.Workbench.ActiveDocument, ctx, (IType) item);
1036
 
                        }
1037
 
                        MessageService.ShowCustomDialog (dialog);
1038
 
                }
1039
 
                
1040
 
                public void OverrideOrImplementMembers ()
1041
 
                {
1042
 
                        MessageService.ShowCustomDialog (new OverridesImplementsDialog (IdeApp.Workbench.ActiveDocument, (IType)item));
1043
 
                }
1044
 
                
1045
 
                public void Rename ()
1046
 
                {
1047
 
                //      RenameItemDialog dialog = new RenameItemDialog (ctx, item);
1048
 
                //      dialog.Show ();
1049
 
                }
1050
 
        }
1051
 
*/
 
396
        }
1052
397
}