Fix Unit Tests, work on FormatedTextEditor, using fixups

This commit is contained in:
jogibear9988 2016-04-09 15:23:40 +02:00
Родитель b4bf83e49f
Коммит d625835a62
29 изменённых файлов: 880 добавлений и 835 удалений

Просмотреть файл

@ -20,13 +20,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls

Просмотреть файл

@ -17,18 +17,10 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Input;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;

Просмотреть файл

@ -35,7 +35,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(typeof(CollapsiblePanel)));
FocusableProperty.OverrideMetadata(typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(false));
new FrameworkPropertyMetadata(SharedInstances.BoxedFalse));
}
public static readonly DependencyProperty IsCollapsedProperty = DependencyProperty.Register(
@ -70,7 +70,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected internal static readonly DependencyProperty AnimationProgressProperty = DependencyProperty.Register(
"AnimationProgress", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble1));
/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
@ -82,7 +82,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected internal static readonly DependencyProperty AnimationProgressXProperty = DependencyProperty.Register(
"AnimationProgressX", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble1));
/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
@ -94,7 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected internal static readonly DependencyProperty AnimationProgressYProperty = DependencyProperty.Register(
"AnimationProgressY", typeof(double), typeof(CollapsiblePanel),
new FrameworkPropertyMetadata(1.0));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble1));
/// <summary>
/// Value between 0 and 1 specifying how far the animation currently is.
@ -159,7 +159,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
public static readonly DependencyProperty CanCollapseProperty =
DependencyProperty.Register("CanCollapse", typeof(bool), typeof(SelfCollapsingPanel),
new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnCanCollapseChanged)));
new FrameworkPropertyMetadata(SharedInstances.BoxedFalse, new PropertyChangedCallback(OnCanCollapseChanged)));
public bool CanCollapse {
get { return (bool)GetValue(CanCollapseProperty); }

Просмотреть файл

@ -16,16 +16,10 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.UIExtensions;

Просмотреть файл

@ -17,12 +17,8 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Controls

Просмотреть файл

@ -16,7 +16,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

Просмотреть файл

@ -16,14 +16,9 @@
// 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.Controls;
using System.Windows.Input;
using System.Windows.Data;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Controls
{

Просмотреть файл

@ -16,10 +16,6 @@
// 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.Controls.Primitives;
using System.Windows;

Просмотреть файл

@ -23,7 +23,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls

Просмотреть файл

@ -1,187 +1,214 @@
// 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.
// 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.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using RichTextBox = System.Windows.Controls.RichTextBox;
//using System;
//using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Documents;
//using System.Windows.Input;
//using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
//using Xceed.Wpf.Toolkit;
//using RichTextBox = System.Windows.Controls.RichTextBox;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Supports editing Text in the Designer
/// </summary>
public class InPlaceEditor : Control
{
static InPlaceEditor()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(InPlaceEditor), new FrameworkPropertyMetadata(typeof(InPlaceEditor)));
}
/// <summary>
/// This property is binded to the Text Property of the editor.
/// </summary>
public static readonly DependencyProperty BindProperty =
DependencyProperty.Register("Bind", typeof(string), typeof(InPlaceEditor), new FrameworkPropertyMetadata());
public string Bind
{
get { return (string)GetValue(BindProperty); }
set { SetValue(BindProperty, value); }
}
readonly DesignItem designItem;
ChangeGroup changeGroup;
TextBlock textBlock;
RichTextBox editor;
bool _isChangeGroupOpen;
/// <summary>
/// This is the name of the property that is being edited for example Window.Title, Button.Content .
/// </summary>
string property;
public InPlaceEditor(DesignItem designItem)
{
this.designItem = designItem;
this.AddCommandHandler(EditingCommands.ToggleBold, Bold, CanBold);
this.AddCommandHandler(EditingCommands.ToggleItalic, Bold, CanBold);
this.AddCommandHandler(EditingCommands.ToggleUnderline, Bold, CanBold);
this.AddCommandHandler(EditingCommands.IncreaseFontSize, Bold, CanBold);
this.AddCommandHandler(EditingCommands.DecreaseFontSize, Bold, CanBold);
}
public bool CanBold()
{
return true;
}
//namespace ICSharpCode.WpfDesign.Designer.Controls
//{
// /// <summary>
// /// Supports editing Text in the Designer
// /// </summary>
// public class InPlaceEditor : Control
// {
// static InPlaceEditor()
// {
// DefaultStyleKeyProperty.OverrideMetadata(typeof (InPlaceEditor), new FrameworkPropertyMetadata(typeof (InPlaceEditor)));
// }
// /// <summary>
// /// This property is binded to the Text Property of the editor.
// /// </summary>
// public static readonly DependencyProperty BindProperty =
// DependencyProperty.Register("Bind", typeof (string), typeof (InPlaceEditor), new FrameworkPropertyMetadata());
// public string Bind{
// get { return (string) GetValue(BindProperty); }
// set { SetValue(BindProperty, value); }
// }
// readonly DesignItem designItem;
// ChangeGroup changeGroup;
// TextBlock textBlock;
// RichTextBox editor;
// bool _isChangeGroupOpen;
// /// <summary>
// /// This is the name of the property that is being edited for example Window.Title, Button.Content .
// /// </summary>
// string property;
// public InPlaceEditor(DesignItem designItem)
// {
// this.designItem = designItem;
// }
public void Bold()
{
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
editor = Template.FindName("editor", this) as RichTextBox; // Gets the TextBox-editor from the Template
editor.PreviewKeyDown += delegate (object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter && (e.KeyboardDevice.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift)
{
e.Handled = true;
}
};
ToolTip = "Edit the Text. Press" + Environment.NewLine + "Enter to make changes." + Environment.NewLine + "Shift+Enter to insert a newline." + Environment.NewLine + "Esc to cancel editing.";
// public override void OnApplyTemplate()
// {
// base.OnApplyTemplate();
// editor = Template.FindName("editor", this) as RichTextBox; // Gets the TextBox-editor from the Template
// editor.PreviewKeyDown+= delegate(object sender, KeyEventArgs e) {
// if (e.Key == Key.Enter && (e.KeyboardDevice.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift)
// {
// e.Handled = true;
// } };
// ToolTip = "Edit the Text. Press"+Environment.NewLine+"Enter to make changes."+Environment.NewLine+"Shift+Enter to insert a newline."+Environment.NewLine+"Esc to cancel editing.";
//RichTextBoxFormatBarManager.SetFormatBar(editor, new RichTextBoxFormatBar());
// RichTextBoxFormatBarManager.SetFormatBar(editor, new RichTextBoxFormatBar());
editor.TextChanged += editor_TextChanged;
FormatedTextEditor.SetRichTextBoxTextFromTextBlock(editor, ((TextBlock)designItem.Component));
}
// editor.TextChanged += editor_TextChanged;
// FormatedTextEditor.SetRichTextBoxTextFromTextBlock(editor, ((TextBlock) designItem.Component));
// }
void editor_TextChanged(object sender, TextChangedEventArgs e)
{
FormatedTextEditor.SetTextBlockTextFromRichTextBlox(this.designItem, editor);
}
// void editor_TextChanged(object sender, TextChangedEventArgs e)
// {
// FormatedTextEditor.SetTextBlockTextFromRichTextBlox(this.designItem, editor);
// }
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
base.OnGotKeyboardFocus(e);
StartEditing();
}
// protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
// {
// base.OnGotKeyboardFocus(e);
// StartEditing();
// }
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
if (changeGroup != null && _isChangeGroupOpen)
{
changeGroup.Abort();
_isChangeGroupOpen = false;
}
if (textBlock != null)
textBlock.Visibility = Visibility.Visible;
Reset();
base.OnLostKeyboardFocus(e);
}
/// <summary>
/// Change is committed if the user releases the Escape Key.
/// </summary>
/// <param name="e"></param>
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
if (e.KeyboardDevice.Modifiers != ModifierKeys.Shift)
{
switch (e.Key)
{
case Key.Enter:
// Commit the changes to DOM.
if (property != null)
designItem.Properties[property].SetValue(Bind);
if (designItem.Properties[Control.FontFamilyProperty].ValueOnInstance != editor.FontFamily)
designItem.Properties[Control.FontFamilyProperty].SetValue(editor.FontFamily);
if ((double)designItem.Properties[Control.FontSizeProperty].ValueOnInstance != editor.FontSize)
designItem.Properties[Control.FontSizeProperty].SetValue(editor.FontSize);
if ((FontStretch)designItem.Properties[Control.FontStretchProperty].ValueOnInstance != editor.FontStretch)
designItem.Properties[Control.FontStretchProperty].SetValue(editor.FontStretch);
if ((FontStyle)designItem.Properties[Control.FontStyleProperty].ValueOnInstance != editor.FontStyle)
designItem.Properties[Control.FontStyleProperty].SetValue(editor.FontStyle);
if ((FontWeight)designItem.Properties[Control.FontWeightProperty].ValueOnInstance != editor.FontWeight)
designItem.Properties[Control.FontWeightProperty].SetValue(editor.FontWeight);
if (changeGroup != null && _isChangeGroupOpen)
{
FormatedTextEditor.SetTextBlockTextFromRichTextBlox(this.designItem, editor);
changeGroup.Commit();
_isChangeGroupOpen = false;
}
changeGroup = null;
this.Visibility = Visibility.Hidden;
((TextBlock)designItem.Component).Visibility = Visibility.Visible;
break;
case Key.Escape:
AbortEditing();
break;
}
}
else if (e.Key == Key.Enter)
{
editor.Selection.Text += Environment.NewLine;
}
}
private void Reset()
{
if (textBlock != null)
{
if (property != null)
textBlock.Text = (string)designItem.Properties[property].ValueOnInstance;
textBlock.FontFamily = (System.Windows.Media.FontFamily)designItem.Properties[Control.FontFamilyProperty].ValueOnInstance;
textBlock.FontSize = (double)designItem.Properties[Control.FontSizeProperty].ValueOnInstance;
textBlock.FontStretch = (FontStretch)designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
textBlock.FontStretch = (FontStretch)designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
textBlock.FontWeight = (FontWeight)designItem.Properties[Control.FontWeightProperty].ValueOnInstance;
}
}
// protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e) {
// if (changeGroup != null && _isChangeGroupOpen)
// {
// changeGroup.Abort();
// _isChangeGroupOpen = false;
// }
// if (textBlock != null)
// textBlock.Visibility = Visibility.Visible;
// Reset();
// base.OnLostKeyboardFocus(e);
// }
public void AbortEditing()
{
if (changeGroup != null && _isChangeGroupOpen)
{
Reset();
changeGroup.Abort();
_isChangeGroupOpen = false;
}
this.Visibility = Visibility.Hidden;
if (textBlock != null)
textBlock.Visibility = Visibility.Visible;
Reset();
}
// /// <summary>
// /// Change is committed if the user releases the Escape Key.
// /// </summary>
// /// <param name="e"></param>
// protected override void OnKeyUp(KeyEventArgs e)
// {
// base.OnKeyUp(e);
// if(e.KeyboardDevice.Modifiers != ModifierKeys.Shift) {
// switch(e.Key) {
// case Key.Enter:
// // Commit the changes to DOM.
// if(property!=null)
// designItem.Properties[property].SetValue(Bind);
// if(designItem.Properties[Control.FontFamilyProperty].ValueOnInstance!=editor.FontFamily)
// designItem.Properties[Control.FontFamilyProperty].SetValue(editor.FontFamily);
// if((double)designItem.Properties[Control.FontSizeProperty].ValueOnInstance!=editor.FontSize)
// designItem.Properties[Control.FontSizeProperty].SetValue(editor.FontSize);
// if((FontStretch)designItem.Properties[Control.FontStretchProperty].ValueOnInstance!=editor.FontStretch)
// designItem.Properties[Control.FontStretchProperty].SetValue(editor.FontStretch);
// if((FontStyle)designItem.Properties[Control.FontStyleProperty].ValueOnInstance!=editor.FontStyle)
// designItem.Properties[Control.FontStyleProperty].SetValue(editor.FontStyle);
// if((FontWeight)designItem.Properties[Control.FontWeightProperty].ValueOnInstance!=editor.FontWeight)
// designItem.Properties[Control.FontWeightProperty].SetValue(editor.FontWeight);
// if (changeGroup != null && _isChangeGroupOpen) {
// FormatedTextEditor.SetTextBlockTextFromRichTextBlox(this.designItem, editor);
// changeGroup.Commit();
// _isChangeGroupOpen = false;
// }
// changeGroup = null;
// this.Visibility = Visibility.Hidden;
// ((TextBlock)designItem.Component).Visibility = Visibility.Visible;
// break;
// case Key.Escape:
// AbortEditing();
// break;
// }
// } else if(e.Key == Key.Enter) {
// editor.Selection.Text += Environment.NewLine;
// }
// }
// private void Reset()
// {
// if (textBlock != null) {
// if (property != null)
// textBlock.Text = (string) designItem.Properties[property].ValueOnInstance;
// textBlock.FontFamily = (System.Windows.Media.FontFamily)designItem.Properties[Control.FontFamilyProperty].ValueOnInstance;
// textBlock.FontSize = (double) designItem.Properties[Control.FontSizeProperty].ValueOnInstance;
// textBlock.FontStretch = (FontStretch) designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
// textBlock.FontStretch = (FontStretch) designItem.Properties[Control.FontStretchProperty].ValueOnInstance;
// textBlock.FontWeight = (FontWeight) designItem.Properties[Control.FontWeightProperty].ValueOnInstance;
// }
// }
// public void AbortEditing() {
// if (changeGroup != null && _isChangeGroupOpen) {
// Reset();
// changeGroup.Abort();
// _isChangeGroupOpen = false;
// }
// this.Visibility = Visibility.Hidden;
// if (textBlock != null)
// textBlock.Visibility = Visibility.Visible;
// Reset();
// }
// public void StartEditing() {
// if (changeGroup == null) {
// changeGroup = designItem.OpenGroup("Change Text");
// _isChangeGroupOpen = true;
// }
// this.Visibility = Visibility.Visible;
// if (textBlock != null)
// textBlock.Visibility = Visibility.Hidden;
// }
// }
//}
public void StartEditing()
{
if (changeGroup == null)
{
changeGroup = designItem.OpenGroup("Change Text");
_isChangeGroupOpen = true;
}
this.Visibility = Visibility.Visible;
if (textBlock != null)
textBlock.Visibility = Visibility.Hidden;
}
}
}

