Browse Source

Support ToolBox and PropertyGrid in WPF designer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2573 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
cb3a1f2069
  1. 6
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs
  2. 2
      src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Gui/ViewContentControl.cs
  3. 4
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs
  4. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfSideTabItem.cs
  5. 110
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs
  6. 77
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  7. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  8. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs
  9. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DragDropExceptionHandler.cs
  10. 46
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  11. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  12. 12
      src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyContainer.cs
  13. 23
      src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyPad.cs
  14. 1
      src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs
  15. 13
      src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SideBar/SideBar.cs

6
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs

@ -87,5 +87,11 @@ namespace ICSharpCode.SettingsEditor @@ -87,5 +87,11 @@ namespace ICSharpCode.SettingsEditor
return propertyContainer;
}
}
public override void Dispose()
{
propertyContainer.Clear();
base.Dispose();
}
}
}

2
src/AddIns/DisplayBindings/WorkflowDesigner/Project/Src/Gui/ViewContentControl.cs

@ -205,7 +205,5 @@ namespace WorkflowDesigner @@ -205,7 +205,5 @@ namespace WorkflowDesigner
}
}
#endregion
}
}

4
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

@ -21,6 +21,9 @@ namespace StandaloneDesigner @@ -21,6 +21,9 @@ namespace StandaloneDesigner
{
public Window1()
{
DragDropExceptionHandler.HandleException = delegate (Exception ex) {
MessageBox.Show(ex.ToString());
};
try {
InitializeComponent();
foreach (object o in toolBar.Items) {
@ -101,3 +104,4 @@ namespace StandaloneDesigner @@ -101,3 +104,4 @@ namespace StandaloneDesigner
}
}

37
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfSideTabItem.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// <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.Drawing;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Description of WpfSideTabItem.
/// </summary>
public class WpfSideTabItem : SharpDevelopSideTabItem
{
public WpfSideTabItem(Type componentType) : base(componentType.Name, new CreateComponentTool(componentType))
{
CanBeRenamed = false;
// this.Icon = tag.Bitmap;
}
///<summary>create a default tabitem : a pointer icon with an empty toolboxitem</summary>
public WpfSideTabItem() : base("Pointer")
{
CanBeRenamed = false;
CanBeDeleted = false;
Bitmap pointerBitmap = new Bitmap(IconService.GetBitmap("Icons.16x16.FormsDesigner.PointerIcon"), 16, 16);
this.Icon = pointerBitmap;
this.Tag = null;
}
}
}

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

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
// <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.Diagnostics;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Widgets.SideBar;
using WPF = System.Windows.Controls;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Manages the WpfToolbox.
/// </summary>
public class WpfToolbox
{
static WpfToolbox instance;
public static WpfToolbox Instance {
get {
Debug.Assert(WorkbenchSingleton.InvokeRequired == false);
if (instance == null) {
instance = new WpfToolbox();
}
return instance;
}
}
IToolService toolService;
WpfSideBar sideBar;
public WpfToolbox()
{
sideBar = new WpfSideBar();
SideTab sideTab = new SideTab(sideBar, "Windows Presentation Foundation");
sideTab.DisplayName = StringParser.Parse(sideTab.Name);
sideTab.CanBeDeleted = false;
sideTab.ChoosedItemChanged += OnChoosedItemChanged;
sideTab.Items.Add(new WpfSideTabItem());
sideTab.Items.Add(new WpfSideTabItem(typeof(WPF.Button)));
sideTab.Items.Add(new WpfSideTabItem(typeof(WPF.CheckBox)));
sideTab.Items.Add(new WpfSideTabItem(typeof(WPF.TextBox)));
sideTab.Items.Add(new WpfSideTabItem(typeof(WPF.Grid)));
sideTab.Items.Add(new WpfSideTabItem(typeof(WPF.Canvas)));
sideBar.Tabs.Add(sideTab);
sideBar.ActiveTab = sideTab;
}
void OnChoosedItemChanged(object sender, EventArgs e)
{
if (toolService != null) {
ITool newTool = null;
if (sideBar.ActiveTab != null && sideBar.ActiveTab.ChoosedItem != null) {
newTool = sideBar.ActiveTab.ChoosedItem.Tag as ITool;
}
toolService.CurrentTool = newTool ?? toolService.PointerTool;
}
}
public Control ToolboxControl {
get { return sideBar; }
}
public IToolService ToolService {
get { return toolService; }
set {
if (toolService != null) {
toolService.CurrentToolChanged -= OnCurrentToolChanged;
}
toolService = value;
if (toolService != null) {
toolService.CurrentToolChanged += OnCurrentToolChanged;
OnCurrentToolChanged(null, null);
}
}
}
void OnCurrentToolChanged(object sender, EventArgs e)
{
Debug.WriteLine("WpfToolbox.OnCurrentToolChanged");
// for (int i = 0; i < this.Items.Count; i++) {
// if (((ListBoxItem)this.Items[i]).Tag == toolService.CurrentTool) {
// this.SelectedIndex = i;
// return;
// }
// }
// this.SelectedIndex = -1;
}
sealed class WpfSideBar : SharpDevelopSideBar
{
protected override object StartItemDrag(SideTabItem draggedItem)
{
if (this.ActiveTab.ChoosedItem != draggedItem && this.ActiveTab.Items.Contains(draggedItem)) {
this.ActiveTab.ChoosedItem = draggedItem;
}
return new System.Windows.DataObject(draggedItem.Tag);
}
}
}
}

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

