Ver 2.0. Fixes and improvements.

This commit is contained in:
2017-08-27 13:05:14 +03:00
parent 9ec10b207b
commit b3f14b4637
52 changed files with 1092 additions and 647 deletions

View File

@@ -56,7 +56,6 @@
<Compile Include="Commands\AsyncCommand.cs" />
<Compile Include="Commands\RelayCommand.cs" />
<Compile Include="Converters\InverseBooleanToVisibilityConverter.cs" />
<Compile Include="Converters\StringHelpConverter.cs" />
<Compile Include="Diagrams\Adorners\ResizeRotateAdorner.cs" />
<Compile Include="Diagrams\Adorners\ResizeRotateChrome.cs" />
<Compile Include="Diagrams\Adorners\SizeAdorner.cs" />
@@ -68,7 +67,6 @@
<Compile Include="Diagrams\Thumbs\ResizeThumb.cs" />
<Compile Include="Diagrams\Thumbs\RotateThumb.cs" />
<Compile Include="Extensions\WpfExtensions.cs" />
<Compile Include="Mvvm\ViewModelBase.cs" />
<Compile Include="ThemeManager.cs" />
<Compile Include="ZoomControl.cs">
<SubType>Code</SubType>

View File

@@ -1,32 +0,0 @@
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Windows.Data;
namespace BrightSharp.Converters
{
public class StringHelpConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter is string && value is string)
{
var parStr = (string)parameter;
switch (parStr)
{
case "SpaceBetweenCaps":
var src = (value ?? string.Empty).ToString();
return Regex.Replace(src, "([a-z])([A-Z])", "$1 $2");
default:
break;
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -20,7 +20,7 @@ namespace Diagrams
{
if (e.Source is DependencyObject)
{
var clickedElement = ((DependencyObject)e.OriginalSource).Ancestors<ContentControl>().FirstOrDefault(el => el.Style == designerStyle && WpfExtensions.GetItemsPanel(el.GetParent(true)) == fe);
var clickedElement = ((DependencyObject)e.OriginalSource).GetAncestors<ContentControl>().FirstOrDefault(el => el.Style == designerStyle && WpfExtensions.GetItemsPanel(el.GetParent(true)) == fe);
if (clickedElement == null)
{
foreach (DependencyObject item in fePanel.Children)
@@ -49,7 +49,7 @@ namespace Diagrams
{
if (e.Source is DependencyObject)
{
var clickedElement = ((DependencyObject)e.Source).Ancestors<ContentControl>().FirstOrDefault(el => el.Style == designerStyle && el.Parent == fe);
var clickedElement = ((DependencyObject)e.Source).GetAncestors<ContentControl>().FirstOrDefault(el => el.Style == designerStyle && el.Parent == fe);
if (clickedElement == null)
{
foreach (DependencyObject item in feItemsControl.Items)

View File

@@ -1,8 +1,8 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
namespace Diagrams
@@ -12,32 +12,35 @@ namespace Diagrams
{
private RotateTransform rotateTransform;
private ContentControl designerItem;
private static int? zIndex = null;
public MoveThumb()
{
DragStarted += new DragStartedEventHandler(this.MoveThumb_DragStarted);
DragDelta += new DragDeltaEventHandler(this.MoveThumb_DragDelta);
public MoveThumb() {
DragStarted += MoveThumb_DragStarted;
DragDelta += MoveThumb_DragDelta;
DragCompleted += MoveThumb_DragCompleted;
}
private void MoveThumb_DragCompleted(object sender, DragCompletedEventArgs e) {
//TODO Need think about ZIndex changes
}
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e)
{
private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e) {
this.designerItem = DataContext as ContentControl;
if (this.designerItem != null)
{
if (this.designerItem != null) {
this.rotateTransform = this.designerItem.RenderTransform as RotateTransform;
if (designerItem.GetBindingExpression(Panel.ZIndexProperty) == null) {
zIndex = Math.Max(zIndex ?? 0, Panel.GetZIndex(designerItem));
Panel.SetZIndex(designerItem, zIndex.Value + 1);
}
}
}
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
if (this.designerItem != null)
{
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e) {
if (this.designerItem != null) {
Point dragDelta = new Point(e.HorizontalChange, e.VerticalChange);
if (this.rotateTransform != null)
{
if (this.rotateTransform != null) {
dragDelta = this.rotateTransform.Transform(dragDelta);
}
if (double.IsNaN(Canvas.GetLeft(this.designerItem))) Canvas.SetLeft(this.designerItem, 0);
@@ -45,6 +48,8 @@ namespace Diagrams
Canvas.SetLeft(this.designerItem, Canvas.GetLeft(this.designerItem) + dragDelta.X);
Canvas.SetTop(this.designerItem, Canvas.GetTop(this.designerItem) + dragDelta.Y);
}
}
}

View File

@@ -9,6 +9,12 @@ namespace BrightSharp.Extensions
{
public static class WpfExtensions
{
/// <summary>
/// Returns Parent item of DependencyObject
/// </summary>
/// <param name="obj">Child object</param>
/// <param name="useLogicalTree">Prefer LogicalTree when need.</param>
/// <returns>Found item</returns>
public static DependencyObject GetParent(this DependencyObject obj, bool useLogicalTree = false)
{
if (!useLogicalTree && (obj is Visual || obj is Visual3D))
@@ -16,7 +22,8 @@ namespace BrightSharp.Extensions
else
return LogicalTreeHelper.GetParent(obj);
}
public static IEnumerable<T> Ancestors<T>(this DependencyObject obj, bool useLogicalTree = false) where T : DependencyObject
public static IEnumerable<T> GetAncestors<T>(this DependencyObject obj, bool useLogicalTree = false) where T : DependencyObject
{
if (obj == null) yield break;
@@ -30,7 +37,7 @@ namespace BrightSharp.Extensions
yield return x as T;
else
yield break;
foreach (var item in Ancestors<T>(x, useLogicalTree))
foreach (var item in GetAncestors<T>(x, useLogicalTree))
{
yield return item;
}
@@ -38,34 +45,97 @@ namespace BrightSharp.Extensions
public static T FindAncestor<T>(this DependencyObject obj) where T : DependencyObject
{
return Ancestors<T>(obj).FirstOrDefault();
return GetAncestors<T>(obj).FirstOrDefault();
}
/// <summary>
/// Try find ItemsPanel of ItemsControl
/// </summary>
/// <param name="itemsControl">Where to search</param>
/// <returns>Panel of ItemsControl</returns>
public static Panel GetItemsPanel(DependencyObject itemsControl)
{
if (itemsControl is Panel) return (Panel)itemsControl;
ItemsPresenter itemsPresenter = GetVisualChild<ItemsPresenter>(itemsControl);
ItemsPresenter itemsPresenter = FindVisualChildren<ItemsPresenter>(itemsControl).FirstOrDefault();
if (itemsPresenter == null) return null;
var itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0) as Panel;
return itemsPanel;
}
public static T GetVisualChild<T>(DependencyObject parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
/// <summary>
/// Check if object is valid (no errors found in logical children)
/// </summary>
/// <param name="obj">Object to search</param>
/// <returns>True if no errors found</returns>
public static bool IsValid(this DependencyObject obj) {
if (obj == null) return true;
if (Validation.GetHasError(obj)) return false;
foreach (var child in LogicalTreeHelper.GetChildren(obj).OfType<DependencyObject>()) {
if (child == null) continue;
if (child is UIElement ui) {
if (!ui.IsVisible || !ui.IsEnabled) continue;
}
if (child != null)
{
break;
if (!IsValid(child)) return false;
}
return true;
}
/// <summary>
/// Search all textboxes to update invalid with UpdateSource(). For ex. when need update validation messages.
/// </summary>
/// <param name="obj">Object where to search TextBoxes</param>
public static void UpdateSources(this DependencyObject obj) {
if (obj == null) return;
if (Validation.GetHasError(obj)) {
//TODO Any types?
if (obj is TextBox tb) tb.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();
}
foreach (var item in FindLogicalChildren<DependencyObject>(obj)) {
UpdateSources(item);
}
}
/// <summary>
/// Find all visual children of type T
/// </summary>
/// <typeparam name="T">Type to search</typeparam>
/// <param name="depObj">Object where to search</param>
/// <returns>Enumerator for items</returns>
public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject depObj) where T : DependencyObject {
if (depObj != null && (depObj is Visual || depObj is Visual3D)) {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) {
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T) {
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child)) {
yield return childOfChild;
}
}
}
}
/// <summary>
/// Find all logical children of type T
/// </summary>
/// <typeparam name="T">Type to search</typeparam>
/// <param name="depObj">Object where to search</param>
/// <returns>Enumerator for items</returns>
public static IEnumerable<T> FindLogicalChildren<T>(this DependencyObject depObj) where T : DependencyObject {
if (depObj != null) {
foreach (object rawChild in LogicalTreeHelper.GetChildren(depObj)) {
if (rawChild is DependencyObject child) {
if (child is T) {
yield return (T)child;
}
foreach (T childOfChild in FindLogicalChildren<T>(child)) {
yield return childOfChild;
}
}
}
}
return child;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,99 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows;
namespace BrightSharp.Mvvm
{
public class ObservableObject : INotifyPropertyChanged
{
static readonly DependencyObject designTimeObject = new DependencyObject();
public static bool IsInDesignTime
{
get
{
try
{
return DesignerProperties.GetIsInDesignMode(designTimeObject);
}
catch(Exception)
{
return true;
}
}
}
protected PropertyChangedEventHandler PropertyChangedHandler
{
get
{
return PropertyChanged;
}
}
public ObservableObject()
{
}
protected static string GetPropertyName<T>(Expression<Func<T>> propertyExpression)
{
if(propertyExpression == null)
{
throw new ArgumentNullException("propertyExpression");
}
MemberExpression body = propertyExpression.Body as MemberExpression;
if(body == null)
{
throw new ArgumentException("Invalid argument", "propertyExpression");
}
PropertyInfo property = body.Member as PropertyInfo;
if(property == null)
{
throw new ArgumentException("Argument is not a property", "propertyExpression");
}
return property.Name;
}
protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(GetPropertyName(propertyExpression)));
}
protected Boolean Set<T>(Expression<Func<T>> propertyExpression, ref T field, T newValue)
{
if(EqualityComparer<T>.Default.Equals(field, newValue))
{
return false;
}
field = newValue;
this.RaisePropertyChanged(propertyExpression);
return true;
}
protected bool Set<T>(string propertyName, ref T field, T newValue)
{
if(EqualityComparer<T>.Default.Equals(field, newValue))
{
return false;
}
field = newValue;
RaisePropertyChanged(propertyName);
return true;
}
protected void RaisePropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected void RaisePropertyChangedAll()
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
public event PropertyChangedEventHandler PropertyChanged;
}
}

View File

@@ -52,8 +52,8 @@ using System.Windows.Markup;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: XmlnsPrefix("http://schemas.brightsharp.com/developer", "bs")]
[assembly: XmlnsDefinition("http://schemas.brightsharp.com/developer", "BrightSharp")]
[assembly: XmlnsDefinition("http://schemas.brightsharp.com/developer", "BrightSharp.Extensions")]

View File

@@ -19,7 +19,7 @@ namespace BrightSharp.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {

View File

@@ -12,7 +12,7 @@ namespace BrightSharp.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@@ -276,7 +276,7 @@
<SolidColorBrush x:Key="ScrollBarBackgroundBrush" Color="#F0F0F0" />
<SolidColorBrush x:Key="SynWindowBackgroundBrush" Color="#FFD1D1D1" />
<Color x:Key="SelectedBackgroundColor">#FFE6D745</Color>
<Color x:Key="SelectedBackgroundColor">#FFFFF8B8</Color>
<SolidColorBrush x:Key="OnWindowForegroundBrush" Color="{DynamicResource OnWindowForegroundColor}" />
<SolidColorBrush x:Key="HighLightForegroundBrush" Color="#FF500000" />
<Color x:Key="UiForegroundColor">Black</Color>

View File

@@ -20,7 +20,7 @@
<Color x:Key="ControlMediumColor" >#FF10405B</Color>
<Color x:Key="ControlDarkColor" >#FF2B404B</Color>
<Color x:Key="ControlMouseOverColor" >#FFA5A7BA</Color>
<Color x:Key="ControlMouseOverColor" >#FF414888</Color>
<Color x:Key="ControlPressedColor" >#FF47909B</Color>
<Color x:Key="ValidationErrorColor" >#FF3333</Color>
@@ -36,10 +36,36 @@
<SolidColorBrush x:Key="LightBorderBrush" Color="DarkGray" />
<SolidColorBrush x:Key="MainMenuForegroundBrush" Color="White"/>
<LinearGradientBrush x:Key="WindowBackgroundBrush">
<GradientStop Color="#444444" />
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#444444" />
<LinearGradientBrush x:Key="GradientWindowBackgroundBrush" EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="#FF35373C" Offset="0"/>
<GradientStop Color="#FF32353C" Offset="0.2"/>
<GradientStop Color="#FF242629" Offset="0.75"/>
<GradientStop Color="#FF222326" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="WindowHeaderBrush" EndPoint="0,1">
<GradientStop Color="#FF556176" />
<GradientStop Color="#FF282B32" Offset="0.2" />
<GradientStop Color="#FF262634" Offset="0.8" />
<GradientStop Color="#FF15212C" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="WindowBorderBrush" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FF2E2E2E" Offset="0"/>
<GradientStop Color="#FF1B1B1B" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="WindowInnerBorderBrush" StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#181818" Offset="1" />
<GradientStop Color="#1D1C21" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="WindowHeaderInactiveBrush" EndPoint="0,1">
<GradientStop Color="#5E5E5E" />
<GradientStop Color="#FF3B3B3B" Offset="0.2" />
<GradientStop Color="#FF3B3B3B" Offset="0.8" />
<GradientStop Color="#5E5E5E" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="GlyphBrush" Color="#ffffff" />
<SolidColorBrush x:Key="LightColorBrush" Color="#FF57575F" />
@@ -124,27 +150,28 @@
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF7599AA" Offset="0.0"/>
<GradientStop Color="#FF37738F" Offset="1.0"/>
<GradientStop Color="#FF368BB4" Offset="0.0"/>
<GradientStop Color="#FF306178" Offset="0.55"/>
<GradientStop Color="#FF37738F" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="TogglePressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF7599AA" Offset="0.0"/>
<GradientStop Color="#FF37738F" Offset="1.0"/>
<GradientStop Color="#FF306178" Offset="0.55"/>
<GradientStop Color="#FF156489" Offset="0.0"/>
<GradientStop Color="#FF2B86B2" Offset="0.2"/>
<GradientStop Color="#FF2187B8" Offset="0.55"/>
<GradientStop Color="#FF358FB9" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="VerticalPressedBrush" StartPoint="0,0" EndPoint="1,0">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF7599AA" Offset="0.0"/>
<GradientStop Color="#FF37738F" Offset="1.0"/>
<GradientStop Color="#FF368BB4" Offset="0.0"/>
<GradientStop Color="#FF306178" Offset="0.55"/>
<GradientStop Color="#FF37738F" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>

View File

@@ -222,13 +222,13 @@
<SolidColorBrush x:Key="AlternatingRowBackgroundBrush" Color="White" />
<Color x:Key="SelectedBackgroundColor">#C5C5C5</Color>
<Color x:Key="SelectedBackgroundColor">#E3E3E3</Color>
<Color x:Key="SelectedUnfocusedColor">#FFB6B6B6</Color>
<Color x:Key="ControlLightColor">#FFFFFFFF</Color>
<Color x:Key="ControlMediumColor">#FFC5C5C5</Color>
<Color x:Key="ControlDarkColor">#FF6B6B6B</Color>
<Color x:Key="ControlMouseOverColor">#FFA5A7BA</Color>
<Color x:Key="ControlMouseOverColor">#FFEEEEEE</Color>
<Color x:Key="ControlPressedColor">#FF47909B</Color>

View File

@@ -260,9 +260,14 @@
</LinearGradientBrush>
<SolidColorBrush x:Key="ScrollBarBackgroundBrush" Color="#F0F0F0" />
<SolidColorBrush x:Key="SynWindowBackgroundBrush" Color="#FFE4E4E4" />
<LinearGradientBrush x:Key="GradientWindowBackgroundBrush" EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#FFF8F8F8" Offset="0.2"/>
<GradientStop Color="#FFE3E3E3" Offset="0.75"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="HighLightForegroundBrush" Color="DarkRed" />
<SolidColorBrush x:Key="HighLightForegroundBrush" Color="#410000" />
<Color x:Key="UiForegroundColor">Black</Color>
<SolidColorBrush x:Key="UiForegroundBrush" Color="{DynamicResource UiForegroundColor}" />
@@ -270,13 +275,13 @@
<Color x:Key="SelectedBackgroundColor">SkyBlue</Color>
<Color x:Key="SelectedBackgroundColor">#DEDEDE</Color>
<Color x:Key="SelectedUnfocusedColor">#FFB6B6B6</Color>
<Color x:Key="ControlLightColor">#FFFFFFFF</Color>
<Color x:Key="ControlMediumColor">#FFC5C5C5</Color>
<Color x:Key="ControlDarkColor">#FF6B6B6B</Color>
<Color x:Key="ControlMouseOverColor">#FFA5A7BA</Color>
<Color x:Key="ControlMouseOverColor">#FFCED0E1</Color>
<Color x:Key="ControlPressedColor">#FF47909B</Color>

View File

@@ -123,9 +123,11 @@ namespace Diagrams
anim.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseInOut };
this.BeginAnimation(ZoomControl.RenderZoomProperty, anim);
}
else
else
{
RenderZoom = newValue;
DoubleAnimation anim = new DoubleAnimation(newValue, TimeSpan.FromSeconds(0));
anim.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseInOut };
this.BeginAnimation(ZoomControl.RenderZoomProperty, anim);
}
RaiseZoomChangedEvent();
@@ -144,7 +146,13 @@ namespace Diagrams
}
else
{
TranslateX = translateXTo; TranslateY = translateYTo;
DoubleAnimation anim = new DoubleAnimation(translateXTo, TimeSpan.FromSeconds(0));
anim.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseInOut };
this.BeginAnimation(ZoomControl.TranslateXProperty, anim);
anim = new DoubleAnimation(translateYTo, TimeSpan.FromSeconds(0));
anim.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseInOut };
this.BeginAnimation(ZoomControl.TranslateYProperty, anim);
}
e.Handled = true;