Просмотреть файл

@ -16,7 +16,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

Просмотреть файл

@ -21,14 +21,9 @@ using System.Windows.Input;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls

Просмотреть файл

@ -16,7 +16,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

Просмотреть файл

@ -63,7 +63,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public double Value {
get { return (double)GetValue(ValueProperty); }
@ -72,7 +72,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public static readonly DependencyProperty SmallChangeProperty =
DependencyProperty.Register("SmallChange", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(1.0));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble1));
public double SmallChange {
get { return (double)GetValue(SmallChangeProperty); }

Просмотреть файл

@ -38,11 +38,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
static PageClone()
{
Control.IsTabStopProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(SharedInstances.BoxedFalse));
KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(PageClone), new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
}

Просмотреть файл

@ -42,7 +42,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(Picker),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
new FrameworkPropertyMetadata(SharedInstances.BoxedDouble0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public double Value {
get { return (double)GetValue(ValueProperty); }

Просмотреть файл

@ -38,7 +38,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// Dependency property for <see cref="IsPrimarySelection"/>.
/// </summary>
public static readonly DependencyProperty ThumbVisibleProperty
= DependencyProperty.Register("ThumbVisible", typeof(bool), typeof(DesignerThumb), new FrameworkPropertyMetadata(true));
= DependencyProperty.Register("ThumbVisible", typeof(bool), typeof(DesignerThumb), new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
/// <summary>
/// Dependency property for <see cref="OperationMenu"/>.

Просмотреть файл

@ -41,9 +41,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(typeof(WindowClone)));
Control.IsTabStopProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances.BoxedFalse));
KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(KeyboardNavigationMode.Cycle));
KeyboardNavigation.DirectionalNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
KeyboardNavigation.TabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
KeyboardNavigation.ControlTabNavigationProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances<KeyboardNavigationMode>.Box(KeyboardNavigationMode.Cycle)));
FocusManager.IsFocusScopeProperty.OverrideMetadata(typeof(WindowClone), new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
}

Просмотреть файл

@ -68,7 +68,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public static readonly DependencyProperty MouseWheelZoomProperty =
DependencyProperty.Register("MouseWheelZoom", typeof(bool), typeof(ZoomScrollViewer),
new FrameworkPropertyMetadata(true));
new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
public bool MouseWheelZoom {
get { return (bool)GetValue(MouseWheelZoomProperty); }
@ -77,7 +77,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public static readonly DependencyProperty AlwaysShowZoomButtonsProperty =
DependencyProperty.Register("AlwaysShowZoomButtons", typeof(bool), typeof(ZoomScrollViewer),
new FrameworkPropertyMetadata(false, CalculateZoomButtonCollapsed));
new FrameworkPropertyMetadata(SharedInstances.BoxedFalse, CalculateZoomButtonCollapsed));
public bool AlwaysShowZoomButtons {
get { return (bool)GetValue(AlwaysShowZoomButtonsProperty); }
@ -86,7 +86,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
static readonly DependencyPropertyKey ComputedZoomButtonCollapsedPropertyKey =
DependencyProperty.RegisterReadOnly("ComputedZoomButtonCollapsed", typeof(bool), typeof(ZoomScrollViewer),
new FrameworkPropertyMetadata(true));
new FrameworkPropertyMetadata(SharedInstances.BoxedTrue));
public static readonly DependencyProperty ComputedZoomButtonCollapsedProperty = ComputedZoomButtonCollapsedPropertyKey.DependencyProperty;

Просмотреть файл