@ -6,39 +6,46 @@ @@ -6,39 +6,46 @@
// </file>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Xml;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.PropertyEditor;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Description of WpfViewContent.
/// </summary>
public class WpfViewContent : AbstractViewContentHandlingLoadErrors
public class WpfViewContent : AbstractViewContentHandlingLoadErrors, IHasPropertyContainer, IToolsHost
{
ElementHost wpfHost;
DesignSurface designer;
public WpfViewContent(OpenedFile file) : base(file)
{
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
}
protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
{
if (designer == null) {
// initialize designer on first load
DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError;
wpfHost = new ElementHost();
designer = new DesignSurface();
wpfHost.Child = designer;
this.UserControl = wpfHost;
InitPropertyEditor();
}
using (XmlTextReader r = new XmlTextReader(stream)) {
designer.LoadDesigner(r);
designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
}
}
@ -49,5 +56,69 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -49,5 +56,69 @@ namespace ICSharpCode.WpfDesign.AddIn
designer.SaveDesigner(xmlWriter);
}
}
#region Property editor / SelectionChanged
Designer.PropertyEditor propertyEditor;
ElementHost propertyEditorHost;
void InitPropertyEditor()
{
propertyEditorHost = new ElementHost();
propertyEditor = new Designer.PropertyEditor();
propertyEditorHost.Child = propertyEditor;
propertyContainer.PropertyGridReplacementControl = propertyEditorHost;
}
ICollection<DesignItem> oldItems = new DesignItem[0];
void OnSelectionChanged(object sender, DesignItemCollectionEventArgs e)
{
ISelectionService selectionService = designer.DesignContext.Services.Selection;
ICollection<DesignItem> items = selectionService.SelectedItems;
if (!IsCollectionWithSameElements(items, oldItems)) {
IPropertyEditorDataSource dataSource = DesignItemDataSource.GetDataSourceForDesignItems(items);
propertyEditor.EditedObject = dataSource;
oldItems = items;
}
}
static bool IsCollectionWithSameElements(ICollection<DesignItem> a, ICollection<DesignItem> b)
{
return ContainsAll(a, b) && ContainsAll(b, a);
}
static bool ContainsAll(ICollection<DesignItem> a, ICollection<DesignItem> b)
{
foreach (DesignItem item in a) {
if (!b.Contains(item))
return false;
}
return true;
}
PropertyContainer propertyContainer = new PropertyContainer();
public PropertyContainer PropertyContainer {
get { return propertyContainer; }
}
#endregion
public Control ToolsControl {
get { return WpfToolbox.Instance.ToolboxControl; }
}
public override void Dispose()
{
propertyContainer.Clear();
base.Dispose();
}
protected override void OnSwitchedTo(EventArgs e)
{
base.OnSwitchedTo(e);
if (designer != null && designer.DesignContext != null) {
WpfToolbox.Instance.ToolService = designer.DesignContext.Services.Tool;
}
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj

@ -53,6 +53,8 @@ @@ -53,6 +53,8 @@
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" />
<Compile Include="Src\WpfSideTabItem.cs" />
<Compile Include="Src\WpfToolbox.cs" />
<Compile Include="Src\WpfViewContent.cs" />
</ItemGroup>
<ItemGroup>
@ -66,6 +68,11 @@ @@ -66,6 +68,11 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs

@ -20,7 +20,7 @@ using ICSharpCode.WpfDesign.PropertyEditor; @@ -20,7 +20,7 @@ using ICSharpCode.WpfDesign.PropertyEditor;
namespace ICSharpCode.WpfDesign.Designer
{
/// <summary>
/// Description of PropertyGrid.
/// Shows a list of properties; supports data binding.
/// </summary>
public partial class PropertyEditor : UserControl
{
@ -32,7 +32,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -32,7 +32,7 @@ namespace ICSharpCode.WpfDesign.Designer
new FrameworkPropertyMetadata(null, _OnEditedObjectPropertyChanged));
/// <summary>
/// Creates a new PropertyGrid instance.
/// Creates a new PropertyEditor instance.
/// </summary>
public PropertyEditor()
{

24
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DragDropExceptionHandler.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// <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.WpfDesign.Designer
{
/// <summary>
/// When the designer is hosted in a Windows.Forms application, exceptions in
/// drag'n'drop handlers are silently ignored.
/// Applications hosting the designer should specify a delegate to their own exception handling
/// method. The default is Environment.FailFast.
/// </summary>
public static class DragDropExceptionHandler
{
public static Action<Exception> HandleException = delegate(Exception ex) {
Environment.FailFast(ex.ToString());
};
}
}

46
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -67,31 +67,39 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -67,31 +67,39 @@ namespace ICSharpCode.WpfDesign.Designer.Services
void OnDragOver(object sender, DragEventArgs e)
{
if (e.Data.GetData(typeof(CreateComponentTool)) == this) {
e.Effects = DragDropEffects.Copy;
e.Handled = true;
} else {
e.Effects = DragDropEffects.None;
try {
if (e.Data.GetData(typeof(CreateComponentTool)) == this) {
e.Effects = DragDropEffects.Copy;
e.Handled = true;
} else {
e.Effects = DragDropEffects.None;
}
} catch (Exception ex) {
DragDropExceptionHandler.HandleException(ex);
}
}
void OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetData(typeof(CreateComponentTool)) != this)
return;
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true);
if (result.ModelHit != null) {
designPanel.Focus();
try {
if (e.Data.GetData(typeof(CreateComponentTool)) != this)
return;
e.Handled = true;
DesignItem createdItem = CreateItem(designPanel.Context);
AddItemWithDefaultSize(result.ModelHit, createdItem, e.GetPosition(result.ModelHit.View));
}
if (designPanel.Context.Services.Tool.CurrentTool is CreateComponentTool) {
designPanel.Context.Services.Tool.CurrentTool = designPanel.Context.Services.Tool.PointerTool;
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true);
if (result.ModelHit != null) {
designPanel.Focus();
DesignItem createdItem = CreateItem(designPanel.Context);
AddItemWithDefaultSize(result.ModelHit, createdItem, e.GetPosition(result.ModelHit.View));
}
if (designPanel.Context.Services.Tool.CurrentTool is CreateComponentTool) {
designPanel.Context.Services.Tool.CurrentTool = designPanel.Context.Services.Tool.PointerTool;
}
} catch (Exception ex) {
DragDropExceptionHandler.HandleException(ex);
}
}

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

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
<Compile Include="Controls\TypeEditors\ContentEditor.cs" />
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="DragDropExceptionHandler.cs" />
<Compile Include="Extensions\GridAdornerProvider.cs" />
<Compile Include="Extensions\GridPlacementSupport.cs" />
<Compile Include="ModelTools.cs" />

12
src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyContainer.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Gui
{
@ -95,6 +96,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -95,6 +96,16 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
Control propertyGridReplacementControl;
public Control PropertyGridReplacementControl {
get { return propertyGridReplacementControl; }
set {
propertyGridReplacementControl = value;
PropertyPad.UpdatePropertyGridReplacementControl(this);
}
}
/// <summary>
/// Clears all properties on this container.
/// When a ViewContent is closed, it should call Clear on it's property container to
@ -105,6 +116,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -105,6 +116,7 @@ namespace ICSharpCode.SharpDevelop.Gui
Host = null;
SelectableObjects = null;
SelectedObject = null;
PropertyGridReplacementControl = null;
}
}
}

