Browse Source

- Commands routing (for integrated and standalone WPF Designer, CCP still not implemented)

- Rework DesignSurface (more xaml, popular controls through metadata)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3435 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Ivan Shumilin 17 years ago
parent
commit
945d491f87
  1. 1
      samples/XamlDesigner/MainWindow.xaml.cs
  2. 28
      samples/XamlDesigner/MainWindow_Commands.cs
  3. 33
      samples/XamlDesigner/Toolbox.cs
  4. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs
  5. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs
  6. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  7. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  8. 78
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SingleVisualChildElement.cs
  9. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml
  10. 301
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs
  11. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ExtensionMethods.cs
  12. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
  13. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  14. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  15. 49
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs
  16. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/PropertyNode.cs

1
samples/XamlDesigner/MainWindow.xaml.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.XamlDesigner @@ -31,6 +31,7 @@ namespace ICSharpCode.XamlDesigner
Shell.Instance.PropertyGrid = uxPropertyGridView.PropertyGrid;
AvalonDockWorkaround();
RouteDesignSurfaceCommands();
LoadSettings();
ProcessPaths(App.Args);
}

28
samples/XamlDesigner/MainWindow_Commands.cs

@ -3,6 +3,7 @@ using System.Collections.Generic; @@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
namespace ICSharpCode.XamlDesigner
{
@ -67,5 +68,32 @@ namespace ICSharpCode.XamlDesigner @@ -67,5 +68,32 @@ namespace ICSharpCode.XamlDesigner
{
e.CanExecute = Shell.Instance.CurrentDocument != null;
}
void RouteDesignSurfaceCommands()
{
RouteDesignSurfaceCommand(ApplicationCommands.Undo);
RouteDesignSurfaceCommand(ApplicationCommands.Redo);
RouteDesignSurfaceCommand(ApplicationCommands.Copy);
RouteDesignSurfaceCommand(ApplicationCommands.Cut);
RouteDesignSurfaceCommand(ApplicationCommands.Paste);
RouteDesignSurfaceCommand(ApplicationCommands.SelectAll);
RouteDesignSurfaceCommand(ApplicationCommands.Delete);
}
void RouteDesignSurfaceCommand(RoutedCommand command)
{
var cb = new CommandBinding(command);
cb.CanExecute += delegate(object sender, CanExecuteRoutedEventArgs e) {
if (Shell.Instance.CurrentDocument != null) {
Shell.Instance.CurrentDocument.DesignSurface.RaiseEvent(e);
}else {
e.CanExecute = false;
}
};
cb.Executed += delegate(object sender, ExecutedRoutedEventArgs e) {
Shell.Instance.CurrentDocument.DesignSurface.RaiseEvent(e);
};
CommandBindings.Add(cb);
}
}
}

33
samples/XamlDesigner/Toolbox.cs