@ -1,261 +1,272 @@
// 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.ComponentModel;
//using System.Diagnostics;
//using System.Windows;
//using System.Windows.Media;
//using System.Windows.Media.Effects;
//using System.Windows.Input;
//using System.Windows.Controls;
//using System.Windows.Data;
//using ICSharpCode.WpfDesign.Adorners;
//using ICSharpCode.WpfDesign.Extensions;
//using ICSharpCode.WpfDesign.Designer.Controls;
//using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
//using ICSharpCode.WpfDesign.UIExtensions;
//namespace ICSharpCode.WpfDesign.Designer.Extensions
//{
// /// <summary>
// /// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock
// /// </summary>
// [ExtensionFor(typeof(TextBlock))]
// public class InPlaceEditorExtension : PrimarySelectionAdornerProvider
// {
// AdornerPanel adornerPanel;
// RelativePlacement placement;
// InPlaceEditor editor;
// /// <summary> Is the element in the Visual tree of the extended element which is being edited. </summary>
// TextBlock textBlock;
// FrameworkElement element;
// DesignPanel designPanel;
// bool isGettingDragged; // Flag to get/set whether the extended element is dragged.
// bool isMouseDown; // Flag to get/set whether left-button is down on the element.
// int numClicks; // No of left-button clicks on the element.
// public InPlaceEditorExtension()
// {
// adornerPanel = new AdornerPanel();
// isGettingDragged = false;
// isMouseDown = Mouse.LeftButton == MouseButtonState.Pressed ? true : false;
// numClicks = 0;
// }
// protected override void OnInitialized()
// {
// base.OnInitialized();
// element = ExtendedItem.Component as FrameworkElement;
// editor = new InPlaceEditor(ExtendedItem);
// editor.DataContext = element;
// editor.Visibility = Visibility.Hidden; // Hide the editor first, It's visibility is governed by mouse events.
// placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
// adornerPanel.Children.Add(editor);
// Adorners.Add(adornerPanel);
// designPanel = ExtendedItem.Services.GetService<IDesignPanel>() as DesignPanel;
// Debug.Assert(designPanel!=null);
// /* Add mouse event handlers */
// designPanel.PreviewMouseLeftButtonDown += MouseDown;
// designPanel.PreviewMouseLeftButtonUp += MouseUp;
// designPanel.PreviewMouseMove += MouseMove;
// /* To update the position of Editor in case of resize operation */
// ExtendedItem.PropertyChanged += PropertyChanged;
// }
// /// <summary>
// /// Checks whether heigth/width have changed and updates the position of editor
// /// </summary>
// /// <param name="sender"></param>
// /// <param name="e"></param>
// void PropertyChanged(object sender,PropertyChangedEventArgs e)
// {
// if (textBlock != null) {
// if (e.PropertyName == "Width"){
// placement.XOffset = Mouse.GetPosition((IInputElement) element).X - Mouse.GetPosition(textBlock).X-2.8;
// editor.MaxWidth = Math.Max((ModelTools.GetWidth(element) - placement.XOffset), 0);
// }
// if (e.PropertyName == "Height"){
// placement.YOffset = Mouse.GetPosition((IInputElement) element).Y - Mouse.GetPosition(textBlock).Y-1;
// editor.MaxHeight = Math.Max((ModelTools.GetHeight(element) - placement.YOffset), 0);
// }
// AdornerPanel.SetPlacement(editor, placement);
// }
// }
// /// <summary>
// /// Places the handle from a calculated offset using Mouse Positon
// /// </summary>
// /// <param name="text"></param>
// /// <param name="e"></param>
// void PlaceEditor(Visual text,MouseEventArgs e)
// {
// textBlock = text as TextBlock;
// Debug.Assert(textBlock != null);
// /* Gets the offset between the top-left corners of the element and the editor*/
// placement.XOffset = e.GetPosition(element).X - e.GetPosition(textBlock).X -2.8;
// placement.YOffset = e.GetPosition(element).Y - e.GetPosition(textBlock).Y -1;
// placement.XRelativeToAdornerWidth = 0;
// placement.XRelativeToContentWidth = 0;
// placement.YRelativeToAdornerHeight = 0;
// placement.YRelativeToContentHeight = 0;
// /* Change data context of the editor to the TextBlock */
// editor.DataContext = textBlock;
// 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.
// /* Set MaxHeight and MaxWidth so that editor doesn't cross the boundaries of the control */
// editor.SetBinding(FrameworkElement.WidthProperty, new Binding("ActualWidth"));
// editor.SetBinding(FrameworkElement.HeightProperty, new Binding("ActualHeight"));
// /* Hides the TextBlock in control because of some minor offset in placement, overlaping makes text look fuzzy */
// textBlock.Visibility = Visibility.Hidden; //
// AdornerPanel.SetPlacement(editor, placement);
// RemoveBorder(); // Remove the highlight border.
// }
// /// <summary>
// /// Aborts the editing. This aborts the underlying change group of the editor
// /// </summary>
// public void AbortEdit()
// {
// editor.AbortEditing();
// }
// /// <summary>
// /// Starts editing once again. This aborts the underlying change group of the editor
// /// </summary>
// public void StartEdit()
// {
// editor.StartEditing();
// }
// #region MouseEvents
// DesignPanelHitTestResult result;
// Point Current;
// Point Start;
// void MouseDown(object sender, MouseEventArgs e)
// {
// result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
// if (result.ModelHit == ExtendedItem && result.VisualHit is TextBlock) {
// Start = Mouse.GetPosition(null);
// Current = Start;
// isMouseDown = true;
// }
// numClicks++;
// }
// void MouseMove(object sender, MouseEventArgs e)
// {
// Current += e.GetPosition(null) - Start;
// result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
// if (result.ModelHit == ExtendedItem && result.VisualHit is TextBlock) {
// if (numClicks > 0) {
// if (isMouseDown &&
// ((Current-Start).X > SystemParameters.MinimumHorizontalDragDistance
// || (Current-Start).Y > SystemParameters.MinimumVerticalDragDistance)) {
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.UIExtensions;
// isGettingDragged = true;
// editor.Focus();
// }
// }
// DrawBorder((FrameworkElement) result.VisualHit);
// }else{
// RemoveBorder();
// }
// }
// void MouseUp(object sender, MouseEventArgs e)
// {
// result = designPanel.HitTest(e.GetPosition(designPanel), true, true, HitTestType.Default);
// if (((result.ModelHit == ExtendedItem && result.VisualHit is TextBlock) || (result.VisualHit != null && result.VisualHit.TryFindParent<InPlaceEditor>() == editor)) && numClicks > 0) {
// if (!isGettingDragged) {
// PlaceEditor(ExtendedItem.View, e);
// editor.Visibility = Visibility.Visible;
// }
// } else { // Clicked outside the Text - > hide the editor and make the actualt text visible again
// editor.Visibility = Visibility.Hidden;
// if (textBlock != null) textBlock.Visibility = Visibility.Visible;
// }
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock
/// </summary>
[ExtensionFor(typeof(TextBlock))]
public class InPlaceEditorExtension : PrimarySelectionAdornerProvider
{
AdornerPanel adornerPanel;
RelativePlacement placement;
InPlaceEditor editor;
/// <summary> Is the element in the Visual tree of the extended element which is being edited. </summary>
TextBlock textBlock;
FrameworkElement element;
DesignPanel designPanel;
// isMouseDown = false;
// isGettingDragged = false;
// }
// #endregion
// #region HighlightBorder
// private Border _border;
// private sealed class BorderPlacement : AdornerPlacement
// {
// private readonly FrameworkElement _element;
bool isGettingDragged; // Flag to get/set whether the extended element is dragged.
bool isMouseDown; // Flag to get/set whether left-button is down on the element.
int numClicks; // No of left-button clicks on the element.
public InPlaceEditorExtension()
{
adornerPanel = new AdornerPanel();
isGettingDragged = false;
isMouseDown = Mouse.LeftButton == MouseButtonState.Pressed ? true : false;
numClicks = 0;
}
// public BorderPlacement(FrameworkElement element)
// {
// _element = element;
// }
protected override void OnInitialized()
{
base.OnInitialized();
element = ExtendedItem.Component as FrameworkElement;
editor = new InPlaceEditor(ExtendedItem);
editor.DataContext = element;
editor.Visibility = Visibility.Hidden; // Hide the editor first, It's visibility is governed by mouse events.
placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
adornerPanel.Children.Add(editor);
Adorners.Add(adornerPanel);
designPanel = ExtendedItem.Services.GetService<IDesignPanel>() as DesignPanel;
Debug.Assert(designPanel != null);
/* Add mouse event handlers */
designPanel.PreviewMouseLeftButtonDown += MouseDown;
designPanel.PreviewMouseLeftButtonUp += MouseUp;
designPanel.PreviewMouseMove += MouseMove;
/* To update the position of Editor in case of resize operation */
ExtendedItem.PropertyChanged += PropertyChanged;
}
/// <summary>
/// Checks whether heigth/width have changed and updates the position of editor
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (textBlock != null)
{
if (e.PropertyName == "Width")
{
placement.XOffset = Mouse.GetPosition((IInputElement)element).X - Mouse.GetPosition(textBlock).X - 2.8;
editor.MaxWidth = Math.Max((ModelTools.GetWidth(element) - placement.XOffset), 0);
}
if (e.PropertyName == "Height")
{
placement.YOffset = Mouse.GetPosition((IInputElement)element).Y - Mouse.GetPosition(textBlock).Y - 1;
editor.MaxHeight = Math.Max((ModelTools.GetHeight(element) - placement.YOffset), 0);
}
AdornerPanel.SetPlacement(editor, placement);
}
}
/// <summary>
/// Places the handle from a calculated offset using Mouse Positon
/// </summary>
/// <param name="text"></param>
/// <param name="e"></param>
void PlaceEditor(Visual text, MouseEventArgs e)
{
textBlock = text as TextBlock;
Debug.Assert(textBlock != null);
/* Gets the offset between the top-left corners of the element and the editor*/
placement.XOffset = e.GetPosition(element).X - e.GetPosition(textBlock).X - 2.8;
placement.YOffset = e.GetPosition(element).Y - e.GetPosition(textBlock).Y - 1;
placement.XRelativeToAdornerWidth = 0;
placement.XRelativeToContentWidth = 0;
placement.YRelativeToAdornerHeight = 0;
placement.YRelativeToContentHeight = 0;
/* Change data context of the editor to the TextBlock */
editor.DataContext = textBlock;
/* Set MaxHeight and MaxWidth so that editor doesn't cross the boundaries of the control */
editor.SetBinding(FrameworkElement.WidthProperty, new Binding("ActualWidth"));
editor.SetBinding(FrameworkElement.HeightProperty, new Binding("ActualHeight"));
/* Hides the TextBlock in control because of some minor offset in placement, overlaping makes text look fuzzy */
textBlock.Visibility = Visibility.Hidden; //
AdornerPanel.SetPlacement(editor, placement);
RemoveBorder(); // Remove the highlight border.
}
/// <summary>
/// Aborts the editing. This aborts the underlying change group of the editor
/// </summary>
public void AbortEdit()
{
editor.AbortEditing();
}
/// <summary>
/// Starts editing once again. This aborts the underlying change group of the editor
/// </summary>
public void StartEdit()
{
editor.StartEditing();
}
#region MouseEvents
DesignPanelHitTestResult result;
Point Current;
Point Start;
void MouseDown(object sender, MouseEventArgs e)
{
result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
if (result.ModelHit == ExtendedItem && result.VisualHit is TextBlock)
{
Start = Mouse.GetPosition(null);
Current = Start;
isMouseDown = true;
}
numClicks++;
}
void MouseMove(object sender, MouseEventArgs e)
{
Current += e.GetPosition(null) - Start;
result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
if (result.ModelHit == ExtendedItem && result.VisualHit is TextBlock)
{
if (numClicks > 0)
{
if (isMouseDown &&
((Current - Start).X > SystemParameters.MinimumHorizontalDragDistance
|| (Current - Start).Y > SystemParameters.MinimumVerticalDragDistance))
{
// public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
// {
// Point p = _element.TranslatePoint(new Point(), panel.AdornedElement);
// var rect = new Rect(p, _element.RenderSize);
// rect.Inflate(3, 1);
// adorner.Arrange(rect);
// }
// }
// private void DrawBorder(FrameworkElement item)
// {
// if (editor != null && editor.Visibility != Visibility.Visible) {
// if (adornerPanel.Children.Contains(_border))
// adornerPanel.Children.Remove(_border);
// _border = new Border {BorderBrush = Brushes.Gray, BorderThickness = new Thickness(1.4), ToolTip = "Edit this Text", SnapsToDevicePixels = true};
// var shadow = new DropShadowEffect {Color = Colors.LightGray, ShadowDepth = 3};
// _border.Effect = shadow;
// var bp = new BorderPlacement(item);
// AdornerPanel.SetPlacement(_border, bp);
// adornerPanel.Children.Add(_border);
// }
// }
isGettingDragged = true;
editor.Focus();
}
}
DrawBorder((FrameworkElement)result.VisualHit);
}
else {
RemoveBorder();
}
}
void MouseUp(object sender, MouseEventArgs e)
{
result = designPanel.HitTest(e.GetPosition(designPanel), true, true, HitTestType.Default);
if (((result.ModelHit == ExtendedItem && result.VisualHit is TextBlock) || (result.VisualHit != null && result.VisualHit.TryFindParent<InPlaceEditor>() == editor)) && numClicks > 0)
{
if (!isGettingDragged)
{
PlaceEditor(ExtendedItem.View, e);
editor.Visibility = Visibility.Visible;
}
}
else { // Clicked outside the Text - > hide the editor and make the actualt text visible again
editor.Visibility = Visibility.Hidden;
if (textBlock != null) textBlock.Visibility = Visibility.Visible;
}
// private void RemoveBorder()
// {
// if (adornerPanel.Children.Contains(_border))
// adornerPanel.Children.Remove(_border);
// }
// #endregion
// protected override void OnRemove()
// {
// if (textBlock != null)
// textBlock.Visibility = Visibility.Visible;
// ExtendedItem.PropertyChanged -= PropertyChanged;
// designPanel.PreviewMouseLeftButtonDown -= MouseDown;
// designPanel.PreviewMouseMove -= MouseMove;
// designPanel.PreviewMouseLeftButtonUp -= MouseUp;
// base.OnRemove();
// }
// }
//}
isMouseDown = false;
isGettingDragged = false;
}
#endregion
#region HighlightBorder
private Border _border;
private sealed class BorderPlacement : AdornerPlacement
{
private readonly FrameworkElement _element;
public BorderPlacement(FrameworkElement element)
{
_element = element;
}
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = _element.TranslatePoint(new Point(), panel.AdornedElement);
var rect = new Rect(p, _element.RenderSize);
rect.Inflate(3, 1);
adorner.Arrange(rect);
}
}
private void DrawBorder(FrameworkElement item)
{
if (editor != null && editor.Visibility != Visibility.Visible)
{
if (adornerPanel.Children.Contains(_border))
adornerPanel.Children.Remove(_border);
_border = new Border { BorderBrush = Brushes.Gray, BorderThickness = new Thickness(1.4), ToolTip = "Edit this Text", SnapsToDevicePixels = true };
var shadow = new DropShadowEffect { Color = Colors.LightGray, ShadowDepth = 3 };
_border.Effect = shadow;
var bp = new BorderPlacement(item);
AdornerPanel.SetPlacement(_border, bp);
adornerPanel.Children.Add(_border);
}
}
private void RemoveBorder()
{
if (adornerPanel.Children.Contains(_border))
adornerPanel.Children.Remove(_border);
}
#endregion
protected override void OnRemove()
{
if (textBlock != null)
textBlock.Visibility = Visibility.Visible;
ExtendedItem.PropertyChanged -= PropertyChanged;
designPanel.PreviewMouseLeftButtonDown -= MouseDown;
designPanel.PreviewMouseMove -= MouseMove;
designPanel.PreviewMouseLeftButtonUp -= MouseUp;
base.OnRemove();
}
}
}