23
src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyPad.cs

@ -30,9 +30,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -30,9 +30,11 @@ namespace ICSharpCode.SharpDevelop.Gui
if (pc == null)
return;
activeContainer = pc;
UpdateHostIfActive(pc);
UpdateSelectedObjectIfActive(pc);
UpdateSelectableIfActive(pc);
UpdatePropertyGridReplacementControl(pc);
}
internal static void UpdateSelectedObjectIfActive(PropertyContainer container)
@ -70,6 +72,27 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -70,6 +72,27 @@ namespace ICSharpCode.SharpDevelop.Gui
instance.SetSelectableObjects(container.SelectableObjects);
}
internal static void UpdatePropertyGridReplacementControl(PropertyContainer container)
{
if (instance == null) return;
if (instance.activeContainer != container)
return;
LoggingService.Debug("UpdatePropertyGridReplacementControl");
if (container.PropertyGridReplacementControl != null) {
if (!instance.panel.Controls.Contains(container.PropertyGridReplacementControl)) {
instance.panel.Controls.Clear();
container.PropertyGridReplacementControl.Dock = DockStyle.Fill;
instance.panel.Controls.Add(container.PropertyGridReplacementControl);
}
} else {
if (!instance.panel.Controls.Contains(instance.grid)) {
instance.panel.Controls.Clear();
instance.panel.Controls.Add(instance.grid);
instance.panel.Controls.Add(instance.comboBox);
}
}
}
Panel panel;
ComboBox comboBox;
PropertyGrid grid;

