From 47eb1adee80b36b9b1268252b5e8cdbff4447c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kon=C3=AD=C4=8Dek?= Date: Sun, 1 Aug 2010 17:07:41 +0000 Subject: [PATCH] Derived classes etc. popup opens at cursor position again. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6357 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../ContextActions/ContextActionsPopup.cs | 32 ++++++++++++++++--- .../ContextActionsHelper.cs | 6 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs index adbe7f8102..02674a2192 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsPopup.cs @@ -8,8 +8,9 @@ using System; using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Input; - +using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Gui; namespace ICSharpCode.SharpDevelop.Refactoring { @@ -18,6 +19,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// public class ContextActionsPopup : ContextActionsPopupBase { + /// + /// DOM Entity (IClass, IMember etc.) for which this popup is displayed. + /// + public IEntity Symbol { get; set; } + public ContextActionsPopup() { // Close on lost focus @@ -37,8 +43,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring public ContextActionsViewModel Actions { get { return (ContextActionsViewModel)ActionsControl.DataContext; } - set { - ActionsControl.DataContext = value; + set { + ActionsControl.DataContext = value; } } @@ -49,10 +55,26 @@ namespace ICSharpCode.SharpDevelop.Refactoring public void OpenAtCaretAndFocus() { - OpenAtMousePosition(); - //OpenAtPosition(editor, editor.Caret.Line, editor.Caret.Column, true); + ITextEditor currentEditor = GetCurrentEditor(); + if (currentEditor == null) { + OpenAtMousePosition(); + return; + } + // Should look if symbol under caret is the same as this.Symbol, so that when opened from class browser, popup opens at mouse pos + //var rr = ParserService.Resolve(currentEditor.Caret.Offset, currentEditor.Document, currentEditor.FileName); + OpenAtPosition(currentEditor, currentEditor.Caret.Line, currentEditor.Caret.Column, true); this.Focus(); } + + ITextEditor GetCurrentEditor() + { + if (WorkbenchSingleton.Workbench == null) + return null; + var activeViewContent = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; + if (activeViewContent == null) + return null; + return activeViewContent.TextEditor; + } void OpenAtMousePosition() { diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs index 149da82fcb..c0002d02bf 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActionsHelper.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse( "${res:SharpDevelop.Refactoring.ClassesDerivingFrom}", new StringTagPair("Name", baseClass.Name)))}; popupViewModel.Actions = new PopupTreeViewModelBuilder().BuildTreeViewModel(derivedClassesTree); - return new ContextActionsPopup { Actions = popupViewModel }; + return new ContextActionsPopup { Actions = popupViewModel, Symbol = baseClass }; } public static ContextActionsPopup MakePopupWithBaseClasses(IClass @class) @@ -37,7 +37,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse( "${res:SharpDevelop.Refactoring.BaseClassesOf}", new StringTagPair("Name", @class.Name)))}; popupViewModel.Actions = new PopupListViewModelBuilder().BuildListViewModel(baseClassList); - return new ContextActionsPopup { Actions = popupViewModel }; + return new ContextActionsPopup { Actions = popupViewModel, Symbol = @class }; } public static ContextActionsPopup MakePopupWithOverrides(IMember member) @@ -46,7 +46,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse( "${res:SharpDevelop.Refactoring.OverridesOf}", new string[,] {{ "Name", member.FullyQualifiedName }}))}; popupViewModel.Actions = new OverridesPopupTreeViewModelBuilder(member).BuildTreeViewModel(derivedClassesTree); - return new ContextActionsPopup { Actions = popupViewModel }; + return new ContextActionsPopup { Actions = popupViewModel, Symbol = member }; } class PopupViewModelBuilder