From 5e3e8c3432ca54c172e038797e06b87d8501d28d Mon Sep 17 00:00:00 2001 From: jkuehner Date: Fri, 24 Oct 2014 16:36:40 +0200 Subject: [PATCH] Started to work on a Formated Text Editor for TextBlock! --- .../WpfDesign.Designer/Project/DesignPanel.cs | 49 ++++++- .../Extensions/InPlaceEditorExtension.cs | 2 +- .../RightClickContextMenuExtension.cs | 9 +- .../Extensions/SnaplinePlacementBehavior.cs | 33 +++-- .../TextBlockRightClickContextMenu.xaml | 7 + .../TextBlockRightClickContextMenu.xaml.cs | 62 ++++++++ ...TextBlockRightClickContextMenuExtension.cs | 36 +++++ .../FormatedTextEditor.xaml | 20 +++ .../FormatedTextEditor.xaml.cs | 136 ++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 18 ++- .../Project/CollectionSupport.cs | 6 +- .../Project/PropertyGrid/TypeHelper.cs | 1 + .../WpfDesign/WpfDesign/Project/Tools.cs | 2 +- 13 files changed, 355 insertions(+), 26 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 055b4d988a..558585c50e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -17,11 +17,15 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Linq; using System.Windows; using System.Windows.Controls; +using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; @@ -443,5 +447,48 @@ namespace ICSharpCode.WpfDesign.Designer PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); } - } + + #region ContextMenu + + private Dictionary> contextMenusAndEntries = new Dictionary>(); + + public void AddContextMenu(ContextMenu contextMenu) + { + contextMenusAndEntries.Add(contextMenu, new List(contextMenu.Items.Cast())); + contextMenu.Items.Clear(); + + UpdateContextMenu(); + } + + public void RemoveContextMenu(ContextMenu contextMenu) + { + contextMenusAndEntries.Remove(contextMenu); + + UpdateContextMenu(); + } + + private void UpdateContextMenu() + { + if (contextMenusAndEntries.Count == 0) + this.ContextMenu = null; + + if (this.ContextMenu == null) + this.ContextMenu = new ContextMenu(); + + this.ContextMenu.Items.Clear(); + + foreach (var entries in contextMenusAndEntries.Values) + { + if (this.ContextMenu.Items.Count > 0) + this.ContextMenu.Items.Add(new Separator()); + + foreach (var entry in entries) + { + ContextMenu.Items.Add(entry); + } + } + } + + #endregion + } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs index 81a24d77c4..7fd51036ee 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock /// - [ExtensionFor(typeof(FrameworkElement))] + //[ExtensionFor(typeof(FrameworkElement))] public class InPlaceEditorExtension : PrimarySelectionAdornerProvider { AdornerPanel adornerPanel; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs index 20dd2adacd..2db14f2ae2 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs @@ -18,6 +18,7 @@ using System; using System.Windows; +using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; @@ -35,18 +36,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions public sealed class RightClickContextMenuExtension : PrimarySelectionAdornerProvider { DesignPanel panel; + ContextMenu contextMenu; protected override void OnInitialized() { base.OnInitialized(); - + + contextMenu = new RightClickContextMenu(ExtendedItem); panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; - panel.ContextMenu = new RightClickContextMenu(ExtendedItem); + panel.AddContextMenu(contextMenu); } protected override void OnRemove() { - panel.ContextMenu = null; + panel.RemoveContextMenu(contextMenu); base.OnRemove(); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs index 90520ca808..12aace83a1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs @@ -235,23 +235,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions void AddLines(Rect r, double inflate, bool requireOverlap, List h, List v, PlacementAlignment? filter) { - Rect r2 = r; - r2.Inflate(inflate, inflate); + if (r != Rect.Empty) + { + Rect r2 = r; + r2.Inflate(inflate, inflate); - if (filter == null || filter.Value.Vertical == VerticalAlignment.Top) - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right }); - if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom) - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right }); - if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left) - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom }); - if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right) - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom }); + if (filter == null || filter.Value.Vertical == VerticalAlignment.Top) + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right }); + if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom) + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right }); + if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left) + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom }); + if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right) + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom }); - if (filter == null) - { - h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right }); - v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom }); - } + if (filter == null) + { + h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top + Math.Abs((r2.Top - r2.Bottom) / 2), Start = r.Left, End = r.Right }); + v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left + Math.Abs((r2.Left - r2.Right) / 2), Start = r.Top, End = r.Bottom }); + } + } } void AddBaseline(DesignItem item, Rect bounds, List list) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml new file mode 100644 index 0000000000..e4bc9cd3c6 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml @@ -0,0 +1,7 @@ + + + diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs new file mode 100644 index 0000000000..679c4b3a31 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs @@ -0,0 +1,62 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +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 ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; +using ICSharpCode.WpfDesign.PropertyGrid; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + public partial class TextBlockRightClickContextMenu + { + private DesignItem designItem; + + public TextBlockRightClickContextMenu(DesignItem designItem) + { + this.designItem = designItem; + + InitializeComponent(); + } + + void Click_EditFormatedText(object sender, RoutedEventArgs e) + { + var dlg = new Window() + { + Content = new FormatedTextEditor(designItem), + Width = 400, + Height = 200, + WindowStyle = WindowStyle.ToolWindow, + Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent(), + }; + + dlg.ShowDialog(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs new file mode 100644 index 0000000000..e54c136d8b --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + [ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))] + [ExtensionFor(typeof (TextBlock))] + public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider + { + DesignPanel panel; + ContextMenu contextMenu; + + protected override void OnInitialized() + { + base.OnInitialized(); + + contextMenu = new TextBlockRightClickContextMenu(ExtendedItem); + panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; + panel.AddContextMenu(contextMenu); + } + + protected override void OnRemove() + { + panel.RemoveContextMenu(contextMenu); + + base.OnRemove(); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml new file mode 100644 index 0000000000..37cc227739 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml @@ -0,0 +1,20 @@ + + + + + + + + + +