Browse Source

r7305@daniel-notebook (orig r3336): daniel | 2008-08-14 07:39:30 +0200

Fixed adding secondary view contents.
 Convert AbstractViewContentHandlingLoadErrors to WPF.
 Allow WPF property pad.


git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0wpf@3338 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
f3f1ed2f05
  1. 2
      src/AddIns/DisplayBindings/ResourceEditor/Project/Src/DisplayDefinition.cs
  2. 94
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopElementHost.cs
  3. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  4. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  5. 44
      src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs
  6. 12
      src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyContainer.cs
  7. 28
      src/Main/Base/Project/Src/Gui/Pads/PropertyPad/PropertyPad.cs
  8. 1
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs
  9. 2
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs
  10. 23
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs
  11. 36
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs

2
src/AddIns/DisplayBindings/ResourceEditor/Project/Src/DisplayDefinition.cs

@ -57,7 +57,7 @@ namespace ResourceEditor
public ResourceEditWrapper(OpenedFile file) public ResourceEditWrapper(OpenedFile file)
{ {
this.TabPageText = "Resource editor"; this.TabPageText = "Resource editor";
base.UserControl = resourceEditor; base.UserContent = resourceEditor;
resourceEditor.ResourceList.Changed += new EventHandler(SetDirty); resourceEditor.ResourceList.Changed += new EventHandler(SetDirty);
this.Files.Add(file); this.Files.Add(file);
} }

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

@ -1,94 +0,0 @@
// <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.Input;
using System.Windows.Forms.Integration;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Hosts a WPF element inside a Windows.Forms application.
/// </summary>
public class SharpDevelopElementHost : ElementHost, IUndoHandler, IClipboardHandler
{
static bool IsEnabled(ICommand command)
{
return command.CanExecute(null);
}
static void Run(ICommand command)
{
command.Execute(null);
}
public bool EnableUndo {
get { return IsEnabled(ApplicationCommands.Undo); }
}
public bool EnableRedo {
get { return IsEnabled(ApplicationCommands.Redo); }
}
public void Undo()
{
Run(ApplicationCommands.Undo);
}
public void Redo()
{
Run(ApplicationCommands.Redo);
}
public bool EnableCut {
get { return IsEnabled(ApplicationCommands.Undo); }
}
public bool EnableCopy {
get { return IsEnabled(ApplicationCommands.Copy); }
}
public bool EnablePaste {
get { return IsEnabled(ApplicationCommands.Paste); }
}
public bool EnableDelete {
get { return IsEnabled(ApplicationCommands.Delete); }
}
public bool EnableSelectAll {
get { return IsEnabled(ApplicationCommands.SelectAll); }
}
public void Cut()
{
Run(ApplicationCommands.Cut);
}
public void Copy()
{
Run(ApplicationCommands.Copy);
}
public void Paste()
{
Run(ApplicationCommands.Paste);
}
public void Delete()
{
Run(ApplicationCommands.Delete);
}
public void SelectAll()
{
Run(ApplicationCommands.SelectAll);
}
}
}

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