@ -7,6 +7,7 @@ using System.Collections.ObjectModel; @@ -7,6 +7,7 @@ using System.Collections.ObjectModel;
using ICSharpCode.XamlDesigner.Configuration;
using System.Windows;
using System.Collections.Specialized;
using ICSharpCode.WpfDesign;
namespace ICSharpCode.XamlDesigner
{
@ -26,36 +27,6 @@ namespace ICSharpCode.XamlDesigner @@ -26,36 +27,6 @@ namespace ICSharpCode.XamlDesigner
AddAssembly(path, true);
}
string[] popularControls = new string[] {
"Border",
"Button",
"Canvas",
"CheckBox",
"ComboBox",
"DockPanel",
"Ellipse",
"FlowDocumentScrollViewer",
"Grid",
"GridSplitter",
"Label",
"Line",
"ListBox",
"PasswordBox",
"RadioButton",
"Rectangle",
"RichTextBox",
"ScrollBar",
"ScrollViewer",
"Slider",
"StackPanel",
"TabControl",
"TextBlock",
"TextBox",
"UniformGrid",
"Viewbox",
"WrapPanel"
};
void AddAssembly(string path, bool updateSettings)
{
var assembly = Assembly.LoadFile(path);
@ -64,7 +35,7 @@ namespace ICSharpCode.XamlDesigner @@ -64,7 +35,7 @@ namespace ICSharpCode.XamlDesigner
node.Assembly = assembly;
node.Path = path;
foreach (var t in assembly.GetExportedTypes()) {
if (IsControl(t) && popularControls.Contains(t.Name)) {
if (IsControl(t) && Metadata.IsPopularControl(t)) {
node.Controls.Add(new ControlNode() { Type = t });
}
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs

@ -22,28 +22,38 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -22,28 +22,38 @@ namespace ICSharpCode.WpfDesign.AddIn
[ThreadStatic]
static bool registeredErrorHandler;
public SharpDevelopElementHost()
public SharpDevelopElementHost(WpfViewContent viewContent, UIElement child)
{
if (!registeredErrorHandler) {
registeredErrorHandler = true;
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_UnhandledException;
}
this.viewContent = viewContent;
this.Child = child;
}
WpfViewContent viewContent;
static void CurrentDispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
ICSharpCode.Core.MessageService.ShowError(e.Exception, "Unhandled WPF exception");
e.Handled = true;
}
static bool IsEnabled(ICommand command)
bool IsEnabled(RoutedCommand command)
{
return command.CanExecute(null);
if (command.CanExecute(null, null)) return true;
return command.CanExecute(null, viewContent.DesignSurface);
}
static void Run(ICommand command)
void Run(RoutedCommand command)
{
command.Execute(null);
if (command.CanExecute(null, null)) {
command.Execute(null, null);
} else {
command.Execute(null, viewContent.DesignSurface);
}
}
public bool EnableUndo {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -45,7 +45,7 @@ namespace ICSharpCode.WpfDesign.AddIn
sideTab.ChoosedItemChanged += OnChoosedItemChanged;
sideTab.Items.Add(new WpfSideTabItem());
foreach (Type t in Designer.DesignSurface.SupportedToolboxControls)
foreach (Type t in Metadata.GetPopularControls())
sideTab.Items.Add(new WpfSideTabItem(t));
sideBar.Tabs.Add(sideTab);

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

@ -28,29 +28,32 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -28,29 +28,32 @@ namespace ICSharpCode.WpfDesign.AddIn
/// IViewContent implementation that hosts the WPF designer.
/// </summary>
public class WpfViewContent : AbstractViewContentHandlingLoadErrors, IHasPropertyContainer, IToolsHost
{
{
public WpfViewContent(OpenedFile file) : base(file)
{
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged;
}
ElementHost wpfHost;
DesignSurface designer;
public DesignSurface DesignSurface {
get { return designer; }
}
public DesignContext DesignContext {
get { return designer.DesignContext; }
}
public WpfViewContent(OpenedFile file) : base(file)
{
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged;
}
protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
{
Debug.Assert(file == this.PrimaryFile);
if (designer == null) {
// initialize designer on first load
DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError;
wpfHost = new SharpDevelopElementHost();
designer = new DesignSurface();
wpfHost.Child = designer;
wpfHost = new SharpDevelopElementHost(this, designer);
this.UserControl = wpfHost;
InitPropertyEditor();
}
@ -99,9 +102,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -99,9 +102,8 @@ namespace ICSharpCode.WpfDesign.AddIn
void InitPropertyEditor()
{
propertyEditorHost = new SharpDevelopElementHost();
propertyGridView = new PropertyGridView();
propertyEditorHost.Child = propertyGridView;
propertyEditorHost = new SharpDevelopElementHost(this, propertyGridView);
propertyContainer.PropertyGridReplacementControl = propertyEditorHost;
}

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

@ -19,7 +19,7 @@ using System.Windows.Navigation; @@ -19,7 +19,7 @@ using System.Windows.Navigation;
namespace ICSharpCode.WpfDesign.Designer
{
public class BasicMetadata
public class BasicMetadata : IMetadata
{
public BasicMetadata()
{
@ -190,6 +190,36 @@ namespace ICSharpCode.WpfDesign.Designer @@ -190,6 +190,36 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.HideProperty(typeof(Window), "Owner");
//Metadata.DisablePlacement(typeof(Button));
Metadata.AddPopularControl(typeof(Button));
Metadata.AddPopularControl(typeof(CheckBox));
Metadata.AddPopularControl(typeof(ComboBox));
Metadata.AddPopularControl(typeof(Label));
Metadata.AddPopularControl(typeof(TextBox));
Metadata.AddPopularControl(typeof(RadioButton));
Metadata.AddPopularControl(typeof(Canvas));
Metadata.AddPopularControl(typeof(Grid));
Metadata.AddPopularControl(typeof(Border));
Metadata.AddPopularControl(typeof(DockPanel));
Metadata.AddPopularControl(typeof(Expander));
Metadata.AddPopularControl(typeof(GroupBox));
Metadata.AddPopularControl(typeof(Image));
Metadata.AddPopularControl(typeof(InkCanvas));
Metadata.AddPopularControl(typeof(ListBox));
Metadata.AddPopularControl(typeof(ListView));
Metadata.AddPopularControl(typeof(Menu));
Metadata.AddPopularControl(typeof(PasswordBox));
Metadata.AddPopularControl(typeof(ProgressBar));
Metadata.AddPopularControl(typeof(RichTextBox));
Metadata.AddPopularControl(typeof(ScrollViewer));
Metadata.AddPopularControl(typeof(Slider));
Metadata.AddPopularControl(typeof(StackPanel));
Metadata.AddPopularControl(typeof(TabControl));
Metadata.AddPopularControl(typeof(ToolBar));
Metadata.AddPopularControl(typeof(TreeView));
Metadata.AddPopularControl(typeof(Viewbox));
Metadata.AddPopularControl(typeof(Viewport3D));
Metadata.AddPopularControl(typeof(WrapPanel));
}
}
}

78
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SingleVisualChildElement.cs

@ -1,78 +0,0 @@ @@ -1,78 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Base class for elements that have a single visual child.
/// </summary>
public class SingleVisualChildElement : FrameworkElement
{
UIElement _visualChild;
/// <summary>
/// Gets/sets the visual child.
/// </summary>
protected UIElement VisualChild {
get { return _visualChild; }
set {
RemoveVisualChild(_visualChild);
_visualChild = value;
AddVisualChild(_visualChild);
InvalidateMeasure();
}
}
/// <summary>
/// Gets the visual child.
/// </summary>
protected override Visual GetVisualChild(int index)
{
if (index == 0 && _visualChild != null)
return _visualChild;
else
throw new ArgumentOutOfRangeException("index");
}
/// <summary>
/// Gets the number of visual children.
/// </summary>
protected override int VisualChildrenCount {
get { return _visualChild != null ? 1 : 0; }
}
/// <summary>
/// Measure the visual child.
/// </summary>
protected override Size MeasureOverride(Size availableSize)
{
if (_visualChild != null) {
_visualChild.Measure(availableSize);
return _visualChild.DesiredSize;
} else {
return base.MeasureOverride(availableSize);
}
}
/// <summary>
/// Arrange the visual child.
/// </summary>
protected override Size ArrangeOverride(Size finalSize)
{
if (_visualChild != null) {
_visualChild.Arrange(new Rect(new Point(0, 0), finalSize));
return finalSize;
} else {
return base.ArrangeOverride(finalSize);
}
}
}
}

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
<UserControl x:Class="ICSharpCode.WpfDesign.Designer.DesignSurface"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.WpfDesign.Designer"
DataContext="{x:Null}">
<ScrollViewer HorizontalScrollBarVisibility="Visible"
VerticalScrollBarVisibility="Visible">
<Default:DesignPanel x:Name="_designPanel">
<Border x:Name="_sceneContainer" Padding="10" />
</Default:DesignPanel>
</ScrollViewer>
</UserControl>

301
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs

@ -1,155 +1,43 @@ @@ -1,155 +1,43 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Diagnostics;
namespace ICSharpCode.WpfDesign.Designer
{
/// <summary>
/// Surface hosting the WPF designer.
/// </summary>
public sealed class DesignSurface : SingleVisualChildElement
public partial class DesignSurface
{
public static Type[] SupportedToolboxControls = {
typeof(Button),
typeof(CheckBox),
typeof(ComboBox),
typeof(Label),
typeof(TextBox),
typeof(RadioButton),
typeof(Canvas),
typeof(Grid),
typeof(Border),
typeof(DockPanel),
typeof(Expander),
typeof(GroupBox),
typeof(Image),
typeof(InkCanvas),
typeof(ListBox),
typeof(ListView),
typeof(Menu),
typeof(PasswordBox),
typeof(ProgressBar),
typeof(RichTextBox),
typeof(ScrollViewer),
typeof(Slider),
typeof(StackPanel),
typeof(TabControl),
typeof(ToolBar),
typeof(TreeView),
typeof(Viewbox),
typeof(Viewport3D),
typeof(WrapPanel)
};
readonly ScrollViewer _scrollViewer;
readonly DesignPanel _designPanel;
DesignContext _designContext;
/// <summary>
/// Create a new DesignSurface instance.
/// </summary>
public DesignSurface()
{
_scrollViewer = new ScrollViewer();
_designPanel = new DesignPanel();
_scrollViewer.Content = _designPanel;
_scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
_scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
InitializeComponent();
this.VisualChild = _scrollViewer;
this.DataContext = null;
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, OnUndoExecuted, OnUndoCanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, OnRedoExecuted, OnRedoCanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, OnDeleteExecuted, OnDeleteCanExecute));
}
T GetService<T>() where T : class
{
if (_designContext != null)
return _designContext.Services.GetService<T>();
else
return null;
}
#region Command: Undo/Redo
void OnUndoExecuted(object sender, ExecutedRoutedEventArgs e)
{
UndoService undoService = GetService<UndoService>();
IUndoAction action = undoService.UndoActions.First();
Debug.WriteLine("Undo " + action.Title);
undoService.Undo();
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
void OnUndoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
UndoService undoService = GetService<UndoService>();
e.CanExecute = undoService != null && undoService.CanUndo;
}
void OnRedoExecuted(object sender, ExecutedRoutedEventArgs e)
{
UndoService undoService = GetService<UndoService>();
IUndoAction action = undoService.RedoActions.First();
Debug.WriteLine("Redo " + action.Title);
undoService.Redo();
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
void OnRedoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
UndoService undoService = GetService<UndoService>();
e.CanExecute = undoService != null && undoService.CanRedo;
}
// Filters an element list, dropping all elements that are not part of the xaml document
// (e.g. because they were deleted).
static List<DesignItem> GetLiveElements(ICollection<DesignItem> items)
{
List<DesignItem> result = new List<DesignItem>(items.Count);
foreach (DesignItem item in items) {
if (ModelTools.IsInDocument(item) && ModelTools.CanSelectComponent(item)) {
result.Add(item);
}
}
return result;
}
#endregion
#region Command: Delete
void OnDeleteExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (_designContext != null) {
ModelTools.DeleteComponents(_designContext.Services.Selection.SelectedItems);
}
}
void OnDeleteCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (_designContext != null) {
e.CanExecute = ModelTools.CanDeleteComponents(_designContext.Services.Selection.SelectedItems);
} else {
e.CanExecute = false;
}
this.AddCommandHandler(ApplicationCommands.Undo, Undo, CanUndo);
this.AddCommandHandler(ApplicationCommands.Redo, Redo, CanRedo);
this.AddCommandHandler(ApplicationCommands.Copy, Copy, HasSelection);
this.AddCommandHandler(ApplicationCommands.Cut, Cut, HasSelection);
this.AddCommandHandler(ApplicationCommands.Delete, Delete, CanDelete);
this.AddCommandHandler(ApplicationCommands.Paste, Paste, CanPaste);
this.AddCommandHandler(ApplicationCommands.SelectAll, SelectAll, CanSelectAll);
}
#endregion
DesignContext _designContext;
/// <summary>
/// Gets the active design context.
/// </summary>
@ -160,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -160,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Initializes the designer content from the specified XmlReader.
/// </summary>
public void LoadDesigner(XmlReader xamlReader, Xaml.XamlLoadSettings loadSettings)
public void LoadDesigner(XmlReader xamlReader, XamlLoadSettings loadSettings)
{
UnloadDesigner();
InitializeDesigner(new Xaml.XamlDesignContext(xamlReader, loadSettings ?? new Xaml.XamlLoadSettings()));
InitializeDesigner(new XamlDesignContext(xamlReader, loadSettings ?? new XamlLoadSettings()));
}
/// <summary>
@ -180,10 +68,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -180,10 +68,8 @@ namespace ICSharpCode.WpfDesign.Designer
_designContext = context;
_designPanel.Context = context;
Border designPanelBorder = new Border();
designPanelBorder.Padding = new Thickness(10);
_designPanel.Child = designPanelBorder;
designPanelBorder.Child = context.RootItem.View;
_sceneContainer.Child = context.RootItem.View;
context.Services.RunWhenAvailable<UndoService>(
undoService => undoService.UndoStackChanged += delegate {
CommandManager.InvalidateRequerySuggested();
@ -207,8 +93,141 @@ namespace ICSharpCode.WpfDesign.Designer @@ -207,8 +93,141 @@ namespace ICSharpCode.WpfDesign.Designer
}
_designContext = null;
_designPanel.Context = null;
_designPanel.Child = null;
_sceneContainer.Child = null;
_designPanel.Adorners.Clear();
}
#region Commands
public bool CanUndo()
{
UndoService undoService = GetService<UndoService>();
return undoService != null && undoService.CanUndo;
}
public void Undo()
{
UndoService undoService = GetService<UndoService>();
IUndoAction action = undoService.UndoActions.First();
Debug.WriteLine("Undo " + action.Title);
undoService.Undo();
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
public bool CanRedo()
{
UndoService undoService = GetService<UndoService>();
return undoService != null && undoService.CanRedo;
}
public void Redo()
{
UndoService undoService = GetService<UndoService>();
IUndoAction action = undoService.RedoActions.First();
Debug.WriteLine("Redo " + action.Title);
undoService.Redo();
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
public bool HasSelection()
{
return false;
}
public void Copy()
{
}
public void Cut()
{
}
public bool CanDelete()
{
if (_designContext != null) {
return ModelTools.CanDeleteComponents(_designContext.Services.Selection.SelectedItems);
}
return false;
}
public void Delete()
{
if (_designContext != null) {
ModelTools.DeleteComponents(_designContext.Services.Selection.SelectedItems);
}
}
public bool CanPaste()
{
return false;
}
public void Paste()
{
}
public bool CanSelectAll()
{
return DesignContext != null;
}
//TODO: Do not select layout root
public void SelectAll()
{
var items = Descendants(DesignContext.RootItem).Where(item => ModelTools.CanSelectComponent(item)).ToArray();
DesignContext.Services.Selection.SetSelectedComponents(items);
}
//TODO: Share with Outline / PlacementBehavior
public static IEnumerable<DesignItem> DescendantsAndSelf(DesignItem item)
{
yield return item;
foreach (var child in Descendants(item)) {
yield return child;
}
}
public static IEnumerable<DesignItem> Descendants(DesignItem item)
{
if (item.ContentPropertyName != null) {
var content = item.ContentProperty;
if (content.IsCollection) {
foreach (var child in content.CollectionElements) {
foreach (var child2 in DescendantsAndSelf(child)) {
yield return child2;
}
}
} else {
if (content.Value != null) {
foreach (var child2 in DescendantsAndSelf(content.Value)) {
yield return child2;
}
}
}
}
}
// Filters an element list, dropping all elements that are not part of the xaml document
// (e.g. because they were deleted).
static List<DesignItem> GetLiveElements(ICollection<DesignItem> items)
{
List<DesignItem> result = new List<DesignItem>(items.Count);
foreach (DesignItem item in items) {
if (ModelTools.IsInDocument(item) && ModelTools.CanSelectComponent(item)) {
result.Add(item);
}
}
return result;
}
T GetService<T>() where T : class
{
if (_designContext != null)
return _designContext.Services.GetService<T>();
else
return null;
}
#endregion
}
}

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ExtensionMethods.cs

@ -6,6 +6,7 @@ using System.Reflection; @@ -6,6 +6,7 @@ using System.Reflection;
using System.Collections;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer
{
@ -51,6 +52,26 @@ namespace ICSharpCode.WpfDesign.Designer @@ -51,6 +52,26 @@ namespace ICSharpCode.WpfDesign.Designer
if (result != null) return result;
}
return null;
}
}
public static void AddCommandHandler(this UIElement element, ICommand command, Action execute)
{
AddCommandHandler(element, command, execute, null);
}
public static void AddCommandHandler(this UIElement element, ICommand command, Action execute, Func<bool> canExecute)
{
var cb = new CommandBinding(command);
if (canExecute != null) {
cb.CanExecute += delegate(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = canExecute();
e.Handled = true;
};
}
cb.Executed += delegate(object sender, ExecutedRoutedEventArgs e) {
execute();
};
element.CommandBindings.Add(cb);
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

@ -180,7 +180,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid @@ -180,7 +180,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
Category PickCategory(PropertyNode node)
{
if (Metadata.IsPopular(node.FirstProperty)) return popularCategory;
if (Metadata.IsPopularProperty(node.FirstProperty)) return popularCategory;
var typeName = node.FirstProperty.DeclaringType.FullName;
if (typeName.StartsWith("System.Windows.") || typeName.StartsWith("ICSharpCode.WpfDesign.Designer.Controls."))
return otherCategory;

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

@ -83,12 +83,14 @@ @@ -83,12 +83,14 @@
<Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\ResizeThumb.cs" />
<Compile Include="Controls\SingleVisualChildElement.cs" />
<Compile Include="CallExtension.cs" />
<Compile Include="Controls\DragListener.cs" />
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="Converters.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="DesignSurface.xaml.cs">
<DependentUpon>DesignSurface.xaml</DependentUpon>
</Compile>
<Compile Include="DragDropExceptionHandler.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs">
@ -173,7 +175,6 @@ @@ -173,7 +175,6 @@
<Compile Include="Services\ToolService.cs" />
<Compile Include="Services\UndoService.cs" />
<Compile Include="Services\ViewService.cs" />
<Compile Include="DesignSurface.cs" />
<Compile Include="Services\WpfTopLevelWindowService.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
@ -205,6 +206,10 @@ @@ -205,6 +206,10 @@
<SubType>Designer</SubType>
</Page>
<Page Include="Controls\ControlStyles.xaml" />
<Page Include="DesignSurface.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PropertyGrid\Editors\BoolEditor.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -27,7 +27,6 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -27,7 +27,6 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
static XamlDesignContext()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
new BasicMetadata();
}
readonly XamlDocument _doc;

49
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -6,11 +6,29 @@ using System.Reflection; @@ -6,11 +6,29 @@ using System.Reflection;
using System.Collections;
using System.Windows;
using System.ComponentModel;
using System.Diagnostics;
namespace ICSharpCode.WpfDesign
{
public static class Metadata
{
//TODO: Another way?
static Metadata()
{
foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {
RegisterAssembly(a);
}
}
public static void RegisterAssembly(Assembly a)
{
foreach (var t in a.GetExportedTypes()) {
if (t.GetInterface("IMetadata") == typeof(IMetadata)) {
Activator.CreateInstance(t);
}
}
}
public static string GetFullName(this DependencyProperty p)
{
return p.OwnerType.FullName + "." + p.Name;
@ -150,7 +168,7 @@ namespace ICSharpCode.WpfDesign @@ -150,7 +168,7 @@ namespace ICSharpCode.WpfDesign
}
}
public static bool IsPopular(DesignItemProperty p)
public static bool IsPopularProperty(DesignItemProperty p)
{
lock (popularProperties) {
if (popularProperties.Contains(p.DependencyFullName)) {
@ -160,6 +178,31 @@ namespace ICSharpCode.WpfDesign @@ -160,6 +178,31 @@ namespace ICSharpCode.WpfDesign
return false;
}
static HashSet<Type> popularControls = new HashSet<Type>();
public static void AddPopularControl(Type t)
{
lock (popularControls) {
popularControls.Add(t);
}
}
public static IEnumerable<Type> GetPopularControls()
{
lock (popularControls) {
foreach (var t in popularControls) {
yield return t;
}
}
}
public static bool IsPopularControl(Type t)
{
lock (popularControls) {
return popularControls.Contains(t);
}
}
static Dictionary<string, NumberRange> ranges = new Dictionary<string, NumberRange>();
public static void AddValueRange(DependencyProperty p, double min, double max)
@ -197,6 +240,10 @@ namespace ICSharpCode.WpfDesign @@ -197,6 +240,10 @@ namespace ICSharpCode.WpfDesign
}
}
public interface IMetadata
{
}
public class NumberRange
{
public double Min;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/PropertyNode.cs

@ -275,7 +275,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -275,7 +275,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
foreach (var node in list) {
if (Metadata.IsBrowsable(node.FirstProperty)) {
node.IsVisible = true;
if (Metadata.IsPopular(node.FirstProperty)) {
if (Metadata.IsPopularProperty(node.FirstProperty)) {
Children.Add(node);
} else {
MoreChildren.Add(node);

Loading…
Cancel
Save