From 0a6a63e58e26f43272e198a1e0d38237cd162980 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 24 Aug 2013 18:01:07 +0200 Subject: [PATCH] reimplement Copy and SelectAll commands --- .../Src/Gui/Pads/ErrorList/ErrorListPad.cs | 40 +++++++---------- .../Src/Gui/Pads/TaskList/TaskListPad.cs | 44 ++++++++----------- 2 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Pads/ErrorList/ErrorListPad.cs b/src/Main/Base/Project/Src/Gui/Pads/ErrorList/ErrorListPad.cs index b06341c021..77b87c6eab 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ErrorList/ErrorListPad.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ErrorList/ErrorListPad.cs @@ -6,15 +6,15 @@ using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using ICSharpCode.Core; using ICSharpCode.Core.Presentation; using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.SharpDevelop.WinForms; using ICSharpCode.SharpDevelop.Workbench; namespace ICSharpCode.SharpDevelop.Gui { - public class ErrorListPad : AbstractPadContent, IClipboardHandler + public class ErrorListPad : AbstractPadContent { public const string DefaultContextMenuAddInTreeEntry = "/SharpDevelop/Pads/ErrorList/TaskContextMenu"; @@ -105,6 +105,9 @@ namespace ICSharpCode.SharpDevelop.Gui errorView.Style = (Style)new TaskViewResources()["TaskListView"]; errorView.ContextMenu = MenuService.CreateContextMenu(this, DefaultContextMenuAddInTreeEntry); + errorView.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, ExecuteCopy, CanExecuteCopy)); + errorView.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, ExecuteSelectAll, CanExecuteSelectAll)); + errors.CollectionChanged += delegate { MenuService.UpdateText(toolBar.Items); }; InternalShowResults(); @@ -196,35 +199,24 @@ namespace ICSharpCode.SharpDevelop.Gui } } - #region IClipboardHandler interface implementation - public bool EnableCut { - get { return false; } - } - public bool EnableCopy { - get { return errorView.SelectedItem != null; } - } - public bool EnablePaste { - get { return false; } - } - public bool EnableDelete { - get { return false; } - } - public bool EnableSelectAll { - get { return true; } + void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs e) + { + e.CanExecute = errorView.SelectedItem != null; } - public void Cut() {} - public void Paste() {} - public void Delete() {} - - public void Copy() + void ExecuteCopy(object sender, ExecutedRoutedEventArgs e) { TaskViewResources.CopySelectionToClipboard(errorView); } - public void SelectAll() + + void CanExecuteSelectAll(object sender, CanExecuteRoutedEventArgs e) + { + e.CanExecute = true; + } + + void ExecuteSelectAll(object sender, ExecutedRoutedEventArgs e) { errorView.SelectAll(); } - #endregion } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskListPad.cs b/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskListPad.cs index 59a12beefa..5ec5690716 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskListPad.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/TaskList/TaskListPad.cs @@ -9,16 +9,16 @@ using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Input; using ICSharpCode.Core.Presentation; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.SharpDevelop.WinForms; using ICSharpCode.SharpDevelop.Workbench; namespace ICSharpCode.SharpDevelop.Gui { - public class TaskListPad : AbstractPadContent, IClipboardHandler + public class TaskListPad : AbstractPadContent { public const string DefaultContextMenuAddInTreeEntry = "/SharpDevelop/Pads/TaskList/TaskContextMenu"; @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Gui readonly ObservableCollection tasks; IUnresolvedTypeDefinition oldClass; int selectedScopeIndex = 0; - bool isInitialized = false; + bool isInitialized; public bool IsInitialized { get { return isInitialized; } @@ -151,9 +151,12 @@ namespace ICSharpCode.SharpDevelop.Gui taskView.MouseDoubleClick += TaskViewMouseDoubleClick; taskView.Style = (Style)new TaskViewResources()["TaskListView"]; taskView.ContextMenu = MenuService.CreateContextMenu(taskView, DefaultContextMenuAddInTreeEntry); + + taskView.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, ExecuteCopy, CanExecuteCopy)); + taskView.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, ExecuteSelectAll, CanExecuteSelectAll)); } - void TaskViewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) + void TaskViewMouseDoubleClick(object sender, MouseButtonEventArgs e) { SDTask task = taskView.SelectedItem as SDTask; var item = taskView.ItemContainerGenerator.ContainerFromItem(task) as ListViewItem; @@ -276,36 +279,25 @@ namespace ICSharpCode.SharpDevelop.Gui } } - #region IClipboardHandler interface implementation - public bool EnableCut { - get { return false; } - } - public bool EnableCopy { - get { return taskView.SelectedItem != null; } - } - public bool EnablePaste { - get { return false; } - } - public bool EnableDelete { - get { return false; } - } - public bool EnableSelectAll { - get { return true; } + void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs e) + { + e.CanExecute = taskView.SelectedItem != null; } - public void Cut() {} - public void Paste() {} - public void Delete() {} - - public void Copy() + void ExecuteCopy(object sender, ExecutedRoutedEventArgs e) { TaskViewResources.CopySelectionToClipboard(taskView); } - public void SelectAll() + + void CanExecuteSelectAll(object sender, CanExecuteRoutedEventArgs e) + { + e.CanExecute = true; + } + + void ExecuteSelectAll(object sender, ExecutedRoutedEventArgs e) { taskView.SelectAll(); } - #endregion } }