Просмотреть файл

@ -1,5 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
<!--<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.TextBlockRightClickContextMenu"
<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"
@ -9,4 +8,4 @@
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>-->
</ContextMenu>

Просмотреть файл

@ -1,66 +1,67 @@
// 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.
// 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.Windows;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.themes;
//using System;
//using System.Windows;
//using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
//using ICSharpCode.WpfDesign.UIExtensions;
//using ICSharpCode.WpfDesign.Designer.themes;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public partial class TextBlockRightClickContextMenu
{
private DesignItem designItem;
//namespace ICSharpCode.WpfDesign.Designer.Extensions
//{
// public partial class TextBlockRightClickContextMenu
// {
// private DesignItem designItem;
public TextBlockRightClickContextMenu(DesignItem designItem)
{
this.designItem = designItem;
SpecialInitializeComponent();
}
/// <summary>
/// Fixes InitializeComponent with multiple Versions of same Assembly loaded
/// </summary>
public void SpecialInitializeComponent()
{
if (!this._contentLoaded)
{
this._contentLoaded = true;
Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
Application.LoadComponent(this, resourceLocator);
}
this.InitializeComponent();
}
// public TextBlockRightClickContextMenu(DesignItem designItem)
// {
// this.designItem = designItem;
// SpecialInitializeComponent();
// }
// /// <summary>
// /// Fixes InitializeComponent with multiple Versions of same Assembly loaded
// /// </summary>
// public void SpecialInitializeComponent()
// {
// if (!this._contentLoaded) {
// this._contentLoaded = true;
// Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
// Application.LoadComponent(this, resourceLocator);
// }
// this.InitializeComponent();
// }
void Click_EditFormatedText(object sender, RoutedEventArgs e)
{
var dlg = new Window()
{
Content = new FormatedTextEditor(designItem),
Width = 440,
Height = 200,
WindowStyle = WindowStyle.ToolWindow,
Owner = ((DesignPanel)designItem.Context.Services.DesignPanel).TryFindParent<Window>(),
};
// void Click_EditFormatedText(object sender, RoutedEventArgs e)
// {
// var dlg = new Window()
// {
// Content = new FormatedTextEditor(designItem),
// Width = 440,
// Height = 200,
// WindowStyle = WindowStyle.ToolWindow,
// Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent<Window>(),
// };
// dlg.ShowDialog();
// }
// }
//}
dlg.ShowDialog();
}
}
}

Просмотреть файл

@ -1,51 +1,51 @@
// 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.
// 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.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
//using System.Windows.Controls;
//using ICSharpCode.WpfDesign.Adorners;
//using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionServer(typeof(OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof(TextBlock))]
[Extension(Order = 40)]
public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
//namespace ICSharpCode.WpfDesign.Designer.Extensions
//{
// [ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
// [ExtensionFor(typeof (TextBlock))]
// [Extension(Order = 40)]
// public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider
// {
// DesignPanel panel;
// ContextMenu contextMenu;
protected override void OnInitialized()
{
base.OnInitialized();
// protected override void OnInitialized()
// {
// base.OnInitialized();
contextMenu = new TextBlockRightClickContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
if (panel != null)
panel.AddContextMenu(contextMenu);
}
// contextMenu = new TextBlockRightClickContextMenu(ExtendedItem);
// panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
// if (panel != null)
// panel.AddContextMenu(contextMenu);
// }
protected override void OnRemove()
{
if (panel != null)
panel.RemoveContextMenu(contextMenu);
// protected override void OnRemove()
// {
// if (panel != null)
// panel.RemoveContextMenu(contextMenu);
// base.OnRemove();
// }
// }
//}
base.OnRemove();
}
}
}

Просмотреть файл

@ -1,5 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />
<!--<UserControl x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor.FormatedTextEditor"
<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"
@ -16,7 +15,7 @@
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<Style x:Key="RichTextBoxFormatBarStyle" TargetType="{x:Type xctk:RichTextBoxFormatBar}">
<!--<Style x:Key="RichTextBoxFormatBarStyle" TargetType="{x:Type xctk:RichTextBoxFormatBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type xctk:RichTextBoxFormatBar}">
@ -817,17 +816,17 @@
<Setter Property="Background" Value="Transparent"/>
<Setter Property="IsTabStop" Value="False"/>
</Style>
</Style>-->
</UserControl.Resources>
<Grid>
<xctk:RichTextBox Margin="10,74,10,10" x:Name="richTextBox">
</xctk:RichTextBox>
<RichTextBox Margin="10,74,10,10" x:Name="richTextBox">
</RichTextBox>
<xctk:RichTextBoxFormatBar x:Name="formatBar" Target="{Binding ElementName=richTextBox}" Margin="10,10,0,0" Style="{DynamicResource RichTextBoxFormatBarStyle}" HorizontalAlignment="Left" Width="295" Height="59" VerticalAlignment="Top" />
<!--<xctk:RichTextBoxFormatBar x:Name="formatBar" Target="{Binding ElementName=richTextBox}" Margin="10,10,0,0" Style="{DynamicResource RichTextBoxFormatBarStyle}" HorizontalAlignment="Left" Width="295" Height="59" VerticalAlignment="Top" />-->
<Button Content="Ok" Margin="0,10,10,0" HorizontalAlignment="Right" Width="90" Height="20" VerticalAlignment="Top" Click="Ok_Click" />
<Button Content="Cancel" Margin="0,34,10,0" HorizontalAlignment="Right" Width="90" Height="20" VerticalAlignment="Top" Click="Cancel_Click" />
</Grid>
</UserControl>-->
</UserControl>

Просмотреть файл

