13 changed files with 355 additions and 26 deletions
@ -0,0 +1,7 @@ |
|||||||
|
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.TextBlockRightClickContextMenu" |
||||||
|
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" |
||||||
|
> |
||||||
|
<MenuItem Header="EditFormatedText" Click="Click_EditFormatedText" /> |
||||||
|
</ContextMenu> |
@ -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<Window>(), |
||||||
|
}; |
||||||
|
|
||||||
|
dlg.ShowDialog(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
<UserControl x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor.FormatedTextEditor" |
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||||
|
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" |
||||||
|
mc:Ignorable="d" d:DesignWidth="410" d:DesignHeight="259" > |
||||||
|
|
||||||
|
<Grid> |
||||||
|
<xctk:RichTextBox Margin="10,76,10,10" x:Name="richTextBox"> |
||||||
|
<xctk:RichTextBoxFormatBarManager.FormatBar> |
||||||
|
<xctk:RichTextBoxFormatBar /> |
||||||
|
</xctk:RichTextBoxFormatBarManager.FormatBar> |
||||||
|
</xctk:RichTextBox> |
||||||
|
<!--<xctk:RichTextBoxFormatBar Target="{Binding ElementName=richTextBox}" Margin="10,10,105,188" />--> |
||||||
|
<Button Content="Ok" Margin="0,10,10,0" HorizontalAlignment="Right" Width="90" Height="28" VerticalAlignment="Top" Click="Ok_Click" /> |
||||||
|
<Button Content="Cancel" Margin="0,43,10,0" HorizontalAlignment="Right" Width="90" Height="28" VerticalAlignment="Top" Click="Cancel_Click" /> |
||||||
|
</Grid> |
||||||
|
|
||||||
|
</UserControl> |
@ -0,0 +1,136 @@ |
|||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Linq; |
||||||
|
using System.Security; |
||||||
|
using System.Text; |
||||||
|
using System.Threading.Tasks; |
||||||
|
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.Xml; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interaktionslogik für FormatedTextEditor.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormatedTextEditor |
||||||
|
{ |
||||||
|
private DesignItem designItem; |
||||||
|
|
||||||
|
public FormatedTextEditor(DesignItem designItem) |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
this.designItem = designItem; |
||||||
|
} |
||||||
|
|
||||||
|
private void GetDesignItems(TextElementCollection<Block> blocks, List<DesignItem> list) |
||||||
|
{ |
||||||
|
bool first = true; |
||||||
|
|
||||||
|
foreach (var block in blocks) |
||||||
|
{ |
||||||
|
if (block is Paragraph) |
||||||
|
{ |
||||||
|
if (!first) |
||||||
|
{ |
||||||
|
list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak())); |
||||||
|
list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak())); |
||||||
|
} |
||||||
|
|
||||||
|
foreach (var inline in ((Paragraph) block).Inlines) |
||||||
|
{ |
||||||
|
//yield return inline;
|
||||||
|
list.Add(CloneInline(inline)); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (block is Section) |
||||||
|
{ |
||||||
|
GetDesignItems(((Section)block).Blocks, list); |
||||||
|
} |
||||||
|
|
||||||
|
first = false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private DesignItem CloneInline(Inline inline) |
||||||
|
{ |
||||||
|
DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(inline); |
||||||
|
if (inline is Run) |
||||||
|
{ |
||||||
|
var run = inline as Run; |
||||||
|
|
||||||
|
if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue) |
||||||
|
{ |
||||||
|
d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (inline is Span) |
||||||
|
{ } |
||||||
|
else if (inline is LineBreak) |
||||||
|
{ } |
||||||
|
else |
||||||
|
{ |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background); |
||||||
|
if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground); |
||||||
|
if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily); |
||||||
|
if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize); |
||||||
|
if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch); |
||||||
|
if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle); |
||||||
|
if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); |
||||||
|
if (inline.ReadLocalValue(TextElement.TextEffectsProperty) != DependencyProperty.UnsetValue) |
||||||
|
d.Properties.GetProperty(TextElement.TextEffectsProperty).SetValue(inline.TextEffects); |
||||||
|
|
||||||
|
return d; |
||||||
|
} |
||||||
|
|
||||||
|
private void Ok_Click(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
var changeGroup = designItem.OpenGroup("Formated Text"); |
||||||
|
|
||||||
|
designItem.Properties.GetProperty(TextBlock.TextProperty).Reset(); |
||||||
|
|
||||||
|
var inlinesProperty = designItem.Properties.GetProperty("Inlines"); |
||||||
|
inlinesProperty.CollectionElements.Clear(); |
||||||
|
|
||||||
|
var doc = richTextBox.Document; |
||||||
|
richTextBox.Document = new FlowDocument(); |
||||||
|
|
||||||
|
var inlines = new List<DesignItem>(); |
||||||
|
GetDesignItems(doc.Blocks, inlines); |
||||||
|
|
||||||
|
foreach (var inline in inlines) |
||||||
|
{ |
||||||
|
|
||||||
|
inlinesProperty.CollectionElements.Add(inline); |
||||||
|
} |
||||||
|
|
||||||
|
changeGroup.Commit(); |
||||||
|
|
||||||
|
this.TryFindParent<Window>().Close(); |
||||||
|
} |
||||||
|
|
||||||
|
private void Cancel_Click(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
this.TryFindParent<Window>().Close(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue