Browse Source

Replace DelegateCommand and DesignCommand with RelayCommand.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
cc470ec86e
  1. 1
      src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj
  2. 3
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcControllerToProjectViewModel.cs
  3. 9
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs
  4. 43
      src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/DelegateCommand.cs
  5. 43
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignCommand.cs
  6. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  7. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/FocusNavigator.cs
  8. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

1
src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj

@ -133,7 +133,6 @@ @@ -133,7 +133,6 @@
<Compile Include="Src\Completion\RazorCSharpResolver.cs" />
<Compile Include="Src\CurrentAppDomain.cs" />
<Compile Include="Src\CurrentAppDomainFactory.cs" />
<Compile Include="Src\DelegateCommand.cs" />
<Compile Include="Src\FileSystem.cs" />
<Compile Include="Src\Folding\CharacterReader.cs" />
<Compile Include="Src\Folding\HtmlFoldParser.cs" />

3
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcControllerToProjectViewModel.cs

@ -6,6 +6,7 @@ using System.Collections.Generic; @@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.AspNet.Mvc;
namespace ICSharpCode.AspNet.Mvc
@ -56,7 +57,7 @@ namespace ICSharpCode.AspNet.Mvc @@ -56,7 +57,7 @@ namespace ICSharpCode.AspNet.Mvc
void CreateCommands()
{
AddMvcControllerCommand = new DelegateCommand(param => AddMvcController(), param => CanAddMvcController());
AddMvcControllerCommand = new RelayCommand(AddMvcController, CanAddMvcController);
}
public ICommand AddMvcControllerCommand { get; private set; }

9
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/AddMvcViewToProjectViewModel.cs

@ -7,6 +7,7 @@ using System.Collections.ObjectModel; @@ -7,6 +7,7 @@ using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.AspNet.Mvc
{
@ -63,10 +64,10 @@ namespace ICSharpCode.AspNet.Mvc @@ -63,10 +64,10 @@ namespace ICSharpCode.AspNet.Mvc
void CreateCommands()
{
AddMvcViewCommand = new DelegateCommand(param => AddMvcView(), param => CanAddMvcView());
OpenSelectMasterPageViewCommand = new DelegateCommand(param => OpenSelectMasterPageView());
CloseSelectMasterPageViewCommand = new DelegateCommand(param => CloseSelectMasterPageView());
SelectMasterPageCommand = new DelegateCommand(param => SelectMasterPage(), param => CanSelectMasterPage());
AddMvcViewCommand = new RelayCommand(AddMvcView, CanAddMvcView);
OpenSelectMasterPageViewCommand = new RelayCommand(OpenSelectMasterPageView);
CloseSelectMasterPageViewCommand = new RelayCommand(CloseSelectMasterPageView);
SelectMasterPageCommand = new RelayCommand(SelectMasterPage, CanSelectMasterPage);
}
public ICommand AddMvcViewCommand { get; private set; }

43
src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/DelegateCommand.cs

@ -1,43 +0,0 @@ @@ -1,43 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Input;
namespace ICSharpCode.AspNet.Mvc
{
public class DelegateCommand : ICommand
{
Action<object> execute;
Predicate<object> canExecute;
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
this.execute = execute;
this.canExecute = canExecute;
}
public DelegateCommand(Action<object> execute)
: this(execute, null)
{
}
public event EventHandler CanExecuteChanged {
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
execute(parameter);
}
public bool CanExecute(object parameter)
{
if (canExecute != null) {
return canExecute(parameter);
}
return true;
}
}
}

43
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignCommand.cs