@ -48,10 +48,8 @@ namespace ICSharpCode.WpfDesign.AddIn
if (designer == null) { if (designer == null) {
// initialize designer on first load // initialize designer on first load
DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError; DragDropExceptionHandler.HandleException = ICSharpCode.Core.MessageService.ShowError;
wpfHost = new SharpDevelopElementHost();
designer = new DesignSurface(); designer = new DesignSurface();
wpfHost.Child = designer; this.UserContent = designer;
this.UserControl = wpfHost;
InitPropertyEditor(); InitPropertyEditor();
} }
using (XmlTextReader r = new XmlTextReader(stream)) { using (XmlTextReader r = new XmlTextReader(stream)) {
@ -94,15 +92,12 @@ namespace ICSharpCode.WpfDesign.AddIn
#region Property editor / SelectionChanged #region Property editor / SelectionChanged
ElementHost propertyEditorHost;
PropertyGridView propertyGridView; PropertyGridView propertyGridView;
void InitPropertyEditor() void InitPropertyEditor()
{ {
propertyEditorHost = new SharpDevelopElementHost();
propertyGridView = new PropertyGridView(); propertyGridView = new PropertyGridView();
propertyEditorHost.Child = propertyGridView; propertyContainer.PropertyGridReplacementContent = propertyGridView;
propertyContainer.PropertyGridReplacementControl = propertyEditorHost;
} }
ICollection<DesignItem> oldItems = new DesignItem[0]; ICollection<DesignItem> oldItems = new DesignItem[0];

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

@ -66,7 +66,6 @@
<DependentUpon>ObjectEditor.xaml</DependentUpon> <DependentUpon>ObjectEditor.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Src\PropertyDescriptionService.cs" /> <Compile Include="Src\PropertyDescriptionService.cs" />
<Compile Include="Src\SharpDevelopElementHost.cs" />
<Compile Include="Src\WpfAndWinFormsTopLevelWindowService.cs" /> <Compile Include="Src\WpfAndWinFormsTopLevelWindowService.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" /> <Compile Include="Src\WpfDisplayBinding.cs" />
<Compile Include="Src\WpfSideTabItem.cs" /> <Compile Include="Src\WpfSideTabItem.cs" />

44
src/Main/Base/Project/Src/Gui/AbstractViewContentHandlingLoadErrors.cs

@ -7,10 +7,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ICSharpCode.SharpDevelop.Gui namespace ICSharpCode.SharpDevelop.Gui
{ {
@ -28,8 +29,8 @@ namespace ICSharpCode.SharpDevelop.Gui
/// </summary> /// </summary>
public abstract class AbstractViewContentHandlingLoadErrors : AbstractViewContent public abstract class AbstractViewContentHandlingLoadErrors : AbstractViewContent
{ {
Panel panel = new Panel(); ContentControl contentControl = new ContentControl();
Control userControl; object userContent;
protected AbstractViewContentHandlingLoadErrors() protected AbstractViewContentHandlingLoadErrors()
{ {
@ -40,20 +41,16 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
public sealed override object Content { public sealed override object Content {
get { return panel; } get { return contentControl; }
} }
protected Control UserControl { protected object UserContent {
get { return userControl; } get { return userContent; }
set { set {
if (userControl != value) { if (userContent != value) {
if (errorList.Count == 0 && userControl != null) { userContent = value;
panel.Controls.Remove(userControl); if (errorList.Count == 0) {
} contentControl.SetContent(userContent);
userControl = value;
userControl.Dock = DockStyle.Fill;
if (errorList.Count == 0 && userControl != null) {
panel.Controls.Add(userControl);
} }
} }
} }
@ -90,15 +87,11 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
if (errorTextBox == null) { if (errorTextBox == null) {
errorTextBox = new TextBox(); errorTextBox = new TextBox();
errorTextBox.Multiline = true; errorTextBox.IsReadOnly = true;
errorTextBox.ScrollBars = ScrollBars.Both; errorTextBox.Background = SystemColors.WindowBrush;
errorTextBox.ReadOnly = true;
errorTextBox.BackColor = SystemColors.Window;
errorTextBox.Dock = DockStyle.Fill;
} }
errorTextBox.Text = ex.ToString(); errorTextBox.Text = ex.ToString();
panel.Controls.Clear(); contentControl.Content = errorTextBox;
panel.Controls.Add(errorTextBox);
} }
Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>(); Dictionary<OpenedFile, LoadError> errorList = new Dictionary<OpenedFile, LoadError>();
@ -110,10 +103,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (errorList.Count > 0) { if (errorList.Count > 0) {
errorList.Remove(file); errorList.Remove(file);
if (errorList.Count == 0) { if (errorList.Count == 0) {
panel.Controls.Clear(); contentControl.SetContent(userContent);
if (userControl != null) {
panel.Controls.Add(userControl);
}
} else { } else {
ShowError(errorList.Values.First().exception); ShowError(errorList.Values.First().exception);
} }

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

@ -105,13 +105,13 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
Control propertyGridReplacementControl; object propertyGridReplacementContent;
public Control PropertyGridReplacementControl { public object PropertyGridReplacementContent {
get { return propertyGridReplacementControl; } get { return propertyGridReplacementContent; }
set { set {
propertyGridReplacementControl = value; propertyGridReplacementContent = value;
PropertyPad.UpdatePropertyGridReplacementControl(this); PropertyPad.UpdatePropertyGridReplacementContent(this);
} }
} }
@ -125,7 +125,7 @@ namespace ICSharpCode.SharpDevelop.Gui
Host = null; Host = null;
SelectableObjects = null; SelectableObjects = null;
SelectedObject = null; SelectedObject = null;
PropertyGridReplacementControl = null; PropertyGridReplacementContent = null;
} }
} }
} }

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

@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Gui
UpdateHostIfActive(pc); UpdateHostIfActive(pc);
UpdateSelectedObjectIfActive(pc); UpdateSelectedObjectIfActive(pc);
UpdateSelectableIfActive(pc); UpdateSelectableIfActive(pc);
UpdatePropertyGridReplacementControl(pc); UpdatePropertyGridReplacementContent(pc);
} }
internal static void UpdateSelectedObjectIfActive(PropertyContainer container) internal static void UpdateSelectedObjectIfActive(PropertyContainer container)
@ -81,30 +81,23 @@ namespace ICSharpCode.SharpDevelop.Gui
instance.SetSelectableObjects(container.SelectableObjects); instance.SetSelectableObjects(container.SelectableObjects);
} }
internal static void UpdatePropertyGridReplacementControl(PropertyContainer container) internal static void UpdatePropertyGridReplacementContent(PropertyContainer container)
{ {
if (instance == null) return; if (instance == null) return;
if (instance.activeContainer != container) if (instance.activeContainer != container)
return; return;
LoggingService.Debug("UpdatePropertyGridReplacementControl"); LoggingService.Debug("UpdatePropertyGridReplacementControl");
if (container.PropertyGridReplacementControl != null) { if (container.PropertyGridReplacementContent != null) {
if (!instance.panel.Controls.Contains(container.PropertyGridReplacementControl)) { instance.contentControl.SetContent(container.PropertyGridReplacementContent);
instance.panel.Controls.Clear();
container.PropertyGridReplacementControl.Dock = DockStyle.Fill;
instance.panel.Controls.Add(container.PropertyGridReplacementControl);
}
} else { } else {
if (!instance.panel.Controls.Contains(instance.grid)) { instance.contentControl.SetContent(instance.panel);
instance.panel.Controls.Clear();
instance.panel.Controls.Add(instance.grid);
instance.panel.Controls.Add(instance.comboBox);
}
} }
} }
Panel panel; System.Windows.Controls.ContentControl contentControl;
ComboBox comboBox; Panel panel;
PropertyGrid grid; ComboBox comboBox;
PropertyGrid grid;
IDesignerHost host; IDesignerHost host;
/// <summary> /// <summary>
@ -125,7 +118,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public override object Content { public override object Content {
get { get {
return panel; return contentControl;
} }
} }
@ -157,6 +150,7 @@ namespace ICSharpCode.SharpDevelop.Gui
public PropertyPad() public PropertyPad()
{ {
instance = this; instance = this;
contentControl = new System.Windows.Controls.ContentControl();
panel = new Panel(); panel = new Panel();
grid = new PropertyGrid(); grid = new PropertyGrid();

1
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

@ -212,6 +212,7 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
AvalonWorkbenchWindow window = new AvalonWorkbenchWindow(this); AvalonWorkbenchWindow window = new AvalonWorkbenchWindow(this);
window.ViewContents.Add(content); window.ViewContents.Add(content);
window.ViewContents.AddRange(content.SecondaryViewContents);
documentPane.Items.Add(window); documentPane.Items.Add(window);
dockingManager.Show(window); dockingManager.Show(window);
return window; return window;

2
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonPadContent.cs

@ -50,7 +50,7 @@ namespace ICSharpCode.SharpDevelop.Gui
placeholder.IsVisibleChanged -= AvalonPadContent_IsVisibleChanged; placeholder.IsVisibleChanged -= AvalonPadContent_IsVisibleChanged;
content = descriptor.PadContent; content = descriptor.PadContent;
if (content != null) { if (content != null) {
this.Content = AvalonWorkbenchWindow.WrapContent(content.Content); this.SetContent(content.Content);
placeholder = null; placeholder = null;
} }
} }

23
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -118,7 +118,7 @@ namespace ICSharpCode.SharpDevelop.Gui
window.RegisterNewContent(item); window.RegisterNewContent(item);
if (Count == 1) { if (Count == 1) {
window.Content = WrapContent(item.Content); window.SetContent(item.Content);
} else { } else {
if (Count == 2) { if (Count == 2) {
window.CreateViewTabControl(); window.CreateViewTabControl();
@ -127,13 +127,13 @@ namespace ICSharpCode.SharpDevelop.Gui
TabItem oldPage = new TabItem(); TabItem oldPage = new TabItem();
oldPage.Header = StringParser.Parse(oldItem.TabPageText); oldPage.Header = StringParser.Parse(oldItem.TabPageText);
oldPage.Content = WrapContent(oldItem.Content); oldPage.SetContent(oldItem.Content);
window.viewTabControl.Items.Add(oldPage); window.viewTabControl.Items.Add(oldPage);
} }
TabItem newPage = new TabItem(); TabItem newPage = new TabItem();
newPage.Header = StringParser.Parse(item.TabPageText); newPage.Header = StringParser.Parse(item.TabPageText);
newPage.Content = WrapContent(item.Content); newPage.SetContent(item.Content);
window.viewTabControl.Items.Insert(index, newPage); window.viewTabControl.Items.Insert(index, newPage);
} }
@ -149,7 +149,7 @@ namespace ICSharpCode.SharpDevelop.Gui
if (Count < 2) { if (Count < 2) {
window.ClearContent(); window.ClearContent();
if (Count == 1) { if (Count == 1) {
window.Content = this[0].Content; window.SetContent(this[0].Content);
} }
} else { } else {
window.viewTabControl.Items.RemoveAt(index); window.viewTabControl.Items.RemoveAt(index);
@ -167,27 +167,16 @@ namespace ICSharpCode.SharpDevelop.Gui
if (Count == 1) { if (Count == 1) {
window.ClearContent(); window.ClearContent();
window.Content = WrapContent(item.Content); window.SetContent(item.Content);
} else { } else {
TabItem page = (TabItem)window.viewTabControl.Items[index]; TabItem page = (TabItem)window.viewTabControl.Items[index];
page.Content = WrapContent(item.Content); page.SetContent(item.Content);
page.Header = StringParser.Parse(item.TabPageText); page.Header = StringParser.Parse(item.TabPageText);
} }
window.UpdateActiveViewContent(); window.UpdateActiveViewContent();
} }
} }
internal static object WrapContent(object content)
{
if (content is System.Windows.Forms.Control) {
return new System.Windows.Forms.Integration.WindowsFormsHost {
Child = (System.Windows.Forms.Control)content
};
} else {
return content;
}
}
readonly ViewContentCollection viewContents; readonly ViewContentCollection viewContents;
public IList<IViewContent> ViewContents { public IList<IViewContent> ViewContents {

36
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -10,7 +10,9 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Windows.Forms;
using WinForms = System.Windows.Forms;
using System.Windows.Controls;
namespace ICSharpCode.SharpDevelop namespace ICSharpCode.SharpDevelop
{ {
@ -50,11 +52,11 @@ namespace ICSharpCode.SharpDevelop
return string.Join(separator, input.ToArray()); return string.Join(separator, input.ToArray());
} }
public static IEnumerable<Control> GetRecursive(this Control.ControlCollection collection) public static IEnumerable<WinForms.Control> GetRecursive(this WinForms.Control.ControlCollection collection)
{ {
foreach (Control ctl in collection) { foreach (WinForms.Control ctl in collection) {
yield return ctl; yield return ctl;
foreach (Control subCtl in ctl.Controls.GetRecursive()) { foreach (WinForms.Control subCtl in ctl.Controls.GetRecursive()) {
yield return subCtl; yield return subCtl;
} }
} }
@ -89,7 +91,7 @@ namespace ICSharpCode.SharpDevelop
/// <summary> /// <summary>
/// Gets the IWin32Window associated with a WPF window. /// Gets the IWin32Window associated with a WPF window.
/// </summary> /// </summary>
public static System.Windows.Forms.IWin32Window GetWin32Window(this System.Windows.Window window) public static WinForms.IWin32Window GetWin32Window(this System.Windows.Window window)
{ {
var wnd = System.Windows.PresentationSource.FromVisual(window) as System.Windows.Interop.IWin32Window; var wnd = System.Windows.PresentationSource.FromVisual(window) as System.Windows.Interop.IWin32Window;
if (wnd != null) if (wnd != null)
@ -98,7 +100,7 @@ namespace ICSharpCode.SharpDevelop
return null; return null;
} }
sealed class Win32WindowAdapter : System.Windows.Forms.IWin32Window sealed class Win32WindowAdapter : WinForms.IWin32Window
{ {
System.Windows.Interop.IWin32Window window; System.Windows.Interop.IWin32Window window;
@ -111,5 +113,27 @@ namespace ICSharpCode.SharpDevelop
get { return window.Handle; } get { return window.Handle; }
} }
} }
/// <summary>
/// Sets the Content property of the specified ControlControl to the specified content.
/// If the content is a Windows-Forms control, it is wrapped in a WindowsFormsHost.
/// If the content control already contains a WindowsFormsHost with that content,
/// the old WindowsFormsHost is kept.
/// </summary>
public static void SetContent(this ContentControl contentControl, object content)
{
if (contentControl == null)
throw new ArgumentNullException("contentControl");
if (content is WinForms.Control) {
var host = contentControl.Content as WinForms.Integration.WindowsFormsHost;
if (host == null || host.Child != content) {
contentControl.Content = new WinForms.Integration.WindowsFormsHost {
Child = (System.Windows.Forms.Control)content
};
}
} else {
contentControl.Content = content;
}
}
} }
} }

Loading…
Cancel
Save