@ -1,246 +1,247 @@
// 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.
// 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.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.themes;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Documents;
//using ICSharpCode.WpfDesign.UIExtensions;
//using ICSharpCode.WpfDesign.Designer.themes;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
{
/// <summary>
/// Interaktionslogik für FormatedTextEditor.xaml
/// </summary>
public partial class FormatedTextEditor
{
private DesignItem designItem;
//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)
{
SpecialInitializeComponent();
// public FormatedTextEditor(DesignItem designItem)
// {
// SpecialInitializeComponent();
this.designItem = designItem;
// this.designItem = designItem;
var tb = ((TextBlock)designItem.Component);
SetRichTextBoxTextFromTextBlock(richTextBox, tb);
// var tb = ((TextBlock)designItem.Component);
// SetRichTextBoxTextFromTextBlock(richTextBox, tb);
richTextBox.Foreground = tb.Foreground;
richTextBox.Background = tb.Background;
}
// richTextBox.Foreground = tb.Foreground;
// richTextBox.Background = tb.Background;
// }
// public static void SetRichTextBoxTextFromTextBlock(RichTextBox richTextBox, TextBlock textBlock)
// {
// IEnumerable<Inline> inlines = null;
public static void SetRichTextBoxTextFromTextBlock(RichTextBox richTextBox, TextBlock textBlock)
{
IEnumerable<Inline> inlines = null;
// inlines = textBlock.Inlines.Select(x => CloneInline(x)).ToList();
inlines = textBlock.Inlines.Select(x => CloneInline(x)).ToList();
// var paragraph = richTextBox.Document.Blocks.First() as Paragraph;
// paragraph.Inlines.AddRange(inlines);
var paragraph = richTextBox.Document.Blocks.First() as Paragraph;
paragraph.Inlines.AddRange(inlines);
// richTextBox.Document.Blocks.Add(paragraph);
// }
richTextBox.Document.Blocks.Add(paragraph);
}
/// <summary>
/// Fixes InitializeComponent with multiple Versions of same Assembly loaded
/// </summary>
public void SpecialInitializeComponent()
{
if (!this._contentLoaded)
{
this._contentLoaded = true;
Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
Application.LoadComponent(this, resourceLocator);
}
this.InitializeComponent();
}
// /// <summary>
// /// Fixes InitializeComponent with multiple Versions of same Assembly loaded
// /// </summary>
// public void SpecialInitializeComponent()
// {
// if (!this._contentLoaded) {
// this._contentLoaded = true;
// Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
// Application.LoadComponent(this, resourceLocator);
// }
// this.InitializeComponent();
// }
private static void GetDesignItems(DesignItem designItem, TextElementCollection<Block> blocks, List<DesignItem> list)
{
bool first = true;
// private static void GetDesignItems(DesignItem designItem, 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 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)
{
list.Add(InlineToDesignItem(designItem, inline));
}
}
else if (block is Section)
{
GetDesignItems(designItem, ((Section)block).Blocks, list);
}
// foreach (var inline in ((Paragraph) block).Inlines)
// {
// list.Add(InlineToDesignItem(designItem, inline));
// }
// }
// else if (block is Section)
// {
// GetDesignItems(designItem, ((Section)block).Blocks, list);
// }
first = false;
}
}
// first = false;
// }
// }
private static Inline CloneInline(Inline inline)
{
Inline retVal = null;
if (inline is LineBreak)
retVal = new LineBreak();
else if (inline is Span)
retVal = new Span();
else if (inline is Run)
{
retVal = new Run(((Run)inline).Text);
}
// private static Inline CloneInline(Inline inline)
// {
// Inline retVal = null;
// if (inline is LineBreak)
// retVal = new LineBreak();
// else if (inline is Span)
// retVal = new Span();
// else if (inline is Run)
// {
// retVal = new Run(((Run) inline).Text);
// }
if (inline.ReadLocalValue(Inline.BackgroundProperty) != DependencyProperty.UnsetValue)
retVal.Background = inline.Background;
if (inline.ReadLocalValue(Inline.ForegroundProperty) != DependencyProperty.UnsetValue)
retVal.Foreground = inline.Foreground;
if (inline.ReadLocalValue(Inline.FontFamilyProperty) != DependencyProperty.UnsetValue)
retVal.FontFamily = inline.FontFamily;
if (inline.ReadLocalValue(Inline.FontSizeProperty) != DependencyProperty.UnsetValue)
retVal.FontSize = inline.FontSize;
if (inline.ReadLocalValue(Inline.FontStretchProperty) != DependencyProperty.UnsetValue)
retVal.FontStretch = inline.FontStretch;
if (inline.ReadLocalValue(Inline.FontStyleProperty) != DependencyProperty.UnsetValue)
retVal.FontStyle = inline.FontStyle;
if (inline.ReadLocalValue(Inline.FontWeightProperty) != DependencyProperty.UnsetValue)
retVal.FontWeight = inline.FontWeight;
if (inline.ReadLocalValue(Inline.TextEffectsProperty) != DependencyProperty.UnsetValue)
retVal.TextEffects = inline.TextEffects;
if (inline.ReadLocalValue(Inline.TextDecorationsProperty) != DependencyProperty.UnsetValue)
retVal.TextDecorations = inline.TextDecorations;
// if (inline.ReadLocalValue(Inline.BackgroundProperty) != DependencyProperty.UnsetValue)
// retVal.Background = inline.Background;
// if (inline.ReadLocalValue(Inline.ForegroundProperty) != DependencyProperty.UnsetValue)
// retVal.Foreground = inline.Foreground;
// if (inline.ReadLocalValue(Inline.FontFamilyProperty) != DependencyProperty.UnsetValue)
// retVal.FontFamily = inline.FontFamily;
// if (inline.ReadLocalValue(Inline.FontSizeProperty) != DependencyProperty.UnsetValue)
// retVal.FontSize = inline.FontSize;
// if (inline.ReadLocalValue(Inline.FontStretchProperty) != DependencyProperty.UnsetValue)
// retVal.FontStretch = inline.FontStretch;
// if (inline.ReadLocalValue(Inline.FontStyleProperty) != DependencyProperty.UnsetValue)
// retVal.FontStyle = inline.FontStyle;
// if (inline.ReadLocalValue(Inline.FontWeightProperty) != DependencyProperty.UnsetValue)
// retVal.FontWeight = inline.FontWeight;
// if (inline.ReadLocalValue(Inline.TextEffectsProperty) != DependencyProperty.UnsetValue)
// retVal.TextEffects = inline.TextEffects;
// if (inline.ReadLocalValue(Inline.TextDecorationsProperty) != DependencyProperty.UnsetValue)
// retVal.TextDecorations = inline.TextDecorations;
return retVal;
}
// return retVal;
// }
private static DesignItem InlineToDesignItem(DesignItem designItem, Inline inline)
{
DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline));
if (inline is Run)
{
var run = inline as Run;
// private static DesignItem InlineToDesignItem(DesignItem designItem, Inline inline)
// {
// DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(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 (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.TextDecorations.Count > 0)
{
d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection());
var tdColl = d.Properties.GetProperty("TextDecorations");
// 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.TextDecorations.Count > 0)
// {
// d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection());
// var tdColl = d.Properties.GetProperty("TextDecorations");
foreach (var td in inline.TextDecorations)
{
var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration());
if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue)
newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location);
if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue)
newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen);
// foreach (var td in inline.TextDecorations)
// {
// var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration());
// if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue)
// newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location);
// if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue)
// newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen);
tdColl.CollectionElements.Add(newTd);
}
}
return d;
}
// tdColl.CollectionElements.Add(newTd);
// }
// }
// return d;
// }
public static void SetTextBlockTextFromRichTextBlox(DesignItem designItem, RichTextBox richTextBox)
{
designItem.Properties.GetProperty(TextBlock.TextProperty).Reset();
// public static void SetTextBlockTextFromRichTextBlox(DesignItem designItem, RichTextBox richTextBox)
// {
// designItem.Properties.GetProperty(TextBlock.TextProperty).Reset();
var inlinesProperty = designItem.Properties.GetProperty("Inlines");
inlinesProperty.CollectionElements.Clear();
// var inlinesProperty = designItem.Properties.GetProperty("Inlines");
// inlinesProperty.CollectionElements.Clear();
var doc = richTextBox.Document;
//richTextBox.Document = new FlowDocument();
var inlines = new List<DesignItem>();
GetDesignItems(designItem, doc.Blocks, inlines);
// var doc = richTextBox.Document;
// //richTextBox.Document = new FlowDocument();
foreach (var inline in inlines)
{
inlinesProperty.CollectionElements.Add(inline);
}
}
// var inlines = new List<DesignItem>();
// GetDesignItems(designItem, doc.Blocks, inlines);
private void Ok_Click(object sender, RoutedEventArgs e)
{
var changeGroup = designItem.OpenGroup("Formated Text");
// foreach (var inline in inlines)
// {
// inlinesProperty.CollectionElements.Add(inline);
// }
// }
SetTextBlockTextFromRichTextBlox(designItem, richTextBox);
// private void Ok_Click(object sender, RoutedEventArgs e)
// {
// var changeGroup = designItem.OpenGroup("Formated Text");
changeGroup.Commit();
// SetTextBlockTextFromRichTextBlox(designItem, richTextBox);
this.TryFindParent<Window>().Close();
}
// changeGroup.Commit();
private void Cancel_Click(object sender, RoutedEventArgs e)
{
this.TryFindParent<Window>().Close();
}
// this.TryFindParent<Window>().Close();
// }
private void StrikeThroughButton_Click(object sender, RoutedEventArgs e)
{
TextRange range = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);
// private void Cancel_Click(object sender, RoutedEventArgs e)
// {
// this.TryFindParent<Window>().Close();
// }
TextDecorationCollection tdc = (TextDecorationCollection)richTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty);
// private void StrikeThroughButton_Click(object sender, RoutedEventArgs e)
// {
// TextRange range = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);
// TextDecorationCollection tdc = (TextDecorationCollection) richTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty);
// if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
// {
// tdc = TextDecorations.Strikethrough;
// }
// else
// {
// tdc = null;
// }
// range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
// }
// }
//}
if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
{
tdc = TextDecorations.Strikethrough;
}
else
{
tdc = null;
}
range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
}
}
}