@ -1,43 +0,0 @@ @@ -1,43 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Input;
using System.Diagnostics;
namespace ICSharpCode.WpfDesign.Designer
{
/// <summary>
/// Custom implementation of ICommand based on the RelayCommand model by Josh Smith for the designer.
/// </summary>
public class DesignCommand : ICommand
{
private readonly Action<object> _action;
private readonly Func<object, bool> _canExecute;
public DesignCommand(Action<object> action,Func<object,bool> canExecute)
{
Debug.Assert(action != null);
this._action = action;
this._canExecute = canExecute;
}
public void Execute(object parameter)
{
_action(parameter);
}
public bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute(parameter);
return true;
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Adorners;
@ -30,13 +31,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -30,13 +31,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
this.AddAdorners(placement, _menu);
var kbs = this.ExtendedItem.Services.GetService(typeof (IKeyBindingService)) as IKeyBindingService;
var command = new DesignCommand(delegate
var command = new RelayCommand(delegate
{
_menu.MainHeader.IsSubmenuOpen = true;
_menu.MainHeader.Focus();
}, delegate
{
return true;
});
_keyBinding=new KeyBinding(command, Key.Enter, ModifierKeys.Alt);
if (kbs != null)

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/FocusNavigator.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Widgets;
namespace ICSharpCode.WpfDesign.Designer
{
@ -30,8 +31,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -30,8 +31,8 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public void Start()
{
DesignCommand tabFocus = new DesignCommand(parameter => this.MoveFocusForward(_surface), parameter => CanMoveFocusForward(_surface));
DesignCommand shiftTabFocus = new DesignCommand(parameter => this.MoveFocusBack(_surface), parameter => this.CanMoveFocusBack(_surface));
var tabFocus = new RelayCommand(this.MoveFocusForward, this.CanMoveFocusForward);
var shiftTabFocus = new RelayCommand(this.MoveFocusBack, this.CanMoveFocusBack);
_tabBinding = new KeyBinding(tabFocus, new KeyGesture(Key.Tab));
_shiftTabBinding = new KeyBinding(shiftTabFocus, new KeyGesture(Key.Tab, ModifierKeys.Shift));
IKeyBindingService kbs = _surface.DesignContext.Services.GetService(typeof(IKeyBindingService)) as IKeyBindingService;
@ -58,9 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -58,9 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Moves the Foucus down the tree.
/// </summary>
void MoveFocusForward(object surface)
void MoveFocusForward()
{
var designSurface = surface as DesignSurface;
var designSurface = _surface;
if (designSurface != null) {
var context = designSurface.DesignContext;
ISelectionService selection=context.Services.Selection;
@ -106,9 +107,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -106,9 +107,9 @@ namespace ICSharpCode.WpfDesign.Designer
/// Checks if focus navigation should be for down-the-tree be done.
/// </summary>
/// <param name="surface">Design Surface</param>
bool CanMoveFocusForward(object surface)
bool CanMoveFocusForward()
{
var designSurface = surface as DesignSurface;
var designSurface = _surface;
if (designSurface != null)
if (Keyboard.FocusedElement == designSurface._designPanel)
return true;
@ -118,9 +119,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -118,9 +119,9 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Moves focus up-the-tree.
/// </summary>
void MoveFocusBack(object surface)
void MoveFocusBack()
{
var designSurface = surface as DesignSurface;
var designSurface = _surface;
if (designSurface != null) {
var context = designSurface.DesignContext;
ISelectionService selection = context.Services.Selection;
@ -158,9 +159,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -158,9 +159,9 @@ namespace ICSharpCode.WpfDesign.Designer
/// Checks if focus navigation for the up-the-tree should be done.
/// </summary>
/// <param name="surface">Design Surface</param>
bool CanMoveFocusBack(object surface)
bool CanMoveFocusBack()
{
var designSurface = surface as DesignSurface;
var designSurface = _surface;
if (designSurface != null)
if (Keyboard.FocusedElement == designSurface._designPanel)
return true;

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -108,7 +108,6 @@ @@ -108,7 +108,6 @@
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="Controls\ZoomControl.cs" />
<Compile Include="Converters.cs" />
<Compile Include="DesignCommand.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="DesignSurface.xaml.cs">
<DependentUpon>DesignSurface.xaml</DependentUpon>

Loading…
Cancel
Save