diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs index fcd5af6e66..e8be8d8b5a 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActionsRenderer.cs @@ -68,36 +68,28 @@ namespace ICSharpCode.AvalonEdit.AddIn void ContextActionsRenderer_KeyDown(object sender, KeyEventArgs e) { + if (this.popup == null) + return; if (e.Key == Key.T && Keyboard.Modifiers == ModifierKeys.Control) { - if (popup != null && popup.Actions != null && popup.Actions.Actions != null && popup.Actions.Actions.Count > 0) { + if (popup.ViewModel != null && popup.ViewModel.Actions != null && popup.ViewModel.Actions.Count > 0) { popup.IsDropdownOpen = true; popup.Focus(); + } else { + // Popup is not shown but user explicitely requests it + var popupVM = BuildPopupViewModel(this.Editor); + popupVM.LoadHiddenActions(); + if (popupVM.HiddenActions.Count == 0) + return; + this.popup.ViewModel = popupVM; + this.popup.IsDropdownOpen = true; + this.popup.IsHiddenActionsExpanded = true; + this.popup.OpenAtLineStart(this.Editor); + this.popup.Focus(); } } } - void WorkbenchSingleton_Workbench_ViewClosed(object sender, ViewContentEventArgs e) - { - try { - // prevent memory leaks - if (e.Content.PrimaryFileName == this.Editor.FileName) { - WorkbenchSingleton.Workbench.ViewClosed -= WorkbenchSingleton_Workbench_ViewClosed; - WorkbenchSingleton.Workbench.ActiveViewContentChanged -= WorkbenchSingleton_Workbench_ActiveViewContentChanged; - } - } catch {} - } - - void WorkbenchSingleton_Workbench_ActiveViewContentChanged(object sender, EventArgs e) - { - ClosePopup(); - try { - // open the popup again if in current file - if (((IViewContent)WorkbenchSingleton.Workbench.ActiveContent).PrimaryFileName == this.Editor.FileName) - CaretPositionChanged(this, EventArgs.Empty); - } catch {} - } - void ScrollChanged(object sender, EventArgs e) { ClosePopup(); @@ -109,19 +101,22 @@ namespace ICSharpCode.AvalonEdit.AddIn if (!IsEnabled) return; ClosePopup(); - var availableActions = ContextActionsService.Instance.GetAvailableActions(this.Editor); - var availableActionsVM = new ObservableCollection( - availableActions.Select(a => new ContextActionViewModel(a))); - if (availableActionsVM.Count == 0) - return; - this.popup.Actions = new ContextActionsViewModel { - //Image = ClassBrowserIconService.Class.ImageSource, - Actions = availableActionsVM - }; + ContextActionsHiddenViewModel popupVM = BuildPopupViewModel(this.Editor); + //availableActionsVM.Title = + //availableActionsVM.Image = + if (popupVM.Actions.Count == 0) + return; + this.popup.ViewModel = popupVM; this.popup.OpenAtLineStart(this.Editor); } + ContextActionsHiddenViewModel BuildPopupViewModel(ITextEditor editor) + { + var actionsProvider = ContextActionsService.Instance.GetAvailableActions(editor); + return new ContextActionsHiddenViewModel(actionsProvider); + } + void CaretPositionChanged(object sender, EventArgs e) { if (this.popup.IsOpen) @@ -136,7 +131,29 @@ namespace ICSharpCode.AvalonEdit.AddIn { this.popup.Close(); this.popup.IsDropdownOpen = false; - this.popup.Actions = null; + this.popup.IsHiddenActionsExpanded = false; + this.popup.ViewModel = null; + } + + void WorkbenchSingleton_Workbench_ViewClosed(object sender, ViewContentEventArgs e) + { + try { + // prevent memory leaks + if (e.Content.PrimaryFileName == this.Editor.FileName) { + WorkbenchSingleton.Workbench.ViewClosed -= WorkbenchSingleton_Workbench_ViewClosed; + WorkbenchSingleton.Workbench.ActiveViewContentChanged -= WorkbenchSingleton_Workbench_ActiveViewContentChanged; + } + } catch {} + } + + void WorkbenchSingleton_Workbench_ActiveViewContentChanged(object sender, EventArgs e) + { + ClosePopup(); + try { + // open the popup again if in current file + if (((IViewContent)WorkbenchSingleton.Workbench.ActiveContent).PrimaryFileName == this.Editor.FileName) + CaretPositionChanged(this, EventArgs.Empty); + } catch {} } } } diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/AddUsing.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/AddUsing.cs index dddc29481b..b2ec2f25ac 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/AddUsing.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/AddUsing.cs @@ -16,9 +16,9 @@ namespace SharpRefactoring.ContextActions /// /// Description of AddUsing. /// - public class AddUsingProvider : IContextActionsProvider + public class AddUsingProvider : ContextActionsProvider { - public IEnumerable GetAvailableActions(EditorContext context) + public override IEnumerable GetAvailableActions(EditorContext context) { var currentLineAST = context.CurrentLineAST; if (currentLineAST == null) diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/CacheClassAtCaret.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/CacheClassAtCaret.cs index 3c0be26ea2..820dae0577 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/CacheClassAtCaret.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/CacheClassAtCaret.cs @@ -47,6 +47,7 @@ namespace SharpRefactoring.ContextActions public void Initialize(EditorContext context) { + // class at caret (either declaration of usage) this.Class = GetClass(context.CurrentSymbol); if (this.Class == null) return; diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs index 4377b907af..b36586221d 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/GenerateMember.cs @@ -16,9 +16,9 @@ namespace SharpRefactoring.ContextActions /// /// Description of GenerateMember. /// - public class GenerateMemberProvider : IContextActionsProvider + public class GenerateMemberProvider : ContextActionsProvider { - public IEnumerable GetAvailableActions(EditorContext context) + public override IEnumerable GetAvailableActions(EditorContext context) { if (string.IsNullOrEmpty(context.CurrentExpression.Expression)) { yield break; diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs index a6693a4e6d..dff5a8e69d 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementAbstractClass.cs @@ -19,9 +19,9 @@ namespace SharpRefactoring.ContextActions /// /// Description of ImplementAbstractClass. /// - public class ImplementAbstractClassProvider : IContextActionsProvider + public class ImplementAbstractClassProvider : ContextActionsProvider { - public IEnumerable GetAvailableActions(EditorContext editorContext) + public override IEnumerable GetAvailableActions(EditorContext editorContext) { var ambience = AmbienceService.GetCurrentAmbience(); diff --git a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs index 50cc958e4f..059c126b8b 100644 --- a/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs +++ b/src/AddIns/Misc/SharpRefactoring/Project/Src/ContextActions/ImplementInterface.cs @@ -22,9 +22,9 @@ namespace SharpRefactoring.ContextActions /// /// Description of ImplementInterface. /// - public class ImplementInterfaceProvider : IContextActionsProvider + public class ImplementInterfaceProvider : ContextActionsProvider { - public IEnumerable GetAvailableActions(EditorContext editorContext) + public override IEnumerable GetAvailableActions(EditorContext editorContext) { // Using CurrentLineAST is basically OK, but when the "class" keyword is on different line than class name, // parsing only one line never tells us that we are looking at TypeDeclaration diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 0c3525a925..a2356e011b 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -341,7 +341,9 @@ ContextActionsHeaderedControl.xaml Code + + diff --git a/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs b/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs index d4b2f50b7b..2cd340abc3 100644 --- a/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs +++ b/src/Main/Base/Project/Src/Commands/FileTabStripCommands.cs @@ -84,8 +84,9 @@ namespace ICSharpCode.SharpDevelop.Commands.TabStrip { public override void Run() { - var c = ProjectBrowserPad.Instance.Control as ProjectBrowserPanel; - c.ProjectBrowserControl.SelectFileAndExpand(((IWorkbenchWindow)Owner).ActiveViewContent.PrimaryFileName); + var projectBrowser = (ProjectBrowserPad.Instance.Control as ProjectBrowserPanel).ProjectBrowserControl; + projectBrowser.SelectFileAndExpand(((IWorkbenchWindow)Owner).ActiveViewContent.PrimaryFileName); + projectBrowser.Focus(); } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs index 7768354a07..d4b513435c 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs @@ -257,7 +257,6 @@ namespace ICSharpCode.SharpDevelop.Project // Node for this file does not exist yet (the tree view is lazy loaded) SelectDeepestOpenNodeForPath(fileName); } - this.Focus(); } finally { inSelectFile = false; } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextAction.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextAction.cs index 1fd0cf6f68..04e5f42121 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextAction.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextAction.cs @@ -16,6 +16,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring { public abstract string Title { get; } + public bool IsVisible { get; set; } + public abstract bool IsAvailable(EditorContext context); public abstract void Execute(EditorContext context); diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs index d0e7ed16f1..65f73f19c4 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionViewModel.cs @@ -20,6 +20,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring { public ContextActionViewModel() { + this.IsVisible = true; } public ContextActionViewModel(IContextAction action) @@ -35,6 +36,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring public ImageSource Image { get; set; } + /// + /// Is this action enabled to be offered automatically? + /// + public bool IsVisible { get; set; } + public ObservableCollection ChildActions { get; set; } IContextAction action; diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml index f03f2bb1a9..53cc607f8c 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml @@ -6,14 +6,137 @@ + M 0 0 L 2 3 L 4 0 Z + + + + + @@ -37,7 +160,7 @@ - + - + + + + \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs index 583adcbf55..5605cb6c53 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbControl.xaml.cs @@ -33,6 +33,12 @@ namespace ICSharpCode.SharpDevelop.Refactoring remove { this.ActionsTreeView.ActionExecuted -= value; } } + public new ContextActionsHiddenViewModel DataContext + { + get { return (ContextActionsHiddenViewModel)base.DataContext; } + set { base.DataContext = value; } + } + bool isOpen; public bool IsOpen { get { return isOpen; } @@ -40,10 +46,18 @@ namespace ICSharpCode.SharpDevelop.Refactoring isOpen = value; this.Header.Opacity = isOpen ? 1.0 : 0.7; this.Header.BorderThickness = isOpen ? new Thickness(1, 1, 1, 0) : new Thickness(1); - this.ActionsTreeView.Visibility = isOpen ? Visibility.Visible : Visibility.Collapsed; + // Show / hide + this.ActionsTreeView.Visibility = this.HiddenActionsExpander.Visibility = + isOpen ? Visibility.Visible : Visibility.Collapsed; } } + public bool IsHiddenActionsExpanded + { + get { return this.HiddenActionsExpander.IsExpanded; } + set { this.HiddenActionsExpander.IsExpanded = value; } + } + public new void Focus() { if (this.ActionsTreeView != null) @@ -54,5 +68,27 @@ namespace ICSharpCode.SharpDevelop.Refactoring { this.IsOpen = !this.IsOpen; } + + void ActionsTreeView_ActionVisibleChanged(object sender, ContextActionViewModelEventArgs e) + { + var clickedAction = e.Action; + this.DataContext.Model.SetVisible(clickedAction.Action, false); +// this.DataContext.Actions.Remove(clickedAction); +// this.DataContext.HiddenActions.Add(clickedAction); + + } + + void HiddenActionsTreeView_ActionVisibleChanged(object sender, ContextActionViewModelEventArgs e) + { + var clickedAction = e.Action; + this.DataContext.Model.SetVisible(clickedAction.Action, true); +// this.DataContext.HiddenActions.Remove(clickedAction); +// this.DataContext.Actions.Add(clickedAction); + } + + void Expander_Expanded(object sender, RoutedEventArgs e) + { + this.DataContext.LoadHiddenActions(); + } } } \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs index 4577d593cd..8092cac412 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsBulbPopup.cs @@ -18,30 +18,34 @@ namespace ICSharpCode.SharpDevelop.Refactoring { this.StaysOpen = true; this.AllowsTransparency = true; - this.ActionsControl = new ContextActionsBulbControl(); + this.ChildControl = new ContextActionsBulbControl(); // Close when any action excecuted - this.ActionsControl.ActionExecuted += delegate { this.Close(); }; + this.ChildControl.ActionExecuted += delegate { this.Close(); }; } - public ContextActionsBulbControl ActionsControl + private new ContextActionsBulbControl ChildControl { get { return (ContextActionsBulbControl)this.Child; } set { this.Child = value; } } - public ContextActionsViewModel Actions + public ContextActionsHiddenViewModel ViewModel { - get { return (ContextActionsViewModel)ActionsControl.DataContext; } - set { - ActionsControl.DataContext = value; - } + get { return (ContextActionsHiddenViewModel)this.DataContext; } + set { this.DataContext = value; } } - public bool IsDropdownOpen { get { return ActionsControl.IsOpen; } set {ActionsControl.IsOpen = value; } } + public bool IsDropdownOpen { get { return ChildControl.IsOpen; } set {ChildControl.IsOpen = value; } } + + public bool IsHiddenActionsExpanded { get { return ChildControl.IsHiddenActionsExpanded; } set {ChildControl.IsHiddenActionsExpanded = value; } } public new void Focus() { - this.ActionsControl.Focus(); + if (this.ViewModel.Actions.Count > 0) { + this.ChildControl.ActionsTreeView.Focus(); + } else { + this.ChildControl.HiddenActionsTreeView.Focus(); + } } public void OpenAtLineStart(ITextEditor editor) diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml index 4f1a481b92..28a8115763 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml @@ -6,11 +6,9 @@ xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> - + - - - - - + @@ -102,15 +98,14 @@ - + + + - - - - + \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs index d4065b9c73..d3ade5037f 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsControl.xaml.cs @@ -57,5 +57,31 @@ namespace ICSharpCode.SharpDevelop.Refactoring } return null; } + + public event EventHandler ActionVisibleChanged; + + void CheckBox_Changed(object sender, RoutedEventArgs e) + { + var contextActionVM = (ContextActionViewModel)((CheckBox)sender).DataContext; + if (ActionVisibleChanged != null) + ActionVisibleChanged(sender, new ContextActionViewModelEventArgs(contextActionVM)); + } + + void CheckBox_Click(object sender, RoutedEventArgs e) + { + e.Handled = true; + } + } + + public class ContextActionViewModelEventArgs : EventArgs + { + public ContextActionViewModel Action { get; private set; } + + public ContextActionViewModelEventArgs(ContextActionViewModel action) + { + if (action == null) + throw new ArgumentNullException("action"); + this.Action = action; + } } } \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml index 8044f150a8..378f99ed35 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHeaderedControl.xaml @@ -1,8 +1,8 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Refactoring" + xmlns:aero="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"> @@ -18,7 +18,7 @@ - @@ -32,7 +32,13 @@ - - + + + + + + + + \ No newline at end of file diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHiddenViewModel.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHiddenViewModel.cs new file mode 100644 index 0000000000..7b48275898 --- /dev/null +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsHiddenViewModel.cs @@ -0,0 +1,42 @@ +// +// +// +// +// $Revision: $ +// +using System; +using System.Collections.ObjectModel; +using System.Linq; + +namespace ICSharpCode.SharpDevelop.Refactoring +{ + /// + /// Description of ContextActionsHiddenViewModel. + /// + public class ContextActionsHiddenViewModel : ContextActionsViewModel + { + public EditorActionsProvider Model { get; private set; } + + public ObservableCollection HiddenActions { get; set; } + + public ContextActionsHiddenViewModel(EditorActionsProvider model) + { + this.Model = model; + this.Actions = new ObservableCollection( + model.GetVisibleActions().Select(a => new ContextActionViewModel(a) { IsVisible = true } )); + this.HiddenActions = new ObservableCollection(); + } + + bool hiddenActionsLoaded = false; + + public void LoadHiddenActions() + { + if (hiddenActionsLoaded) + return; + + this.HiddenActions.AddRange( + Model.GetHiddenActions().Select(a => new ContextActionViewModel(a) { IsVisible = false } )); + hiddenActionsLoaded = true; + } + } +} diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsProvider.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsProvider.cs new file mode 100644 index 0000000000..0d955bebd4 --- /dev/null +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsProvider.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision: $ +// +using System; +using System.Collections.Generic; +using ICSharpCode.SharpDevelop.Refactoring; + +namespace ICSharpCode.SharpDevelop.Refactoring +{ + /// + /// Description of ContextActionsProvider. + /// + public abstract class ContextActionsProvider : IContextActionsProvider + { + public bool IsVisible { get; set; } + + public abstract IEnumerable GetAvailableActions(EditorContext context); + } +} diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs index 3ba22e15f6..6e1d0da380 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsService.cs @@ -32,32 +32,81 @@ namespace ICSharpCode.SharpDevelop.Refactoring private ContextActionsService() { this.providers = AddInTree.BuildItems("/SharpDevelop/ViewContent/AvalonEdit/ContextActions", null, false); + foreach (var provider in providers) { + // load from configuration + provider.IsVisible = true; + } + } + + public EditorActionsProvider GetAvailableActions(ITextEditor editor) + { + return new EditorActionsProvider(editor, this.providers); + } + } + + + public class EditorActionsProvider + { + ITextEditor editor { get; set; } + IList providers { get; set; } + EditorContext context { get; set; } + + public EditorActionsProvider(ITextEditor editor, IList providers) + { + if (editor == null) + throw new ArgumentNullException("editor"); + if (providers == null) + throw new ArgumentNullException("providers"); + this.editor = editor; + this.providers = providers; + ParserService.ParseCurrentViewContent(); + this.context = new EditorContext(editor); + } + + public IEnumerable GetVisibleActions() + { + return GetActions(this.providers.Where(p => p.IsVisible)); + } + + public IEnumerable GetHiddenActions() + { + return GetActions(this.providers.Where(p => !p.IsVisible)); } + public void SetVisible(IContextAction action, bool isVisible) + { + IContextActionsProvider provider; + if (providerForAction.TryGetValue(action, out provider)) { + provider.IsVisible = isVisible; + } + } + + Dictionary providerForAction = new Dictionary(); + /// /// Gets actions available for current caret position in the editor. /// - public IEnumerable GetAvailableActions(ITextEditor editor) + IEnumerable GetActions(IEnumerable providers) { if (ParserService.LoadSolutionProjectsThreadRunning) yield break; - ParserService.ParseCurrentViewContent(); // DO NOT USE Wait on the main thread! // causes deadlocks! //parseTask.Wait(); var sw = new Stopwatch(); sw.Start(); - var editorContext = new EditorContext(editor); + var editorContext = new EditorContext(this.editor); long elapsedEditorContextMs = sw.ElapsedMilliseconds; // could run providers in parallel - foreach (var provider in this.providers) { + foreach (var provider in providers) { foreach (var action in provider.GetAvailableActions(editorContext)) { + providerForAction[action] = provider; yield return action; } } - ICSharpCode.Core.LoggingService.Debug(string.Format("Context actions elapsed {0}ms ({1}ms in EditorContext)", - sw.ElapsedMilliseconds, elapsedEditorContextMs)); +// ICSharpCode.Core.LoggingService.Debug(string.Format("Context actions elapsed {0}ms ({1}ms in EditorContext)", +// sw.ElapsedMilliseconds, elapsedEditorContextMs)); } } } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsViewModel.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsViewModel.cs index ee8f384d90..f9b310f8ff 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsViewModel.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/ContextActionsViewModel.cs @@ -20,6 +20,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring public string Title { get; set; } - public ObservableCollection Actions { get; set; } + public ObservableCollection Actions { get; set; } } } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextAction.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextAction.cs index 42f53a2fd8..721dab7e24 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextAction.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextAction.cs @@ -15,7 +15,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring public interface IContextAction { string Title { get; } - //string Id { get; } void Execute(); } } diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextActionsProvider.cs b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextActionsProvider.cs index 0036c55ba7..cffbfe6c07 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextActionsProvider.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/ContextActions/IContextActionsProvider.cs @@ -20,5 +20,10 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// Gets actions available for current line of the editor. /// IEnumerable GetAvailableActions(EditorContext context); + + /// + /// Is this provider enabled by user? + /// + bool IsVisible { get; set; } } }