Просмотреть файл

@ -16,12 +16,17 @@
// 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;
namespace ICSharpCode.WpfDesign.Designer
{
static class SharedInstances
{
internal static readonly object BoxedTrue = true;
internal static readonly object BoxedFalse = false;
internal static readonly object BoxedDouble1 = 1.0;
internal static readonly object BoxedDouble0 = 0.0;
internal static readonly object[] EmptyObjectArray = new object[0];
internal static readonly DesignItem[] EmptyDesignItemArray = new DesignItem[0];
@ -30,4 +35,23 @@ namespace ICSharpCode.WpfDesign.Designer
return value ? BoxedTrue : BoxedFalse;
}
}
static class SharedInstances<T> where T: struct, IConvertible
{
private static Dictionary<T, object> _boxedEnumValues;
static SharedInstances()
{
_boxedEnumValues = new Dictionary<T, object>();
foreach (var value in Enum.GetValues(typeof(T)))
{
_boxedEnumValues.Add((T)value, value);
}
}
internal static object Box(T value)
{
return _boxedEnumValues[value];
}
}
}

Просмотреть файл

@ -70,7 +70,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
if (xamlContext != null) {
xamlContext.XamlEditAction.Cut(grid.ContentProperty.CollectionElements);
var cutXaml = Clipboard.GetText(TextDataFormat.Xaml);
Assert.AreEqual("<Buttonxmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter + "<Buttonxmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter, cutXaml.Replace(" ", ""));
Assert.AreEqual("<Buttonxmlns:x=\"" + XamlConstants.XamlNamespace + "\"xmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter + "<Buttonxmlns:x=\"" + XamlConstants.XamlNamespace + "\"xmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter, cutXaml.Replace(" ", ""));
Assert.AreEqual(0, grid.ContentProperty.CollectionElements.Count);
} else {
Assert.Fail();
@ -85,7 +85,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
if (xamlContext != null) {
xamlContext.XamlEditAction.Copy(grid.ContentProperty.CollectionElements);
var cutXaml = Clipboard.GetText(TextDataFormat.Xaml);
Assert.AreEqual("<Buttonxmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter + "<Buttonxmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter, cutXaml.Replace(" ", ""));
Assert.AreEqual("<Buttonxmlns:x=\"" + XamlConstants.XamlNamespace + "\"xmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter + "<Buttonxmlns:x=\"" + XamlConstants.XamlNamespace + "\"xmlns=\"" + XamlConstants.PresentationNamespace + "\"/>" + xamlContext.XamlEditAction.Delimeter, cutXaml.Replace(" ", ""));
Assert.AreEqual(2, grid.ContentProperty.CollectionElements.Count);
} else {
Assert.Fail();
@ -265,8 +265,8 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
"</sdtcontrols:CustomButton>\n";
AssertGridDesignerOutput(expectedXaml, grid.Context,
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"",
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"");
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"",
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"");
}
[Test]

Просмотреть файл

@ -22,9 +22,9 @@ using System.Windows.Markup;
using System.Xml;
using System.IO;
using System.Linq;
using System.Windows.Documents;
using System.Windows.Media;
using System.Collections.Generic;
using System.Reflection;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -33,6 +33,20 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public sealed class XamlDocument
{
static XamlDocument()
{
_colorBrushDictionary = new Dictionary<Color, string>();
foreach (var brushProp in typeof(Brushes).GetProperties(BindingFlags.Static|BindingFlags.Public))
{
var brush = brushProp.GetValue(null, null) as SolidColorBrush;
if (!_colorBrushDictionary.ContainsKey(brush.Color)) {
_colorBrushDictionary.Add(brush.Color, brushProp.Name);
}
}
}
private static Dictionary<Color, string> _colorBrushDictionary;
XmlDocument _xmlDoc;
XamlObject _rootElement;
IServiceProvider _serviceProvider;
@ -185,6 +199,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
ctx.Instance = instance;
bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string));
if (forProperty != null && hasStringConverter) {
if (instance is SolidColorBrush && _colorBrushDictionary.ContainsKey(((SolidColorBrush)instance).Color)) {
var name = _colorBrushDictionary[((SolidColorBrush)instance).Color];
return new XamlTextValue(this, name);
}
return new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance));
}
@ -195,21 +215,24 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (hasStringConverter && (XamlObject.GetContentPropertyName(elementType) != null || IsNativeType(instance))) {
xml.InnerText = c.ConvertToInvariantString(instance);
} else if (instance is Brush && forProperty != null) { // TODO: this is a hacky fix, because Brush Editor doesn't
// edit Design Items and so we have no XML, only the Brush
// object and we need to parse the Brush to XAML!
} else if (instance is Brush && forProperty != null) { // TODO: this is a hacky fix, because Brush Editor doesn't
// edit Design Items and so we have no XML, only the Brush
// object and we need to parse the Brush to XAML!
var s = new MemoryStream();
XamlWriter.Save(instance, s);
s.Seek(0, SeekOrigin.Begin);
XmlDocument doc = new XmlDocument();
doc.Load(s);
xml = (XmlElement)_xmlDoc.ImportNode(doc.DocumentElement, true);
xml = (XmlElement) _xmlDoc.ImportNode(doc.DocumentElement, true);
var attLst = xml.Attributes.Cast<XmlAttribute>().ToList();
foreach (XmlAttribute att in attLst) {
if (att.Name.StartsWith(XamlConstants.Xmlns)) {
foreach (XmlAttribute att in attLst)
{
if (att.Name.StartsWith(XamlConstants.Xmlns))
{
var rootAtt = doc.DocumentElement.GetAttributeNode(att.Name);
if (rootAtt != null && rootAtt.Value == att.Value) {
if (rootAtt != null && rootAtt.Value == att.Value)
{
xml.Attributes.Remove(att);
}
}

Просмотреть файл

@ -25,7 +25,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Xml;
using System.Windows.Media;