1
src/Main/Base/Project/Src/Gui/Workbench/DefaultWorkbench.cs

@ -218,7 +218,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -218,7 +218,6 @@ namespace ICSharpCode.SharpDevelop.Gui
if (activeContent != value) {
activeContent = value;
if (ActiveContentChanged != null) {
Console.WriteLine(Environment.StackTrace);
ActiveContentChanged(this, EventArgs.Empty);
}
}

13
src/Main/ICSharpCode.SharpDevelop.Widgets/Project/SideBar/SideBar.cs

@ -707,6 +707,14 @@ namespace ICSharpCode.SharpDevelop.Widgets.SideBar @@ -707,6 +707,14 @@ namespace ICSharpCode.SharpDevelop.Widgets.SideBar
sideTabContent.Refresh();
}
protected virtual object StartItemDrag(SideTabItem draggedItem)
{
SpecialDataObject dataObject = new SpecialDataObject();
dataObject.SetData(draggedItem.Tag);
dataObject.SetData(draggedItem);
return dataObject;
}
protected class SideTabContent : UserControl
{
SideBarControl sideBar = null;
@ -893,11 +901,8 @@ namespace ICSharpCode.SharpDevelop.Widgets.SideBar @@ -893,11 +901,8 @@ namespace ICSharpCode.SharpDevelop.Widgets.SideBar
if (item != null) {
if (IsDragStarted(mouseDownPos, e.Location)) {
sideBar.Tabs.DragOverTab = sideBar.activeTab;
SpecialDataObject dataObject = new SpecialDataObject();
dataObject.SetData(item.Tag);
dataObject.SetData(item);
DoDragDrop(dataObject, sideBar.activeTab.CanDragDrop ? DragDropEffects.All : (DragDropEffects.Copy | DragDropEffects.None));
DoDragDrop(sideBar.StartItemDrag(item), sideBar.activeTab.CanDragDrop ? DragDropEffects.All : (DragDropEffects.Copy | DragDropEffects.None));
}
Refresh();
}

Loading…
Cancel
Save