Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0wpf@3298 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
13 changed files with 431 additions and 54 deletions
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
<Window x:Class = "ICSharpCode.SharpDevelop.Gui.WpfWorkbench" |
||||
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:corePresentation = "clr-namespace:ICSharpCode.Core.Presentation;assembly=ICSharpCode.Core.Presentation" |
||||
Title = "SharpDevelop (experimental WPF build)" |
||||
WindowStartupLocation = "Manual" |
||||
> |
||||
<Window.Resources> |
||||
<Style TargetType="{x:Type Image}" x:Key="{x:Static corePresentation:ToolBarService.ImageStyleKey}"> |
||||
<Style.Triggers> |
||||
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False"> |
||||
<Setter Property="Opacity" Value="0.50" /> |
||||
</DataTrigger> |
||||
</Style.Triggers> |
||||
</Style> |
||||
</Window.Resources> |
||||
<DockPanel Name="dockPanel"> |
||||
<Menu Name="mainMenu" DockPanel.Dock="Top"/> |
||||
<!-- Toolbars --> |
||||
<ContentControl Name="mainContent"/> |
||||
</DockPanel> |
||||
</Window> |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// A Separator that is invisible when it is excluded by a condition.
|
||||
/// </summary>
|
||||
sealed class ConditionalSeparator : Separator, IStatusUpdate |
||||
{ |
||||
readonly Codon codon; |
||||
readonly object caller; |
||||
|
||||
public ConditionalSeparator(Codon codon, object caller, bool inToolbar) |
||||
{ |
||||
this.codon = codon; |
||||
this.caller = caller; |
||||
|
||||
if (inToolbar) { |
||||
SetResourceReference(FrameworkElement.StyleProperty, ToolBar.SeparatorStyleKey); |
||||
} |
||||
} |
||||
|
||||
public void UpdateText() |
||||
{ |
||||
} |
||||
|
||||
public void UpdateStatus() |
||||
{ |
||||
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude) |
||||
this.Visibility = Visibility.Collapsed; |
||||
else |
||||
this.Visibility = Visibility.Visible; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
public interface IStatusUpdate |
||||
{ |
||||
void UpdateText(); |
||||
void UpdateStatus(); |
||||
} |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
class MenuCommand : CoreMenuItem |
||||
{ |
||||
ICommand menuCommand; |
||||
|
||||
public MenuCommand(Codon codon, object caller, bool createCommand) : base(codon, caller) |
||||
{ |
||||
if (createCommand) { |
||||
CreateCommand(); |
||||
} |
||||
} |
||||
|
||||
protected override bool IsEnabledCore { |
||||
get { |
||||
if (!base.IsEnabledCore) |
||||
return false; |
||||
|
||||
if (menuCommand != null && menuCommand is IMenuCommand) { |
||||
return ((IMenuCommand)menuCommand).IsEnabled; |
||||
} else { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void CreateCommand() |
||||
{ |
||||
try { |
||||
string link = codon.Properties["link"]; |
||||
if (link != null && link.Length > 0) { |
||||
if (MenuService.LinkCommandCreator == null) |
||||
throw new NotSupportedException("MenuCommand.LinkCommandCreator is not set, cannot create LinkCommands."); |
||||
menuCommand = MenuService.LinkCommandCreator(codon.Properties["link"]); |
||||
} else { |
||||
menuCommand = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]); |
||||
} |
||||
if (menuCommand != null) { |
||||
menuCommand.Owner = caller; |
||||
} |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e, "Can't create menu command : " + codon.Id); |
||||
} |
||||
} |
||||
|
||||
protected override void OnClick() |
||||
{ |
||||
base.OnClick(); |
||||
if (menuCommand == null) { |
||||
CreateCommand(); |
||||
} |
||||
if (menuCommand != null && IsEnabledCore) { |
||||
menuCommand.Run(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
sealed class ToolBarButton : Button, IStatusUpdate |
||||
{ |
||||
readonly Codon codon; |
||||
readonly object caller; |
||||
ICommand menuCommand; |
||||
|
||||
public ToolBarButton(Codon codon, object caller, bool createCommand) |
||||
{ |
||||
ToolTipService.SetShowOnDisabled(this, true); |
||||
|
||||
this.codon = codon; |
||||
this.caller = caller; |
||||
|
||||
if (createCommand) { |
||||
CreateCommand(); |
||||
} |
||||
|
||||
if (codon.Properties.Contains("icon")) { |
||||
Image image = new Image { |
||||
Source = PresentationResourceService.GetBitmapSource(StringParser.Parse(codon.Properties["icon"])), |
||||
Height = 16 |
||||
}; |
||||
image.SetResourceReference(StyleProperty, ToolBarService.ImageStyleKey); |
||||
this.Content = image; |
||||
} |
||||
UpdateText(); |
||||
|
||||
SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ButtonStyleKey); |
||||
} |
||||
|
||||
protected override void OnClick() |
||||
{ |
||||
base.OnClick(); |
||||
if (menuCommand == null) { |
||||
CreateCommand(); |
||||
} |
||||
if (menuCommand != null) { |
||||
menuCommand.Run(); |
||||
} |
||||
} |
||||
|
||||
void CreateCommand() |
||||
{ |
||||
menuCommand = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]); |
||||
if (menuCommand != null) { |
||||
menuCommand.Owner = caller; |
||||
} |
||||
} |
||||
|
||||
public void UpdateText() |
||||
{ |
||||
if (codon.Properties.Contains("label")){ |
||||
this.Content = StringParser.Parse(codon.Properties["label"]); |
||||
} |
||||
if (codon.Properties.Contains("tooltip")) { |
||||
this.ToolTip = StringParser.Parse(codon.Properties["tooltip"]); |
||||
} |
||||
} |
||||
|
||||
public void UpdateStatus() |
||||
{ |
||||
this.IsEnabled = this.IsEnabledCore; |
||||
if (this.IsEnabled) { |
||||
this.Visibility = Visibility.Visible; |
||||
} else { |
||||
if (codon.GetFailedAction(caller) == ConditionFailedAction.Exclude) |
||||
this.Visibility = Visibility.Collapsed; |
||||
else |
||||
this.Visibility = Visibility.Visible; |
||||
} |
||||
} |
||||
|
||||
protected override bool IsEnabledCore { |
||||
get { |
||||
ConditionFailedAction failedAction = codon.GetFailedAction(caller); |
||||
bool isEnabled = failedAction == ConditionFailedAction.Nothing; |
||||
if (isEnabled && menuCommand != null && menuCommand is IMenuCommand) { |
||||
isEnabled = ((IMenuCommand)menuCommand).IsEnabled; |
||||
} |
||||
return isEnabled; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <author name="Daniel Grunwald"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Controls; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Creates WPF toolbars from the AddIn Tree.
|
||||
/// </summary>
|
||||
public static class ToolBarService |
||||
{ |
||||
/// <summary>
|
||||
/// Style key used for toolbar images.
|
||||
/// </summary>
|
||||
public static readonly object ImageStyleKey = new object(); |
||||
|
||||
public static void UpdateStatus(IEnumerable toolBarItems) |
||||
{ |
||||
MenuService.UpdateStatus(toolBarItems); |
||||
} |
||||
|
||||
public static IList CreateToolBarItems(object owner, string addInTreePath) |
||||
{ |
||||
return CreateToolBarItems(AddInTree.BuildItems<ToolbarItemDescriptor>(addInTreePath, owner, false)); |
||||
} |
||||
|
||||
static IList CreateToolBarItems(IEnumerable descriptors) |
||||
{ |
||||
ArrayList result = new ArrayList(); |
||||
foreach (ToolbarItemDescriptor descriptor in descriptors) { |
||||
object item = CreateToolBarItemFromDescriptor(descriptor); |
||||
if (item is IMenuItemBuilder) { |
||||
IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item; |
||||
result.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Caller)); |
||||
} else { |
||||
result.Add(item); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
static object CreateToolBarItemFromDescriptor(ToolbarItemDescriptor descriptor) |
||||
{ |
||||
Codon codon = descriptor.Codon; |
||||
object caller = descriptor.Caller; |
||||
string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Item"; |
||||
|
||||
bool createCommand = codon.Properties["loadclasslazy"] == "false"; |
||||
|
||||
switch (type) { |
||||
case "Separator": |
||||
return new ConditionalSeparator(codon, caller, true); |
||||
case "CheckBox": |
||||
return "CheckBox"; |
||||
//return new ToolBarCheckBox(codon, caller);
|
||||
case "Item": |
||||
return new ToolBarButton(codon, caller, createCommand); |
||||
case "ComboBox": |
||||
return "ComboBox"; |
||||
//return new ToolBarComboBox(codon, caller);
|
||||
case "TextBox": |
||||
return "TextBox"; |
||||
//return new ToolBarTextBox(codon, caller);
|
||||
case "Label": |
||||
return "Label"; |
||||
//return new ToolBarLabel(codon, caller);
|
||||
case "DropDownButton": |
||||
return "DropDownButton"; |
||||
//return new ToolBarDropDownButton(codon, caller, MenuService.CreateMenuItems(descriptor.SubItems));
|
||||
case "SplitButton": |
||||
return "SplitButton"; |
||||
//return new ToolBarSplitButton(codon, caller, MenuService.CreateMenuItems(descriptor.SubItems));
|
||||
case "Builder": |
||||
return codon.AddIn.CreateObject(codon.Properties["class"]); |
||||
default: |
||||
throw new System.NotSupportedException("unsupported menu item type : " + type); |
||||
} |
||||
} |
||||
|
||||
static ToolBar CreateToolBar(object owner, AddInTreeNode treeNode) |
||||
{ |
||||
ToolBar tb = new ToolBar(); |
||||
tb.ItemsSource = CreateToolBarItems(treeNode.BuildChildItems<ToolbarItemDescriptor>(owner)); |
||||
UpdateStatus(tb.ItemsSource); // setting Visible is only possible after the items have been added
|
||||
//new LanguageChangeWatcher(toolStrip);
|
||||
return tb; |
||||
} |
||||
|
||||
public static ToolBar CreateToolBar(object owner, string addInTreePath) |
||||
{ |
||||
return CreateToolBar(owner, AddInTree.GetTreeNode(addInTreePath)); |
||||
} |
||||
|
||||
public static ToolBar[] CreateToolBars(object owner, string addInTreePath) |
||||
{ |
||||
AddInTreeNode treeNode; |
||||
try { |
||||
treeNode = AddInTree.GetTreeNode(addInTreePath); |
||||
} catch (TreePathNotFoundException) { |
||||
return null; |
||||
} |
||||
List<ToolBar> toolBars = new List<ToolBar>(); |
||||
foreach (AddInTreeNode childNode in treeNode.ChildNodes.Values) { |
||||
toolBars.Add(CreateToolBar(owner, childNode)); |
||||
} |
||||
return toolBars.ToArray(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue