diff --git a/samples/XamlDesigner/ActionManager.cs b/samples/XamlDesigner/ActionManager.cs deleted file mode 100644 index ca6a9a4db2..0000000000 --- a/samples/XamlDesigner/ActionManager.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Input; -using System.Windows.Documents; -using System.Windows.Controls.Primitives; -using System.Windows.Controls; -using System.Windows.Media; -using System.Windows; -using System.Windows.Markup; -using System.ComponentModel; -using System.Globalization; -using System.Windows.Threading; - -namespace ICSharpCode.XamlDesigner -{ - public enum DisableMode - { - Disable, Collapse - } - - public class ActionArgs - { - public FrameworkElement Element { get; internal set; } - } - - public delegate void ActionHandler(ActionArgs e); - public delegate bool CanActionHandler(ActionArgs e); - - public class Action - { - public Action() - { - Elements = new List(); - Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded, new System.Action(RegisterRequery)); - } - - void RegisterRequery() - { - CommandManager.RequerySuggested += new EventHandler(CommandManager_RequerySuggested); - } - - void CommandManager_RequerySuggested(object sender, EventArgs e) - { - UpdateElements(); - } - - public string Text { get; set; } - public Shortcut Shortcut { get; set; } - public ImageSource IconSource { get; set; } - public DisableMode DisableMode { get; set; } - public event ActionHandler Executed; - public event CanActionHandler CanExecute; - public List Elements { get; private set; } - - public object ExecuteHost { - get { - if (Executed != null) return Executed.Target; - return null; - } - } - - public void AttachTo(FrameworkElement f) - { - SetText(f); - SetShortcut(f); - SetIcon(f); - SetEvent(f); - - Elements.Add(f); - } - - public void UpdateElements() - { - if (CanExecute != null) { - foreach (var f in Elements) { - f.IsEnabled = CanExecute(new ActionArgs() { Element = f }); - } - } - } - - void SetText(FrameworkElement f) - { - if (Text == null) return; - if (f is ContentControl) { - (f as ContentControl).Content = Text; - } - else if (f is HeaderedItemsControl) { - (f as HeaderedItemsControl).Header = Text; - } - } - - void SetShortcut(FrameworkElement f) - { - if (Shortcut == null) return; - if (f is MenuItem) { - (f as MenuItem).InputGestureText = Shortcut.ToString(); - } - if (ExecuteHost == null) return; - (ExecuteHost as IInputElement).KeyDown += delegate(object sender, KeyEventArgs e) { - if (e.Key == Shortcut.Key && Keyboard.Modifiers == Shortcut.Modifiers) { - Executed(new ActionArgs() { Element = f }); - } - }; - } - - void SetIcon(FrameworkElement f) - { - if (IconSource == null) return; - if (f is MenuItem) { - (f as MenuItem).Icon = new Image() { Source = IconSource }; - } - } - - void SetEvent(FrameworkElement f) - { - if (Executed == null) return; - f.PreviewMouseLeftButtonUp += delegate { - Executed(new ActionArgs() { Element = f }); - }; - } - } - - public static class ActionManager - { - public static void SetAction(DependencyObject obj, object value) - { - Action a = value as Action; - if (a == null) { - if (obj is FrameworkElement) { - a = (Action)(obj as FrameworkElement).FindResource(value); - } - } - a.AttachTo(obj as FrameworkElement); - } - } - - [TypeConverter(typeof(ShortcutConverter))] - public class Shortcut - { - public ModifierKeys Modifiers; - public Key Key; - - static KeyConverter KeyConverter = new KeyConverter(); - static ModifierKeysConverter ModifierKeysConverter = new ModifierKeysConverter(); - - public static Shortcut FromString(string s) - { - var result = new Shortcut(); - var pos = s.LastIndexOf('+'); - if (pos < 0) { - result.Key = (Key)KeyConverter.ConvertFromString(s); - } - else { - result.Modifiers = (ModifierKeys)ModifierKeysConverter.ConvertFromString(s.Substring(0, pos)); - result.Key = (Key)KeyConverter.ConvertFromString(s.Substring(pos + 1)); - } - return result; - } - - public override string ToString() - { - if (Modifiers == ModifierKeys.None) return KeyConverter.ConvertToString(Key); - return ModifierKeysConverter.ConvertToString(Modifiers) + "+" + KeyConverter.ConvertToString(Key); - } - } - - public class ShortcutConverter : TypeConverter - { - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - { - return sourceType == typeof(string); - } - - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - return Shortcut.FromString((string)value); - } - } -} diff --git a/samples/XamlDesigner/App.xaml b/samples/XamlDesigner/App.xaml index f4aa915e30..92f0a6eb37 100644 --- a/samples/XamlDesigner/App.xaml +++ b/samples/XamlDesigner/App.xaml @@ -2,7 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:ICSharpCode.XamlDesigner.Converters" - StartupUri="MainWindow.xaml"> + StartupUri="MainWindow.xaml" + ShutdownMode="OnMainWindowClose"> diff --git a/samples/XamlDesigner/Converters.cs b/samples/XamlDesigner/Converters.cs index 3590603bf4..feeb6d9d02 100644 --- a/samples/XamlDesigner/Converters.cs +++ b/samples/XamlDesigner/Converters.cs @@ -50,4 +50,17 @@ namespace ICSharpCode.XamlDesigner.Converters throw new NotImplementedException(); } } + + public class LevelConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return new Thickness(5 + 19 * (int)value, 0, 5, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } } diff --git a/samples/XamlDesigner/Document.cs b/samples/XamlDesigner/Document.cs index 5c1da59c5b..b3fa6a79f6 100644 --- a/samples/XamlDesigner/Document.cs +++ b/samples/XamlDesigner/Document.cs @@ -48,28 +48,31 @@ namespace ICSharpCode.XamlDesigner DocumentMode mode; - void SetMode(DocumentMode newMode) - { - mode = newMode; - if (IsDesign) { - UpdateDesign(); + public DocumentMode Mode { + get { + return mode; } - else { - UpdateXaml(); + set { + mode = value; + if (InDesignMode) { + UpdateDesign(); + } + else { + UpdateXaml(); + } + RaisePropertyChanged("Mode"); + RaisePropertyChanged("InXamlMode"); + RaisePropertyChanged("InDesignMode"); + RaisePropertyChanged("SelectionService"); } - RaisePropertyChanged("IsXaml"); - RaisePropertyChanged("IsDesign"); - RaisePropertyChanged("SelectionService"); } - public bool IsXaml { - get { return mode == DocumentMode.Xaml; } - set { if (value) SetMode(DocumentMode.Xaml); } + public bool InXamlMode { + get { return Mode == DocumentMode.Xaml; } } - public bool IsDesign { - get { return mode == DocumentMode.Design; } - set { if (value) SetMode(DocumentMode.Design); } + public bool InDesignMode { + get { return Mode == DocumentMode.Design; } } string filePath; @@ -134,13 +137,25 @@ namespace ICSharpCode.XamlDesigner public ISelectionService SelectionService { get { - if (IsDesign && DesignContext != null) { + if (InDesignMode && DesignContext != null) { return DesignContext.Services.Selection; } return null; } } + OutlineNode outlineRoot; + + public OutlineNode OutlineRoot { + get { + return outlineRoot; + } + private set { + outlineRoot = value; + RaisePropertyChanged("OutlineRoot"); + } + } + void ReloadFile() { Text = File.ReadAllText(FilePath); @@ -150,7 +165,7 @@ namespace ICSharpCode.XamlDesigner public void Save() { - if (IsDesign) { + if (InDesignMode) { UpdateXaml(); } File.WriteAllText(FilePath, Text); @@ -184,13 +199,27 @@ namespace ICSharpCode.XamlDesigner using (var xmlReader = XmlReader.Create(new StringReader(Text))) { DesignSurface.LoadDesigner(xmlReader, settings); } - UndoService.UndoStackChanged += delegate { IsDirty = true; }; + if (DesignContext.RootItem == null) { + OutlineRoot = null; + } + else { + OutlineRoot = new OutlineNode(DesignContext.RootItem); + } + UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged); } catch (Exception x) { Shell.ReportException(x); } } + void UndoService_UndoStackChanged(object sender, EventArgs e) + { + IsDirty = true; + if (InXamlMode) { + UpdateXaml(); + } + } + #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; @@ -203,10 +232,10 @@ namespace ICSharpCode.XamlDesigner } #endregion + } - enum DocumentMode - { - Xaml, Design - } + public enum DocumentMode + { + Xaml, Design } } diff --git a/samples/XamlDesigner/DocumentView.xaml b/samples/XamlDesigner/DocumentView.xaml index c2fc424bea..f78c793074 100644 --- a/samples/XamlDesigner/DocumentView.xaml +++ b/samples/XamlDesigner/DocumentView.xaml @@ -4,36 +4,18 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Integration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" xmlns:TextEditor="clr-namespace:ICSharpCode.TextEditor;assembly=ICSharpCode.TextEditor" + xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner" > - - - - - - + - + + Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/> diff --git a/samples/XamlDesigner/DragListener.cs b/samples/XamlDesigner/DragListener.cs index e2d3cec7c9..a446d9f19e 100644 --- a/samples/XamlDesigner/DragListener.cs +++ b/samples/XamlDesigner/DragListener.cs @@ -7,51 +7,51 @@ using System.Windows.Input; namespace ICSharpCode.XamlDesigner { - class DragListener - { - public DragListener(IInputElement target) - { - this.target = target; - target.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(target_PreviewMouseLeftButtonDown); - target.PreviewMouseMove += new MouseEventHandler(target_PreviewMouseMove); - } + public class DragListener + { + public DragListener(FrameworkElement target) + { + this.target = target; + target.AddHandler(Mouse.MouseDownEvent, new MouseButtonEventHandler(MouseButtonDown), true); + target.PreviewMouseMove += MouseMove; + target.PreviewMouseLeftButtonUp += MouseLeftButtonUp; + } - public event MouseEventHandler DragStarted; - - IInputElement target; - Window window; - Point startPoint; - bool readyToRaise; + public event MouseButtonEventHandler DragStarted; - Point GetMousePosition() - { - if (window == null) { - window = Window.GetWindow(target as DependencyObject); - } - return Mouse.GetPosition(window); - } + FrameworkElement target; + Point startPoint; + bool ready; + MouseButtonEventArgs args; - bool IsMovementBigEnough() - { - Point currentPoint = GetMousePosition(); - return (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance || - Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance); - } + void MouseButtonDown(object sender, MouseButtonEventArgs e) + { + if (e.ChangedButton == MouseButton.Left && Mouse.Captured == null) { + ready = true; + startPoint = e.GetPosition(target); + args = e; + target.CaptureMouse(); + } + } - void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) - { - readyToRaise = true; - startPoint = GetMousePosition(); - } + void MouseMove(object sender, MouseEventArgs e) + { + if (ready) { + var currentPoint = e.GetPosition(target); + if (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance || + Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance) { + ready = false; + if (DragStarted != null) { + DragStarted(this, args); + } + } + } + } - void target_PreviewMouseMove(object sender, MouseEventArgs e) - { - if (readyToRaise && IsMovementBigEnough()) { - readyToRaise = false; - if (DragStarted != null) { - DragStarted(target, e); - } - } - } - } + void MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + ready = false; + target.ReleaseMouseCapture(); + } + } } diff --git a/samples/XamlDesigner/DragTreeView.cs b/samples/XamlDesigner/DragTreeView.cs new file mode 100644 index 0000000000..833d9425f1 --- /dev/null +++ b/samples/XamlDesigner/DragTreeView.cs @@ -0,0 +1,327 @@ +using System; +using System.Collections.Generic; +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.Collections.Specialized; +using ICSharpCode.XamlDesigner.Converters; +using System.Collections; + +namespace ICSharpCode.XamlDesigner +{ + // limitations: + // - Do not use ItemsSource (use Root) + // - Do not use Items (use Root) + public class DragTreeView : TreeView + { + static DragTreeView() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(DragTreeView), + new FrameworkPropertyMetadata(typeof(DragTreeView))); + } + + public DragTreeView() + { + AllowDrop = true; + new DragListener(this).DragStarted += new MouseButtonEventHandler(DragTreeView_DragStarted); + } + + DragTreeViewItem dropTarget; + DragTreeViewItem treeItem; + DragTreeViewItem dropAfter; + int part; + bool dropInside; + bool dropCopy; + bool canDrop; + + Border insertLine; + + public static readonly DependencyProperty RootProperty = + DependencyProperty.Register("Root", typeof(object), typeof(DragTreeView)); + + public object Root { + get { return (object)GetValue(RootProperty); } + set { SetValue(RootProperty, value); } + } + + //public object[] SelectedItems + //{ + // get { return Selection.Select(item => item.DataContext).ToArray(); } + //} + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + if (e.Property == RootProperty) { + ItemsSource = new[] { Root }; + } + } + + void DragTreeView_DragStarted(object sender, MouseButtonEventArgs e) + { + DragDrop.DoDragDrop(this, this, DragDropEffects.All); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + insertLine = (Border)Template.FindName("PART_InsertLine", this); + } + + protected override DependencyObject GetContainerForItemOverride() + { + return new DragTreeViewItem(); + } + + protected override bool IsItemItsOwnContainerOverride(object item) + { + return item is DragTreeViewItem; + } + + protected override void OnDragEnter(DragEventArgs e) + { + ProcessDrag(e); + } + + protected override void OnDragOver(DragEventArgs e) + { + ProcessDrag(e); + } + + protected override void OnDrop(DragEventArgs e) + { + ProcessDrop(e); + } + + protected override void OnDragLeave(DragEventArgs e) + { + HideDropMarker(); + } + + void PrepareDropInfo(DragEventArgs e) + { + dropTarget = null; + dropAfter = null; + treeItem = (e.OriginalSource as DependencyObject).FindAncestor(); + + if (treeItem != null) { + var parent = ItemsControl.ItemsControlFromItemContainer(treeItem) as DragTreeViewItem; + ContentPresenter header = treeItem.HeaderPresenter; + Point p = e.GetPosition(header); + part = (int)(p.Y / (header.ActualHeight / 3)); + dropCopy = Keyboard.IsKeyDown(Key.LeftCtrl); + dropInside = false; + + if (part == 1 || parent == null) { + dropTarget = treeItem; + dropInside = true; + if (treeItem.Items.Count > 0) { + dropAfter = treeItem.ItemContainerGenerator.ContainerFromIndex(treeItem.Items.Count - 1) as DragTreeViewItem; + } + } + else if (part == 0) { + dropTarget = parent; + var index = dropTarget.ItemContainerGenerator.IndexFromContainer(treeItem); + if (index > 0) { + dropAfter = dropTarget.ItemContainerGenerator.ContainerFromIndex(index - 1) as DragTreeViewItem; + } + } + else { + dropTarget = parent; + dropAfter = treeItem; + } + } + } + + void ProcessDrag(DragEventArgs e) + { + e.Effects = DragDropEffects.None; + e.Handled = true; + canDrop = false; + + if (e.Data.GetData(GetType()) != this) return; + + HideDropMarker(); + PrepareDropInfo(e); + + if (dropTarget != null && CanInsertInternal()) { + canDrop = true; + e.Effects = dropCopy ? DragDropEffects.Copy : DragDropEffects.Move; + DrawDropMarker(); + } + } + + void ProcessDrop(DragEventArgs e) + { + HideDropMarker(); + + if (canDrop) { + InsertInternal(); + } + } + + void DrawDropMarker() + { + if (dropInside) { + dropTarget.IsDragHover = true; + } + else { + var header = treeItem.HeaderPresenter; + var p = header.TransformToVisual(this).Transform( + new Point(0, part == 0 ? 0 : header.ActualHeight)); + + insertLine.Visibility = Visibility.Visible; + insertLine.Margin = new Thickness(p.X, p.Y, 0, 0); + } + } + + void HideDropMarker() + { + insertLine.Visibility = Visibility.Collapsed; + if (dropTarget != null) { + dropTarget.IsDragHover = false; + } + } + + internal HashSet Selection = new HashSet(); + DragTreeViewItem upSelection; + + internal void ItemMouseDown(DragTreeViewItem item) + { + upSelection = null; + bool control = Keyboard.IsKeyDown(Key.LeftCtrl); + + if (Selection.Contains(item)) { + if (control) { + Unselect(item); + } + else { + upSelection = item; + } + } + else { + if (control) { + Select(item); + } + else { + SelectOnly(item); + } + } + } + + internal void ItemMouseUp(DragTreeViewItem item) + { + if (upSelection == item) { + SelectOnly(item); + } + upSelection = null; + } + + internal void ItemAttached(DragTreeViewItem item) + { + if (item.IsSelected) Selection.Add(item); + } + + internal void ItemDetached(DragTreeViewItem item) + { + if (item.IsSelected) Selection.Remove(item); + } + + internal void ItemIsSelectedChanged(DragTreeViewItem item) + { + if (item.IsSelected) { + Selection.Add(item); + } + else { + Selection.Remove(item); + } + } + + void Select(DragTreeViewItem item) + { + Selection.Add(item); + item.IsSelected = true; + OnSelectionChanged(); + } + + void Unselect(DragTreeViewItem item) + { + Selection.Remove(item); + item.IsSelected = false; + OnSelectionChanged(); + } + + void SelectOnly(DragTreeViewItem item) + { + ClearSelection(); + Select(item); + OnSelectionChanged(); + } + + void ClearSelection() + { + foreach (var treeItem in Selection.ToArray()) { + treeItem.IsSelected = false; + } + Selection.Clear(); + OnSelectionChanged(); + } + + void OnSelectionChanged() + { + } + + bool CanInsertInternal() + { + if (!dropCopy) { + var item = dropTarget; + while (true) { + if (Selection.Contains(item)) return false; + item = ItemsControl.ItemsControlFromItemContainer(item) as DragTreeViewItem; + if (item == null) break; + } + + if (Selection.Contains(dropAfter)) return false; + } + + return CanInsert(dropTarget, Selection.ToArray(), dropAfter, dropCopy); + } + + void InsertInternal() + { + var selection = Selection.ToArray(); + + if (!dropCopy) { + foreach (var item in Selection.ToArray()) { + var parent = ItemsControl.ItemsControlFromItemContainer(item) as DragTreeViewItem; + //TODO + if (parent != null) { + Remove(parent, item); + } + } + } + Insert(dropTarget, selection, dropAfter, dropCopy); + } + + protected virtual bool CanInsert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy) + { + return true; + } + + protected virtual void Insert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy) + { + } + + protected virtual void Remove(DragTreeViewItem target, DragTreeViewItem item) + { + } + } +} diff --git a/samples/XamlDesigner/DragTreeViewItem.cs b/samples/XamlDesigner/DragTreeViewItem.cs new file mode 100644 index 0000000000..6738e36c42 --- /dev/null +++ b/samples/XamlDesigner/DragTreeViewItem.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +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.Windows.Controls.Primitives; + +namespace ICSharpCode.XamlDesigner +{ + public class DragTreeViewItem : TreeViewItem + { + static DragTreeViewItem() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(DragTreeViewItem), + new FrameworkPropertyMetadata(typeof(DragTreeViewItem))); + } + + public DragTreeViewItem() + { + Loaded += new RoutedEventHandler(DragTreeViewItem_Loaded); + Unloaded += new RoutedEventHandler(DragTreeViewItem_Unloaded); + } + + void DragTreeViewItem_Loaded(object sender, RoutedEventArgs e) + { + ParentTree = this.FindAncestor(); + if (ParentTree != null) { + ParentTree.ItemAttached(this); + } + } + + void DragTreeViewItem_Unloaded(object sender, RoutedEventArgs e) + { + if (ParentTree != null) { + ParentTree.ItemDetached(this); + } + ParentTree = null; + } + + public new static readonly DependencyProperty IsSelectedProperty = + Selector.IsSelectedProperty.AddOwner(typeof(DragTreeViewItem)); + + public new bool IsSelected { + get { return (bool)GetValue(IsSelectedProperty); } + set { SetValue(IsSelectedProperty, value); } + } + + public static readonly DependencyProperty IsDragHoverProperty = + DependencyProperty.Register("IsDragHover", typeof(bool), typeof(DragTreeViewItem)); + + public bool IsDragHover { + get { return (bool)GetValue(IsDragHoverProperty); } + set { SetValue(IsDragHoverProperty, value); } + } + + internal ContentPresenter HeaderPresenter { + get { return (ContentPresenter)Template.FindName("PART_Header", this); } + } + + public static readonly DependencyProperty LevelProperty = + DependencyProperty.Register("Level", typeof(int), typeof(DragTreeViewItem)); + + public int Level { + get { return (int)GetValue(LevelProperty); } + set { SetValue(LevelProperty, value); } + } + + public DragTreeView ParentTree { get; private set; } + + protected override void OnVisualParentChanged(DependencyObject oldParent) + { + base.OnVisualParentChanged(oldParent); + + var parentItem = ItemsControl.ItemsControlFromItemContainer(this) as DragTreeViewItem; + if (parentItem != null) Level = parentItem.Level + 1; + } + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + if (e.Property == IsSelectedProperty) { + if (ParentTree != null) { + ParentTree.ItemIsSelectedChanged(this); + } + } + } + + protected override DependencyObject GetContainerForItemOverride() + { + return new DragTreeViewItem(); + } + + protected override bool IsItemItsOwnContainerOverride(object item) + { + return item is DragTreeViewItem; + } + + protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) + { + base.OnMouseLeftButtonDown(e); + if (e.Source is ToggleButton || e.Source is ItemsPresenter) return; + ParentTree.ItemMouseDown(this); + } + + protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) + { + base.OnMouseLeftButtonUp(e); + ParentTree.ItemMouseUp(this); + } + } +} diff --git a/samples/XamlDesigner/EnumBar.xaml b/samples/XamlDesigner/EnumBar.xaml new file mode 100644 index 0000000000..b47b79b00f --- /dev/null +++ b/samples/XamlDesigner/EnumBar.xaml @@ -0,0 +1,7 @@ + + + diff --git a/samples/XamlDesigner/EnumBar.xaml.cs b/samples/XamlDesigner/EnumBar.xaml.cs new file mode 100644 index 0000000000..9d7e3c4ea5 --- /dev/null +++ b/samples/XamlDesigner/EnumBar.xaml.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +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.Windows.Controls.Primitives; + +namespace ICSharpCode.XamlDesigner +{ + public partial class EnumBar + { + public EnumBar() + { + InitializeComponent(); + } + + Type currentEnumType; + + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(object), typeof(EnumBar), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + public object Value { + get { return (object)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + + if (e.Property == ValueProperty) { + var type = e.NewValue.GetType(); + + if (currentEnumType != type) { + currentEnumType = type; + uxPanel.Children.Clear(); + foreach (var v in Enum.GetValues(type)) { + var b = new EnumButton(); + b.Value = v; + b.Content = Enum.GetName(type, v); + b.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(button_PreviewMouseLeftButtonDown); + uxPanel.Children.Add(b); + } + } + + foreach (EnumButton c in uxPanel.Children) { + if (c.Value.Equals(Value)) { + c.IsChecked = true; + } + else { + c.IsChecked = false; + } + } + } + } + + void button_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + Value = (sender as EnumButton).Value; + e.Handled = true; + } + } +} diff --git a/samples/XamlDesigner/EnumButton.cs b/samples/XamlDesigner/EnumButton.cs new file mode 100644 index 0000000000..a8a86d7d4a --- /dev/null +++ b/samples/XamlDesigner/EnumButton.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Controls.Primitives; +using System.Windows; + +namespace ICSharpCode.XamlDesigner +{ + public class EnumButton : ToggleButton + { + static EnumButton() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(EnumButton), + new FrameworkPropertyMetadata(typeof(EnumButton))); + } + + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(object), typeof(EnumButton)); + + public object Value { + get { return (object)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + } +} diff --git a/samples/XamlDesigner/IconItem.cs b/samples/XamlDesigner/IconItem.cs new file mode 100644 index 0000000000..f0d929ff05 --- /dev/null +++ b/samples/XamlDesigner/IconItem.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows.Controls; +using System.Windows; +using System.Windows.Media; + +namespace ICSharpCode.XamlDesigner +{ + public class IconItem : Control + { + static IconItem() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(IconItem), + new FrameworkPropertyMetadata(typeof(IconItem))); + } + + public static readonly DependencyProperty IconProperty = + DependencyProperty.Register("Icon", typeof(ImageSource), typeof(IconItem)); + + public ImageSource Icon { + get { return (ImageSource)GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + + public static readonly DependencyProperty TextProperty = + DependencyProperty.Register("Text", typeof(string), typeof(IconItem)); + + public string Text { + get { return (string)GetValue(TextProperty); } + set { SetValue(TextProperty, value); } + } + } +} diff --git a/samples/XamlDesigner/MainWindow.xaml b/samples/XamlDesigner/MainWindow.xaml index 3fda7bd62e..d7313aebda 100644 --- a/samples/XamlDesigner/MainWindow.xaml +++ b/samples/XamlDesigner/MainWindow.xaml @@ -4,7 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sd="http://sharpdevelop.net" xmlns:AvalonDock="clr-namespace:AvalonDock;assembly=AvalonDock" - xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner" + xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner" SnapsToDevicePixels="True" AllowDrop="True" Title="{Binding Title}"> @@ -22,7 +22,7 @@ CanExecute="CurrentDocument_CanExecute" PreviewExecuted="CloseCommand_PreviewExecuted"/> - @@ -34,11 +34,11 @@ Executed="SaveAsCommand_Executed" CanExecute="CurrentDocument_CanExecute" /> - - @@ -51,18 +51,18 @@ - + - + - + @@ -87,19 +87,19 @@ - + - + - + diff --git a/samples/XamlDesigner/Outline.xaml b/samples/XamlDesigner/Outline.xaml index 4f82d8f516..115e753e33 100644 --- a/samples/XamlDesigner/Outline.xaml +++ b/samples/XamlDesigner/Outline.xaml @@ -1,107 +1,29 @@  + xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner" + xmlns:Converters="clr-namespace:ICSharpCode.XamlDesigner.Converters"> + - - - - - - - - + - + + + + + diff --git a/samples/XamlDesigner/Outline.xaml.cs b/samples/XamlDesigner/Outline.xaml.cs index f7186ac275..c3ba8f9e31 100644 --- a/samples/XamlDesigner/Outline.xaml.cs +++ b/samples/XamlDesigner/Outline.xaml.cs @@ -20,5 +20,13 @@ namespace ICSharpCode.XamlDesigner { InitializeComponent(); } + + public static readonly DependencyProperty RootProperty = + DependencyProperty.Register("Root", typeof(OutlineNode), typeof(Outline)); + + public OutlineNode Root { + get { return (OutlineNode)GetValue(RootProperty); } + set { SetValue(RootProperty, value); } + } } } diff --git a/samples/XamlDesigner/OutlineNode.cs b/samples/XamlDesigner/OutlineNode.cs new file mode 100644 index 0000000000..2331add9cf --- /dev/null +++ b/samples/XamlDesigner/OutlineNode.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.ComponentModel; +using ICSharpCode.WpfDesign; +using System.Collections.ObjectModel; +using System.Collections; + +namespace ICSharpCode.XamlDesigner +{ + public class OutlineNode : INotifyPropertyChanged + { + public OutlineNode(DesignItem designItem) + { + DesignItem = designItem; + UpdateChildren(); + + //TODO (possible bug) + DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged); + DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged); + SelectionService.SelectionChanged += new EventHandler(Selection_SelectionChanged); + } + + bool freezeChildren; + + public DesignItem DesignItem { get; private set; } + public OutlineNode Parent { get; private set; } + + public ISelectionService SelectionService { + get { return DesignItem.Services.Selection; } + } + + bool isExpanded = true; + + public bool IsExpanded { + get { + return isExpanded; + } + set { + isExpanded = value; + RaisePropertyChanged("IsExpanded"); + } + } + + bool isSelected; + + public bool IsSelected { + get { + return isSelected; + } + set { + if (isSelected != value) { + isSelected = value; + SelectionService.SetSelectedComponents(new[] { DesignItem }, + value ? SelectionTypes.Add : SelectionTypes.Remove); + RaisePropertyChanged("IsSelected"); + } + } + } + + ObservableCollection children = new ObservableCollection(); + + public ObservableCollection Children { + get { return children; } + } + + public string Name { + get { + if (string.IsNullOrEmpty(DesignItem.Name)) { + return DesignItem.ComponentType.Name; + } + return DesignItem.ComponentType.Name + " (" + DesignItem.Name + ")"; + } + } + + void Selection_SelectionChanged(object sender, DesignItemCollectionEventArgs e) + { + IsSelected = DesignItem.Services.Selection.IsComponentSelected(DesignItem); + } + + void DesignItem_NameChanged(object sender, EventArgs e) + { + RaisePropertyChanged("Name"); + } + + void DesignItem_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + if (e.PropertyName == DesignItem.ContentPropertyName) { + UpdateChildren(); + } + } + + void UpdateChildren() + { + if (freezeChildren) return; + if (DesignItem.ContentPropertyName != null) { + var content = DesignItem.ContentProperty; + if (content.IsCollection) { + UpdateChildrenCore(content.CollectionElements); + } + else { + if (content.Value != null) { + UpdateChildrenCore(new[] { content.Value }); + } + } + } + } + + void UpdateChildrenCore(IEnumerable items) + { + var cache = Children.ToDictionary(n => n.DesignItem); + + Children.Clear(); + + foreach (var item in items) { + OutlineNode node; + if (!cache.TryGetValue(item, out node)) { + node = new OutlineNode(item); + } + Children.Add(node); + node.Parent = this; + } + } + + public bool CanInsert(IEnumerable nodes, OutlineNode after, bool copy) + { + if (DesignItem.ContentPropertyName == null) return false; + + if (DesignItem.ContentProperty.IsCollection) { + foreach (var node in nodes) { + if (!CanAdd(DesignItem.ContentProperty.ReturnType, + node.DesignItem.ComponentType)) { + return false; + } + } + return true; + } + else { + return after == null && nodes.Count() == 1 && + DesignItem.ContentProperty.DeclaringType.IsAssignableFrom( + nodes.First().DesignItem.ComponentType); + } + } + + public static bool CanAdd(Type col, Type item) + { + var e = col.GetInterface("IEnumerable`1"); + if (e != null && e.IsGenericType) { + var a = e.GetGenericArguments()[0]; + return a.IsAssignableFrom(item); + } + return true; + } + + public void Insert(IEnumerable nodes, OutlineNode after, bool copy) + { + freezeChildren = true; + + if (copy) { + nodes = nodes.Select(n => new OutlineNode(n.DesignItem.Clone())); + } + else { + foreach (var node in nodes) { + Remove(node); + } + } + + var index = after == null ? 0 : Children.IndexOf(after) + 1; + var tempIndex = index; + + foreach (var node in nodes) { + Children.Insert(tempIndex++, node); + node.Parent = this; + } + + var content = DesignItem.ContentProperty; + if (content.IsCollection) { + tempIndex = index; + foreach (var node in nodes) { + content.CollectionElements.Insert(tempIndex++, node.DesignItem); + } + } + else { + content.SetValue(nodes.First().DesignItem); + } + + freezeChildren = false; + } + + void Remove(OutlineNode node) + { + node.DesignItem.Remove(); + + if (node.Parent != null) { + node.Parent.Children.Remove(node); + node.Parent = null; + } + } + + #region INotifyPropertyChanged Members + + public event PropertyChangedEventHandler PropertyChanged; + + void RaisePropertyChanged(string name) + { + if (PropertyChanged != null) { + PropertyChanged(this, new PropertyChangedEventArgs(name)); + } + } + + #endregion + } +} diff --git a/samples/XamlDesigner/OutlineTree.cs b/samples/XamlDesigner/OutlineTree.cs deleted file mode 100644 index 806cd34aa6..0000000000 --- a/samples/XamlDesigner/OutlineTree.cs +++ /dev/null @@ -1,267 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Controls; -using System.Windows; -using System.Collections.ObjectModel; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Controls.Primitives; - -namespace ICSharpCode.XamlDesigner -{ - public class OutlineTree : TreeView - { - public OutlineTree() - { - AllowDrop = true; - new DragListener(this).DragStarted += new MouseEventHandler(TreeList_DragStarted); - DragEnter += new DragEventHandler(TreeList_DragEnter); - DragOver += new DragEventHandler(TreeList_DragOver); - Drop += new DragEventHandler(TreeList_Drop); - - //Selection = new ObservableCollection(); - } - - Border insertLine; - OutlineTreeItem markedItem; - OutlineTreeItem possibleSelection; - List selectionNodes = new List(); - - public static readonly DependencyProperty SelectionProperty = - DependencyProperty.Register("Selection", typeof(ObservableCollection), typeof(OutlineTree)); - - public ObservableCollection Selection { - get { return (ObservableCollection)GetValue(SelectionProperty); } - set { SetValue(SelectionProperty, value); } - } - - protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) - { - base.OnPropertyChanged(e); - } - - public override void OnApplyTemplate() - { - base.OnApplyTemplate(); - insertLine = (Border)Template.FindName("PART_InsertLine", this); - } - - protected override DependencyObject GetContainerForItemOverride() - { - return new OutlineTreeItem(); - } - - protected override bool IsItemItsOwnContainerOverride(object item) - { - return item is OutlineTreeItem; - } - - protected virtual DragDropEffects CanDrag(object obj) - { - return DragDropEffects.Move; - } - - protected virtual DragDropEffects CanDrop(object obj, object parent, int index) - { - return DragDropEffects.Move; - } - - void TreeList_DragOver(object sender, DragEventArgs e) - { - ProcessDrag(e); - } - - void TreeList_DragEnter(object sender, DragEventArgs e) - { - ProcessDrag(e); - } - - void TreeList_Drop(object sender, DragEventArgs e) - { - ProcessDrop(e); - } - - protected override void OnDragLeave(DragEventArgs e) - { - HideDropMarkers(); - } - - void TreeList_DragStarted(object sender, MouseEventArgs e) - { - possibleSelection = null; - object obj = (e.OriginalSource as FrameworkElement).DataContext; - if (obj != null) { - DragDropEffects effects = CanDrag(obj); - if (effects != DragDropEffects.None) { - DragDrop.DoDragDrop(this, obj, effects); - } - } - } - - void ProcessDrag(DragEventArgs e) - { - e.Effects = DragDropEffects.Move; - e.Handled = true; - - OutlineTreeItem treeItem = (e.OriginalSource as DependencyObject).FindAncestor(); - if (treeItem != null) { - HideDropMarkers(); - - ContentPresenter header = treeItem.HeaderPresenter; - Point p = e.GetPosition(header); - int part = (int)(p.Y / (header.ActualHeight / 3)); - - if (part == 1) { - markedItem = treeItem; - markedItem.Background = insertLine.Background; - } - else { - insertLine.Visibility = Visibility.Visible; - p = header.TransformToVisual(this).Transform(new Point()); - double y = part == 0 ? p.Y : p.Y + header.ActualHeight; - insertLine.Margin = new Thickness(0, y, 0, 0); - } - } - } - - void ProcessDrop(DragEventArgs e) - { - HideDropMarkers(); - } - - void HideDropMarkers() - { - insertLine.Visibility = Visibility.Collapsed; - if (markedItem != null) { - markedItem.ClearValue(OutlineTreeItem.BackgroundProperty); - } - } - - void Select(OutlineTreeItem item) - { - item.IsSelected = true; - Selection.Add(item.Element); - selectionNodes.Add(item); - } - - void SelectOnly(OutlineTreeItem item) - { - foreach (var node in selectionNodes) { - node.IsSelected = false; - } - Selection.Clear(); - Select(item); - } - - void Unselect(OutlineTreeItem item) - { - item.IsSelected = false; - Selection.Remove(item.Element); - selectionNodes.Remove(item); - } - - internal void HandleItemMouseDown(OutlineTreeItem item) - { - bool control = Keyboard.IsKeyDown(Key.LeftCtrl); - if (item.IsSelected) { - if (control) { - Unselect(item); - } - else { - possibleSelection = item; - } - } - else { - if (control) { - Select(item); - } - else { - SelectOnly(item); - } - } - } - - internal void HandleItemMouseUp(OutlineTreeItem item) - { - if (possibleSelection != null) { - SelectOnly(possibleSelection); - } - } - } - - public class OutlineTreeItem : TreeViewItem - { - public new static readonly DependencyProperty IsSelectedProperty = - Selector.IsSelectedProperty.AddOwner(typeof(OutlineTreeItem)); - - public new bool IsSelected { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } - } - - public ContentPresenter HeaderPresenter { - get { return (ContentPresenter)Template.FindName("PART_Header", this); } - } - - public DocumentElement Element { - get { return DataContext as DocumentElement; } - } - - public static readonly DependencyProperty IndentProperty = - DependencyProperty.Register("Indent", typeof(Thickness), typeof(OutlineTreeItem)); - - public Thickness Indent { - get { return (Thickness)GetValue(IndentProperty); } - set { SetValue(IndentProperty, value); } - } - - protected override void OnVisualParentChanged(DependencyObject oldParent) - { - base.OnVisualParentChanged(oldParent); - OutlineTreeItem parent = ItemsControl.ItemsControlFromItemContainer(this) as OutlineTreeItem; - Indent = parent == null ? new Thickness() : new Thickness(parent.Indent.Left + 19, 0, 0, 0); - } - - protected override DependencyObject GetContainerForItemOverride() - { - return new OutlineTreeItem(); - } - - protected override bool IsItemItsOwnContainerOverride(object item) - { - return item is OutlineTreeItem; - } - - protected override void OnPreviewMouseDown(MouseButtonEventArgs e) - { - if (e.Source is ToggleButton || e.Source is ItemsPresenter) return; - - OutlineTree tree = this.FindAncestor(); - if (tree != null) { - tree.HandleItemMouseDown(this); - e.Handled = true; - } - } - - protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) - { - OutlineTree tree = this.FindAncestor(); - if (tree != null) { - tree.HandleItemMouseUp(this); - } - } - } - - public class TreeNode : ContentControl - { - public static readonly DependencyProperty ImageProperty = - DependencyProperty.Register("Image", typeof(ImageSource), typeof(TreeNode)); - - public ImageSource Image { - get { return (ImageSource)GetValue(ImageProperty); } - set { SetValue(ImageProperty, value); } - } - } -} diff --git a/samples/XamlDesigner/OutlineTreeView.cs b/samples/XamlDesigner/OutlineTreeView.cs new file mode 100644 index 0000000000..d0066fe5e9 --- /dev/null +++ b/samples/XamlDesigner/OutlineTreeView.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ICSharpCode.XamlDesigner +{ + public class OutlineTreeView : DragTreeView + { + protected override bool CanInsert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy) + { + return (target.DataContext as OutlineNode).CanInsert(items.Select(t => t.DataContext as OutlineNode), + after == null ? null : after.DataContext as OutlineNode, copy); + } + + protected override void Insert(DragTreeViewItem target, DragTreeViewItem[] items, DragTreeViewItem after, bool copy) + { + (target.DataContext as OutlineNode).Insert(items.Select(t => t.DataContext as OutlineNode), + after == null ? null : after.DataContext as OutlineNode, copy); + } + } +} diff --git a/samples/XamlDesigner/Themes/Generic.xaml b/samples/XamlDesigner/Themes/Generic.xaml new file mode 100644 index 0000000000..7445a7b52b --- /dev/null +++ b/samples/XamlDesigner/Themes/Generic.xaml @@ -0,0 +1,159 @@ + + + + + + + + + #FFC73C + + + + + + + + \ No newline at end of file diff --git a/samples/XamlDesigner/Toolbox.cs b/samples/XamlDesigner/Toolbox.cs index 259c3041fc..784e3ddac1 100644 --- a/samples/XamlDesigner/Toolbox.cs +++ b/samples/XamlDesigner/Toolbox.cs @@ -26,6 +26,36 @@ 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); @@ -34,7 +64,7 @@ namespace ICSharpCode.XamlDesigner node.Assembly = assembly; node.Path = path; foreach (var t in assembly.GetExportedTypes()) { - if (IsControl(t)) { + if (IsControl(t) && popularControls.Contains(t.Name)) { node.Controls.Add(new ControlNode() { Type = t }); } } diff --git a/samples/XamlDesigner/ToolboxView.xaml b/samples/XamlDesigner/ToolboxView.xaml index bf8d9f258b..ad34a80bb9 100644 --- a/samples/XamlDesigner/ToolboxView.xaml +++ b/samples/XamlDesigner/ToolboxView.xaml @@ -1,36 +1,19 @@  + xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner"> - - - - - - - + - - - - - - - + + diff --git a/samples/XamlDesigner/ToolboxView.xaml.cs b/samples/XamlDesigner/ToolboxView.xaml.cs index 679307affc..4c2851d1d5 100644 --- a/samples/XamlDesigner/ToolboxView.xaml.cs +++ b/samples/XamlDesigner/ToolboxView.xaml.cs @@ -25,13 +25,13 @@ namespace ICSharpCode.XamlDesigner DataContext = Toolbox.Instance; InitializeComponent(); - new DragListener(this).DragStarted += new MouseEventHandler(Toolbox_DragStarted); + new DragListener(this).DragStarted += Toolbox_DragStarted; } - void Toolbox_DragStarted(object sender, MouseEventArgs e) - { - PrepareTool(e.GetDataContext() as ControlNode, true); - } + void Toolbox_DragStarted(object sender, MouseButtonEventArgs e) + { + PrepareTool(e.GetDataContext() as ControlNode, true); + } void uxTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) { diff --git a/samples/XamlDesigner/XamlDesigner.csproj b/samples/XamlDesigner/XamlDesigner.csproj index 7a7e0a5f47..e6789e211b 100644 --- a/samples/XamlDesigner/XamlDesigner.csproj +++ b/samples/XamlDesigner/XamlDesigner.csproj @@ -92,6 +92,9 @@ Configuration\GlobalAssemblyInfo.cs + + BitmapButton.xaml + Code @@ -106,8 +109,21 @@ DocumentView.xaml + + + + + EnumBar.xaml + + + + Outline.xaml + Code + + + MainWindow.xaml @@ -124,10 +140,18 @@ Designer PreserveNewest + + MSBuild:Compile + Designer + Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -138,6 +162,14 @@ Designer + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/DependencyPropertyDotButton.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/DependencyPropertyDotButton.cs deleted file mode 100644 index 3d2bb659fc..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/DependencyPropertyDotButton.cs +++ /dev/null @@ -1,133 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; -using ICSharpCode.WpfDesign.PropertyEditor; - -namespace ICSharpCode.WpfDesign.Designer.Controls -{ - /// - /// The "dot" button appearing after dependency properties to specified advanced values like data bindings. - /// - public class DependencyPropertyDotButton : ButtonBase - { - /// - /// Dependency property for . - /// - public static readonly DependencyProperty CheckedProperty - = DependencyProperty.Register("Checked", typeof(bool), typeof(DependencyPropertyDotButton), - new FrameworkPropertyMetadata(false)); - - static DependencyPropertyDotButton() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(DependencyPropertyDotButton), new FrameworkPropertyMetadata(typeof(DependencyPropertyDotButton))); - } - - /// - /// Creates a new DependencyPropertyDotButton instance. - /// - public DependencyPropertyDotButton() - { - } - - IPropertyEditorDataProperty property; - - bool isIsSetChangedEventHandlerAttached; - - /// - /// Creates a new DependencyPropertyDotButton instance that binds its Checked property to the - /// data properties IsSet property. - /// - public DependencyPropertyDotButton(IPropertyEditorDataProperty property) - { - if (property == null) - throw new ArgumentNullException("property"); - this.property = property; - - this.Loaded += delegate { - if (!isIsSetChangedEventHandlerAttached) { - isIsSetChangedEventHandlerAttached = true; - this.property.IsSetChanged += OnIsSetChanged; - OnIsSetChanged(null, null); - } - }; - this.Unloaded += delegate { - if (isIsSetChangedEventHandlerAttached) { - isIsSetChangedEventHandlerAttached = false; - this.property.IsSetChanged -= OnIsSetChanged; - } - }; - OnIsSetChanged(null, null); - } - - /// - /// Creates the context menu on-demand. - /// - protected override void OnContextMenuOpening(ContextMenuEventArgs e) - { - ContextMenu = CreateContextMenu(); - base.OnContextMenuOpening(e); - } - - /// - /// Gets/Sets if the button looks checked. - /// - public bool Checked { - get { return (bool)GetValue(CheckedProperty); } - set { SetValue(CheckedProperty, value); } - } - - void OnIsSetChanged(object sender, EventArgs e) - { - this.Checked = property.IsSet; - } - - /// - /// Fires the Click event and opens the context menu. - /// - protected override void OnClick() - { - base.OnClick(); - ContextMenu = CreateContextMenu(); - ContextMenu.IsOpen = true; - } - - internal ContextMenu CreateContextMenu() - { - ContextMenu contextMenu = new ContextMenu(); - if (property.IsSet) { - contextMenu.Items.Add(CreateMenuItem("_Reset", OnResetClick)); - } else { - contextMenu.Items.Add(CreateMenuItem("_Copy to local", OnCopyToLocalClick)); - } - return contextMenu; - } - - MenuItem CreateMenuItem(string title, RoutedEventHandler handler) - { - MenuItem item = new MenuItem(); - item.Header = title; - item.Click += handler; - return item; - } - - void OnResetClick(object sender, RoutedEventArgs e) - { - property.IsSet = false; - } - - void OnCopyToLocalClick(object sender, RoutedEventArgs e) - { - property.IsSet = true; - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/EventHandlerEditor.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/EventHandlerEditor.cs deleted file mode 100644 index 168b7d54ce..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/EventHandlerEditor.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -// -// -// -// $Revision: 2667$ -// - -using System; -using System.Windows; -using System.Windows.Input; -using System.Windows.Controls; -using ICSharpCode.WpfDesign.PropertyEditor; - -namespace ICSharpCode.WpfDesign.Designer.Controls -{ - /// - /// The combo box used to enter the event handler which an event is connected to. - /// - sealed class EventHandlerEditor : ComboBox - { - readonly IPropertyEditorDataEvent dataEvent; - - public EventHandlerEditor(IPropertyEditorDataEvent dataEvent) - { - this.dataEvent = dataEvent; - this.IsEditable = true; - - Loaded += delegate { - dataEvent.HandlerNameChanged += OnEventHandlerNameChanged; - OnEventHandlerNameChanged(null, null); - }; - Unloaded += delegate { - dataEvent.HandlerNameChanged -= OnEventHandlerNameChanged; - }; - } - - void OnEventHandlerNameChanged(object sender, EventArgs e) - { - this.Text = dataEvent.HandlerName; - } - - protected override void OnKeyDown(System.Windows.Input.KeyEventArgs e) - { - base.OnKeyDown(e); - - if (e.Handled) - return; - if (e.Key == Key.Enter) { - dataEvent.HandlerName = this.Text; - if (!string.IsNullOrEmpty(dataEvent.HandlerName)) { - dataEvent.GoToHandler(); - } - e.Handled = true; - } else if (e.Key == Key.Escape) { - this.Text = dataEvent.HandlerName; - e.Handled = true; - } - } - - protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e) - { - base.OnLostKeyboardFocus(e); - if (string.IsNullOrEmpty(this.Text)) - dataEvent.HandlerName = null; - else - this.Text = dataEvent.HandlerName; - } - - protected override void OnMouseDoubleClick(MouseButtonEventArgs e) - { - e.Handled = true; - DoubleClick(); - } - - public void DoubleClick() - { - dataEvent.GoToHandler(); - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs deleted file mode 100644 index 0e09c99d2f..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs +++ /dev/null @@ -1,197 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.ComponentModel; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Shapes; -using ICSharpCode.WpfDesign.Designer.Controls; -using ICSharpCode.WpfDesign.PropertyEditor; - -namespace ICSharpCode.WpfDesign.Designer -{ - /// - /// Shows a list of properties; supports data binding. - /// - public partial class PropertyEditor : UserControl - { - /// - /// Dependency property for . - /// - public static readonly DependencyProperty EditedObjectProperty - = DependencyProperty.Register("EditedObject", typeof(IPropertyEditorDataSource), typeof(PropertyEditor), - new FrameworkPropertyMetadata(null, _OnEditedObjectPropertyChanged)); - - /// - /// Creates a new PropertyEditor instance. - /// - public PropertyEditor() - { - try { - InitializeComponent(); - } catch (Exception ex) { - Debug.WriteLine(ex.ToString()); - throw; - } - } - - /// - /// Gets/Sets the object being edited. - /// - public IPropertyEditorDataSource EditedObject { - get { return (IPropertyEditorDataSource)GetValue(EditedObjectProperty); } - set { SetValue(EditedObjectProperty, value); } - } - - /// - /// Is raised when the value of the property changes. - /// - public event EventHandler EditedObjectChanged; - - static void _OnEditedObjectPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) - { - ((PropertyEditor)obj).OnEditedObjectPropertyChanged(e); - } - - void OnEditedObjectPropertyChanged(DependencyPropertyChangedEventArgs e) - { - IPropertyEditorDataSource dataSource = e.NewValue as IPropertyEditorDataSource; - componentImage.Fill = dataSource != null ? dataSource.CreateThumbnailBrush() : null; - ShowProperties(dataSource); - if (EditedObjectChanged != null) { - EditedObjectChanged(this, EventArgs.Empty); - } - } - - void ShowPropertiesButton_Click(object sender, RoutedEventArgs e) - { - ShowProperties(this.EditedObject); - } - - void ShowEventsButton_Click(object sender, RoutedEventArgs e) - { - ShowEvents(this.EditedObject); - } - - bool useCategories = false; - - void ShowProperties(IPropertyEditorDataSource dataSource) - { - contentStackPanel.Children.Clear(); - if (dataSource == null) - return; - - if (useCategories) { - List categories = new List(); - foreach (IPropertyEditorDataProperty p in dataSource.Properties.OrderBy(p2 => p2.Name)) { - if (p.Name == "Name") { - continue; - } - PropertyEditorCategoryView cv = GetOrCreateCategory(categories, p.Category); - PropertyGridView grid = (PropertyGridView)cv.Content; - grid.AddProperty(p); - } - // Sort category titles alphabetically - categories.Sort(delegate (PropertyEditorCategoryView c1, PropertyEditorCategoryView c2) { - return c1.Header.ToString().CompareTo(c2.Header.ToString()); - }); - // Add categories to contentStackPanel - foreach (PropertyEditorCategoryView c in categories) { - contentStackPanel.Children.Add(c); - } - } else { - PropertyGridView grid = new PropertyGridView(); - contentStackPanel.Children.Add(grid); - foreach (IPropertyEditorDataProperty p in dataSource.Properties.OrderBy(p2 => p2.Name)) { - if (p.Name == "Name") { - continue; - } - grid.AddProperty(p); - } - } - } - - void ShowEvents(IPropertyEditorDataSource dataSource) - { - contentStackPanel.Children.Clear(); - if (dataSource == null) - return; - - PropertyGridView grid = new PropertyGridView(); - contentStackPanel.Children.Add(grid); - foreach (IPropertyEditorDataEvent e in dataSource.Events.OrderBy(p => p.Name)) { - grid.AddEvent(e); - } - } - - HashSet expandedCategories = new HashSet(); - - PropertyEditorCategoryView GetOrCreateCategory(List categories, string category) - { - foreach (PropertyEditorCategoryView c in categories) { - if (c.Header.ToString() == category) - return c; - } - PropertyEditorCategoryView newCategory = new PropertyEditorCategoryView(); - newCategory.Header = category; - newCategory.Content = new PropertyGridView(); - newCategory.IsExpanded = expandedCategories.Contains(category); - newCategory.Expanded += delegate { - expandedCategories.Add(category); - }; - newCategory.Collapsed += delegate { - expandedCategories.Remove(category); - }; - categories.Add(newCategory); - return newCategory; - } - - /* - void clearSearchButton_Click(object sender, RoutedEventArgs e) - { - searchTextBox.Text = ""; - } - */ - - void nameTextBox_SizeChanged(object sender, RoutedEventArgs e) - { - // Display componentImage only if there is enough space left. - const double minimalNameTextBoxWidth = 80; - const double switchTreshold = 5; - if (componentImage.Visibility != Visibility.Collapsed) { - if (nameTextBox.ActualWidth < minimalNameTextBoxWidth - switchTreshold) { - componentImage.Visibility = Visibility.Collapsed; - } - } else { - if (nameTextBox.ActualWidth > minimalNameTextBoxWidth + componentImage.Width + switchTreshold) { - componentImage.Visibility = Visibility.Visible; - } - } - } - - void nameTextBox_KeyDown(object sender, KeyEventArgs e) - { - if (e.Handled) return; - if (e.Key == Key.Enter) { - nameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource(); - } else if (e.Key == Key.Escape) { - nameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget(); - } - } - - public TextBox NameTextBox { - get { return nameTextBox; } - } - } -} - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.xaml deleted file mode 100644 index 6cd3b684f2..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.xaml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorCategoryView.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorCategoryView.cs deleted file mode 100644 index 7fa4f671c9..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorCategoryView.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Windows; -using System.Windows.Controls; - -namespace ICSharpCode.WpfDesign.Designer.Controls -{ - /// - /// Control used to view a property grid category. - /// - public sealed class PropertyEditorCategoryView : Expander - { - static PropertyEditorCategoryView() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyEditorCategoryView), new FrameworkPropertyMetadata(typeof(PropertyEditorCategoryView))); - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorStyles.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorStyles.xaml deleted file mode 100644 index c466b66d25..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditorStyles.xaml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyGridView.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyGridView.cs deleted file mode 100644 index e5e1abd873..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyGridView.cs +++ /dev/null @@ -1,102 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Windows; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Data; -using System.Windows.Controls; -using ICSharpCode.WpfDesign.PropertyEditor; - -namespace ICSharpCode.WpfDesign.Designer.Controls -{ - /// - /// Control used to view a property grid category. - /// - public sealed class PropertyGridView : Grid - { - static PropertyGridView() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyGridView), new FrameworkPropertyMetadata(typeof(PropertyGridView))); - } - - /// - /// Creates a new PropertyGridView instance. - /// - public PropertyGridView() - { - this.ColumnDefinitions.Add(new ColumnDefinition()); - this.ColumnDefinitions.Add(new ColumnDefinition()); - this.ColumnDefinitions.Add(new ColumnDefinition()); - this.ColumnDefinitions[0].Width = new GridLength(0.48, GridUnitType.Star); - this.ColumnDefinitions[0].MinWidth = 40; - this.ColumnDefinitions[1].Width = new GridLength(0.52, GridUnitType.Star); - this.ColumnDefinitions[2].Width = new GridLength(16); - } - - /// - /// Adds a new property to the PropertyGridView. - /// - public void AddProperty(IPropertyEditorDataProperty property) - { - this.RowDefinitions.Add(new RowDefinition()); - - // Column 0: name of the property - PropertyNameTextBlock propertyNameText = new PropertyNameTextBlock(property); - propertyNameText.Margin = new Thickness(0, 0, 2, 0); - SetRow(propertyNameText, this.RowDefinitions.Count - 1); - SetColumn(propertyNameText, 0); - this.Children.Add(propertyNameText); - - // Column 1: the actual property editor - UIElement editor = property.CreateEditor(); - SetRow(editor, this.RowDefinitions.Count - 1); - SetColumn(editor, 1); - this.Children.Add(editor); - - // Column 2: a "dot" button - DependencyPropertyDotButton dotButton = new DependencyPropertyDotButton(property); - dotButton.VerticalAlignment = VerticalAlignment.Center; - dotButton.HorizontalAlignment = HorizontalAlignment.Center; - SetRow(dotButton, this.RowDefinitions.Count - 1); - SetColumn(dotButton, 2); - this.Children.Add(dotButton); - propertyNameText.ContextMenuProvider = dotButton; - } - - /// - /// Adds a new event to the PropertyGridView. - /// - public void AddEvent(IPropertyEditorDataEvent dataEvent) - { - this.RowDefinitions.Add(new RowDefinition()); - - // Column 0: name of the event - PropertyNameTextBlock propertyNameText = new PropertyNameTextBlock(dataEvent); - propertyNameText.Margin = new Thickness(0, 0, 2, 0); - SetRow(propertyNameText, this.RowDefinitions.Count - 1); - SetColumn(propertyNameText, 0); - this.Children.Add(propertyNameText); - - // Column 1: the actual property editor - EventHandlerEditor editor = new EventHandlerEditor(dataEvent); - SetRow(editor, this.RowDefinitions.Count - 1); - SetColumn(editor, 1); - this.Children.Add(editor); - - propertyNameText.MouseDown += delegate(object sender, MouseButtonEventArgs e) { - if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2) { - e.Handled = true; - editor.DoubleClick(); - } - }; - - // Column 2: empty - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs deleted file mode 100644 index 4d406a7f49..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using ICSharpCode.WpfDesign.PropertyEditor; - -namespace ICSharpCode.WpfDesign.Designer.Controls -{ - // Text block used in the first column of the PropertyGridView. - // Creates ToolTip and ContextMenu objects on-demand. - sealed class PropertyNameTextBlock : TextBlock - { - readonly IPropertyEditorDataMember property; - readonly DockPanel toolTipDockPanel; - bool toolTipInitialized; - internal DependencyPropertyDotButton ContextMenuProvider; - - public PropertyNameTextBlock(IPropertyEditorDataMember property) - : base(new Run(property.Name)) - { - this.property = property; - this.TextAlignment = TextAlignment.Right; - this.TextTrimming = TextTrimming.CharacterEllipsis; - - this.ToolTip = toolTipDockPanel = new DockPanel(); - } - - protected override void OnToolTipOpening(ToolTipEventArgs e) - { - CreateToolTip(); - base.OnToolTipOpening(e); - } - - protected override void OnContextMenuOpening(ContextMenuEventArgs e) - { - if (ContextMenuProvider != null) { - this.ContextMenu = ContextMenuProvider.CreateContextMenu(); - } - base.OnContextMenuOpening(e); - } - - void CreateToolTip() - { - if (toolTipInitialized) - return; - toolTipInitialized = true; - TextBlock textBlock = new TextBlock(); - textBlock.TextAlignment = TextAlignment.Left; - textBlock.Inlines.Add(new Bold(new Run(property.Name))); - if (property.ReturnType != null) { - textBlock.Inlines.Add(" (" + property.ReturnType.Name + ")"); - } - DockPanel.SetDock(textBlock, Dock.Top); - toolTipDockPanel.Children.Add(textBlock); - object description = property.GetDescription(); - if (description is UIElement) { - toolTipDockPanel.Children.Add((UIElement)description); - } else if (description is string) { - textBlock.Inlines.Add(new LineBreak()); - textBlock.Inlines.Add((string)description); - } else if (description != null) { - ContentControl cc = new ContentControl(); - cc.Content = description; - toolTipDockPanel.Children.Add(cc); - } - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SelectionFrame.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SelectionFrame.cs index 9aaefb4bcd..b3e1f4159d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SelectionFrame.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/SelectionFrame.cs @@ -1,4 +1,4 @@ -// +// // // // diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditor.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditor.cs deleted file mode 100644 index b6a3fa2abd..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditor.cs +++ /dev/null @@ -1,234 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.ComponentModel; -using ICSharpCode.WpfDesign.PropertyEditor; -using System.Windows.Media; -using System.Reflection; -using System.Windows; - -namespace ICSharpCode.WpfDesign.Designer.Controls.TypeEditors.BrushEditor -{ - public enum BrushEditorKind - { - None, - Solid, - Linear, - Radial, - List - } - - public class BrushItem - { - public string Name { get; set; } - public Brush Brush { get; set; } - } - - public class BrushEditor : INotifyPropertyChanged - { - public BrushEditor() - { - GradientStopCollection stops = new GradientStopCollection(); - stops.Add(new GradientStop(Colors.Black, 0)); - stops.Add(new GradientStop(Colors.White, 1)); - - linearGradientBrush = new LinearGradientBrush(stops); - linearGradientBrush.EndPoint = new Point(1, 0); - radialGradientBrush = new RadialGradientBrush(stops); - } - - public static BrushEditor Instance = new BrushEditor(); - - public static BrushItem[] SystemBrushes = typeof(SystemColors) - .GetProperties(BindingFlags.Static | BindingFlags.Public) - .Where(p => p.PropertyType == typeof(SolidColorBrush)) - .Select(p => new BrushItem() { Name = p.Name, Brush = (Brush)p.GetValue(null, null) }) - .ToArray(); - - public static BrushItem[] SystemColors = typeof(SystemColors) - .GetProperties(BindingFlags.Static | BindingFlags.Public) - .Where(p => p.PropertyType == typeof(Color)) - .Select(p => new BrushItem() - { - Name = p.Name, - Brush = new SolidColorBrush((Color)p.GetValue(null, null)) - }) - .ToArray(); - - SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.White); - LinearGradientBrush linearGradientBrush; - RadialGradientBrush radialGradientBrush; - - IPropertyEditorDataProperty property; - - public IPropertyEditorDataProperty Property - { - get - { - return property; - } - set - { - property = value; - if (property != null) - { - var f = property.Value as Freezable; - if (f != null && f.IsFrozen) property.Value = f.Clone(); - } - DetermineCurrentKind(); - RaisePropertyChanged("Property"); - RaisePropertyChanged("Brush"); - } - } - - public Brush Brush - { - get - { - if (property != null) - { - return property.Value as Brush; - } - return null; - } - set - { - if (property != null && property.Value != value) - { - if (value != null && value.IsFrozen) - { - value = value.Clone(); - } - property.Value = value; - DetermineCurrentKind(); - RaisePropertyChanged("Brush"); - } - } - } - - void DetermineCurrentKind() - { - if (Brush == null) - { - CurrentKind = BrushEditorKind.None; - } - else if (Brush is SolidColorBrush) - { - solidColorBrush = Brush as SolidColorBrush; - CurrentKind = BrushEditorKind.Solid; - } - else if (Brush is LinearGradientBrush) - { - linearGradientBrush = Brush as LinearGradientBrush; - radialGradientBrush.GradientStops = linearGradientBrush.GradientStops; - CurrentKind = BrushEditorKind.Linear; - } - else if (Brush is RadialGradientBrush) - { - radialGradientBrush = Brush as RadialGradientBrush; - linearGradientBrush.GradientStops = linearGradientBrush.GradientStops; - CurrentKind = BrushEditorKind.Radial; - } - } - - BrushEditorKind currentKind; - - public BrushEditorKind CurrentKind - { - get - { - return currentKind; - } - set - { - currentKind = value; - RaisePropertyChanged("CurrentKind"); - - switch (CurrentKind) - { - case BrushEditorKind.None: - Brush = null; - break; - - case BrushEditorKind.Solid: - Brush = solidColorBrush; - break; - - case BrushEditorKind.Linear: - Brush = linearGradientBrush; - break; - - case BrushEditorKind.Radial: - Brush = radialGradientBrush; - break; - - case BrushEditorKind.List: - Brush = solidColorBrush; - break; - } - } - } - - public double GradientAngle - { - get - { - var x = linearGradientBrush.EndPoint.X - linearGradientBrush.StartPoint.X; - var y = linearGradientBrush.EndPoint.Y - linearGradientBrush.StartPoint.Y; - return Vector.AngleBetween(new Vector(1, 0), new Vector(x, -y)); - } - set - { - var d = value * Math.PI / 180; - var p = new Point(Math.Cos(d), -Math.Sin(d)); - var k = 1 / Math.Max(Math.Abs(p.X), Math.Abs(p.Y)); - p.X *= k; - p.Y *= k; - var p2 = new Point(-p.X, -p.Y); - linearGradientBrush.StartPoint = new Point((p2.X + 1) / 2, (p2.Y + 1) / 2); - linearGradientBrush.EndPoint = new Point((p.X + 1) / 2, (p.Y + 1) / 2); - RaisePropertyChanged("GradientAngle"); - } - } - - public IEnumerable AvailableColors - { - get { return SystemColors; } - } - - public IEnumerable AvailableBrushes - { - get { return SystemBrushes; } - } - - public void MakeGradientHorizontal() - { - GradientAngle = 0; - } - - public void MakeGradientVertical() - { - GradientAngle = -90; - } - - public void Commit() - { - Property.Value = Property.Value; - } - - #region INotifyPropertyChanged Members - - public event PropertyChangedEventHandler PropertyChanged; - - void RaisePropertyChanged(string name) - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(name)); - } - } - - #endregion - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml deleted file mode 100644 index ca14c05174..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml.cs deleted file mode 100644 index cb67d876c8..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorPopup.xaml.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -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.Diagnostics; - -namespace ICSharpCode.WpfDesign.Designer.Controls.TypeEditors.BrushEditor -{ - public partial class BrushEditorPopup - { - public BrushEditorPopup() - { - InitializeComponent(); - } - - public static BrushEditorPopup Instance = new BrushEditorPopup(); - - protected override void OnClosed(EventArgs e) - { - base.OnClosed(e); - BrushEditor.Instance.Commit(); - } - - protected override void OnKeyDown(KeyEventArgs e) - { - if (e.Key == Key.Escape) IsOpen = false; - } - } -} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorView.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorView.xaml deleted file mode 100644 index ad30afbf41..0000000000 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/TypeEditors/BrushEditor/BrushEditorView.xaml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -