Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2444 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
19 changed files with 377 additions and 46 deletions
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
// <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.Diagnostics; |
||||
using System.Windows; |
||||
using System.Windows.Data; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Media; |
||||
using System.Windows.Threading; |
||||
using ICSharpCode.WpfDesign.PropertyEditor; |
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Controls.TypeEditors |
||||
{ |
||||
/// <summary>
|
||||
/// Description of ContentEditor.
|
||||
/// </summary>
|
||||
[PropertyEditor(typeof(ContentControl), "Content")] |
||||
[PropertyEditor(typeof(HeaderedContentControl), "Header")] |
||||
[PropertyEditor(typeof(HeaderedItemsControl), "Header")] |
||||
public class ContentEditor : DockPanel |
||||
{ |
||||
readonly IPropertyEditorDataProperty property; |
||||
Button createObjectButton = new Button(); |
||||
readonly TextBoxEditor textBoxEditor; |
||||
readonly FallbackEditor fallbackEditor; |
||||
readonly DataPropertyWithCustomOnValueChangedEvent textBoxEditorDataProperty, fallbackEditorDataProperty; |
||||
UIElement activeEditor; |
||||
DataPropertyWithCustomOnValueChangedEvent activeEditorDataProperty; |
||||
|
||||
public ContentEditor(IPropertyEditorDataProperty property) |
||||
{ |
||||
this.property = property; |
||||
PropertyEditorBindingHelper.AddValueChangedEventHandler(this, property, OnValueChanged); |
||||
|
||||
createObjectButton.Content = "C"; |
||||
createObjectButton.ContextMenuOpening += delegate { |
||||
createObjectButton.ContextMenu = CreateContextMenu(); |
||||
}; |
||||
createObjectButton.Click += delegate { |
||||
createObjectButton.ContextMenu = CreateContextMenu(); |
||||
createObjectButton.ContextMenu.IsOpen = true; |
||||
}; |
||||
SetDock(createObjectButton, Dock.Right); |
||||
this.Children.Add(createObjectButton); |
||||
|
||||
textBoxEditor = new TextBoxEditor(textBoxEditorDataProperty = new DataPropertyWithCustomOnValueChangedEvent(property)); |
||||
fallbackEditor = new FallbackEditor(fallbackEditorDataProperty = new DataPropertyWithCustomOnValueChangedEvent(property)); |
||||
|
||||
OnValueChanged(null, null); |
||||
} |
||||
|
||||
#region CreateObjectButton Context menu
|
||||
ContextMenu CreateContextMenu() |
||||
{ |
||||
ContextMenu contextMenu = new ContextMenu(); |
||||
contextMenu.Items.Add(CreateMenuItem("Set to _null", delegate { property.Value = null; })); |
||||
contextMenu.Items.Add(CreateMenuItem("Create _string", delegate { property.Value = ""; })); |
||||
return contextMenu; |
||||
} |
||||
|
||||
static MenuItem CreateMenuItem(string title, RoutedEventHandler handler) |
||||
{ |
||||
MenuItem item = new MenuItem(); |
||||
item.Header = title; |
||||
item.Click += handler; |
||||
return item; |
||||
} |
||||
#endregion
|
||||
|
||||
void SetActiveEditor(UIElement newEditor, DataPropertyWithCustomOnValueChangedEvent newDataProperty) |
||||
{ |
||||
if (activeEditor != newEditor) { |
||||
if (activeEditorDataProperty != null) { |
||||
activeEditorDataProperty.preventSetValue = true; |
||||
} |
||||
this.Children.Remove(activeEditor); |
||||
this.Children.Add(newEditor); |
||||
activeEditor = newEditor; |
||||
newDataProperty.preventSetValue = false; |
||||
activeEditorDataProperty = newDataProperty; |
||||
} |
||||
} |
||||
|
||||
void OnValueChanged(object sender, EventArgs e) |
||||
{ |
||||
object val = property.Value; |
||||
if (val is string) { |
||||
SetActiveEditor(textBoxEditor, textBoxEditorDataProperty); |
||||
} else { |
||||
SetActiveEditor(fallbackEditor, fallbackEditorDataProperty); |
||||
} |
||||
// raise ValueChanged after the new editor's Loaded event has fired
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, |
||||
(Action)activeEditorDataProperty.RaiseValueChanged); |
||||
} |
||||
|
||||
sealed class DataPropertyWithCustomOnValueChangedEvent : ProxyPropertyEditorDataProperty |
||||
{ |
||||
internal DataPropertyWithCustomOnValueChangedEvent(IPropertyEditorDataProperty property) |
||||
: base(property) |
||||
{ |
||||
} |
||||
|
||||
EventHandler valueChangedListeners; |
||||
internal bool preventSetValue; |
||||
|
||||
public override object Value { |
||||
get { return base.Value; } |
||||
set { |
||||
if (!preventSetValue) { |
||||
base.Value = value; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override event EventHandler ValueChanged { |
||||
add { valueChangedListeners += value; } |
||||
remove { valueChangedListeners -= value; } |
||||
} |
||||
|
||||
public override System.ComponentModel.TypeConverter TypeConverter { |
||||
get { return System.ComponentModel.TypeDescriptor.GetConverter(typeof(string)); } |
||||
} |
||||
|
||||
internal void RaiseValueChanged() |
||||
{ |
||||
if (valueChangedListeners != null) { |
||||
valueChangedListeners(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
// <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; |
||||
|
||||
namespace ICSharpCode.WpfDesign.PropertyEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Implements IPropertyEditorDataProperty by forwarding all calls to another IPropertyEditorDataProperty.
|
||||
/// </summary>
|
||||
public abstract class ProxyPropertyEditorDataProperty : IPropertyEditorDataProperty |
||||
{ |
||||
readonly IPropertyEditorDataProperty data; |
||||
|
||||
/// <summary></summary>
|
||||
protected ProxyPropertyEditorDataProperty(IPropertyEditorDataProperty data) |
||||
{ |
||||
if (data == null) |
||||
throw new ArgumentNullException("data"); |
||||
this.data = data; |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual event EventHandler IsSetChanged { |
||||
add { data.IsSetChanged += value; } |
||||
remove { data.IsSetChanged -= value; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual event EventHandler ValueChanged { |
||||
add { data.ValueChanged += value; } |
||||
remove { data.ValueChanged -= value; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual IPropertyEditorDataSource OwnerDataSource { |
||||
get { return data.OwnerDataSource; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual string Category { |
||||
get { return data.Category; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual string Name { |
||||
get { return data.Name; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual Type ReturnType { |
||||
get { return data.ReturnType; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual Type DeclaringType { |
||||
get { return data.DeclaringType; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual System.ComponentModel.TypeConverter TypeConverter { |
||||
get { return data.TypeConverter; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual bool IsSet { |
||||
get { return data.IsSet; } |
||||
set { data.IsSet = value; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual bool IsAmbiguous { |
||||
get { return data.IsAmbiguous; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual object Value { |
||||
get { return data.Value; } |
||||
set { data.Value = value; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual bool CanUseCustomExpression { |
||||
get { return data.CanUseCustomExpression; } |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual object GetDescription() |
||||
{ |
||||
return data.GetDescription(); |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual void SetCustomExpression(string expression) |
||||
{ |
||||
data.SetCustomExpression(expression); |
||||
} |
||||
|
||||
/// <summary>See <see cref="IPropertyEditorDataProperty"/></summary>
|
||||
public virtual System.Windows.UIElement CreateEditor() |
||||
{ |
||||
return data.CreateEditor(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue