Browse Source

Add support for <MenuItem type="CheckBox"/> in WPF menus.

pull/23/head
Daniel Grunwald 14 years ago
parent
commit
5843b2b30b
  1. 10
      src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/ParallelStacksViewCommands.cs
  2. 3
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Commands/FormsCommands.cs
  3. 5
      src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs
  4. 5
      src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageViewToolbarCommands.cs
  5. 5
      src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyPadCommands.cs
  6. 1
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  7. 55
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuCheckBox.cs
  8. 3
      src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs
  9. 9
      src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs

10
src/AddIns/Debugger/Debugger.AddIn/Pads/Commands/ParallelStacksViewCommands.cs

@ -25,11 +25,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
get { return pad.IsZoomControlVisible; } get { return pad.IsZoomControlVisible; }
set { pad.IsZoomControlVisible = value; } set { pad.IsZoomControlVisible = value; }
} }
public override void Run()
{
IsChecked = !IsChecked;
}
} }
public sealed class ToggleMethodViewCommand : AbstractCheckableMenuCommand public sealed class ToggleMethodViewCommand : AbstractCheckableMenuCommand
@ -50,11 +45,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
get { return pad.IsMethodView; } get { return pad.IsMethodView; }
set { pad.IsMethodView = value; } set { pad.IsMethodView = value; }
} }
public override void Run()
{
IsChecked = !IsChecked;
}
} }
public sealed class ParallelStacksViewCommand : AbstractComboBoxCommand public sealed class ParallelStacksViewCommand : AbstractComboBoxCommand

3
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Commands/FormsCommands.cs

@ -428,9 +428,6 @@ namespace ICSharpCode.FormsDesigner.Commands
} }
} }
public override void Run()
{
}
} }
#endregion #endregion

5
src/Main/Base/Project/Src/Gui/Pads/AbstractConsolePad.cs

@ -458,10 +458,5 @@ namespace ICSharpCode.SharpDevelop.Gui
get { return pad.WordWrap; } get { return pad.WordWrap; }
set { pad.WordWrap = value; } set { pad.WordWrap = value; }
} }
public override void Run()
{
IsChecked = !IsChecked;
}
} }
} }

5
src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/CompilerMessageViewToolbarCommands.cs

@ -83,10 +83,5 @@ namespace ICSharpCode.SharpDevelop.Gui
checkBox = (ToolBarCheckBox)Owner; checkBox = (ToolBarCheckBox)Owner;
} }
} }
public override void Run()
{
IsChecked = !IsChecked;
}
} }
} }

5
src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyPadCommands.cs

@ -29,10 +29,5 @@ namespace ICSharpCode.SharpDevelop.Gui
PropertyPad.Grid.HelpVisible = value; PropertyPad.Grid.HelpVisible = value;
} }
} }
public override void Run()
{
PropertyPad.Grid.HelpVisible = !PropertyPad.Grid.HelpVisible;
}
} }
} }

1
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -72,6 +72,7 @@
</Compile> </Compile>
<Compile Include="ExtendedPopup.cs" /> <Compile Include="ExtendedPopup.cs" />
<Compile Include="GlobalStyles.cs" /> <Compile Include="GlobalStyles.cs" />
<Compile Include="Menu\MenuCheckBox.cs" />
<Compile Include="RestrictDesiredSize.cs" /> <Compile Include="RestrictDesiredSize.cs" />
<Compile Include="SortableGridViewColumn.cs" /> <Compile Include="SortableGridViewColumn.cs" />
<Compile Include="ConditionalSeparator.cs" /> <Compile Include="ConditionalSeparator.cs" />

55
src/Main/ICSharpCode.Core.Presentation/Menu/MenuCheckBox.cs

@ -0,0 +1,55 @@
// 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.Threading;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
namespace ICSharpCode.Core.Presentation
{
sealed class MenuCheckBox : CoreMenuItem
{
BindingExpressionBase isCheckedBinding;
public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller)
: base(codon, caller)
{
this.Command = CommandWrapper.GetCommand(codon, caller, true);
CommandWrapper wrapper = this.Command as CommandWrapper;
if (wrapper != null) {
ICheckableMenuCommand cmd = wrapper.GetAddInCommand() as ICheckableMenuCommand;
if (cmd != null) {
isCheckedBinding = SetBinding(IsCheckedProperty, new Binding("IsChecked") { Source = cmd, Mode = BindingMode.OneWay });
}
}
if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) {
KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]);
MenuCommand.AddGestureToInputBindingOwner(inputBindingOwner, kg, this.Command, null);
this.InputGestureText = kg.GetDisplayStringForCulture(Thread.CurrentThread.CurrentUICulture);
}
}
public override void UpdateStatus()
{
base.UpdateStatus();
if (isCheckedBinding != null)
isCheckedBinding.UpdateTarget();
}
protected override void OnClick()
{
base.OnClick();
Dispatcher.BeginInvoke(
DispatcherPriority.DataBind,
new Action(
delegate {
if (isCheckedBinding != null)
isCheckedBinding.UpdateTarget();
}));
}
}
}

3
src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs

@ -214,8 +214,7 @@ namespace ICSharpCode.Core.Presentation
case "Separator": case "Separator":
return new ConditionalSeparator(codon, descriptor.Caller, false); return new ConditionalSeparator(codon, descriptor.Caller, false);
case "CheckBox": case "CheckBox":
return "CheckBox"; return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Caller);
//return new MenuCheckBox(codon, descriptor.Caller);
case "Item": case "Item":
case "Command": case "Command":
return new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod); return new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod);

9
src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarCheckBox.cs

@ -6,6 +6,7 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading;
namespace ICSharpCode.Core.Presentation namespace ICSharpCode.Core.Presentation
{ {
@ -52,12 +53,20 @@ namespace ICSharpCode.Core.Presentation
this.Visibility = Visibility.Collapsed; this.Visibility = Visibility.Collapsed;
else else
this.Visibility = Visibility.Visible; this.Visibility = Visibility.Visible;
if (isCheckedBinding != null)
isCheckedBinding.UpdateTarget();
} }
protected override void OnClick() protected override void OnClick()
{ {
base.OnClick(); base.OnClick();
Dispatcher.BeginInvoke(
DispatcherPriority.DataBind,
new Action(
delegate {
if (isCheckedBinding != null)
isCheckedBinding.UpdateTarget(); isCheckedBinding.UpdateTarget();
}));
} }
} }
} }

Loading…
Cancel
Save