From e61e0346b656dc58a423e51abb85a1ec3e5aea9f Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sat, 23 May 2020 13:17:13 +0300 Subject: [PATCH 01/17] some refact, add command for items and buttons --- .../Helpers/Commands/Command.cs | 18 +- .../Helpers/Commands/CommandWithUndoRedo.cs | 48 ---- .../Helpers/Commands/ICommandWithUndoRedo.cs | 48 ++++ .../Helpers/Commands/Interface1.cs | 62 ----- .../Commands/ReactiveCommandWithUndoRedo.cs | 43 ---- .../Helpers/Commands/SimpleCommand.cs | 55 ----- .../Commands/SimpleCommandWithParameter.cs | 68 ------ .../Commands/SimpleCommandWithResult.cs | 63 ------ .../Commands/ValidateObjectProperty.cs | 21 -- .../Extensions/ReactiveCommandExtension.cs | 4 - ...ollapseUpGroup.xaml => CollapseUpAll.xaml} | 2 +- ...xpandDownGroup.xaml => ExpandDownAll.xaml} | 2 +- SimpleStateMachineNodeEditor/Icons/Icons.xaml | 4 +- .../View/MainWindow.xaml | 16 +- .../View/MainWindow.xaml.cs | 93 +++++--- .../View/ViewNode.xaml.cs | 16 +- .../View/ViewNodesCanvas.xaml.cs | 31 ++- .../View/ViewRightConnector.xaml.cs | 8 +- .../ViewModel/ViewModelConnect.cs | 4 +- .../ViewModel/ViewModelConnector.cs | 23 +- .../ViewModel/ViewModelCutter.cs | 4 +- .../ViewModel/ViewModelMainWindow.cs | 8 +- .../ViewModel/ViewModelNode.cs | 129 ++++++----- .../ViewModel/ViewModelNodesCanvas.cs | 214 +++++++++++------- .../ViewModel/ViewModelSelector.cs | 4 +- 25 files changed, 395 insertions(+), 593 deletions(-) delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/CommandWithUndoRedo.cs create mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/ICommandWithUndoRedo.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/Interface1.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/ReactiveCommandWithUndoRedo.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommand.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithParameter.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithResult.cs delete mode 100644 SimpleStateMachineNodeEditor/Helpers/Commands/ValidateObjectProperty.cs rename SimpleStateMachineNodeEditor/Icons/{CollapseUpGroup.xaml => CollapseUpAll.xaml} (91%) rename SimpleStateMachineNodeEditor/Icons/{ExpandDownGroup.xaml => ExpandDownAll.xaml} (91%) diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs index efed073..494adb2 100644 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs +++ b/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs @@ -4,7 +4,7 @@ namespace SimpleStateMachineNodeEditor.Helpers.Commands { - public class Command : CommandWithUndoRedo, ICommand, ICloneable + public class Command : ICommandWithUndoRedo, ICommand, ICloneable { private readonly Func _execute; @@ -74,10 +74,10 @@ public void Execute(object parameter) Result = this._execute(Parameters, Result).Cast(); //Добавляем копию команды в стек команд, которые можно отменить - CommandWithUndoRedo.AddInUndo(this.Clone() as CommandWithUndoRedo); + ICommandWithUndoRedo.AddInUndo(this.Clone() as ICommandWithUndoRedo); //Очищаем список отмененнных команд ( началась новая ветка изменений) - CommandWithUndoRedo.StackRedo.Clear(); + ICommandWithUndoRedo.StackRedo.Clear(); //Очищаем результат ( чтобы не передавать его при повторном выполнении) Result = default(TResult); @@ -97,30 +97,30 @@ public void UnExecute() this._unExecute(Parameters, Result); //Добавляем копию команды в стек команд, которые можно выполнить повторно - CommandWithUndoRedo.AddInRedo(this.Clone() as CommandWithUndoRedo); + ICommandWithUndoRedo.AddInRedo(this.Clone() as ICommandWithUndoRedo); } /// /// Повторное выполнения команды /// - public void Execute() + public void ExecuteWithSubscribe() { //Выполянем команду this.Result = this._execute(this.Parameters, this.Result); //Добавляем копию команды в стек команд, которые можно отменить - CommandWithUndoRedo.AddInUndo(this.Clone() as CommandWithUndoRedo); + ICommandWithUndoRedo.AddInUndo(this.Clone() as ICommandWithUndoRedo); } /// /// Создать отменяемую команду /// /// Объкт, которому принадлежит команда - /// Функция, которая будет вызвана при выполнении команды + /// Функция, которая будет вызвана при выполнении команды /// Функция, которая будет вызвана при отмене команды - public Command(Func execute, Func unExecute, Action onExecute = null) + public Command(Func ExecuteWithSubscribe, Func unExecute, Action onExecute = null) { - _execute = execute; + _execute = ExecuteWithSubscribe; _unExecute = unExecute; diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/CommandWithUndoRedo.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/CommandWithUndoRedo.cs deleted file mode 100644 index 571740f..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/CommandWithUndoRedo.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; - - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public interface CommandWithUndoRedo - { - public static Stack StackRedo { get; set; } = new Stack(); - - public static Stack StackUndo { get; set; } = new Stack(); - - public static void Redo() - { - if (StackRedo.Count > 0) - { - CommandWithUndoRedo last = StackRedo.Pop(); - last.Execute(); - } - } - - public static void Undo() - { - if (StackUndo.Count > 0) - { - CommandWithUndoRedo last = StackUndo.Pop(); - last.UnExecute(); - } - } - - public static CommandWithUndoRedo AddInRedo(CommandWithUndoRedo command) - { - StackRedo.Push(command); - - return command; - } - - public static CommandWithUndoRedo AddInUndo(CommandWithUndoRedo command) - { - StackUndo.Push(command); - - return command; - } - - public void Execute(); - public void UnExecute(); - - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/ICommandWithUndoRedo.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/ICommandWithUndoRedo.cs new file mode 100644 index 0000000..5b58098 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Commands/ICommandWithUndoRedo.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; + + +namespace SimpleStateMachineNodeEditor.Helpers.Commands +{ + public interface ICommandWithUndoRedo + { + public static Stack StackRedo { get; set; } = new Stack(); + + public static Stack StackUndo { get; set; } = new Stack(); + + public static void Redo() + { + if (StackRedo.Count > 0) + { + ICommandWithUndoRedo last = StackRedo.Pop(); + last.ExecuteWithSubscribe(); + } + } + + public static void Undo() + { + if (StackUndo.Count > 0) + { + ICommandWithUndoRedo last = StackUndo.Pop(); + last.UnExecute(); + } + } + + public static ICommandWithUndoRedo AddInRedo(ICommandWithUndoRedo command) + { + StackRedo.Push(command); + + return command; + } + + public static ICommandWithUndoRedo AddInUndo(ICommandWithUndoRedo command) + { + StackUndo.Push(command); + + return command; + } + + public void ExecuteWithSubscribe(); + public void UnExecute(); + + } +} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/Interface1.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/Interface1.cs deleted file mode 100644 index 75baa2e..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/Interface1.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public interface Interface1 - { - /// - /// Стек отмененных команд, которые можно выполнить повторно - /// - public static Stack StackRedo { get; set; } = new Stack(); - - /// - /// Стек выполненных команд, которые можно отменить - /// - public static Stack StackUndo { get; set; } = new Stack(); - - /// - /// Функция для команды повторного выполнения - /// - public static void Redo() - { - if (CommandWithUndoRedo.StackRedo.Count > 0) - { - CommandWithUndoRedo last = CommandWithUndoRedo.StackRedo.Pop(); - last.Execute(); - } - } - - /// - /// Функция для команды отмены - /// - public static void Undo() - { - if (CommandWithUndoRedo.StackUndo.Count > 0) - { - CommandWithUndoRedo last = CommandWithUndoRedo.StackUndo.Pop(); - last.UnExecute(); - } - } - - public abstract void Execute(); - public abstract void UnExecute(); - - /// - /// Добавить команду в стек команд, которые можно выполнить повторно - /// - public void AddInRedo(Interface1 command) - { - StackRedo.Push(command); - } - - /// - /// Добавить команду в стек команд, которые можно отменить - /// - public void AddInUndo(Interface1 command) - { - StackUndo.Push(command); - } - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/ReactiveCommandWithUndoRedo.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/ReactiveCommandWithUndoRedo.cs deleted file mode 100644 index bc80cbb..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/ReactiveCommandWithUndoRedo.cs +++ /dev/null @@ -1,43 +0,0 @@ -using ReactiveUI; -using System; -using System.Collections.Generic; -using System.Reactive.Concurrency; -using System.Text; -using System.Windows.Input; - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public class ReactiveCommandWithUndoRedo : ReactiveCommand - { - //private readonly Func _unExecute; - //private readonly Func _unExecute2; - //public void UnExecute() - //{ - // _unExecute = _unExecute2; - // _unExecute2 = _unExecute; - // //Выполняем отмену команду - // this._unExecute(Parameters, Result); - - // //Добавляем копию команды в стек команд, которые можно выполнить повторно - // CommandWithUndoRedo.AddInRedo(this.Clone() as CommandWithUndoRedo); - //} - - ///// - ///// Повторное выполнения команды - ///// - //public void Execute() - //{ - // //Выполянем команду - // this.Result = this._execute(this.Parameters, this.Result); - - // //Добавляем копию команды в стек команд, которые можно отменить - // CommandWithUndoRedo.AddInUndo(this.Clone() as CommandWithUndoRedo); - //} - - protected internal ReactiveCommandWithUndoRedo(Func> execute, IObservable canExecute, IScheduler outputScheduler):base(execute, canExecute, outputScheduler) - { - - } - - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommand.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommand.cs deleted file mode 100644 index b0913b0..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommand.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Windows.Input; - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public class SimpleCommand : ICommand - { - /// - /// Функция с параметром, которая будет вызвана при выполнении команды - /// - private Action _execute; - - public Action OnExecute { get; set; } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - public event EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - /// - /// Всегда возвращает true - public bool CanExecute(object parameter) - { - return true; - } - - /// - /// Выполнение команды - /// - /// Параметр команды - public void Execute(object parameter = null) - { - this._execute(); - OnExecute?.Invoke(); - } - - /// - /// Создать команду - /// - /// Объкт, которому принадлежит команда - /// Функция, которая будет вызвана при выполнении команды - public SimpleCommand(Action execute, Action onExecute = null) - { - _execute = execute; - OnExecute += onExecute; - } - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithParameter.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithParameter.cs deleted file mode 100644 index e091707..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithParameter.cs +++ /dev/null @@ -1,68 +0,0 @@ -using SimpleStateMachineNodeEditor.Helpers.Extensions; -using System; -using System.DirectoryServices; -using System.Windows.Input; - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - /// - /// Команда без Undo/Redo - /// - /// - public class SimpleCommandWithParameter : ICommand - { - /// - /// Функция с параметром, которая будет вызвана при выполнении команды - /// - private Action _execute; - - public Action OnExecute { get; set; } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - public event EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - /// - /// Всегда возвращает true - public bool CanExecute(object parameter) - { - return true; - } - - /// - /// Выполнение команды - /// - /// Параметр команды - public void Execute(object parameter) - { - - this._execute(parameter.Cast()); - - OnExecute?.Invoke(); - } - - /// - /// Создать команду - /// - /// Объкт, которому принадлежит команда - /// Функция, которая будет вызвана при выполнении команды - public SimpleCommandWithParameter(Action execute, Action onExecute = null) - { - _execute = execute; - OnExecute += onExecute; - } - - public static SimpleCommandWithParameter Create(Action execute, Action onExecute = null) - { - return new SimpleCommandWithParameter(execute, onExecute); - } - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithResult.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithResult.cs deleted file mode 100644 index c00561d..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/SimpleCommandWithResult.cs +++ /dev/null @@ -1,63 +0,0 @@ -using System; -using System.Windows.Input; - - -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public class SimpleCommandWithResul : ICommand - { - /// - /// Функция с параметром, которая будет вызвана при выполнении команды - /// - private Func _execute; - - public Action OnExecute { get; set; } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - public event EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value; } - } - - /// - /// Результат выполнения команды - /// - /// Например здесь может храниться список объектов, которые были изменены - public TResult Result { get; set; } - - /// - /// Требуется интерфейсом ICloneable, не используется - /// - /// - /// Всегда возвращает true - public bool CanExecute(object parameter) - { - return true; - } - - /// - /// Выполнение команды - /// - /// Параметр команды - public void Execute(object parameter = null) - { - //Result = this._execute(Parameters, Result) as TResult; - this._execute(); - OnExecute?.Invoke(); - } - - /// - /// Создать команду - /// - /// Объкт, которому принадлежит команда - /// Функция, которая будет вызвана при выполнении команды - public SimpleCommandWithResul(Func execute, Action onExecute = null) - { - _execute = execute; - OnExecute += onExecute; - } - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/ValidateObjectProperty.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/ValidateObjectProperty.cs deleted file mode 100644 index 4d87f34..0000000 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/ValidateObjectProperty.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SimpleStateMachineNodeEditor.Helpers.Commands -{ - public class ValidateObjectProperty where TObject : class where TProperty : class - { - public ValidateObjectProperty(TObject obj, TProperty property) - { - Obj = obj; - Property = property; - } - /// - /// Объект, для которого будем валидировать значенин - /// - public TObject Obj { get; set; } - - /// - /// Новое значение, которое будем валидировать - /// - public TProperty Property { get; set; } - - } -} diff --git a/SimpleStateMachineNodeEditor/Helpers/Extensions/ReactiveCommandExtension.cs b/SimpleStateMachineNodeEditor/Helpers/Extensions/ReactiveCommandExtension.cs index caf346f..fc1ac52 100644 --- a/SimpleStateMachineNodeEditor/Helpers/Extensions/ReactiveCommandExtension.cs +++ b/SimpleStateMachineNodeEditor/Helpers/Extensions/ReactiveCommandExtension.cs @@ -12,9 +12,5 @@ public static IDisposable ExecuteWithSubscribe(this ReactiveCom { return reactiveCommand.Execute(parameter).Subscribe(); } - public static ReactiveCommandWithUndoRedo CreateCommandWithUndoRedo(TParam parameter = default) - { - return null; - } } } diff --git a/SimpleStateMachineNodeEditor/Icons/CollapseUpGroup.xaml b/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml similarity index 91% rename from SimpleStateMachineNodeEditor/Icons/CollapseUpGroup.xaml rename to SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml index 08321a1..535f979 100644 --- a/SimpleStateMachineNodeEditor/Icons/CollapseUpGroup.xaml +++ b/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml @@ -1,6 +1,6 @@  - + diff --git a/SimpleStateMachineNodeEditor/Icons/ExpandDownGroup.xaml b/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml similarity index 91% rename from SimpleStateMachineNodeEditor/Icons/ExpandDownGroup.xaml rename to SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml index 2df7298..f16cf41 100644 --- a/SimpleStateMachineNodeEditor/Icons/ExpandDownGroup.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml @@ -1,6 +1,6 @@  - + diff --git a/SimpleStateMachineNodeEditor/Icons/Icons.xaml b/SimpleStateMachineNodeEditor/Icons/Icons.xaml index 3320b4b..081fc85 100644 --- a/SimpleStateMachineNodeEditor/Icons/Icons.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Icons.xaml @@ -7,7 +7,7 @@ - + @@ -21,7 +21,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml b/SimpleStateMachineNodeEditor/View/MainWindow.xaml index b2fdee6..092fbc9 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml @@ -3,11 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:SimpleStateMachineNodeEditor" - xmlns:styles="clr-namespace:SimpleStateMachineNodeEditor.Styles" - xmlns:sys="clr-namespace:System;assembly=mscorlib" - - xmlns:view="clr-namespace:SimpleStateMachineNodeEditor.View" xmlns:sys1="clr-namespace:System;assembly=System.Runtime" + xmlns:view="clr-namespace:SimpleStateMachineNodeEditor.View" x:Class="SimpleStateMachineNodeEditor.View.MainWindow" mc:Ignorable="d" Title="SimpleStateMachineNodeEditor" d:DesignWidth="808.96" Height="738.592" BorderThickness="1" Padding="7,0,7,7" ResizeMode="CanResizeWithGrip" BorderBrush="{StaticResource ColorWindowBorder}" Background="{StaticResource ColorWindowHeader}" Foreground="{x:Null}" WindowStyle="None" AllowsTransparency="True" Style="{StaticResource CustomWindowStyle}"> @@ -141,11 +137,11 @@ - - @@ -226,7 +222,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index cbd7010..0504aca 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -22,6 +22,10 @@ using System.Linq; using SimpleStateMachineNodeEditor.Helpers.Commands; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using System.Reactive.Concurrency; +using System.Threading.Tasks; +using System.Threading; +using System.Reactive; namespace SimpleStateMachineNodeEditor.View { @@ -49,26 +53,50 @@ object IViewFor.ViewModel public MainWindow() { InitializeComponent(); - ViewModel = new ViewModelMainWindow(); + ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel); + SetupCommands(); SetupSubscriptions(); SetupBinding(); SetupEvents(); - //SetupCommands(); + } #region Setup Binding - + private void SetupBinding() { + this.WhenActivated(disposable => { - this.ViewModel.NodesCanvas = this.NodesCanvas.ViewModel; var SelectedItem = this.ObservableForProperty(x => x.MessageList.SelectedItem).Select(x=>(x.Value as ViewModelMessage)?.Text); - this.BindCommand(this.ViewModel,x=>x.CommandCopyError, x=>x.BindingCopyError, SelectedItem).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandCopyError, x => x.BindingCopyError, SelectedItem).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandCopyError, x => x.ItemCopyError, SelectedItem).DisposeWith(disposable); + this.OneWayBind(this.ViewModel, x => x.Messages, x => x.MessageList.ItemsSource).DisposeWith(disposable); - this.OneWayBind(this.ViewModel, x=>x.DebugEnable, x=>x.LabelDebug.Visibility).DisposeWith(disposable); + this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable); + + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo, x => x.ButtonUndo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomIn, x => x.ButtonZoomIn).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOut, x => x.ButtonZoomOut).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOriginalSize, x => x.ButtonZoomOriginalSize).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandCollapseUpAll, x => x.ButtonCollapseUpAll).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExpandDownAll, x => x.ButtonExpandDownAll).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo , x => x.ItemUndo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable); + + + //ItemSave.Command = CommandSave; + //this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable); + + //this.OneWayBind(this, x => x.CommandSave, x => x.BindingSave.Command).DisposeWith(disposable); + + //this.OneWayBind(this.ViewModel, x=>x.CommandCopyError, x=>x.BindingSave.Command) + //this.ItemSave.Inp @@ -79,6 +107,7 @@ private void SetupBinding() }); } #endregion Setup Binding + #region Setup Subscriptions private void SetupSubscriptions() @@ -100,19 +129,20 @@ private void UpdateSchemeName(string newName) } } #endregion Setup Subscriptions + #region Setup Commands - //public ReactiveCommand CommandSave { get; set; } - //private void SetupCommands() - //{ - // this.WhenActivated(disposable => - // { - // CommandSave = ReactiveCommand.Create(Save); - - // //this.Events().KeyUp.Where(x => x.Key == Key.S && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))).Subscribe(_ => Save()).DisposeWith(disposable); - // //this.Events().KeyUp.Where(x => x.Key == Key.F4 && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))).Subscribe(_ => Close()).DisposeWith(disposable); - // }); - //} + public ReactiveCommand CommandSave { get; set; } + private void SetupCommands() + { + this.WhenActivated(disposable => + { + CommandSave = ReactiveCommand.Create(Save); + + //this.Events().KeyUp.Where(x => x.Key == Key.S && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))).Subscribe(_ => Save()).DisposeWith(disposable); + //this.Events().KeyUp.Where(x => x.Key == Key.F4 && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))).Subscribe(_ => Close()).DisposeWith(disposable); + }); + } #endregion Setup Commands #region SetupEvents @@ -131,14 +161,13 @@ private void SetupEvents() this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable); this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable); + - this.ItemSave.Events().Click.Subscribe(_=> Save()).DisposeWith(disposable); + //this.ItemSave.Events().Click.Subscribe(_=> Save()).DisposeWith(disposable); this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable); - this.ItemOpen.Events().Click.Subscribe(_ => WithoutSaving(Open)).DisposeWith(disposable); + this.ItemOpen.Events().Click.Subscribe(async _ => await WithoutSavingAsync(OpenAsync)).DisposeWith(disposable); this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable); - this.ItemUndo.Events().Click.Subscribe(_=>this.NodesCanvas.ViewModel.CommandUndo.Execute()).DisposeWith(disposable); - this.ItemRedo.Events().Click.Subscribe(_ => this.NodesCanvas.ViewModel.CommandRedo.Execute()).DisposeWith(disposable); this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable); this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); @@ -257,7 +286,17 @@ void WithoutSaving(Action action) if (result == MessageBoxResult.Yes) action.Invoke(); } + async Task WithoutSavingAsync(Func action) + { + var result = MessageBoxResult.Yes; + if (!this.NodesCanvas.ViewModel.ItSaved) + { + result = System.Windows.MessageBox.Show("Exit without saving ?", "Test", MessageBoxButton.YesNo); + } + if (result == MessageBoxResult.Yes) + await action.Invoke(); + } void Save() { if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.Path)) @@ -266,7 +305,7 @@ void Save() } else { - this.NodesCanvas.ViewModel.CommandSave.Execute(this.ViewModel.NodesCanvas.Path); + this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.Path); } } void SaveAs() @@ -278,7 +317,7 @@ void SaveAs() DialogResult dialogResult = dlg.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { - this.NodesCanvas.ViewModel.CommandSave.Execute(dlg.FileName); + this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(dlg.FileName); } } private string SchemeName() @@ -292,7 +331,7 @@ private string SchemeName() return "SimpleStateMachine"; } } - void Open() + async Task OpenAsync() { OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName = SchemeName(); @@ -301,10 +340,10 @@ void Open() DialogResult dialogResult = dlg.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { - this.NodesCanvas.ViewModel.CommandOpen.Execute(dlg.FileName); - + //this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName); + await this.NodesCanvas.ViewModel.CommandOpen.Execute(dlg.FileName); } - + } #endregion SetupEvents diff --git a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs index 8cd3a54..8eb4bce 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs @@ -19,6 +19,7 @@ using SimpleStateMachineNodeEditor.Helpers; using SimpleStateMachineNodeEditor.Helpers.Transformations; using SimpleStateMachineNodeEditor.Helpers.Enums; +using SimpleStateMachineNodeEditor.Helpers.Extensions; namespace SimpleStateMachineNodeEditor.View { @@ -110,8 +111,9 @@ private void SetupEvents() //this.Events().MouseEnter.Subscribe(e => OnEventMouseEnter(e)).DisposeWith(disposable); //this.Events().MouseLeave.Subscribe(e => OnEventMouseMouseLeave(e)).DisposeWith(disposable); - this.NodeHeaderElement.ButtonCollapse.Events().Click.Subscribe(_ => OnEventCollapse()).DisposeWith(disposable); + this.NodeHeaderElement.ButtonCollapse.Events().Click.Subscribe(_ => ViewModel.IsCollapse=!ViewModel.IsCollapse).DisposeWith(disposable); this.NodeHeaderElement.Events().LostFocus.Subscribe(e => Validate(e)).DisposeWith(disposable); + this.ViewModel.WhenAnyValue(x=>x.IsCollapse).Subscribe(value=> OnEventCollapse(value)).DisposeWith(disposable); }); } private void Test(bool value) @@ -123,11 +125,11 @@ private void Test(bool value) private void OnEventMouseLeftDowns(MouseButtonEventArgs e) { Keyboard.Focus(this); - this.ViewModel.CommandSelect.Execute(SelectMode.Click); + this.ViewModel.CommandSelect.ExecuteWithSubscribe(SelectMode.Click); } private void Validate(RoutedEventArgs e) { - ViewModel.CommandValidateName.Execute(NodeHeaderElement.TextBox.Text); + ViewModel.CommandValidateName.ExecuteWithSubscribe(NodeHeaderElement.TextBox.Text); if (NodeHeaderElement.TextBox.Text != ViewModel.Name) NodeHeaderElement.TextBox.Text = ViewModel.Name; } @@ -170,12 +172,10 @@ private void OnEventMouseMouseLeave(MouseEventArgs e) } - private void OnEventCollapse() + private void OnEventCollapse(bool isCollapse) { - bool visible = (this.NodeHeaderElement.ButtonRotate.Angle != 0); - this.NodeHeaderElement.ButtonRotate.Angle = visible ? 0 : 180; - ViewModel.CommandCollapse.Execute(visible); - + //bool visible = (this.NodeHeaderElement.ButtonRotate.Angle != 0); + this.NodeHeaderElement.ButtonRotate.Angle = isCollapse ? 180 : 0; } #endregion Setup Events diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs index f2e91ab..b914907 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs @@ -63,9 +63,10 @@ public ViewNodesCanvas() { InitializeComponent(); ViewModel = new ViewModelNodesCanvas(); + SetupCommands(); SetupBinding(); SetupEvents(); - SetupCommands(); + } #region Setup Binding private void SetupBinding() @@ -99,20 +100,28 @@ private void SetupCommands() var positionLeftClickObservable = this.ObservableForProperty(x => x.PositionLeftClick).Select(x => x.Value); var positionRightClickObservable = this.ObservableForProperty(x => x.PositionRightClick).Select(x => x.Value); - this.BindCommand(this.ViewModel, x => x.CommandRedo, x => x.BindingRedo).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandUndo, x => x.BindingUndo).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.BindingSelectAll).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelect, positionLeftClickObservable).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandCut, x => x.BindingCut, positionLeftClickObservable).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.BindingAddNode, positionLeftClickObservable).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.ItemAddNode, positionRightClickObservable).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.CommandRedo, x => x.BindingRedo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandUndo, x => x.BindingUndo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.BindingSelectAll).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandUndo, x => x.ItemCollapsUp).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.ItemExpandDown).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedElements, x => x.BindingDeleteSelectedElements).DisposeWith(disposable); //this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedNodes, x => x.BindingDeleteSelected).DisposeWith(disposable); //this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedConnectors, x => x.BindingDeleteSelected).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelect, positionLeftClickObservable).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandCut, x => x.BindingCut, positionLeftClickObservable).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.BindingAddNode, positionLeftClickObservable).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandAddNodeWithUndoRedo, x => x.ItemAddNode, positionRightClickObservable).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.CommandCollapseUpSelected, x => x.ItemCollapsUp).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.CommandExpandDownSelected, x => x.ItemExpandDown).DisposeWith(disposable); + + this.WhenAnyValue(x => x.ViewModel.Selector.Size).WithoutParameter().InvokeCommand(ViewModel,x=>x.CommandSelectorIntersect).DisposeWith(disposable); this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint.Value).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandCutterIntersect).DisposeWith(disposable); @@ -190,7 +199,7 @@ private void OnEventMouseWheel(MouseWheelEventArgs e) //var position = e.GetPosition(this.Canvas); //this.Scale.CenterX = position.X / this.ViewModel.Scale.Value; //this.Scale.CenterY = position.Y / this.ViewModel.Scale.Value; - this.ViewModel.CommandZoom.Execute(e.Delta); + this.ViewModel.CommandZoom.ExecuteWithSubscribe(e.Delta); } private void OnEventMouseUp(MouseButtonEventArgs e) @@ -215,13 +224,13 @@ private void OnEventMouseMove(MouseEventArgs e) SumMove += delta; if (this.IsMouseCaptured) { - //ViewModel.CommandPartMoveAllNode.Execute(delta).Subscribe(); + //ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta).Subscribe(); ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta); Move = MoveNodes.MoveAll; } else { - //ViewModel.CommandPartMoveAllSelectedNode.Execute(delta); + //ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); Move = MoveNodes.MoveSelected; } diff --git a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs index f2dbbab..4b459be 100644 --- a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs @@ -110,7 +110,7 @@ private void SetupEvents() private void Validate(RoutedEventArgs e) { - ViewModel.CommandValidateName.Execute(TextBoxElement.Text); + ViewModel.CommandValidateName.ExecuteWithSubscribe(TextBoxElement.Text); if (TextBoxElement.Text != ViewModel.Name) TextBoxElement.Text = ViewModel.Name; } @@ -150,15 +150,15 @@ private void ConnectorDrag(MouseButtonEventArgs e) } else if (Keyboard.IsKeyDown(Key.LeftShift)) { - this.ViewModel.CommandSelect.Execute(SelectMode.ClickWithShift); + this.ViewModel.CommandSelect.ExecuteWithSubscribe(SelectMode.ClickWithShift); } else if (Keyboard.IsKeyDown(Key.LeftCtrl)) { - this.ViewModel.CommandSelect.Execute(SelectMode.ClickWithCtrl); + this.ViewModel.CommandSelect.ExecuteWithSubscribe(SelectMode.ClickWithCtrl); } else { - this.ViewModel.CommandSelect.Execute(SelectMode.Click); + this.ViewModel.CommandSelect.ExecuteWithSubscribe(SelectMode.Click); return; } e.Handled = true; diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs index 773d0aa..bae3ded 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs @@ -128,11 +128,11 @@ private void NotSaved() } //private void Add() //{ - // NodesCanvas.CommandAddConnect.Execute(this); + // NodesCanvas.CommandAddConnect.ExecuteWithSubscribe(this); //} //private void Delete() //{ - // NodesCanvas.CommandDeleteConnect.Execute(this); + // NodesCanvas.CommandDeleteConnect.ExecuteWithSubscribe(this); //} //private void AddWithConnect() //{ diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs index d8c6814..4355a4e 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs @@ -100,8 +100,8 @@ private void SetupBinding() //public ReactiveCommand CommandDelete { get; set; } //public ReactiveCommand CommandAddWithConnect { get; set; } //public ReactiveCommand CommandDeleteWithConnect { get; set; } - public SimpleCommandWithParameter CommandSelect { get; set; } - public SimpleCommandWithParameter CommandValidateName { get; set; } + public ReactiveCommand CommandSelect { get; set; } + public ReactiveCommand CommandValidateName { get; set; } private void SetupCommands() { @@ -120,9 +120,9 @@ private void SetupCommands() //CommandAddWithConnect = ReactiveCommand.Create(AddWithConnect); //CommandDeleteWithConnect = ReactiveCommand.Create(DeleteWithConnect); - CommandValidateName = new SimpleCommandWithParameter(ValidateName, NotSaved); + CommandValidateName = ReactiveCommand.Create(ValidateName); - CommandSelect = new SimpleCommandWithParameter(Select); + CommandSelect = ReactiveCommand.Create(Select); //SimpleCommandWithResult> t = new SimpleCommandWithResult>() @@ -132,6 +132,7 @@ private void SetupCommands() private void NotSavedSubscribe() { CommandSetAsLoop.Subscribe(_=>NotSaved()); + CommandValidateName.Subscribe(_ => NotSaved()); } private void Select(bool value) @@ -149,7 +150,7 @@ private void Select(SelectMode selectMode) if(!this.Selected) { //this.Node.CommandUnSelectedAllConnectorsExecuteWithSubscribe(); - this.Node.CommandSetConnectorAsStartSelect.Execute(this); + this.Node.CommandSetConnectorAsStartSelect.ExecuteWithSubscribe(this); //this.Selected = true; } @@ -162,7 +163,7 @@ private void Select(SelectMode selectMode) } case SelectMode.ClickWithShift: { - this.Node.CommandSelectWithShiftForConnectors.Execute(this); + this.Node.CommandSelectWithShiftForConnectors.ExecuteWithSubscribe(this); break; } } @@ -185,11 +186,11 @@ private void SetAsLoop() } //private void Add() //{ - // Node.CommandAddConnector.Execute((0, this)); + // Node.CommandAddConnector.ExecuteWithSubscribe((0, this)); //} //private void Delete() //{ - // Node.CommandDeleteConnector.Execute(this); + // Node.CommandDeleteConnector.ExecuteWithSubscribe(this); //} //private void AddWithConnect() //{ @@ -203,7 +204,7 @@ private void SetAsLoop() //} private void ConnectPointDrag() { - NodesCanvas.CommandAddDraggedConnect.Execute(Node.CurrentConnector); + NodesCanvas.CommandAddDraggedConnect.ExecuteWithSubscribe(Node.CurrentConnector); } private void DragConnector(ViewModelConnector draggedConnector) { @@ -231,7 +232,7 @@ private void CheckConnectPointDrop() NodesCanvas.CommandAddConnectorWithConnect.Execute(Node.CurrentConnector); Node.CommandAddEmptyConnector.ExecuteWithSubscribe(); - //NodesCanvas.CommandAddConnectWithUndoRedo.Execute(Node.NodesCanvas.DraggedConnect); + //NodesCanvas.CommandAddConnectWithUndoRedo.ExecuteWithSubscribe(Node.NodesCanvas.DraggedConnect); NodesCanvas.DraggedConnect = null; } } @@ -284,7 +285,7 @@ private void ConnectorDrop() } private void ValidateName(string newName) { - NodesCanvas.CommandValidateConnectName.Execute(new ValidateObjectProperty(this, newName)); + NodesCanvas.CommandValidateConnectName.ExecuteWithSubscribe((this, newName)); } public XElement ToXElement() diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs index ad3443d..f832e53 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs @@ -41,12 +41,12 @@ public ViewModelCutter(ViewModelNodesCanvas nodesCanvas) NodesCanvas = nodesCanvas; } #region Setup Commands - public SimpleCommandWithParameter CommandStartCut { get; set; } + public ReactiveCommand CommandStartCut { get; set; } public ReactiveCommand CommandEndCut { get; set; } private void SetupCommands() { - CommandStartCut = new SimpleCommandWithParameter(StartCut); + CommandStartCut = ReactiveCommand.Create(StartCut); CommandEndCut = ReactiveCommand.Create(EndCut); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs index f89d8b9..1e631b2 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs @@ -11,6 +11,7 @@ using SimpleStateMachineNodeEditor.Helpers.Enums; using System.Reactive.Linq; using System.Collections.ObjectModel; +using System.Reactive; namespace SimpleStateMachineNodeEditor.ViewModel { @@ -27,8 +28,9 @@ public class ViewModelMainWindow: ReactiveObject - public ViewModelMainWindow() + public ViewModelMainWindow(ViewModelNodesCanvas viewModelNodesCanvas) { + NodesCanvas = viewModelNodesCanvas; SetupCommands(); SetupSubscriptions(); } @@ -67,11 +69,11 @@ bool CheckForDisplay(TypeMessage typeMessage) #endregion Setup Subscriptions #region Setup Commands - public SimpleCommandWithParameter CommandCopyError { get; set; } + public ReactiveCommand CommandCopyError { get; set; } private void SetupCommands() { - CommandCopyError = new SimpleCommandWithParameter(CopyError); + CommandCopyError = ReactiveCommand.Create(CopyError); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index 775177e..f88fc7d 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -17,6 +17,7 @@ using DynamicData; using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using System.Threading.Tasks; namespace SimpleStateMachineNodeEditor.ViewModel { @@ -32,6 +33,7 @@ public class ViewModelNode : ReactiveValidationObject [Reactive] public bool? TransitionsVisible { get; set; } = true; [Reactive] public bool? RollUpVisible { get; set; } = true; [Reactive] public bool CanBeDelete { get; set; } = true; + [Reactive] public bool IsCollapse { get; set; } [Reactive] public ViewModelConnector Input { get; set; } [Reactive] public ViewModelConnector Output { get; set; } [Reactive] public ViewModelConnector CurrentConnector { get; set; } @@ -49,9 +51,10 @@ public ViewModelNode(ViewModelNodesCanvas nodesCanvas) NodesCanvas = nodesCanvas; Zindex = nodesCanvas.Nodes.Count; - SetupBinding(); SetupConnectors(); SetupCommands(); + SetupBinding(); + } #region SetupBinding @@ -59,6 +62,7 @@ private void SetupBinding() { this.WhenAnyValue(x => x.Selected).Subscribe(value => { this.BorderBrush = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Brushes.LightGray; }); this.WhenAnyValue(x => x.Point1.Value, x => x.Size).Subscribe(_ => UpdatePoint2()); + this.WhenAnyValue(x => x.IsCollapse).Subscribe(value => Collapse(value)); } #endregion SetupBinding @@ -79,58 +83,43 @@ private void SetupConnectors() #endregion Connectors #region Setup Commands - public SimpleCommandWithParameter CommandSelect { get; set; } - public SimpleCommandWithParameter CommandMove { get; set; } - public SimpleCommandWithParameter CommandCollapse { get; set; } - //public SimpleCommandWithParameter<(int index, ViewModelConnector connector)> CommandAddConnector { get; set; } - //public SimpleCommandWithParameter CommandDeleteConnector { get; set; } - public SimpleCommandWithParameter<(int index, ViewModelConnector connector)> CommandAddConnectorWithConnect { get; set; } - public SimpleCommandWithParameter CommandDeleteConnectorWithConnect { get; set; } - public SimpleCommandWithParameter CommandValidateName { get; set; } - public SimpleCommandWithParameter CommandSelectWithShiftForConnectors { get; set; } - public SimpleCommandWithParameter CommandSetConnectorAsStartSelect { get; set; } - public ReactiveCommand CommandUnSelectedAllConnectors { get; set; } - public ReactiveCommand CommandAddEmptyConnector { get; set; } + public ReactiveCommand CommandUnSelectedAllConnectors { get; set; } + public ReactiveCommand CommandAddEmptyConnector { get; set; } + public ReactiveCommand CommandSelect { get; set; } + public ReactiveCommand CommandMove { get; set; } + //public ReactiveCommand CommandCollapse { get; set; } + public ReactiveCommand<(int index, ViewModelConnector connector), Unit> CommandAddConnectorWithConnect { get; set; } + public ReactiveCommand CommandDeleteConnectorWithConnect { get; set; } + public ReactiveCommand CommandValidateName { get; set; } - - //public ReactiveCommand CommandTransitionsDragLeave { get; set; } - - //public ReactiveCommand CommandTransitionsDragEnter { get; set; } - - //public ReactiveCommand CommandTransitionsDrop { get; set; } - - //public ReactiveCommand CommandTransitionsDragOver { get; set; } - - //public SimpleCommandWithParameter CommandConnectorDrag { get; set; } + public ReactiveCommand CommandSelectWithShiftForConnectors { get; set; } + public ReactiveCommand CommandSetConnectorAsStartSelect { get; set; } private void SetupCommands() { - CommandSelect = new SimpleCommandWithParameter(Select); - CommandMove = new SimpleCommandWithParameter(Move, NotSaved); + CommandSelect = ReactiveCommand.Create(Select); + CommandMove = ReactiveCommand.Create(Move); CommandAddEmptyConnector = ReactiveCommand.Create(AddEmptyConnector); - CommandCollapse = new SimpleCommandWithParameter(Collapse, NotSaved); - CommandSelectWithShiftForConnectors = new SimpleCommandWithParameter(SelectWithShiftForConnectors); - CommandSetConnectorAsStartSelect = new SimpleCommandWithParameter(SetConnectorAsStartSelect); + //CommandCollapse = ReactiveCommand.Create(Collapse); + CommandSelectWithShiftForConnectors = ReactiveCommand.Create(SelectWithShiftForConnectors); + CommandSetConnectorAsStartSelect = ReactiveCommand.Create(SetConnectorAsStartSelect); CommandUnSelectedAllConnectors = ReactiveCommand.Create(UnSelectedAllConnectors); - //CommandTransitionsDragLeave = ReactiveCommand.Create(TransitionsDragLeave); - //CommandTransitionsDragEnter = ReactiveCommand.Create(TransitionsDragEnter); - //CommandTransitionsDrop = ReactiveCommand.Create(TransitionsDrop); - //CommandTransitionsDragOver = ReactiveCommand.Create(TransitionsDragOver); - //CommandConnectorDrag = new SimpleCommandWithParameter(this, ConnectorDrag); - - //CommandAddConnector = new SimpleCommandWithParameter<(int index, ViewModelConnector connector)>(AddConnector, NotSaved); - //CommandDeleteConnector = new SimpleCommandWithParameter(DeleteConnector, NotSaved); - - CommandAddConnectorWithConnect = new SimpleCommandWithParameter<(int index, ViewModelConnector connector)>(AddConnectorWithConnect, NotSaved); - CommandDeleteConnectorWithConnect = new SimpleCommandWithParameter(DeleteConnectorWithConnec, NotSaved); - + CommandAddConnectorWithConnect = ReactiveCommand.Create<(int index, ViewModelConnector connector)>(AddConnectorWithConnect); + CommandDeleteConnectorWithConnect = ReactiveCommand.Create(DeleteConnectorWithConnec); + CommandValidateName = ReactiveCommand.Create(ValidateName); + } + private void NotSavedSubscrube() + { + CommandMove.Subscribe(_ => NotSaved()); + //CommandCollapse.Subscribe(_ => NotSaved()); + CommandAddConnectorWithConnect.Subscribe(_ => NotSaved()); + CommandDeleteConnectorWithConnect.Subscribe(_ => NotSaved()); + CommandValidateName.Subscribe(_ => NotSaved()); - CommandValidateName = new SimpleCommandWithParameter(ValidateName, NotSaved); } - private void NotSaved() { NodesCanvas.ItSaved = false; @@ -139,9 +128,9 @@ private void NotSaved() private void Collapse(bool value) { - if (value) + if (!value) { - TransitionsVisible = value; + TransitionsVisible = true; Output.Visible = null; } else @@ -150,21 +139,13 @@ private void Collapse(bool value) Output.Visible = true; UnSelectedAllConnectors(); } + NotSaved(); } public int GetConnectorIndex(ViewModelConnector connector) { return Transitions.IndexOf(connector); } - //private void AddConnector((int index, ViewModelConnector connector) element) - //{ - // Transitions.Insert(element.index, element.connector); - //} - //private void DeleteConnector(ViewModelConnector connector) - //{ - // Transitions.Remove(connector); - // //connector.Connect?.Comma - //} private void AddConnectorWithConnect((int index, ViewModelConnector connector) element) { Transitions.Insert(element.index, element.connector); @@ -177,7 +158,7 @@ private void DeleteConnectorWithConnec(ViewModelConnector connector) { if (connector.Connect != null) { - NodesCanvas.CommandDeleteConnect.Execute(connector.Connect); + NodesCanvas.CommandDeleteConnect.ExecuteWithSubscribe(connector.Connect); } Transitions.Remove(connector); } @@ -200,7 +181,7 @@ private void Move(MyPoint delta) } private void ValidateName(string newName) { - NodesCanvas.CommandValidateNodeName.Execute((this, newName)); + NodesCanvas.CommandValidateNodeName.ExecuteWithSubscribe((this, newName)); } private void UpdatePoint2() { @@ -256,7 +237,7 @@ public XElement ToXElement() XElement element = new XElement("State"); element.Add(new XAttribute("Name", Name)); element.Add(new XAttribute("Position", Point1.ToString())); - element.Add(new XAttribute("IsCollapse", (TransitionsVisible!=true).ToString())); + element.Add(new XAttribute("IsCollapse", IsCollapse.ToString())); return element; } @@ -287,9 +268,41 @@ public static ViewModelNode FromXElement(ViewModelNodesCanvas nodesCanvas, XElem var isCollapse = node.Attribute("IsCollapse")?.Value; if (isCollapse != null) - viewModelNode.Collapse(!bool.Parse(isCollapse)); - + viewModelNode.IsCollapse = bool.Parse(isCollapse); + return viewModelNode; } + + //public static async Task<(ViewModelNode node, string message)> FromXElement(ViewModelNodesCanvas nodesCanvas, XElement node, Func actionForCheck) + //{ + // string errorMessage = null; + // ViewModelNode viewModelNode = null; + // string name = node.Attribute("Name")?.Value; + + // if (string.IsNullOrEmpty(name)) + // { + // errorMessage = "Node without name"; + // return (viewModelNode, errorMessage); + // } + + // if (actionForCheck(name)) + // { + // errorMessage = String.Format("Contains more than one node with name \"{0}\"", name); + // return (viewModelNode, errorMessage); + // } + + // viewModelNode = new ViewModelNode(nodesCanvas); + // viewModelNode.Name = name; + + // var position = node.Attribute("Position")?.Value; + // if (position != null) + // viewModelNode.Point1 = MyPoint.Parse(position); + + // var isCollapse = node.Attribute("IsCollapse")?.Value; + // if (isCollapse != null) + // viewModelNode.Collapse(!bool.Parse(isCollapse)); + + // return (viewModelNode, errorMessage); + //} } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs index b084fc0..64666e7 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs @@ -21,6 +21,8 @@ using System.Windows.Input; using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using System.Threading.Tasks; +using System.Threading; namespace SimpleStateMachineNodeEditor.ViewModel { @@ -100,36 +102,49 @@ private void SetAsStart(ViewModelNode node) public ReactiveCommand CommandNewScheme { get; set; } public ReactiveCommand CommandRedo { get; set; } public ReactiveCommand CommandUndo { get; set; } - //public ReactiveCommand CommandSelectAll { get; set; } public ReactiveCommand CommandSelectAll { get; set; } public ReactiveCommand CommandUnSelectAll { get; set; } public ReactiveCommand CommandSelectorIntersect { get; set; } public ReactiveCommand CommandCutterIntersect { get; set; } + public ReactiveCommand CommandDeleteDraggedConnect { get; set; } + public ReactiveCommand CommandZoomIn { get; set; } + public ReactiveCommand CommandZoomOut { get; set; } + public ReactiveCommand CommandZoomOriginalSize { get; set; } + public ReactiveCommand CommandCollapseUpAll { get; set; } + public ReactiveCommand CommandExpandDownAll { get; set; } + public ReactiveCommand CommandCollapseUpSelected { get; set; } + public ReactiveCommand CommandExpandDownSelected { get; set; } - //public SimpleCommandWithParameter CommandAddConnect { get; set; } + + + //public ReactiveCommand CommandAddConnect { get; set; } public ReactiveCommand CommandAddConnect { get; set; } - public SimpleCommandWithParameter CommandDeleteConnect { get; set; } - //public SimpleCommandWithParameter<(int connectorIndex, ViewModelConnect connect)> CommandAddConnectWithConnector { get; set; } - //public SimpleCommandWithParameter CommandDeleteConnectWithConnector { get; set; } - - public SimpleCommandWithParameter CommandAddDraggedConnect { get; set; } - public ReactiveCommand CommandDeleteDraggedConnect { get; set; } - - public SimpleCommandWithParameter<(ViewModelNode objectForValidate, string newValue)> CommandValidateNodeName { get; set; } - public SimpleCommandWithParameter<(ViewModelNode objectForValidate, string newValue)> CommandValidateConnectName { get; set; } - - public SimpleCommandWithParameter CommandZoom { get; set; } - public SimpleCommandWithParameter CommandSelect { get; set; } - public SimpleCommandWithParameter CommandCut { get; set; } - //public SimpleCommandWithParameter CommandPartMoveAllNode { get; set; } - //public SimpleCommandWithParameter CommandPartMoveAllSelectedNode { get; set; } + public ReactiveCommand CommandDeleteConnect { get; set; } + //public ReactiveCommand<(int connectorIndex, ViewModelConnect connect)> CommandAddConnectWithConnector { get; set; } + //public ReactiveCommand CommandDeleteConnectWithConnector { get; set; } + + public ReactiveCommand CommandAddDraggedConnect { get; set; } + + public ReactiveCommand<(ViewModelNode objectForValidate, string newValue), Unit> CommandValidateNodeName { get; set; } + public ReactiveCommand<(ViewModelConnector objectForValidate, string newValue), Unit> CommandValidateConnectName { get; set; } + + public ReactiveCommand CommandZoom { get; set; } + public ReactiveCommand CommandSelect { get; set; } + public ReactiveCommand CommandCut { get; set; } + //public ReactiveCommand CommandPartMoveAllNode { get; set; } + //public ReactiveCommand CommandPartMoveAllSelectedNode { get; set; } public ReactiveCommand CommandPartMoveAllNode { get; set; } public ReactiveCommand CommandPartMoveAllSelectedNode { get; set; } - public SimpleCommandWithParameter CommandLogDebug { get; set; } - public SimpleCommandWithParameter CommandLogError { get; set; } - public SimpleCommandWithParameter CommandLogInformation { get; set; } - public SimpleCommandWithParameter CommandLogWarning { get; set; } + public ReactiveCommand CommandLogDebug { get; set; } + public ReactiveCommand CommandLogError { get; set; } + public ReactiveCommand CommandLogInformation { get; set; } + public ReactiveCommand CommandLogWarning { get; set; } + public ReactiveCommand CommandSave { get; set; } + public ReactiveCommand CommandOpen { get; set; } + + + //public Command CommandAddConnectWithUndoRedo { get; set; } public Command CommandAddConnectorWithConnect {get; set; } public Command> CommandFullMoveAllNode { get; set; } @@ -140,8 +155,7 @@ private void SetAsStart(ViewModelNode node) public Command CommandDeleteSelectedElements { get; set; } - public SimpleCommandWithParameter CommandSave { get; set; } - public SimpleCommandWithParameter CommandOpen{ get; set; } + public double ScaleMax = 5; public double ScaleMin = 0.1; @@ -149,46 +163,55 @@ private void SetAsStart(ViewModelNode node) private void SetupCommands() { - CommandRedo = ReactiveCommand.Create(CommandWithUndoRedo.Redo); - CommandUndo = ReactiveCommand.Create(CommandWithUndoRedo.Undo); + CommandRedo = ReactiveCommand.Create(ICommandWithUndoRedo.Redo); + CommandUndo = ReactiveCommand.Create(ICommandWithUndoRedo.Undo); //CommandSelectAll = new SimpleCommand(SelectedAll); CommandSelectAll = ReactiveCommand.Create(SelectedAll); CommandUnSelectAll = ReactiveCommand.Create(UnSelectedAll); CommandSelectorIntersect = ReactiveCommand.Create(SelectNodes); CommandCutterIntersect = ReactiveCommand.Create(SelectConnects); - CommandValidateNodeName = new SimpleCommandWithParameter<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName); - CommandValidateConnectName = new SimpleCommandWithParameter<(ViewModelNode objectForValidate, string newValue)>(ValidateConnectName); - //CommandAddConnect = new SimpleCommandWithParameter(AddConnect, NotSaved); + CommandZoomIn = ReactiveCommand.Create(()=> { Scale.Value += Scales;}); + CommandZoomOut = ReactiveCommand.Create(() => { Scale.Value -= Scales; }); + CommandZoomOriginalSize = ReactiveCommand.Create(() => { Scale.Value = 1; }); + CommandCollapseUpAll = ReactiveCommand.Create(CollapseUpAll); + CommandExpandDownAll = ReactiveCommand.Create(ExpandDownAll); + CommandCollapseUpSelected = ReactiveCommand.Create(CollapseUpSelected); + CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected); + + CommandValidateNodeName = ReactiveCommand.Create<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName); + CommandValidateConnectName = ReactiveCommand.Create<(ViewModelConnector objectForValidate, string newValue)>(ValidateConnectName); + //CommandAddConnect = ReactiveCommand.Create(AddConnect, NotSaved); CommandAddConnect = ReactiveCommand.Create< ViewModelConnect>(AddConnect); - CommandDeleteConnect = new SimpleCommandWithParameter(DeleteConnect, NotSaved); - - //CommandPartMoveAllNode = new SimpleCommandWithParameter(PartMoveAllNode); - //CommandPartMoveAllSelectedNode = new SimpleCommandWithParameter(PartMoveAllSelectedNode); + CommandDeleteConnect = ReactiveCommand.Create(DeleteConnect); + CommandZoom = ReactiveCommand.Create(Zoom); + CommandLogDebug = ReactiveCommand.Create(LogDebug); + CommandLogError = ReactiveCommand.Create(LogError); + CommandLogInformation = ReactiveCommand.Create(LogInformation); + CommandLogWarning = ReactiveCommand.Create(LogWarning); + CommandSelect = ReactiveCommand.Create(StartSelect); + CommandCut = ReactiveCommand.Create(StartCut); + CommandAddDraggedConnect = ReactiveCommand.Create(AddDraggedConnect); + CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect); + CommandSave = ReactiveCommand.Create(Save); + CommandOpen = ReactiveCommand.CreateFromTask(OpenAsync); + CommandNewScheme = ReactiveCommand.Create(NewScheme); + //CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); + //CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); + CommandFullMoveAllNode = new Command>(FullMoveAllNode, UnFullMoveAllNode, NotSaved); CommandFullMoveAllSelectedNode = new Command>(FullMoveAllSelectedNode, UnFullMoveAllSelectedNode, NotSaved); CommandAddConnectorWithConnect = new Command(AddConnectorWithConnect, DeleteConnectorWithConnect, NotSaved); - CommandZoom = new SimpleCommandWithParameter(Zoom); - CommandLogDebug = new SimpleCommandWithParameter(LogDebug); - CommandLogError = new SimpleCommandWithParameter(LogError); - CommandLogInformation = new SimpleCommandWithParameter(LogInformation); - CommandLogWarning = new SimpleCommandWithParameter(LogWarning); - CommandSelect = new SimpleCommandWithParameter(StartSelect); - CommandCut = new SimpleCommandWithParameter(StartCut); - CommandAddDraggedConnect = new SimpleCommandWithParameter(AddDraggedConnect); - CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect); CommandAddNodeWithUndoRedo = new Command(AddNodeWithUndoRedo, DeleteNodeWithUndoRedo, NotSaved); //CommandAddConnectWithUndoRedo = new Command(AddConnectWithUndoRedo, DeleteConnectWithUndoRedo, NotSaved); CommandDeleteSelectedNodes = new Command(DeleteSelectedNodes, UnDeleteSelectedNodes, NotSaved); CommandDeleteSelectedConnectors = new Command, List<(int index, ViewModelConnector connector)>>(DeleteSelectedConnectors, UnDeleteSelectedConnectors, NotSaved); CommandDeleteSelectedElements = new Command(DeleteSelectedElements, UnDeleteSelectedElements); - CommandSave = new SimpleCommandWithParameter(Save); - CommandOpen = new SimpleCommandWithParameter(Open); - CommandNewScheme = ReactiveCommand.Create(NewScheme); + } private void NotSaved() { @@ -199,8 +222,9 @@ private void NotSavedSubscrube() { CommandRedo.Subscribe(_=> NotSaved()); CommandUndo.Subscribe(_ => NotSaved()); - CommandAddConnect.Subscribe(_ => NotSaved()); + CommandDeleteConnect.Subscribe(_ => NotSaved()); + } #endregion Setup Commands @@ -225,13 +249,41 @@ public void LogWarning(string message) #endregion Logging + private void CollapseUpAll() + { + foreach(var node in Nodes) + { + node.IsCollapse = true; + } + } + private void ExpandDownAll() + { + foreach (var node in Nodes) + { + node.IsCollapse = false; + } + } + private void CollapseUpSelected() + { + foreach (var node in Nodes.Where(x=>x.Selected)) + { + node.IsCollapse = true; + } + } + private void ExpandDownSelected() + { + foreach (var node in Nodes.Where(x => x.Selected)) + { + node.IsCollapse = false; + } + } private void StartSelect(MyPoint point) { - Selector.CommandStartSelect.Execute(point); + Selector.CommandStartSelect.ExecuteWithSubscribe(point); } private void StartCut(MyPoint point) { - Cutter.CommandStartCut.Execute(point); + Cutter.CommandStartCut.ExecuteWithSubscribe(point); } private void SelectedAll() { @@ -254,7 +306,7 @@ private List FullMoveAllNode(MyPoint delta, List n nodes = Nodes.ToList(); myPoint.Clear(); } - nodes.ForEach(node => node.CommandMove.Execute(myPoint)); + nodes.ForEach(node => node.CommandMove.ExecuteWithSubscribe(myPoint)); LogInformation(Messages.Count.ToString()); return nodes; @@ -263,7 +315,7 @@ private List UnFullMoveAllNode(MyPoint delta, List { MyPoint myPoint = delta.Copy(); myPoint.Mirror(); - nodes.ForEach(node => node.CommandMove.Execute(myPoint)); + nodes.ForEach(node => node.CommandMove.ExecuteWithSubscribe(myPoint)); return nodes; } private List FullMoveAllSelectedNode(MyPoint delta, List nodes = null) @@ -274,25 +326,25 @@ private List FullMoveAllSelectedNode(MyPoint delta, List x.Selected).ToList(); myPoint.Clear(); } - nodes.ForEach(node => node.CommandMove.Execute(myPoint)); + nodes.ForEach(node => node.CommandMove.ExecuteWithSubscribe(myPoint)); return nodes; } private List UnFullMoveAllSelectedNode(MyPoint delta, List nodes = null) { MyPoint myPoint = delta.Copy(); myPoint.Mirror(); - nodes.ForEach(node => node.CommandMove.Execute(myPoint)); + nodes.ForEach(node => node.CommandMove.ExecuteWithSubscribe(myPoint)); return nodes; } private void PartMoveAllNode(MyPoint delta) { foreach (var node in Nodes) - { node.CommandMove.Execute(delta); } + { node.CommandMove.ExecuteWithSubscribe(delta); } } private void PartMoveAllSelectedNode(MyPoint delta) { foreach (var node in Nodes.Where(x => x.Selected)) - { node.CommandMove.Execute(delta); } + { node.CommandMove.ExecuteWithSubscribe(delta); } } private string GetNameForNewNode() { @@ -379,12 +431,12 @@ private ViewModelConnector AddConnectorWithConnect(ViewModelConnector parameter, { if (result == null) return parameter; - result.Node.CommandAddConnectorWithConnect.Execute((1, result)); + result.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((1, result)); return result; } private ViewModelConnector DeleteConnectorWithConnect(ViewModelConnector parameter, ViewModelConnector result) { - result.Node.CommandDeleteConnectorWithConnect.Execute(result); + result.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(result); return parameter; } @@ -392,12 +444,12 @@ private ViewModelConnector DeleteConnectorWithConnect(ViewModelConnector paramet //{ // if (result == null) // return parameter; - // result.FromConnector.Node.CommandAddConnectorWithConnect.Execute((1, result.FromConnector)); + // result.FromConnector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((1, result.FromConnector)); // return result; //} //private ViewModelConnect DeleteConnectWithUndoRedo(ViewModelConnect parameter, ViewModelConnect result) //{ - // result.FromConnector.Node.CommandDeleteConnectorWithConnect.Execute(result.FromConnector); + // result.FromConnector.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(result.FromConnector); // return parameter; //} @@ -474,7 +526,7 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res } foreach (var element in result) { - element.connector.Node.CommandDeleteConnectorWithConnect.Execute(element.connector); + element.connector.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(element.connector); } return result; } @@ -482,7 +534,7 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res { foreach(var element in result) { - element.connector.Node.CommandAddConnectorWithConnect.Execute((element.index, element.connector)); + element.connector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((element.index, element.connector)); } return result; @@ -510,7 +562,7 @@ private ElementsForDelete DeleteSelectedNodes(ElementsForDelete parameter, Eleme } foreach(var element in result.ConnectsToDeleteWithConnectors) { - element.connect.FromConnector.Node.CommandDeleteConnectorWithConnect.Execute(element.connect.FromConnector); + element.connect.FromConnector.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(element.connect.FromConnector); } Connects.RemoveMany(result.ConnectsToDelete); @@ -525,7 +577,7 @@ private ElementsForDelete UnDeleteSelectedNodes(ElementsForDelete parameter, Ele result.ConnectsToDeleteWithConnectors.Sort(ElementsForDelete.Sort); foreach (var element in result.ConnectsToDeleteWithConnectors) { - element.connect.FromConnector.Node.CommandAddConnectorWithConnect.Execute((element.connectorIndex, element.connect.FromConnector)); + element.connect.FromConnector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((element.connectorIndex, element.connect.FromConnector)); } return result; @@ -541,7 +593,7 @@ private void ValidateNodeName((ViewModelNode objectForValidate, string newValue) } } } - private void ValidateConnectName((ViewModelNode objectForValidate, string newValue) obj) + private void ValidateConnectName((ViewModelConnector objectForValidate, string newValue) obj) { if (!String.IsNullOrWhiteSpace(obj.newValue)) { @@ -572,20 +624,26 @@ private void NewScheme() this.SetupStartState(); } - private void Open(string fileName) - { + private async Task OpenAsync(string fileName) + { this.Nodes.Clear(); this.Connects.Clear(); - XDocument xDocument = XDocument.Load(fileName); + XDocument xDocument; + + using (var stream = File.Open(fileName, FileMode.Open)) + { + xDocument = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None); + } XElement stateMachineXElement = xDocument.Element("StateMachine"); - if(stateMachineXElement==null) + + if (stateMachineXElement == null) { Error("not contanins StateMachine"); return; } - #region setup states/nodes + #region setup states/nodes var States = stateMachineXElement.Element("States")?.Elements()?.ToList() ?? new List(); ViewModelNode viewModelNode = null; foreach (var state in States) @@ -595,22 +653,22 @@ private void Open(string fileName) return; } - #region setup start state + #region setup start state - var startState = stateMachineXElement.Element("StartState")?.Attribute("Name")?.Value; + var startState = stateMachineXElement.Element("StartState")?.Attribute("Name")?.Value; - if (string.IsNullOrEmpty(startState)) - this.SetupStartState(); - else - this.SetAsStart(this.Nodes.Single(x => x.Name == startState)); + if (string.IsNullOrEmpty(startState)) + this.SetupStartState(); + else + this.SetAsStart(this.Nodes.Single(x => x.Name == startState)); - #endregion setup start state + #endregion setup start state #endregion setup states/nodes #region setup Transitions/connects - var Transitions = stateMachineXElement.Element("Transitions")?.Elements()?.ToList()??new List(); + var Transitions = stateMachineXElement.Element("Transitions")?.Elements()?.ToList() ?? new List(); ViewModelConnect viewModelConnect; foreach (var transition in Transitions) { @@ -625,9 +683,9 @@ private void Open(string fileName) bool WithError(string errorMessage, Action action, T obj) { - if(string.IsNullOrEmpty(errorMessage)) + if (string.IsNullOrEmpty(errorMessage)) { - if(!object.Equals(obj,default(T))) + if (!object.Equals(obj, default(T))) action.Invoke(obj); } else @@ -638,7 +696,7 @@ bool WithError(string errorMessage, Action action, T obj) return false; } void Error(string errorMessage) - { + { LogError("File is not valid: " + errorMessage); NewScheme(); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs index 6b44f91..88c78a8 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs @@ -66,12 +66,12 @@ private void UpdateSize() } #region Setup Commands - public SimpleCommandWithParameter CommandStartSelect { get; set; } + public ReactiveCommand CommandStartSelect { get; set; } public ReactiveCommand CommandEndSelect { get; set; } private void SetupCommands() { - CommandStartSelect = new SimpleCommandWithParameter(StartSelect); + CommandStartSelect = ReactiveCommand.Create(StartSelect); CommandEndSelect = ReactiveCommand.Create(EndSelect); } From 57f88d21eb895a98248daa299a05aa5156123e7a Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sat, 23 May 2020 18:41:55 +0300 Subject: [PATCH 02/17] fix for name --- .../View/MainWindow.xaml | 2 +- .../View/MainWindow.xaml.cs | 61 +++++++++++++---- .../View/ViewNodesCanvas.xaml | 65 +++---------------- .../View/ViewRightConnector.xaml.cs | 4 -- .../ViewModel/ViewModelNode.cs | 16 ++++- .../ViewModel/ViewModelNodesCanvas.cs | 31 ++++++--- 6 files changed, 91 insertions(+), 88 deletions(-) diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml b/SimpleStateMachineNodeEditor/View/MainWindow.xaml index 092fbc9..00d185b 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml @@ -186,7 +186,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index 0504aca..c2a8227 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -26,6 +26,7 @@ using System.Threading.Tasks; using System.Threading; using System.Reactive; +using System.Collections.Generic; namespace SimpleStateMachineNodeEditor.View { @@ -49,10 +50,26 @@ object IViewFor.ViewModel set { ViewModel = (ViewModelMainWindow)value; } } #endregion ViewModel + Dictionary messagesLabels; + static Dictionary labelPostfix = new Dictionary() + { + {TypeMessage.Error, "Error" }, + {TypeMessage.Information, "Information" }, + {TypeMessage.Warning, "Warning" }, + {TypeMessage.Debug, "Debug" }, + }; public MainWindow() { InitializeComponent(); + messagesLabels = new Dictionary() + { + {TypeMessage.Error, LabelError }, + {TypeMessage.Information, LabelInformation }, + {TypeMessage.Warning, LabelWarning }, + {TypeMessage.Debug, LabelDebug }, + }; + ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel); SetupCommands(); SetupSubscriptions(); @@ -90,6 +107,19 @@ private void SetupBinding() this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable); + this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_=> UpdateLabels()); + //var informationCount = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.Value.Where(x=>x.TypeMessage==TypeMessage.Information).Count().ToString()); + ////var SelectedItem = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.); + //this.OneWayBind(this.ViewModel, x => informationCount, x => x.LabelError.Content).DisposeWith(disposable); + + //informationCount.WhenAnyValue().Sub + //this.LabelError.Content. + //this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable); + //this.LabelInformation.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable); + //this.LabelWarning.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable); + //this.LabelDebug.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable); + + //ItemSave.Command = CommandSave; //this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable); @@ -152,18 +182,13 @@ private void SetupEvents() { this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable); this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable); - //this.ButtonImportScheme - - - //this.ItemSave.InputBindings.Bin this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable); this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable); this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable); - - //this.ItemSave.Events().Click.Subscribe(_=> Save()).DisposeWith(disposable); + this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable); this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable); this.ItemOpen.Events().Click.Subscribe(async _ => await WithoutSavingAsync(OpenAsync)).DisposeWith(disposable); this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); @@ -171,16 +196,26 @@ private void SetupEvents() this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable); this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); - this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable); - this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable); - this.LabelInformation.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable); - this.LabelWarning.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable); - this.LabelDebug.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable); + foreach(var label in messagesLabels) + { + label.Value.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, label.Key)).DisposeWith(disposable); + } - //this.LabelUpdate.Events().PreviewMouseLeftButtonDown.Subscribe(_ => this.ViewModel.Messages.Cle).DisposeWith(disposable); - //this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); + this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable); + this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable); }); } + + void UpdateLabels() + { + var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count()); + + foreach(var lable in messagesLabels) + { + lable.Value.Content = (counts.Keys.Contains(lable.Key) ? counts[lable.Key].ToString() : "0") +" "+ labelPostfix[lable.Key]; + } + + } void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage) { if ((ErrorListExpander.IsExpanded)&&(this.ViewModel.NodesCanvas.DisplayMessageType != typeMessage)) diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml index e8d8acf..fdae355 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml @@ -14,14 +14,13 @@ - - + @@ -51,46 +50,6 @@ - - - - @@ -117,21 +76,13 @@ - - - - - - - - - - - + + + + - - - + + diff --git a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs index 4b459be..757d09a 100644 --- a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs @@ -121,8 +121,6 @@ private void ConnectDrag(MouseButtonEventArgs e) { this.ViewModel.CommandSetAsLoop.ExecuteWithSubscribe(); this.ViewModel.NodesCanvas.CommandAddConnectorWithConnect.Execute(this.ViewModel); - - this.ViewModel.NodesCanvas.LogDebug("Зашел 2 "); } else { @@ -132,8 +130,6 @@ private void ConnectDrag(MouseButtonEventArgs e) DragDrop.DoDragDrop(this, data, DragDropEffects.Link); this.ViewModel.CommandCheckConnectPointDrop.ExecuteWithSubscribe(); e.Handled = true; - - this.ViewModel.NodesCanvas.LogDebug("Зашел 1 "); } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index f88fc7d..22c535c 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -38,11 +38,14 @@ public class ViewModelNode : ReactiveValidationObject [Reactive] public ViewModelConnector Output { get; set; } [Reactive] public ViewModelConnector CurrentConnector { get; set; } [Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; } + [Reactive] public int IndexStartSelectConnectors { get; set; } = 0; + public IObservableCollection Transitions { get; set; } = new ObservableCollectionExtended(); public int Zindex { get; private set; } - [Reactive] public int IndexStartSelectConnectors { get; set; } = 0; - public IObservableCollection Transitions { get; set; } = new ObservableCollectionExtended(); + public int TransitionsCount = -1; + + @@ -61,6 +64,8 @@ public ViewModelNode(ViewModelNodesCanvas nodesCanvas) private void SetupBinding() { this.WhenAnyValue(x => x.Selected).Subscribe(value => { this.BorderBrush = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Brushes.LightGray; }); + this.WhenAnyValue(x => x.Transitions.Count).Subscribe(value => UpdateCount(value)); + this.WhenAnyValue(x => x.Point1.Value, x => x.Size).Subscribe(_ => UpdatePoint2()); this.WhenAnyValue(x => x.IsCollapse).Subscribe(value => Collapse(value)); } @@ -124,6 +129,11 @@ private void NotSaved() { NodesCanvas.ItSaved = false; } + private void UpdateCount(int count) + { + if (count > TransitionsCount) + TransitionsCount = count; + } #endregion Setup Commands private void Collapse(bool value) @@ -195,7 +205,7 @@ private void AddEmptyConnector() CurrentConnector.TextEnable = true; CurrentConnector.FormEnable = false; if (string.IsNullOrEmpty(CurrentConnector.Name)) - CurrentConnector.Name = "Transition " + NodesCanvas.Nodes.Sum(x => x.Transitions.Count - 1).ToString(); + CurrentConnector.Name = "Transition " + TransitionsCount.ToString(); } CurrentConnector = new ViewModelConnector(NodesCanvas, this) { diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs index 64666e7..54145d7 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs @@ -39,9 +39,14 @@ public class ViewModelNodesCanvas : ReactiveObject [Reactive] public ViewModelNode StartState { get; set; } [Reactive] public bool ItSaved { get; set; } = true; [Reactive] public string Path { get; set; } + [Reactive] public TypeMessage DisplayMessageType { get; set; } - + + public int NodesCount = 0; + public double ScaleMax = 5; + public double ScaleMin = 0.1; + public double Scales { get; set; } = 0.05; [Reactive] public Scale Scale { get; set; } = new Scale(); public ViewModelNodesCanvas() @@ -49,6 +54,8 @@ public ViewModelNodesCanvas() SetupCommands(); SetupStartState(); Cutter = new ViewModelCutter(this); + this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); + for (int i = 1; i <= 5; i++) { LogError("Error " + i.ToString()); @@ -114,7 +121,7 @@ private void SetAsStart(ViewModelNode node) public ReactiveCommand CommandExpandDownAll { get; set; } public ReactiveCommand CommandCollapseUpSelected { get; set; } public ReactiveCommand CommandExpandDownSelected { get; set; } - + public ReactiveCommand CommandErrorListUpdate { get; set; } @@ -154,13 +161,6 @@ private void SetAsStart(ViewModelNode node) public Command, List<(int index, ViewModelConnector element)>> CommandDeleteSelectedConnectors { get; set; } public Command CommandDeleteSelectedElements { get; set; } - - - - public double ScaleMax = 5; - public double ScaleMin = 0.1; - public double Scales { get; set; } = 0.05; - private void SetupCommands() { CommandRedo = ReactiveCommand.Create(ICommandWithUndoRedo.Redo); @@ -177,6 +177,8 @@ private void SetupCommands() CommandExpandDownAll = ReactiveCommand.Create(ExpandDownAll); CommandCollapseUpSelected = ReactiveCommand.Create(CollapseUpSelected); CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected); + CommandErrorListUpdate = ReactiveCommand.Create(ErrosUpdaate); + CommandValidateNodeName = ReactiveCommand.Create<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName); CommandValidateConnectName = ReactiveCommand.Create<(ViewModelConnector objectForValidate, string newValue)>(ValidateConnectName); @@ -249,6 +251,11 @@ public void LogWarning(string message) #endregion Logging + private void UpdateCount(int count) + { + if (count > NodesCount) + NodesCount = count; + } private void CollapseUpAll() { foreach(var node in Nodes) @@ -263,6 +270,10 @@ private void ExpandDownAll() node.IsCollapse = false; } } + private void ErrosUpdaate() + { + Messages.RemoveMany(Messages.Where(x => x.TypeMessage == DisplayMessageType || DisplayMessageType==TypeMessage.All)); + } private void CollapseUpSelected() { foreach (var node in Nodes.Where(x=>x.Selected)) @@ -348,7 +359,7 @@ private void PartMoveAllSelectedNode(MyPoint delta) } private string GetNameForNewNode() { - return "State " + Nodes.Count.ToString(); + return "State " + NodesCount.ToString(); } private ViewModelNode AddNodeWithUndoRedo(MyPoint parameter, ViewModelNode result) { From abe3c273bc185a1b1a5c5e54ddf7ad3719c59fca Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 15:19:14 +0300 Subject: [PATCH 03/17] before start dialog --- .../Helpers/Enums/DialogResult.cs | 15 + .../Helpers/Enums/DialogType.cs | 10 + .../Helpers/Enums/TypeMove.cs | 13 + .../Extensions/FileDialogResultExtension.cs | 23 + .../Extensions/MessageBoxResultExtension.cs | 21 + .../SimpleStateMachineNodeEditor.csproj | 1 + .../View/MainWindow.xaml.cs | 88 +--- .../View/ViewConnect.xaml.cs | 1 - .../View/ViewDialog.xaml | 9 + .../View/ViewDialog.xaml.cs | 98 ++++ .../View/ViewLeftConnector.xaml.cs | 13 +- .../View/ViewModalDialog.xaml | 8 + .../View/ViewModalDialog.xaml.cs | 44 ++ .../View/ViewNode.xaml.cs | 4 +- .../View/ViewNodesCanvas.xaml | 1 + .../View/ViewNodesCanvas.xaml.cs | 29 +- .../View/ViewRightConnector.xaml.cs | 14 +- .../NodesCanvas/ViewModelNodesCanvas.cs | 140 +++++ .../ViewModelNodesCanvasCommands.cs} | 491 ++++++------------ .../ViewModel/ViewModelConnect.cs | 1 + .../ViewModel/ViewModelConnector.cs | 5 +- .../ViewModel/ViewModelCutter.cs | 1 + .../ViewModel/ViewModelDialog.cs | 55 ++ .../ViewModel/ViewModelMainWindow.cs | 1 + .../ViewModel/ViewModelModalDialog.cs | 33 ++ .../ViewModel/ViewModelNode.cs | 39 +- 26 files changed, 741 insertions(+), 417 deletions(-) create mode 100644 SimpleStateMachineNodeEditor/Helpers/Enums/DialogResult.cs create mode 100644 SimpleStateMachineNodeEditor/Helpers/Enums/DialogType.cs create mode 100644 SimpleStateMachineNodeEditor/Helpers/Enums/TypeMove.cs create mode 100644 SimpleStateMachineNodeEditor/Helpers/Extensions/FileDialogResultExtension.cs create mode 100644 SimpleStateMachineNodeEditor/Helpers/Extensions/MessageBoxResultExtension.cs create mode 100644 SimpleStateMachineNodeEditor/View/ViewDialog.xaml create mode 100644 SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs create mode 100644 SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml create mode 100644 SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs create mode 100644 SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs rename SimpleStateMachineNodeEditor/ViewModel/{ViewModelNodesCanvas.cs => NodesCanvas/ViewModelNodesCanvasCommands.cs} (72%) create mode 100644 SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs create mode 100644 SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs diff --git a/SimpleStateMachineNodeEditor/Helpers/Enums/DialogResult.cs b/SimpleStateMachineNodeEditor/Helpers/Enums/DialogResult.cs new file mode 100644 index 0000000..851e635 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Enums/DialogResult.cs @@ -0,0 +1,15 @@ +namespace SimpleStateMachineNodeEditor.Helpers.Enums +{ + public enum DialogResult + { + noCorrect = 0, + Yes, + No, + Ok, + Cancel, + None, + Abort, + Retry, + Ignore + } +} diff --git a/SimpleStateMachineNodeEditor/Helpers/Enums/DialogType.cs b/SimpleStateMachineNodeEditor/Helpers/Enums/DialogType.cs new file mode 100644 index 0000000..dc16988 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Enums/DialogType.cs @@ -0,0 +1,10 @@ +namespace SimpleStateMachineNodeEditor.Helpers.Enums +{ + public enum DialogType + { + noCorrect = 0, + MessageBox, + SaveFileDialog, + OpenFileDialog, + } +} diff --git a/SimpleStateMachineNodeEditor/Helpers/Enums/TypeMove.cs b/SimpleStateMachineNodeEditor/Helpers/Enums/TypeMove.cs new file mode 100644 index 0000000..313bbe3 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Enums/TypeMove.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SimpleStateMachineNodeEditor.Helpers.Enums +{ + public enum TypeMove + { + None = 0, + MoveAll, + MoveSelected, + } +} diff --git a/SimpleStateMachineNodeEditor/Helpers/Extensions/FileDialogResultExtension.cs b/SimpleStateMachineNodeEditor/Helpers/Extensions/FileDialogResultExtension.cs new file mode 100644 index 0000000..35f7b47 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Extensions/FileDialogResultExtension.cs @@ -0,0 +1,23 @@ +using System; + +namespace SimpleStateMachineNodeEditor.Helpers.Extensions +{ + public static class FileDialogResultExtension + { + public static Enums.DialogResult ToDialogResult(this System.Windows.Forms.DialogResult fileDialogResult) + { + return fileDialogResult switch + { + System.Windows.Forms.DialogResult.Yes => Helpers.Enums.DialogResult.None, + System.Windows.Forms.DialogResult.No => Helpers.Enums.DialogResult.No, + System.Windows.Forms.DialogResult.OK => Helpers.Enums.DialogResult.Ok, + System.Windows.Forms.DialogResult.Cancel => Helpers.Enums.DialogResult.Cancel, + System.Windows.Forms.DialogResult.None => Helpers.Enums.DialogResult.None, + System.Windows.Forms.DialogResult.Abort => Helpers.Enums.DialogResult.Abort, + System.Windows.Forms.DialogResult.Retry => Helpers.Enums.DialogResult.Retry, + System.Windows.Forms.DialogResult.Ignore => Helpers.Enums.DialogResult.Ignore, + _ => throw new NotImplementedException(), + }; + } + } +} diff --git a/SimpleStateMachineNodeEditor/Helpers/Extensions/MessageBoxResultExtension.cs b/SimpleStateMachineNodeEditor/Helpers/Extensions/MessageBoxResultExtension.cs new file mode 100644 index 0000000..9dd5c78 --- /dev/null +++ b/SimpleStateMachineNodeEditor/Helpers/Extensions/MessageBoxResultExtension.cs @@ -0,0 +1,21 @@ +using System; +using System.Windows; + +namespace SimpleStateMachineNodeEditor.Helpers.Extensions +{ + public static class MessageBoxResultExtension + { + public static Helpers.Enums.DialogResult ToDialogResult(this MessageBoxResult messageBoxResult) + { + return messageBoxResult switch + { + MessageBoxResult.Yes => Helpers.Enums.DialogResult.Yes, + MessageBoxResult.No => Helpers.Enums.DialogResult.No, + MessageBoxResult.OK => Helpers.Enums.DialogResult.Ok, + MessageBoxResult.Cancel => Helpers.Enums.DialogResult.Cancel, + MessageBoxResult.None => Helpers.Enums.DialogResult.None, + _ => throw new NotImplementedException() + }; + } + } +} diff --git a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj index 0a7e087..13a07c0 100644 --- a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj +++ b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj @@ -44,6 +44,7 @@ + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index c2a8227..54da9e6 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -50,6 +50,7 @@ object IViewFor.ViewModel set { ViewModel = (ViewModelMainWindow)value; } } #endregion ViewModel + Dictionary messagesLabels; static Dictionary labelPostfix = new Dictionary() { @@ -71,7 +72,6 @@ public MainWindow() }; ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel); - SetupCommands(); SetupSubscriptions(); SetupBinding(); SetupEvents(); @@ -106,34 +106,6 @@ private void SetupBinding() this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable); - - this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_=> UpdateLabels()); - //var informationCount = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.Value.Where(x=>x.TypeMessage==TypeMessage.Information).Count().ToString()); - ////var SelectedItem = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.); - //this.OneWayBind(this.ViewModel, x => informationCount, x => x.LabelError.Content).DisposeWith(disposable); - - //informationCount.WhenAnyValue().Sub - //this.LabelError.Content. - //this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable); - //this.LabelInformation.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable); - //this.LabelWarning.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable); - //this.LabelDebug.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable); - - - //ItemSave.Command = CommandSave; - //this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable); - - //this.OneWayBind(this, x => x.CommandSave, x => x.BindingSave.Command).DisposeWith(disposable); - - //this.OneWayBind(this.ViewModel, x=>x.CommandCopyError, x=>x.BindingSave.Command) - - - //this.ItemSave.Inp - - //this.OneWayBind(this.NodesCanvas.ViewModel, x => x.CommandSave, x => x.BindingSave.Command); - //this.OneWayBind(this.NodesCanvas.ViewModel, x => x.CommandSave, x => x.BindingSave.Command); - - }); } #endregion Setup Binding @@ -144,8 +116,8 @@ private void SetupSubscriptions() { this.WhenActivated(disposable => { - this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.Path).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable); - + this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable); + this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels()); }); } @@ -160,29 +132,17 @@ private void UpdateSchemeName(string newName) } #endregion Setup Subscriptions - #region Setup Commands - - public ReactiveCommand CommandSave { get; set; } - private void SetupCommands() - { - this.WhenActivated(disposable => - { - CommandSave = ReactiveCommand.Create(Save); - - //this.Events().KeyUp.Where(x => x.Key == Key.S && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))).Subscribe(_ => Save()).DisposeWith(disposable); - //this.Events().KeyUp.Where(x => x.Key == Key.F4 && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))).Subscribe(_ => Close()).DisposeWith(disposable); - }); - } - #endregion Setup Commands #region SetupEvents private void SetupEvents() { this.WhenActivated(disposable => { + this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable); this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable); + this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable); this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable); @@ -190,9 +150,10 @@ private void SetupEvents() this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable); this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable); - this.ItemOpen.Events().Click.Subscribe(async _ => await WithoutSavingAsync(OpenAsync)).DisposeWith(disposable); + this.ItemOpen.Events().Click.Subscribe(_ => WithoutSaving(Open)).DisposeWith(disposable); this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable); + this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable); this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); @@ -300,7 +261,7 @@ void ExportToImage(ImageFormats format) dlg.FileName = SchemeName(); dlg.Filter = (format == ImageFormats.JPEG)? "JPEG Image (.jpeg)|*.jpeg":"Png Image (.png)|*.png"; - DialogResult dialogResult = dlg.ShowDialog(); + System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); if(dialogResult==System.Windows.Forms.DialogResult.OK) { this.NodesCanvas.SaveCanvasToImage(dlg.FileName, format); @@ -321,26 +282,16 @@ void WithoutSaving(Action action) if (result == MessageBoxResult.Yes) action.Invoke(); } - async Task WithoutSavingAsync(Func action) - { - var result = MessageBoxResult.Yes; - if (!this.NodesCanvas.ViewModel.ItSaved) - { - result = System.Windows.MessageBox.Show("Exit without saving ?", "Test", MessageBoxButton.YesNo); - } - if (result == MessageBoxResult.Yes) - await action.Invoke(); - } void Save() { - if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.Path)) + if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath)) { SaveAs(); } else { - this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.Path); + this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.SchemePath); } } void SaveAs() @@ -348,35 +299,38 @@ void SaveAs() SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = SchemeName(); dlg.Filter = "XML-File | *.xml"; - - DialogResult dialogResult = dlg.ShowDialog(); + + System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { + Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(dlg.FileName); + Mouse.OverrideCursor = null; } } private string SchemeName() { - if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.Path)) + if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath)) { - return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.Path); + return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.SchemePath); } else { return "SimpleStateMachine"; } } - async Task OpenAsync() + private void Open() { OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName = SchemeName(); dlg.Filter = "XML-File | *.xml"; - DialogResult dialogResult = dlg.ShowDialog(); + System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { - //this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName); - await this.NodesCanvas.ViewModel.CommandOpen.Execute(dlg.FileName); + Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; + this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName); + Mouse.OverrideCursor = null; } } diff --git a/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs index bdc91bc..e36f0d7 100644 --- a/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs @@ -49,7 +49,6 @@ private void SetupBinding() { this.WhenActivated(disposable => { - // Цвет линии this.OneWayBind(this.ViewModel, x => x.Stroke, x => x.PathElement.Stroke).DisposeWith(disposable); diff --git a/SimpleStateMachineNodeEditor/View/ViewDialog.xaml b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml new file mode 100644 index 0000000..fe01f7f --- /dev/null +++ b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml @@ -0,0 +1,9 @@ + + diff --git a/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs new file mode 100644 index 0000000..dbf86c7 --- /dev/null +++ b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs @@ -0,0 +1,98 @@ +using ReactiveUI; +using SimpleStateMachineNodeEditor.Helpers.Enums; +using SimpleStateMachineNodeEditor.Helpers.Extensions; +using SimpleStateMachineNodeEditor.ViewModel; +using System; +using System.Reactive.Disposables; +using System.Reactive.Linq; +using System.Windows; +using System.Windows.Forms; + +namespace SimpleStateMachineNodeEditor.View +{ + /// + /// Interaction logic for ViewDialog.xaml + /// + public partial class ViewDialog : System.Windows.Controls.UserControl, IViewFor + { + #region ViewModel + public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelDialog), typeof(ViewDialog), new PropertyMetadata(null)); + + public ViewModelDialog ViewModel + { + get { return (ViewModelDialog)GetValue(ViewModelProperty); } + set { SetValue(ViewModelProperty, value); } + } + + object IViewFor.ViewModel + { + get { return ViewModel; } + set { ViewModel = (ViewModelDialog)value; } + } + #endregion ViewModel + public ViewDialog() + { + InitializeComponent(); + SetupBinding(); + SetupSubcriptions(); + } + private void SetupBinding() + { + this.WhenActivated(disposable => + { + this.Bind(this.ViewModel, x=>x.Visibility, x=>x.Visibility).DisposeWith(disposable); + }); + } + private void SetupSubcriptions() + { + this.WhenActivated(disposable => + { + this.WhenAnyValue(x => x.Visibility).ObserveOn(RxApp.MainThreadScheduler). + Where(x => x == Visibility.Visible).Subscribe(_ => Show()).DisposeWith(disposable); + }); + } + private void Show() + { + GetAction().Invoke(); + this.Visibility = Visibility.Collapsed; + } + + private Action GetAction() + { + return ViewModel.Type switch + { + DialogType.MessageBox => ShowMessageBox, + DialogType.SaveFileDialog => ShowSaveFileDialog, + DialogType.OpenFileDialog => ShowOpenFileDialog, + DialogType.noCorrect => throw new NotImplementedException(), + _ => throw new NotImplementedException() + }; + } + + private void ShowMessageBox() + { + ViewModel.Result = System.Windows.MessageBox.Show(ViewModel.MessageBoxText, ViewModel.Title, ViewModel.MessageBoxButtons).ToDialogResult(); + } + private void ShowOpenFileDialog() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = ViewModel.Title; + dlg.FileName = ViewModel.FileName; + dlg.Filter = ViewModel.FileDialogFilter; + + ViewModel.Result = dlg.ShowDialog().ToDialogResult(); + ViewModel.FileName = dlg.FileName; + + } + private void ShowSaveFileDialog() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = ViewModel.Title; + dlg.FileName = ViewModel.FileName; + dlg.Filter = ViewModel.FileDialogFilter; + + ViewModel.Result = dlg.ShowDialog().ToDialogResult(); + ViewModel.FileName = dlg.FileName; + } + } +} diff --git a/SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs index be94ed6..2507b3c 100644 --- a/SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs @@ -85,11 +85,22 @@ private void SetupEvents() this.WhenActivated(disposable => { this.EllipseElement.Events().Drop.Subscribe(e => OnEventDrop(e)).DisposeWith(disposable); + this.EllipseElement.Events().DragEnter.Subscribe(e => OnEventDragEnter(e)).DisposeWith(disposable); + this.EllipseElement.Events().DragLeave.Subscribe(e => OnEventDragLeave(e)).DisposeWith(disposable); }); } #endregion SetupEvents - + private void OnEventDragEnter(DragEventArgs e) + { + this.ViewModel.FormStroke = Application.Current.Resources["ColorConnector"] as SolidColorBrush; + e.Handled = true; + } + private void OnEventDragLeave(DragEventArgs e) + { + this.ViewModel.FormStroke = Application.Current.Resources["ColorNodesCanvasBackground"] as SolidColorBrush; + e.Handled = true; + } private void OnEventDrop(DragEventArgs e) { this.ViewModel.CommandConnectPointDrop.ExecuteWithSubscribe(); diff --git a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml new file mode 100644 index 0000000..fe2bf04 --- /dev/null +++ b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml @@ -0,0 +1,8 @@ + + + diff --git a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs new file mode 100644 index 0000000..0a2d72e --- /dev/null +++ b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs @@ -0,0 +1,44 @@ +using ReactiveUI; +using SimpleStateMachineNodeEditor.ViewModel; +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SimpleStateMachineNodeEditor.View +{ + /// + /// Interaction logic for ViewModalDialog.xaml + /// + public partial class ViewModalDialog : UserControl, IViewFor + { + #region ViewModel + public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelModalDialog), typeof(ViewModalDialog), new PropertyMetadata(null)); + + public ViewModelModalDialog ViewModel + { + get { return (ViewModelModalDialog)GetValue(ViewModelProperty); } + set { SetValue(ViewModelProperty, value); } + } + + object IViewFor.ViewModel + { + get { return ViewModel; } + set { ViewModel = (ViewModelModalDialog)value; } + } + #endregion ViewModel + + public ViewModalDialog() + { + InitializeComponent(); + } + } +} diff --git a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs index 8eb4bce..6a5a83b 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs @@ -100,7 +100,7 @@ private void SetupEvents() { this.WhenActivated(disposable => { - this.WhenAnyValue(x=>x.IsMouseOver).Subscribe(value=> Test(value)).DisposeWith(disposable); + this.WhenAnyValue(x=>x.IsMouseOver).Subscribe(value=> OnEventMouseOver(value)).DisposeWith(disposable); this.Events().MouseLeftButtonDown.Subscribe(e => OnEventMouseLeftDowns(e)).DisposeWith(disposable); this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)).DisposeWith(disposable); this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); @@ -116,7 +116,7 @@ private void SetupEvents() this.ViewModel.WhenAnyValue(x=>x.IsCollapse).Subscribe(value=> OnEventCollapse(value)).DisposeWith(disposable); }); } - private void Test(bool value) + private void OnEventMouseOver(bool value) { if (this.ViewModel.Selected != true) this.ViewModel.BorderBrush = value?Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml index fdae355..d9c9343 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml @@ -11,6 +11,7 @@ + diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs index b914907..3594621 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs @@ -20,6 +20,7 @@ using SimpleStateMachineNodeEditor.Helpers.Enums; using SimpleStateMachineNodeEditor.Icons; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.View { @@ -28,12 +29,6 @@ namespace SimpleStateMachineNodeEditor.View /// public partial class ViewNodesCanvas : UserControl, IViewFor, CanBeMove { - enum MoveNodes - { - No = 0, - MoveAll, - MoveSelected - } #region ViewModel public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelNodesCanvas), typeof(ViewNodesCanvas), new PropertyMetadata(null)); @@ -57,7 +52,7 @@ object IViewFor.ViewModel private MyPoint PositionMove { get; set; } = new MyPoint(); private MyPoint SumMove { get; set; } = new MyPoint(); - private MoveNodes Move { get; set; } = MoveNodes.No; + private TypeMove Move { get; set; } = TypeMove.None; public ViewNodesCanvas() { @@ -88,6 +83,8 @@ private void SetupBinding() this.OneWayBind(this.ViewModel, x => x.Selector, x => x.Selector.ViewModel).DisposeWith(disposable); this.OneWayBind(this.ViewModel, x => x.Cutter, x => x.Cutter.ViewModel).DisposeWith(disposable); + + this.OneWayBind(this.ViewModel, x => x.Dialog, x => x.Dialog.ViewModel).DisposeWith(disposable); }); } #endregion Setup Binding @@ -172,15 +169,15 @@ private void UpdateConnector() } private void OnEventMouseLeftUp(MouseButtonEventArgs e) { - if (Move == MoveNodes.No) + if (Move == TypeMove.None) return; - if (Move == MoveNodes.MoveAll) + if (Move == TypeMove.MoveAll) this.ViewModel.CommandFullMoveAllNode.Execute(SumMove); - else if (Move == MoveNodes.MoveSelected) + else if (Move == TypeMove.MoveSelected) this.ViewModel.CommandFullMoveAllSelectedNode.Execute(SumMove); - Move = MoveNodes.No; + Move = TypeMove.None; SumMove = new MyPoint(); } private void OnEventMouseRightDown(MouseButtonEventArgs e) @@ -196,11 +193,7 @@ private void OnEventMouseDown(MouseButtonEventArgs e) } private void OnEventMouseWheel(MouseWheelEventArgs e) { - //var position = e.GetPosition(this.Canvas); - //this.Scale.CenterX = position.X / this.ViewModel.Scale.Value; - //this.Scale.CenterY = position.Y / this.ViewModel.Scale.Value; this.ViewModel.CommandZoom.ExecuteWithSubscribe(e.Delta); - } private void OnEventMouseUp(MouseButtonEventArgs e) { @@ -208,7 +201,7 @@ private void OnEventMouseUp(MouseButtonEventArgs e) PositionMove.Clear(); Keyboard.Focus(this); } - private MyPoint test = new MyPoint(); + private void OnEventMouseMove(MouseEventArgs e) { //if ((Mouse.Captured == null)||(!(Mouse.Captured is CanBeMove))) @@ -226,13 +219,13 @@ private void OnEventMouseMove(MouseEventArgs e) { //ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta).Subscribe(); ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta); - Move = MoveNodes.MoveAll; + Move = TypeMove.MoveAll; } else { //ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); - Move = MoveNodes.MoveSelected; + Move = TypeMove.MoveSelected; } } private void OnEventDragEnter(DragEventArgs e) diff --git a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs index 757d09a..1e7388d 100644 --- a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs @@ -75,10 +75,11 @@ private void SetupBinding() this.WhenAnyValue(x => x.ViewModel.Node.Size, x => x.ViewModel.Node.Point1.Value, x => x.ViewModel.Node.NodesCanvas.Scale.Scales.Value) .Subscribe(_ => { UpdatePositionConnectPoin(); }).DisposeWith(disposable); - this.WhenAnyValue(x =>x.ViewModel.ItsLoop).Subscribe(value=> test(value)).DisposeWith(disposable); + this.WhenAnyValue(x=>x.EllipseElement.IsMouseOver).Subscribe(value=> OnEventMouseOver(value)).DisposeWith(disposable); }); } #endregion SetupBinding + #region Setup Commands private void SetupCommands() { @@ -91,11 +92,6 @@ private void SetupCommands() #endregion Setup Commands #region SetupEvents - private void test(bool value) - { - if (value) - this.ViewModel.CommandSetAsLoop.ExecuteWithSubscribe(); - } private void SetupEvents() { this.WhenActivated(disposable => @@ -107,7 +103,11 @@ private void SetupEvents() this.BorderElement.Events().PreviewDrop.Subscribe(e => ConnectorDrop(e)).DisposeWith(disposable); }); } - + private void OnEventMouseOver(bool value) + { + this.ViewModel.FormStroke = value ? Application.Current.Resources["ColorConnector"] as SolidColorBrush + : Application.Current.Resources["ColorNodesCanvasBackground"] as SolidColorBrush; + } private void Validate(RoutedEventArgs e) { ViewModel.CommandValidateName.ExecuteWithSubscribe(TextBoxElement.Text); diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs new file mode 100644 index 0000000..8b2741f --- /dev/null +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs @@ -0,0 +1,140 @@ +using System; +using System.Linq; +using System.Reactive.Linq; +using ReactiveUI; +using ReactiveUI.Fody.Helpers; +using DynamicData.Binding; +using SimpleStateMachineNodeEditor.Helpers.Transformations; +using SimpleStateMachineNodeEditor.Helpers.Enums; +using System.Windows.Data; +using System.IO; + +namespace SimpleStateMachineNodeEditor.ViewModel.NodesCanvas +{ + public partial class ViewModelNodesCanvas : ReactiveObject + { + public ObservableCollectionExtended Connects = new ObservableCollectionExtended(); + + public ObservableCollectionExtended Nodes = new ObservableCollectionExtended(); + public ObservableCollectionExtended Messages { get; set; } = new ObservableCollectionExtended(); + + [Reactive] public ViewModelSelector Selector { get; set; } = new ViewModelSelector(); + [Reactive] public ViewModelDialog Dialog { get; set; } = new ViewModelDialog(); + [Reactive] public ViewModelCutter Cutter { get; set; } + [Reactive] public ViewModelConnect DraggedConnect { get; set; } + [Reactive] public ViewModelConnector ConnectorPreviewForDrop { get; set; } + [Reactive] public ViewModelNode StartState { get; set; } + [Reactive] public Scale Scale { get; set; } = new Scale(); + [Reactive] public bool ItSaved { get; set; } = true; + [Reactive] public TypeMessage DisplayMessageType { get; set; } + [Reactive] public string SchemePath { get; set; } + + + + public int NodesCount = 0; + public double ScaleMax = 5; + public double ScaleMin = 0.1; + public double Scales { get; set; } = 0.05; + + + public ViewModelNodesCanvas() + { + SetupCommands(); + SetupStartState(); + Cutter = new ViewModelCutter(this); + this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); + + for (int i = 1; i <= 5; i++) + { + LogError("Error " + i.ToString()); + } + for (int i = 1; i <= 5; i++) + { + LogInformation("Information " + i.ToString()); + } + for (int i = 1; i <= 5; i++) + { + LogWarning("Warning " + i.ToString()); + } + for (int i = 1; i <= 5; i++) + { + LogDebug("Debug " + i.ToString()); + } + + } + public readonly object lockNodes = new object(); + public readonly object lockConnects = new object(); + + #region Setup Nodes + + private void SetupStartState() + { + string name = Nodes.Any(x => x.Name == "Start") ? GetNameForNewNode() : "Start"; + StartState = new ViewModelNode(this) + { + Name = name + }; + SetAsStart(StartState); + Nodes.Add(StartState); + this.ItSaved = true; + //ViewModelNode end = new ViewModelNode(this) + //{ + // Name = "End", + // NameEnable = false, + // CanBeDelete = false, + // Point1 = new MyPoint(100, 100) + //}; + //end.TransitionsVisible = null; + //end.RollUpVisible = null; + //Nodes.Add(end); + } + private void SetAsStart(ViewModelNode node) + { + node.Input.Visible = false; + node.CanBeDelete = false; + } + + #endregion Setup Nodes + + + #region Logging + + public void LogDebug(string message) + { + Messages.Add(new ViewModelMessage(TypeMessage.Debug, message)); + } + public void LogError(string message) + { + Messages.Add(new ViewModelMessage(TypeMessage.Error, message)); + } + public void LogInformation(string message) + { + Messages.Add(new ViewModelMessage(TypeMessage.Information, message)); + } + public void LogWarning(string message) + { + Messages.Add(new ViewModelMessage(TypeMessage.Warning, message)); + } + + #endregion Logging + + private void UpdateCount(int count) + { + if (count > NodesCount) + { + NodesCount = count; + } + } + private string SchemeName() + { + if (!string.IsNullOrEmpty(this.SchemePath)) + { + return Path.GetFileNameWithoutExtension(this.SchemePath); + } + else + { + return "SimpleStateMachine"; + } + } + } +} diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs similarity index 72% rename from SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs rename to SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index 54145d7..2e7303b 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -1,118 +1,33 @@ -using System; -using System.Linq; -using System.Collections.Generic; -using System.Reactive.Linq; - +using DynamicData; using ReactiveUI; -using ReactiveUI.Fody.Helpers; - -using DynamicData; -using DynamicData.Binding; - using SimpleStateMachineNodeEditor.Helpers; using SimpleStateMachineNodeEditor.Helpers.Commands; -using SimpleStateMachineNodeEditor.Helpers.Transformations; -using System.IO; -using System.Windows.Data; -using System.Xml.Linq; using SimpleStateMachineNodeEditor.Helpers.Enums; -using System.Windows.Media; -using System.Windows; -using System.Windows.Input; -using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; -using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reactive; +using System.Reactive.Linq; using System.Threading; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Input; +using System.Xml.Linq; -namespace SimpleStateMachineNodeEditor.ViewModel +namespace SimpleStateMachineNodeEditor.ViewModel.NodesCanvas { - public class ViewModelNodesCanvas : ReactiveObject + public partial class ViewModelNodesCanvas { - public ObservableCollectionExtended Connects = new ObservableCollectionExtended(); - public ObservableCollectionExtended Nodes = new ObservableCollectionExtended(); - public ObservableCollectionExtended Messages { get; set; } = new ObservableCollectionExtended(); - - [Reactive] public ViewModelSelector Selector { get; set; } = new ViewModelSelector(); - [Reactive] public ViewModelCutter Cutter { get; set; } - [Reactive] public ViewModelConnect DraggedConnect { get; set; } - [Reactive] public ViewModelConnector ConnectorPreviewForDrop { get; set; } - [Reactive] public ViewModelNode StartState { get; set; } - [Reactive] public bool ItSaved { get; set; } = true; - [Reactive] public string Path { get; set; } - - [Reactive] public TypeMessage DisplayMessageType { get; set; } - - - public int NodesCount = 0; - public double ScaleMax = 5; - public double ScaleMin = 0.1; - public double Scales { get; set; } = 0.05; - [Reactive] public Scale Scale { get; set; } = new Scale(); - - public ViewModelNodesCanvas() - { - SetupCommands(); - SetupStartState(); - Cutter = new ViewModelCutter(this); - this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); - - for (int i = 1; i <= 5; i++) - { - LogError("Error " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogInformation("Information " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogWarning("Warning " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogDebug("Debug " + i.ToString()); - } - - } - - #region Setup Nodes - private void SetupStartState() - { - string name = Nodes.Any(x => x.Name == "Start")? GetNameForNewNode() : "Start"; - StartState = new ViewModelNode(this) - { - Name = name - }; - SetAsStart(StartState); - Nodes.Add(StartState); - this.ItSaved = true; - //ViewModelNode end = new ViewModelNode(this) - //{ - // Name = "End", - // NameEnable = false, - // CanBeDelete = false, - // Point1 = new MyPoint(100, 100) - //}; - //end.TransitionsVisible = null; - //end.RollUpVisible = null; - //Nodes.Add(end); - } - private void SetAsStart(ViewModelNode node) - { - node.Input.Visible = false; - node.CanBeDelete = false; - } - - #endregion Setup Nodes - - #region Setup Commands - public ReactiveCommand CommandNewScheme { get; set; } - public ReactiveCommand CommandRedo { get; set; } - public ReactiveCommand CommandUndo { get; set; } + #region commands without parameter + public ReactiveCommand CommandNewScheme { get; set; } + public ReactiveCommand CommandRedo { get; set; } + public ReactiveCommand CommandUndo { get; set; } public ReactiveCommand CommandSelectAll { get; set; } - public ReactiveCommand CommandUnSelectAll { get; set; } - public ReactiveCommand CommandSelectorIntersect { get; set; } - public ReactiveCommand CommandCutterIntersect { get; set; } + public ReactiveCommand CommandUnSelectAll { get; set; } + public ReactiveCommand CommandSelectorIntersect { get; set; } + public ReactiveCommand CommandCutterIntersect { get; set; } public ReactiveCommand CommandDeleteDraggedConnect { get; set; } public ReactiveCommand CommandZoomIn { get; set; } public ReactiveCommand CommandZoomOut { get; set; } @@ -123,24 +38,18 @@ private void SetAsStart(ViewModelNode node) public ReactiveCommand CommandExpandDownSelected { get; set; } public ReactiveCommand CommandErrorListUpdate { get; set; } + #endregion commands without parameter + #region commands with parameter - //public ReactiveCommand CommandAddConnect { get; set; } public ReactiveCommand CommandAddConnect { get; set; } public ReactiveCommand CommandDeleteConnect { get; set; } - //public ReactiveCommand<(int connectorIndex, ViewModelConnect connect)> CommandAddConnectWithConnector { get; set; } - //public ReactiveCommand CommandDeleteConnectWithConnector { get; set; } - public ReactiveCommand CommandAddDraggedConnect { get; set; } - public ReactiveCommand<(ViewModelNode objectForValidate, string newValue), Unit> CommandValidateNodeName { get; set; } public ReactiveCommand<(ViewModelConnector objectForValidate, string newValue), Unit> CommandValidateConnectName { get; set; } - public ReactiveCommand CommandZoom { get; set; } public ReactiveCommand CommandSelect { get; set; } public ReactiveCommand CommandCut { get; set; } - //public ReactiveCommand CommandPartMoveAllNode { get; set; } - //public ReactiveCommand CommandPartMoveAllSelectedNode { get; set; } public ReactiveCommand CommandPartMoveAllNode { get; set; } public ReactiveCommand CommandPartMoveAllSelectedNode { get; set; } public ReactiveCommand CommandLogDebug { get; set; } @@ -150,10 +59,11 @@ private void SetAsStart(ViewModelNode node) public ReactiveCommand CommandSave { get; set; } public ReactiveCommand CommandOpen { get; set; } + #endregion commands with parameter + #region commands with undo-redo - //public Command CommandAddConnectWithUndoRedo { get; set; } - public Command CommandAddConnectorWithConnect {get; set; } + public Command CommandAddConnectorWithConnect { get; set; } public Command> CommandFullMoveAllNode { get; set; } public Command> CommandFullMoveAllSelectedNode { get; set; } public Command CommandAddNodeWithUndoRedo { get; set; } @@ -161,16 +71,18 @@ private void SetAsStart(ViewModelNode node) public Command, List<(int index, ViewModelConnector element)>> CommandDeleteSelectedConnectors { get; set; } public Command CommandDeleteSelectedElements { get; set; } + #endregion commands with undo-redo + private void SetupCommands() { + CommandRedo = ReactiveCommand.Create(ICommandWithUndoRedo.Redo); CommandUndo = ReactiveCommand.Create(ICommandWithUndoRedo.Undo); - //CommandSelectAll = new SimpleCommand(SelectedAll); CommandSelectAll = ReactiveCommand.Create(SelectedAll); CommandUnSelectAll = ReactiveCommand.Create(UnSelectedAll); CommandSelectorIntersect = ReactiveCommand.Create(SelectNodes); CommandCutterIntersect = ReactiveCommand.Create(SelectConnects); - CommandZoomIn = ReactiveCommand.Create(()=> { Scale.Value += Scales;}); + CommandZoomIn = ReactiveCommand.Create(() => { Scale.Value += Scales; }); CommandZoomOut = ReactiveCommand.Create(() => { Scale.Value -= Scales; }); CommandZoomOriginalSize = ReactiveCommand.Create(() => { Scale.Value = 1; }); CommandCollapseUpAll = ReactiveCommand.Create(CollapseUpAll); @@ -182,9 +94,7 @@ private void SetupCommands() CommandValidateNodeName = ReactiveCommand.Create<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName); CommandValidateConnectName = ReactiveCommand.Create<(ViewModelConnector objectForValidate, string newValue)>(ValidateConnectName); - //CommandAddConnect = ReactiveCommand.Create(AddConnect, NotSaved); - - CommandAddConnect = ReactiveCommand.Create< ViewModelConnect>(AddConnect); + CommandAddConnect = ReactiveCommand.Create(AddConnect); CommandDeleteConnect = ReactiveCommand.Create(DeleteConnect); CommandZoom = ReactiveCommand.Create(Zoom); CommandLogDebug = ReactiveCommand.Create(LogDebug); @@ -196,11 +106,9 @@ private void SetupCommands() CommandAddDraggedConnect = ReactiveCommand.Create(AddDraggedConnect); CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect); CommandSave = ReactiveCommand.Create(Save); - CommandOpen = ReactiveCommand.CreateFromTask(OpenAsync); - CommandNewScheme = ReactiveCommand.Create(NewScheme); - //CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); - //CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); + CommandOpen = ReactiveCommand.Create(Open); + CommandNewScheme = ReactiveCommand.Create(NewScheme); CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); @@ -209,56 +117,32 @@ private void SetupCommands() CommandFullMoveAllSelectedNode = new Command>(FullMoveAllSelectedNode, UnFullMoveAllSelectedNode, NotSaved); CommandAddConnectorWithConnect = new Command(AddConnectorWithConnect, DeleteConnectorWithConnect, NotSaved); CommandAddNodeWithUndoRedo = new Command(AddNodeWithUndoRedo, DeleteNodeWithUndoRedo, NotSaved); - //CommandAddConnectWithUndoRedo = new Command(AddConnectWithUndoRedo, DeleteConnectWithUndoRedo, NotSaved); CommandDeleteSelectedNodes = new Command(DeleteSelectedNodes, UnDeleteSelectedNodes, NotSaved); CommandDeleteSelectedConnectors = new Command, List<(int index, ViewModelConnector connector)>>(DeleteSelectedConnectors, UnDeleteSelectedConnectors, NotSaved); CommandDeleteSelectedElements = new Command(DeleteSelectedElements, UnDeleteSelectedElements); } + private void NotSaved() { ItSaved = false; } - private void NotSavedSubscrube() { - CommandRedo.Subscribe(_=> NotSaved()); + CommandRedo.Subscribe(_ => NotSaved()); CommandUndo.Subscribe(_ => NotSaved()); CommandAddConnect.Subscribe(_ => NotSaved()); CommandDeleteConnect.Subscribe(_ => NotSaved()); } - #endregion Setup Commands - - #region Logging - - public void LogDebug(string message) - { - Messages.Add(new ViewModelMessage(TypeMessage.Debug, message)); - } - public void LogError(string message) - { - Messages.Add(new ViewModelMessage(TypeMessage.Error, message)); - } - public void LogInformation(string message) - { - Messages.Add(new ViewModelMessage(TypeMessage.Information, message)); - } - public void LogWarning(string message) - { - Messages.Add(new ViewModelMessage(TypeMessage.Warning, message)); - } - - #endregion Logging - - private void UpdateCount(int count) + private void SelectedAll() { - if (count > NodesCount) - NodesCount = count; + foreach (var node in Nodes) + { node.Selected = true; } } private void CollapseUpAll() { - foreach(var node in Nodes) + foreach (var node in Nodes) { node.IsCollapse = true; } @@ -272,11 +156,11 @@ private void ExpandDownAll() } private void ErrosUpdaate() { - Messages.RemoveMany(Messages.Where(x => x.TypeMessage == DisplayMessageType || DisplayMessageType==TypeMessage.All)); + Messages.RemoveMany(Messages.Where(x => x.TypeMessage == DisplayMessageType || DisplayMessageType == TypeMessage.All)); } private void CollapseUpSelected() { - foreach (var node in Nodes.Where(x=>x.Selected)) + foreach (var node in Nodes.Where(x => x.Selected)) { node.IsCollapse = true; } @@ -288,6 +172,55 @@ private void ExpandDownSelected() node.IsCollapse = false; } } + private void UnSelectedAll() + { + foreach (var node in Nodes) + { + node.Selected = false; + node.CommandUnSelectedAllConnectors.ExecuteWithSubscribe(); + } + } + private string GetNameForNewNode() + { + return "State " + NodesCount.ToString(); + } + private void SelectConnects() + { + MyPoint cutterStartPoint = Cutter.StartPoint / Scale.Value; + MyPoint cutterEndPoint = Cutter.EndPoint / Scale.Value; + + var connects = Connects.Where(x => MyUtils.CheckIntersectTwoRectangles(MyUtils.GetStartPointDiagonal(x.StartPoint, x.EndPoint), MyUtils.GetEndPointDiagonal(x.StartPoint, x.EndPoint), + MyUtils.GetStartPointDiagonal(cutterStartPoint, cutterEndPoint), MyUtils.GetEndPointDiagonal(cutterStartPoint, cutterEndPoint))); + foreach (var connect in Connects) + { + connect.FromConnector.Selected = false; + } + + foreach (var connect in connects) + { + connect.FromConnector.Selected = MyUtils.CheckIntersectCubicBezierCurveAndLine(connect.StartPoint, connect.Point1, connect.Point2, connect.EndPoint, cutterStartPoint, cutterEndPoint); + } + + } + private void SelectNodes() + { + MyPoint selectorPoint1 = Selector.Point1WithScale / Scale.Value; + MyPoint selectorPoint2 = Selector.Point2WithScale / Scale.Value; + + foreach (ViewModelNode node in Nodes) + { + node.Selected = MyUtils.CheckIntersectTwoRectangles(node.Point1, node.Point2, selectorPoint1, selectorPoint2); + } + } + private void NewScheme() + { + this.Nodes.Clear(); + this.Connects.Clear(); + + this.SetupStartState(); + } + + private void StartSelect(MyPoint point) { Selector.CommandStartSelect.ExecuteWithSubscribe(point); @@ -296,19 +229,68 @@ private void StartCut(MyPoint point) { Cutter.CommandStartCut.ExecuteWithSubscribe(point); } - private void SelectedAll() + private void PartMoveAllNode(MyPoint delta) { foreach (var node in Nodes) - { node.Selected = true; } + { node.CommandMove.ExecuteWithSubscribe(delta); } } - private void UnSelectedAll() + private void PartMoveAllSelectedNode(MyPoint delta) { - foreach (var node in Nodes) + foreach (var node in Nodes.Where(x => x.Selected)) + { node.CommandMove.ExecuteWithSubscribe(delta); } + } + private void Zoom(int delta) + { + bool DeltaIsZero = (delta == 0); + bool DeltaMax = ((delta > 0) && (Scale.Value > ScaleMax)); + bool DeltaMin = ((delta < 0) && (Scale.Value < ScaleMin)); + if (DeltaIsZero || DeltaMax || DeltaMin) + return; + + Scale.Value += (delta > 0) ? Scales : -Scales; + } + private void AddDraggedConnect(ViewModelConnector fromConnector) + { + DraggedConnect = new ViewModelConnect(this, fromConnector); + + AddConnect(DraggedConnect); + } + private void DeleteDraggedConnect() + { + Connects.Remove(DraggedConnect); + DraggedConnect.FromConnector.Connect = null; + + } + private void AddConnect(ViewModelConnect ViewModelConnect) + { + Connects.Add(ViewModelConnect); + } + private void DeleteConnect(ViewModelConnect ViewModelConnect) + { + Connects.Remove(ViewModelConnect); + } + private void ValidateNodeName((ViewModelNode objectForValidate, string newValue) obj) + { + if (!String.IsNullOrWhiteSpace(obj.newValue)) { - node.Selected = false; - node.CommandUnSelectedAllConnectors.ExecuteWithSubscribe(); + if (!NodesExist(obj.newValue)) + { + obj.objectForValidate.Name = obj.newValue; + } + } + } + private void ValidateConnectName((ViewModelConnector objectForValidate, string newValue) obj) + { + if (!String.IsNullOrWhiteSpace(obj.newValue)) + { + if (!ConnectsExist(obj.newValue)) + { + obj.objectForValidate.Name = obj.newValue; + } } } + + private List FullMoveAllNode(MyPoint delta, List nodes = null) { MyPoint myPoint = delta.Copy(); @@ -347,20 +329,6 @@ private List UnFullMoveAllSelectedNode(MyPoint delta, List node.CommandMove.ExecuteWithSubscribe(myPoint)); return nodes; } - private void PartMoveAllNode(MyPoint delta) - { - foreach (var node in Nodes) - { node.CommandMove.ExecuteWithSubscribe(delta); } - } - private void PartMoveAllSelectedNode(MyPoint delta) - { - foreach (var node in Nodes.Where(x => x.Selected)) - { node.CommandMove.ExecuteWithSubscribe(delta); } - } - private string GetNameForNewNode() - { - return "State " + NodesCount.ToString(); - } private ViewModelNode AddNodeWithUndoRedo(MyPoint parameter, ViewModelNode result) { ViewModelNode newNode = result; @@ -382,62 +350,6 @@ private ViewModelNode DeleteNodeWithUndoRedo(MyPoint parameter, ViewModelNode re Nodes.Remove(result); return result; } - - private void Zoom(int delta) - { - bool DeltaIsZero = (delta == 0); - bool DeltaMax = ((delta > 0) && (Scale.Value > ScaleMax)); - bool DeltaMin = ((delta < 0) && (Scale.Value < ScaleMin)); - if (DeltaIsZero || DeltaMax || DeltaMin) - return; - - Scale.Value += (delta > 0) ? Scales : -Scales; - } - private void SelectConnects() - { - MyPoint cutterStartPoint = Cutter.StartPoint / Scale.Value; - MyPoint cutterEndPoint = Cutter.EndPoint / Scale.Value; - - //MyPoint cutterStartPoint = Cutter.StartPoint; - //MyPoint cutterEndPoint = Cutter.EndPoint; - //some optimizations - var connects = Connects.Where(x => MyUtils.CheckIntersectTwoRectangles(MyUtils.GetStartPointDiagonal(x.StartPoint, x.EndPoint), MyUtils.GetEndPointDiagonal(x.StartPoint, x.EndPoint), - MyUtils.GetStartPointDiagonal(cutterStartPoint, cutterEndPoint), MyUtils.GetEndPointDiagonal(cutterStartPoint, cutterEndPoint))); - //var connects = Connects; - foreach (var connect in Connects) - { - connect.FromConnector.Selected = false; - } - - foreach (var connect in connects) - { - connect.FromConnector.Selected = MyUtils.CheckIntersectCubicBezierCurveAndLine(connect.StartPoint, connect.Point1, connect.Point2, connect.EndPoint, cutterStartPoint, cutterEndPoint); - } - - } - private void SelectNodes() - { - MyPoint selectorPoint1 = Selector.Point1WithScale / Scale.Value; - MyPoint selectorPoint2 = Selector.Point2WithScale / Scale.Value; - - foreach (ViewModelNode node in Nodes) - { - node.Selected = MyUtils.CheckIntersectTwoRectangles(node.Point1, node.Point2, selectorPoint1, selectorPoint2); - } - } - - private void AddDraggedConnect(ViewModelConnector fromConnector) - { - DraggedConnect = new ViewModelConnect(this, fromConnector); - - AddConnect(DraggedConnect); - } - private void DeleteDraggedConnect() - { - Connects.Remove(DraggedConnect); - DraggedConnect.FromConnector.Connect = null; - - } private ViewModelConnector AddConnectorWithConnect(ViewModelConnector parameter, ViewModelConnector result) { if (result == null) @@ -450,42 +362,18 @@ private ViewModelConnector DeleteConnectorWithConnect(ViewModelConnector paramet result.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(result); return parameter; } - - //private ViewModelConnect AddConnectWithUndoRedo(ViewModelConnect parameter, ViewModelConnect result) - //{ - // if (result == null) - // return parameter; - // result.FromConnector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((1, result.FromConnector)); - // return result; - //} - //private ViewModelConnect DeleteConnectWithUndoRedo(ViewModelConnect parameter, ViewModelConnect result) - //{ - // result.FromConnector.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(result.FromConnector); - // return parameter; - //} - - - private void AddConnect(ViewModelConnect ViewModelConnect) - { - Connects.Add(ViewModelConnect); - } - private void DeleteConnect(ViewModelConnect ViewModelConnect) - { - Connects.Remove(ViewModelConnect); - } - private DeleteMode DeleteSelectedElements(DeleteMode parameter, DeleteMode result) - { - if(result==DeleteMode.noCorrect) + { + if (result == DeleteMode.noCorrect) { bool keyN = Keyboard.IsKeyDown(Key.N); bool keyC = Keyboard.IsKeyDown(Key.C); - if(keyN == keyC) + if (keyN == keyC) { result = DeleteMode.DeleteAllSelected; } - else if(keyN) + else if (keyN) { result = DeleteMode.DeleteNodes; } @@ -496,9 +384,9 @@ private DeleteMode DeleteSelectedElements(DeleteMode parameter, DeleteMode resul } - if ((result == DeleteMode.DeleteConnects)|| (result == DeleteMode.DeleteAllSelected)) + if ((result == DeleteMode.DeleteConnects) || (result == DeleteMode.DeleteAllSelected)) { - CommandDeleteSelectedConnectors.Execute(null); + CommandDeleteSelectedConnectors.Execute(null); } if ((result == DeleteMode.DeleteNodes) || (result == DeleteMode.DeleteAllSelected)) { @@ -511,15 +399,16 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res { int count = 0; - if((result == DeleteMode.DeleteNodes)|| (result == DeleteMode.DeleteConnects)) + if ((result == DeleteMode.DeleteNodes) || (result == DeleteMode.DeleteConnects)) { count = 1; - }else if (result == DeleteMode.DeleteAllSelected) + } + else if (result == DeleteMode.DeleteAllSelected) { count = 2; } - for (int i = 0;i< count; i++) + for (int i = 0; i < count; i++) { CommandUndo.ExecuteWithSubscribe(); } @@ -530,9 +419,9 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res if (result == null) { result = new List<(int index, ViewModelConnector element)>(); - foreach(var connector in GetAllConnectors().Where(x=>x.Selected)) + foreach (var connector in GetAllConnectors().Where(x => x.Selected)) { - result.Add((connector.Node.GetConnectorIndex(connector), connector)); + result.Add((connector.Node.GetConnectorIndex(connector), connector)); } } foreach (var element in result) @@ -543,7 +432,7 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res } private List<(int index, ViewModelConnector connector)> UnDeleteSelectedConnectors(List<(int index, ViewModelConnector connector)> parameter, List<(int index, ViewModelConnector connector)> result) { - foreach(var element in result) + foreach (var element in result) { element.connector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((element.index, element.connector)); } @@ -559,26 +448,26 @@ private ElementsForDelete DeleteSelectedNodes(ElementsForDelete parameter, Eleme result.ConnectsToDelete = new List(); result.ConnectsToDeleteWithConnectors = new List<(int connectorIndex, ViewModelConnect connect)>(); - foreach(var connect in Connects) + foreach (var connect in Connects) { - if(result.NodesToDelete.Contains(connect.FromConnector.Node)) + if (result.NodesToDelete.Contains(connect.FromConnector.Node)) { result.ConnectsToDelete.Add(connect); } - else if(result.NodesToDelete.Contains(connect.ToConnector.Node)) + else if (result.NodesToDelete.Contains(connect.ToConnector.Node)) { result.ConnectsToDeleteWithConnectors.Add((connect.FromConnector.Node.GetConnectorIndex(connect.FromConnector), connect)); } } } - foreach(var element in result.ConnectsToDeleteWithConnectors) + foreach (var element in result.ConnectsToDeleteWithConnectors) { element.connect.FromConnector.Node.CommandDeleteConnectorWithConnect.ExecuteWithSubscribe(element.connect.FromConnector); } Connects.RemoveMany(result.ConnectsToDelete); Nodes.RemoveMany(result.NodesToDelete); - + return result; } private ElementsForDelete UnDeleteSelectedNodes(ElementsForDelete parameter, ElementsForDelete result) @@ -594,72 +483,38 @@ private ElementsForDelete UnDeleteSelectedNodes(ElementsForDelete parameter, Ele return result; } - private void ValidateNodeName((ViewModelNode objectForValidate, string newValue) obj) - { - if (!String.IsNullOrWhiteSpace(obj.newValue)) - { - if (!NodeExist(obj.newValue)) - { - obj.objectForValidate.Name = obj.newValue; - } - } - } - private void ValidateConnectName((ViewModelConnector objectForValidate, string newValue) obj) - { - if (!String.IsNullOrWhiteSpace(obj.newValue)) - { - if (!ConnectExist(obj.newValue)) - { - obj.objectForValidate.Name = obj.newValue; - } - } - } private IEnumerable GetAllConnectors() { return this.Nodes.SelectMany(x => x.Transitions); } - private bool ConnectExist(string nameConnect) - { - return GetAllConnectors().Any(x=>x.Name == nameConnect); - } - private bool NodeExist(string nameNode) + private bool ConnectsExist(string nameConnect) { - return Nodes.Any(x => x.Name == nameNode); + return GetAllConnectors().Any(x => x.Name == nameConnect); } - - private void NewScheme() + private bool NodesExist(string nameNode) { - this.Nodes.Clear(); - this.Connects.Clear(); - - this.SetupStartState(); + return Nodes.Any(x => x.Name == nameNode); } - private async Task OpenAsync(string fileName) + private void Open(string fileName) { this.Nodes.Clear(); this.Connects.Clear(); - XDocument xDocument; - - using (var stream = File.Open(fileName, FileMode.Open)) - { - xDocument = await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None); - } + XDocument xDocument = XDocument.Load(fileName); XElement stateMachineXElement = xDocument.Element("StateMachine"); - if (stateMachineXElement == null) { Error("not contanins StateMachine"); return; } - #region setup states/nodes + var States = stateMachineXElement.Element("States")?.Elements()?.ToList() ?? new List(); ViewModelNode viewModelNode = null; foreach (var state in States) { - viewModelNode = ViewModelNode.FromXElement(this, state, out string errorMesage, NodeExist); + viewModelNode = ViewModelNode.FromXElement(this, state, out string errorMesage, NodesExist); if (WithError(errorMesage, x => Nodes.Add(x), viewModelNode)) return; } @@ -683,11 +538,11 @@ private async Task OpenAsync(string fileName) ViewModelConnect viewModelConnect; foreach (var transition in Transitions) { - viewModelConnect = ViewModelConnector.FromXElement(this, transition, out string errorMesage, ConnectExist); + viewModelConnect = ViewModelConnector.FromXElement(this, transition, out string errorMesage, ConnectsExist); if (WithError(errorMesage, x => Connects.Add(x), viewModelConnect)) return; } - Path = fileName; + SchemePath = fileName; #endregion setup Transitions/connects @@ -738,7 +593,7 @@ private void Save(string fileName) xDocument.Save(fileName); ItSaved = true; - Path = fileName; + SchemePath = fileName; } public class ElementsForDelete diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs index bae3ded..05e5ef9 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs @@ -12,6 +12,7 @@ using System.Xml.Linq; using SimpleStateMachineNodeEditor.Helpers.Extensions; using SimpleStateMachineNodeEditor.Helpers.Commands; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel { diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs index 4355a4e..daee983 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs @@ -12,6 +12,9 @@ using SimpleStateMachineNodeEditor.Helpers.Enums; using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; +using System.Windows.Documents; +using System.Collections.Generic; namespace SimpleStateMachineNodeEditor.ViewModel { @@ -299,7 +302,7 @@ public XElement ToXElement() return element; } - public static ViewModelConnect FromXElement(ViewModelNodesCanvas nodesCanvas, XElement node, out string errorMessage, Func actionForCheck) + public static ViewModelConnect FromXElement(ViewModelNodesCanvas nodesCanvas,XElement node, out string errorMessage, Func actionForCheck) { ViewModelConnect viewModelConnect = null; diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs index f832e53..b8cf614 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs @@ -8,6 +8,7 @@ using SimpleStateMachineNodeEditor.Helpers; using SimpleStateMachineNodeEditor.Helpers.Commands; using System.Reactive; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel { diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs new file mode 100644 index 0000000..fa8adc4 --- /dev/null +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs @@ -0,0 +1,55 @@ +using ReactiveUI.Fody.Helpers; +using ReactiveUI.Validation.Helpers; +using SimpleStateMachineNodeEditor.Helpers.Enums; +using System.Windows; + +namespace SimpleStateMachineNodeEditor.ViewModel +{ + public class ViewModelDialog : ReactiveValidationObject + { + [Reactive] public bool? Visibility { get; set; } + [Reactive] public DialogType Type { get; set; } + [Reactive] public DialogResult Result { get; set; } + [Reactive] public string Title { get; set; } + + + [Reactive] public string MessageBoxText { get; set; } + [Reactive] public MessageBoxButton MessageBoxButtons{ get; set; } + + + [Reactive] public string FileDialogFilter { get; set; } + [Reactive] public string FileName { get; set; } + + private void Show() + { + Visibility = true; + } + public void ShowMessageBox(string messageBoxText, string caption, MessageBoxButton button) + { + MessageBoxText = messageBoxText; + MessageBoxButtons = button; + Type = DialogType.MessageBox; + Title = caption; + Show(); + } + + public void ShowOpenFileDialog(string filter, string fileName, string title) + { + FileDialogFilter = filter; + FileName = fileName; + Title = title; + Type = DialogType.OpenFileDialog; + Show(); + } + + public void ShowSaveFileDialog(string filter, string fileName, string title) + { + FileDialogFilter = filter; + FileName = fileName; + Title = title; + Type = DialogType.SaveFileDialog; + Show(); + } + + } +} diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs index 1e631b2..5fb5a6a 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs @@ -12,6 +12,7 @@ using System.Reactive.Linq; using System.Collections.ObjectModel; using System.Reactive; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel { diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs new file mode 100644 index 0000000..7770fa2 --- /dev/null +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs @@ -0,0 +1,33 @@ +using MvvmDialogs; +using ReactiveUI.Validation.Helpers; +using SimpleStateMachineNodeEditor.View; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SimpleStateMachineNodeEditor.ViewModel +{ + public class ViewModelModalDialog : ReactiveValidationObject + { + + private readonly IDialogService dialogService; + + public ViewModelModalDialog(IDialogService dialogService) + { + this.dialogService = dialogService; + } + + private void ShowDialog() + { + //dialogService.ShowMessageBox() + //var dialogViewModel = new AddTextDialogViewModel(); + + + //bool? success = dialogService.ShowDialog(this, dialogViewModel); + //if (success == true) + //{ + // Texts.Add(dialogViewModel.Text); + //} + } +} +} diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index 22c535c..93b3b74 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -18,6 +18,7 @@ using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; using System.Threading.Tasks; +using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel { @@ -46,7 +47,11 @@ public class ViewModelNode : ReactiveValidationObject public int TransitionsCount = -1; - + private ViewModelNode() + { + SetupCommands(); + //SetupBinding(); + } public ViewModelNode(ViewModelNodesCanvas nodesCanvas) @@ -273,7 +278,7 @@ public static ViewModelNode FromXElement(ViewModelNodesCanvas nodesCanvas, XElem viewModelNode.Name = name; var position = node.Attribute("Position")?.Value; - if(position!=null) + if (position != null) viewModelNode.Point1 = MyPoint.Parse(position); var isCollapse = node.Attribute("IsCollapse")?.Value; @@ -282,7 +287,37 @@ public static ViewModelNode FromXElement(ViewModelNodesCanvas nodesCanvas, XElem return viewModelNode; } + public static ViewModelNode FromXElement(XElement node) + { + //errorMessage = null; + ViewModelNode viewModelNode = null; + string name = node.Attribute("Name")?.Value; + + //if (string.IsNullOrEmpty(name)) + //{ + // errorMessage = "Node without name"; + // return viewModelNode; + //} + + //if (actionForCheck(name)) + //{ + // errorMessage = String.Format("Contains more than one node with name \"{0}\"", name); + // return viewModelNode; + //} + + viewModelNode = new ViewModelNode(); + viewModelNode.Name = name; + + var position = node.Attribute("Position")?.Value; + if (position != null) + viewModelNode.Point1 = MyPoint.Parse(position); + + var isCollapse = node.Attribute("IsCollapse")?.Value; + if (isCollapse != null) + viewModelNode.IsCollapse = bool.Parse(isCollapse); + return viewModelNode; + } //public static async Task<(ViewModelNode node, string message)> FromXElement(ViewModelNodesCanvas nodesCanvas, XElement node, Func actionForCheck) //{ // string errorMessage = null; From 93c343e772824e710517536e8b2041c074580a1c Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 16:55:22 +0300 Subject: [PATCH 04/17] work with dialog --- .../View/MainWindow.xaml | 32 +- .../View/MainWindow.xaml.cs | 173 ++++------- .../View/ViewDialog.xaml.cs | 3 +- .../View/ViewNodesCanvas.xaml.cs | 4 +- .../NodesCanvas/ViewModelNodesCanvas.cs | 7 +- .../ViewModelNodesCanvasCommands.cs | 279 +++++++++++------- .../ViewModel/ViewModelDialog.cs | 12 + 7 files changed, 250 insertions(+), 260 deletions(-) diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml b/SimpleStateMachineNodeEditor/View/MainWindow.xaml index 00d185b..05d8f45 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml @@ -44,7 +44,7 @@ - + @@ -104,10 +104,10 @@ - - - @@ -144,16 +144,6 @@ - - @@ -222,17 +212,11 @@ - + - - - - - + + + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index 54da9e6..87ed168 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -91,21 +91,46 @@ private void SetupBinding() this.OneWayBind(this.ViewModel, x => x.Messages, x => x.MessageList.ItemsSource).DisposeWith(disposable); - this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable); + this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo, x => x.ButtonUndo).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomIn, x => x.ButtonZoomIn).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOut, x => x.ButtonZoomOut).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOriginalSize, x => x.ButtonZoomOriginalSize).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandCollapseUpAll, x => x.ButtonCollapseUpAll).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExpandDownAll, x => x.ButtonExpandDownAll).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo , x => x.ItemUndo).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo , x => x.ItemUndo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo, x => x.ButtonUndo).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable); + + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ButtonExportToJPEG).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ItemExportToJPEG).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.BindingNew).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.ItemNew).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.ButtonNew).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.BindingOpen).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.ItemOpen).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.ButtonOpen).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.BindingSave).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.ItemSave).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.ButtonSave).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.BindingSaveAs).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.ItemSaveAs).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.ButtonSaveAs).DisposeWith(disposable); + + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.BindingExit).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.ItemExit).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.ButtonClose).DisposeWith(disposable); }); } #endregion Setup Binding @@ -117,8 +142,8 @@ private void SetupSubscriptions() this.WhenActivated(disposable => { this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable); - this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels()); - + this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels()).DisposeWith(disposable); + this.WhenAnyValue(x => x.NodesCanvas.ViewModel.NeedExit).Where(x=>x).Subscribe(_ => this.Close()).DisposeWith(disposable); }); } private void UpdateSchemeName(string newName) @@ -132,28 +157,15 @@ private void UpdateSchemeName(string newName) } #endregion Setup Subscriptions - #region SetupEvents private void SetupEvents() { this.WhenActivated(disposable => { - - this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable); - this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable); - - - this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable); - this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); + this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable); this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable); this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable); - this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable); - this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable); - this.ItemOpen.Events().Click.Subscribe(_ => WithoutSaving(Open)).DisposeWith(disposable); - this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable); - this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable); - this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable); this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); @@ -166,8 +178,8 @@ private void SetupEvents() this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable); }); } - - void UpdateLabels() + + private void UpdateLabels() { var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count()); @@ -177,26 +189,36 @@ void UpdateLabels() } } - void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage) + private void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage) { if ((ErrorListExpander.IsExpanded)&&(this.ViewModel.NodesCanvas.DisplayMessageType != typeMessage)) e.Handled = true; this.ViewModel.NodesCanvas.DisplayMessageType = typeMessage; } - void ErrorListCollapse() + private void ErrorListCollapse() { this.ErrorListSplitter.IsEnabled = false; this.Fotter.Height = new GridLength(); } - void ErrorListExpanded() + private void ErrorListExpanded() { this.ErrorListSplitter.IsEnabled = true; this.Fotter.Height = new GridLength(this.ViewModel.MaxHeightMessagePanel); } - void StateNormalMaximaze() + + + private void ButtonMinClick(RoutedEventArgs e) { - if(this.WindowState == WindowState.Normal) + this.WindowState = WindowState.Minimized; + } + private void ButtonMaxClick(RoutedEventArgs e) + { + StateNormalMaximaze(); + } + private void StateNormalMaximaze() + { + if (this.WindowState == WindowState.Normal) { this.WindowState = WindowState.Maximized; this.ButtonMaxRectangle.Fill = System.Windows.Application.Current.Resources["IconRestore"] as DrawingBrush; @@ -209,19 +231,6 @@ void StateNormalMaximaze() this.ButtonMaxRectangle.ToolTip = "Restore down"; } } - void ButtonCloseClick() - { - this.Close(); - } - void ButtonMinClick(RoutedEventArgs e) - { - this.WindowState = WindowState.Minimized; - } - void ButtonMaxClick(RoutedEventArgs e) - { - StateNormalMaximaze(); - } - private void HeaderClick(MouseButtonEventArgs e) { if (e.OriginalSource is DockPanel) @@ -254,86 +263,6 @@ private void HeaderClick(MouseButtonEventArgs e) } } - void ExportToImage(ImageFormats format) - { - SaveFileDialog dlg = new SaveFileDialog(); - - dlg.FileName = SchemeName(); - dlg.Filter = (format == ImageFormats.JPEG)? "JPEG Image (.jpeg)|*.jpeg":"Png Image (.png)|*.png"; - - System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); - if(dialogResult==System.Windows.Forms.DialogResult.OK) - { - this.NodesCanvas.SaveCanvasToImage(dlg.FileName, format); - } - } - void New() - { - this.NodesCanvas.ViewModel.CommandNewScheme.ExecuteWithSubscribe(); - } - void WithoutSaving(Action action) - { - var result = MessageBoxResult.Yes; - if (!this.NodesCanvas.ViewModel.ItSaved) - { - result = System.Windows.MessageBox.Show("Exit without saving ?", "Test", MessageBoxButton.YesNo); - } - - if (result == MessageBoxResult.Yes) - action.Invoke(); - } - - void Save() - { - if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath)) - { - SaveAs(); - } - else - { - this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.SchemePath); - } - } - void SaveAs() - { - SaveFileDialog dlg = new SaveFileDialog(); - dlg.FileName = SchemeName(); - dlg.Filter = "XML-File | *.xml"; - - System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); - if (dialogResult == System.Windows.Forms.DialogResult.OK) - { - Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; - this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(dlg.FileName); - Mouse.OverrideCursor = null; - } - } - private string SchemeName() - { - if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath)) - { - return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.SchemePath); - } - else - { - return "SimpleStateMachine"; - } - } - private void Open() - { - OpenFileDialog dlg = new OpenFileDialog(); - dlg.FileName = SchemeName(); - dlg.Filter = "XML-File | *.xml"; - - System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog(); - if (dialogResult == System.Windows.Forms.DialogResult.OK) - { - Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; - this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName); - Mouse.OverrideCursor = null; - } - - } #endregion SetupEvents diff --git a/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs index dbf86c7..66c234c 100644 --- a/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs @@ -47,8 +47,7 @@ private void SetupSubcriptions() { this.WhenActivated(disposable => { - this.WhenAnyValue(x => x.Visibility).ObserveOn(RxApp.MainThreadScheduler). - Where(x => x == Visibility.Visible).Subscribe(_ => Show()).DisposeWith(disposable); + this.WhenAnyValue(x => x.Visibility).Where(x => x == Visibility.Visible).Subscribe(_ => Show()).DisposeWith(disposable); }); } private void Show() diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs index 3594621..b782416 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs @@ -123,6 +123,8 @@ private void SetupCommands() this.WhenAnyValue(x => x.ViewModel.Selector.Size).WithoutParameter().InvokeCommand(ViewModel,x=>x.CommandSelectorIntersect).DisposeWith(disposable); this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint.Value).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandCutterIntersect).DisposeWith(disposable); + this.WhenAnyValue(x => x.ViewModel.JPEGPath).Where(x=>!string.IsNullOrEmpty(x)).Subscribe(value=> SaveCanvasToImage(value, ImageFormats.JPEG)).DisposeWith(disposable); + }); } #endregion Setup Commands @@ -283,7 +285,7 @@ private MyPoint GetDeltaDragOver(DragEventArgs e) return result; } - public void SaveCanvasToImage(string filename, ImageFormats format) + private void SaveCanvasToImage(string filename, ImageFormats format) { MyUtils.PanelToImage(this.Canvas, filename, format); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs index 8b2741f..61fdd39 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs @@ -28,8 +28,13 @@ public partial class ViewModelNodesCanvas : ReactiveObject [Reactive] public bool ItSaved { get; set; } = true; [Reactive] public TypeMessage DisplayMessageType { get; set; } [Reactive] public string SchemePath { get; set; } - + /// + /// Flag for close application + /// + [Reactive] public bool NeedExit { get; set; } + + [Reactive] public string JPEGPath{ get; set; } public int NodesCount = 0; public double ScaleMax = 5; diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index 2e7303b..d901d56 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -12,6 +12,7 @@ using System.Reactive.Linq; using System.Threading; using System.Threading.Tasks; +using System.Windows; using System.Windows.Data; using System.Windows.Input; using System.Xml.Linq; @@ -21,7 +22,7 @@ namespace SimpleStateMachineNodeEditor.ViewModel.NodesCanvas public partial class ViewModelNodesCanvas { #region commands without parameter - public ReactiveCommand CommandNewScheme { get; set; } + public ReactiveCommand CommandNew { get; set; } public ReactiveCommand CommandRedo { get; set; } public ReactiveCommand CommandUndo { get; set; } public ReactiveCommand CommandSelectAll { get; set; } @@ -37,6 +38,11 @@ public partial class ViewModelNodesCanvas public ReactiveCommand CommandCollapseUpSelected { get; set; } public ReactiveCommand CommandExpandDownSelected { get; set; } public ReactiveCommand CommandErrorListUpdate { get; set; } + public ReactiveCommand CommandExportToJPEG { get; set; } + public ReactiveCommand CommandOpen { get; set; } + public ReactiveCommand CommandSave { get; set; } + public ReactiveCommand CommandSaveAs { get; set; } + public ReactiveCommand CommandExit { get; set; } #endregion commands without parameter @@ -56,8 +62,6 @@ public partial class ViewModelNodesCanvas public ReactiveCommand CommandLogError { get; set; } public ReactiveCommand CommandLogInformation { get; set; } public ReactiveCommand CommandLogWarning { get; set; } - public ReactiveCommand CommandSave { get; set; } - public ReactiveCommand CommandOpen { get; set; } #endregion commands with parameter @@ -90,7 +94,12 @@ private void SetupCommands() CommandCollapseUpSelected = ReactiveCommand.Create(CollapseUpSelected); CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected); CommandErrorListUpdate = ReactiveCommand.Create(ErrosUpdaate); - + CommandExportToJPEG = ReactiveCommand.Create(ExportToJPEG); + CommandOpen = ReactiveCommand.Create(Open); + CommandSave = ReactiveCommand.Create(Save); + CommandSaveAs = ReactiveCommand.Create(SaveAs); + CommandExit = ReactiveCommand.Create(Exit); + CommandValidateNodeName = ReactiveCommand.Create<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName); CommandValidateConnectName = ReactiveCommand.Create<(ViewModelConnector objectForValidate, string newValue)>(ValidateConnectName); @@ -105,10 +114,8 @@ private void SetupCommands() CommandCut = ReactiveCommand.Create(StartCut); CommandAddDraggedConnect = ReactiveCommand.Create(AddDraggedConnect); CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect); - CommandSave = ReactiveCommand.Create(Save); - CommandOpen = ReactiveCommand.Create(Open); - - CommandNewScheme = ReactiveCommand.Create(NewScheme); + + CommandNew = ReactiveCommand.Create(NewScheme); CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); @@ -121,6 +128,7 @@ private void SetupCommands() CommandDeleteSelectedConnectors = new Command, List<(int index, ViewModelConnector connector)>>(DeleteSelectedConnectors, UnDeleteSelectedConnectors, NotSaved); CommandDeleteSelectedElements = new Command(DeleteSelectedElements, UnDeleteSelectedElements); + NotSavedSubscrube(); } private void NotSaved() @@ -133,7 +141,6 @@ private void NotSavedSubscrube() CommandUndo.Subscribe(_ => NotSaved()); CommandAddConnect.Subscribe(_ => NotSaved()); CommandDeleteConnect.Subscribe(_ => NotSaved()); - } private void SelectedAll() { @@ -212,6 +219,14 @@ private void SelectNodes() node.Selected = MyUtils.CheckIntersectTwoRectangles(node.Point1, node.Point2, selectorPoint1, selectorPoint2); } } + private void ExportToJPEG() + { + Dialog.ShowSaveFileDialog("JPEG Image (.jpeg)|*.jpeg", SchemeName(), "Export scheme"); + if (Dialog.Result != DialogResult.Ok) + return; + //"Png Image (.png)|*.png"; + JPEGPath = Dialog.FileName; + } private void NewScheme() { this.Nodes.Clear(); @@ -219,6 +234,139 @@ private void NewScheme() this.SetupStartState(); } + private void Open() + { + if (!WithoutSaving()) + return; + + Dialog.ShowOpenFileDialog("XML-File | *.xml", SchemeName(), "Import scheme"); + if (Dialog.Result != DialogResult.Ok) + return; + + string fileName = Dialog.FileName; + //string fileName = @"C:\Users\roman\Downloads\100 States.xml"; + this.Nodes.Clear(); + this.Connects.Clear(); + + XDocument xDocument = XDocument.Load(fileName); + XElement stateMachineXElement = xDocument.Element("StateMachine"); + if (stateMachineXElement == null) + { + Error("not contanins StateMachine"); + return; + } + #region setup states/nodes + + var States = stateMachineXElement.Element("States")?.Elements()?.ToList() ?? new List(); + ViewModelNode viewModelNode = null; + foreach (var state in States) + { + viewModelNode = ViewModelNode.FromXElement(this, state, out string errorMesage, NodesExist); + if (WithError(errorMesage, x => Nodes.Add(x), viewModelNode)) + return; + } + + #region setup start state + + var startState = stateMachineXElement.Element("StartState")?.Attribute("Name")?.Value; + + if (string.IsNullOrEmpty(startState)) + this.SetupStartState(); + else + this.SetAsStart(this.Nodes.Single(x => x.Name == startState)); + + #endregion setup start state + + #endregion setup states/nodes + + #region setup Transitions/connects + + var Transitions = stateMachineXElement.Element("Transitions")?.Elements()?.ToList() ?? new List(); + ViewModelConnect viewModelConnect; + foreach (var transition in Transitions) + { + viewModelConnect = ViewModelConnector.FromXElement(this, transition, out string errorMesage, ConnectsExist); + if (WithError(errorMesage, x => Connects.Add(x), viewModelConnect)) + return; + } + SchemePath = fileName; + #endregion setup Transitions/connects + + + + bool WithError(string errorMessage, Action action, T obj) + { + if (string.IsNullOrEmpty(errorMessage)) + { + if (!object.Equals(obj, default(T))) + action.Invoke(obj); + } + else + { + Error(errorMessage); + return true; + } + return false; + } + void Error(string errorMessage) + { + LogError("File is not valid: " + errorMessage); + NewScheme(); + } + } + private void Save() + { + if (string.IsNullOrEmpty(SchemePath)) + { + SaveAs(); + } + else + { + Save(SchemePath); + } + } + private void Exit() + { + if (!WithoutSaving()) + return; + this.NeedExit = true; + } + private void SaveAs() + { + Dialog.ShowSaveFileDialog("XML-File | *.xml", SchemeName(), "Save scheme"); + if (Dialog.Result != DialogResult.Ok) + return; + + Save(Dialog.FileName); + } + private void Save(string fileName) + { + XDocument xDocument = new XDocument(); + XElement stateMachineXElement = new XElement("StateMachine"); + xDocument.Add(stateMachineXElement); + XElement states = new XElement("States"); + stateMachineXElement.Add(states); + foreach (var state in Nodes) + { + states.Add(state.ToXElement()); + } + + XElement startState = new XElement("StartState"); + stateMachineXElement.Add(startState); + startState.Add(new XAttribute("Name", StartState.Name)); + + + XElement transitions = new XElement("Transitions"); + stateMachineXElement.Add(transitions); + foreach (var transition in Nodes.SelectMany(x => x.Transitions.Where(y => !string.IsNullOrEmpty(y.Name))).Reverse()) + { + transitions.Add(transition.ToXElement()); + } + + xDocument.Save(fileName); + ItSaved = true; + SchemePath = fileName; + } private void StartSelect(MyPoint point) @@ -482,7 +630,6 @@ private ElementsForDelete UnDeleteSelectedNodes(ElementsForDelete parameter, Ele return result; } - private IEnumerable GetAllConnectors() { return this.Nodes.SelectMany(x => x.Transitions); @@ -496,106 +643,6 @@ private bool NodesExist(string nameNode) { return Nodes.Any(x => x.Name == nameNode); } - private void Open(string fileName) - { - this.Nodes.Clear(); - this.Connects.Clear(); - - XDocument xDocument = XDocument.Load(fileName); - XElement stateMachineXElement = xDocument.Element("StateMachine"); - if (stateMachineXElement == null) - { - Error("not contanins StateMachine"); - return; - } - #region setup states/nodes - - var States = stateMachineXElement.Element("States")?.Elements()?.ToList() ?? new List(); - ViewModelNode viewModelNode = null; - foreach (var state in States) - { - viewModelNode = ViewModelNode.FromXElement(this, state, out string errorMesage, NodesExist); - if (WithError(errorMesage, x => Nodes.Add(x), viewModelNode)) - return; - } - - #region setup start state - - var startState = stateMachineXElement.Element("StartState")?.Attribute("Name")?.Value; - - if (string.IsNullOrEmpty(startState)) - this.SetupStartState(); - else - this.SetAsStart(this.Nodes.Single(x => x.Name == startState)); - - #endregion setup start state - - #endregion setup states/nodes - - #region setup Transitions/connects - - var Transitions = stateMachineXElement.Element("Transitions")?.Elements()?.ToList() ?? new List(); - ViewModelConnect viewModelConnect; - foreach (var transition in Transitions) - { - viewModelConnect = ViewModelConnector.FromXElement(this, transition, out string errorMesage, ConnectsExist); - if (WithError(errorMesage, x => Connects.Add(x), viewModelConnect)) - return; - } - SchemePath = fileName; - #endregion setup Transitions/connects - - - - bool WithError(string errorMessage, Action action, T obj) - { - if (string.IsNullOrEmpty(errorMessage)) - { - if (!object.Equals(obj, default(T))) - action.Invoke(obj); - } - else - { - Error(errorMessage); - return true; - } - return false; - } - void Error(string errorMessage) - { - LogError("File is not valid: " + errorMessage); - NewScheme(); - } - } - private void Save(string fileName) - { - XDocument xDocument = new XDocument(); - XElement stateMachineXElement = new XElement("StateMachine"); - xDocument.Add(stateMachineXElement); - XElement states = new XElement("States"); - stateMachineXElement.Add(states); - foreach (var state in Nodes) - { - states.Add(state.ToXElement()); - } - - XElement startState = new XElement("StartState"); - stateMachineXElement.Add(startState); - startState.Add(new XAttribute("Name", StartState.Name)); - - - XElement transitions = new XElement("Transitions"); - stateMachineXElement.Add(transitions); - foreach (var transition in Nodes.SelectMany(x => x.Transitions.Where(y => !string.IsNullOrEmpty(y.Name))).Reverse()) - { - transitions.Add(transition.ToXElement()); - } - - xDocument.Save(fileName); - ItSaved = true; - SchemePath = fileName; - } - public class ElementsForDelete { public List NodesToDelete; @@ -607,5 +654,17 @@ public static int Sort((int connectorIndex, ViewModelConnect connect) A, (int co return A.connectorIndex.CompareTo(B.connectorIndex); } } + + bool WithoutSaving() + { + if (!ItSaved) + { + Dialog.ShowMessageBox("Exit without saving ?", "Exit without saving", MessageBoxButton.YesNo); + + return Dialog.Result == DialogResult.Yes; + } + + return true; + } } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs index fa8adc4..6e6c76a 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelDialog.cs @@ -24,8 +24,18 @@ private void Show() { Visibility = true; } + private void Clear() + { + Type = DialogType.noCorrect; + Result = DialogResult.noCorrect; + Title = ""; + MessageBoxText = ""; + FileDialogFilter = ""; + FileName = ""; + } public void ShowMessageBox(string messageBoxText, string caption, MessageBoxButton button) { + Clear(); MessageBoxText = messageBoxText; MessageBoxButtons = button; Type = DialogType.MessageBox; @@ -35,6 +45,7 @@ public void ShowMessageBox(string messageBoxText, string caption, MessageBoxButt public void ShowOpenFileDialog(string filter, string fileName, string title) { + Clear(); FileDialogFilter = filter; FileName = fileName; Title = title; @@ -44,6 +55,7 @@ public void ShowOpenFileDialog(string filter, string fileName, string title) public void ShowSaveFileDialog(string filter, string fileName, string title) { + Clear(); FileDialogFilter = filter; FileName = fileName; Title = title; From 23c8d10ff688917f4ef777cff101db0a76ac06e1 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 16:58:58 +0300 Subject: [PATCH 05/17] fix for hot key --- SimpleStateMachineNodeEditor/View/MainWindow.xaml | 4 ++-- SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml b/SimpleStateMachineNodeEditor/View/MainWindow.xaml index 05d8f45..02773ed 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml @@ -116,7 +116,7 @@ - @@ -217,6 +217,6 @@ - + diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index 87ed168..738d3b5 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -108,9 +108,9 @@ private void SetupBinding() this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable); - - this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ButtonExportToJPEG).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.BindingExportToJPEG).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ItemExportToJPEG).DisposeWith(disposable); + this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ButtonExportToJPEG).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.BindingNew).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.ItemNew).DisposeWith(disposable); From b8c3b8ef4ba59b921664dcf2aca7f0e64658fd76 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 17:14:35 +0300 Subject: [PATCH 06/17] fix for exit command --- .../View/MainWindow.xaml.cs | 41 ++++++------------- .../NodesCanvas/ViewModelNodesCanvas.cs | 32 +++++++-------- .../ViewModelNodesCanvasCommands.cs | 13 ++++-- 3 files changed, 39 insertions(+), 47 deletions(-) diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index 738d3b5..2fcf504 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -51,26 +51,9 @@ object IViewFor.ViewModel } #endregion ViewModel - Dictionary messagesLabels; - static Dictionary labelPostfix = new Dictionary() - { - {TypeMessage.Error, "Error" }, - {TypeMessage.Information, "Information" }, - {TypeMessage.Warning, "Warning" }, - {TypeMessage.Debug, "Debug" }, - }; - public MainWindow() { InitializeComponent(); - messagesLabels = new Dictionary() - { - {TypeMessage.Error, LabelError }, - {TypeMessage.Information, LabelInformation }, - {TypeMessage.Warning, LabelWarning }, - {TypeMessage.Debug, LabelDebug }, - }; - ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel); SetupSubscriptions(); SetupBinding(); @@ -169,11 +152,10 @@ private void SetupEvents() this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable); this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable); - foreach(var label in messagesLabels) - { - label.Value.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, label.Key)).DisposeWith(disposable); - } - + this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable); + this.LabelWarning.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable); + this.LabelInformation.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable); + this.LabelDebug.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable); this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable); this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable); }); @@ -182,12 +164,15 @@ private void SetupEvents() private void UpdateLabels() { var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count()); - - foreach(var lable in messagesLabels) - { - lable.Value.Content = (counts.Keys.Contains(lable.Key) ? counts[lable.Key].ToString() : "0") +" "+ labelPostfix[lable.Key]; - } - + var countError = counts.Keys.Contains(TypeMessage.Error) ? counts[TypeMessage.Error].ToString() : "0"; + var countWarning = counts.Keys.Contains(TypeMessage.Warning) ? counts[TypeMessage.Warning].ToString() : "0"; + var countInformation = counts.Keys.Contains(TypeMessage.Information) ? counts[TypeMessage.Information].ToString() : "0"; + var countDebug = counts.Keys.Contains(TypeMessage.Debug) ? counts[TypeMessage.Debug].ToString() : "0"; + + LabelError.Content = countError + " Error"; + LabelWarning.Content = countWarning + " Warning"; + LabelInformation.Content = countInformation + " Information"; + LabelDebug.Content = countDebug + " Debug"; } private void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage) { diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs index 61fdd39..ca85ff1 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs @@ -49,22 +49,22 @@ public ViewModelNodesCanvas() Cutter = new ViewModelCutter(this); this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); - for (int i = 1; i <= 5; i++) - { - LogError("Error " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogInformation("Information " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogWarning("Warning " + i.ToString()); - } - for (int i = 1; i <= 5; i++) - { - LogDebug("Debug " + i.ToString()); - } + //for (int i = 1; i <= 5; i++) + //{ + // LogError("Error " + i.ToString()); + //} + //for (int i = 1; i <= 5; i++) + //{ + // LogInformation("Information " + i.ToString()); + //} + //for (int i = 1; i <= 5; i++) + //{ + // LogWarning("Warning " + i.ToString()); + //} + //for (int i = 1; i <= 5; i++) + //{ + // LogDebug("Debug " + i.ToString()); + //} } public readonly object lockNodes = new object(); diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index d901d56..5cbb573 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -95,6 +95,7 @@ private void SetupCommands() CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected); CommandErrorListUpdate = ReactiveCommand.Create(ErrosUpdaate); CommandExportToJPEG = ReactiveCommand.Create(ExportToJPEG); + CommandNew = ReactiveCommand.Create(New); CommandOpen = ReactiveCommand.Create(Open); CommandSave = ReactiveCommand.Create(Save); CommandSaveAs = ReactiveCommand.Create(SaveAs); @@ -115,7 +116,7 @@ private void SetupCommands() CommandAddDraggedConnect = ReactiveCommand.Create(AddDraggedConnect); CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect); - CommandNew = ReactiveCommand.Create(NewScheme); + CommandPartMoveAllNode = ReactiveCommand.Create(PartMoveAllNode); CommandPartMoveAllSelectedNode = ReactiveCommand.Create(PartMoveAllSelectedNode); @@ -227,7 +228,13 @@ private void ExportToJPEG() //"Png Image (.png)|*.png"; JPEGPath = Dialog.FileName; } - private void NewScheme() + private void New() + { + if (!WithoutSaving()) + return; + ClearScheme(); + } + private void ClearScheme() { this.Nodes.Clear(); this.Connects.Clear(); @@ -311,7 +318,7 @@ bool WithError(string errorMessage, Action action, T obj) void Error(string errorMessage) { LogError("File is not valid: " + errorMessage); - NewScheme(); + ClearScheme(); } } private void Save() From 2c34e38a7c0b6a0220e71d557f382fead8ab00d2 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 20:34:08 +0300 Subject: [PATCH 07/17] some refactoring --- .../Helpers/Commands/Command.cs | 63 +------------- .../Helpers/MyPoint.cs | 5 -- .../SimpleStateMachineNodeEditor.csproj | 1 - .../View/MainWindow.xaml.cs | 9 -- .../View/ViewConnect.xaml.cs | 20 +---- .../View/ViewCutter.xaml.cs | 23 ++---- .../View/ViewMessage.xaml.cs | 6 -- .../View/ViewModalDialog.xaml | 8 -- .../View/ViewModalDialog.xaml.cs | 44 ---------- .../View/ViewNode.xaml.cs | 6 +- .../View/ViewNodesCanvas.xaml.cs | 39 ++------- .../View/ViewRightConnector.xaml.cs | 31 +------ .../View/ViewSelector.xaml.cs | 11 --- .../NodesCanvas/ViewModelNodesCanvas.cs | 35 ++------ .../ViewModelNodesCanvasCommands.cs | 47 +++++++---- .../ViewModel/ViewModelConnect.cs | 22 ----- .../ViewModel/ViewModelConnector.cs | 82 +------------------ .../ViewModel/ViewModelCutter.cs | 18 ++-- .../ViewModel/ViewModelMainWindow.cs | 5 -- .../ViewModel/ViewModelMessage.cs | 11 +-- .../ViewModel/ViewModelModalDialog.cs | 33 -------- .../ViewModel/ViewModelNode.cs | 74 +---------------- .../ViewModel/ViewModelSelector.cs | 19 +++-- 23 files changed, 87 insertions(+), 525 deletions(-) delete mode 100644 SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml delete mode 100644 SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs delete mode 100644 SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs diff --git a/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs b/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs index 494adb2..775c7a1 100644 --- a/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs +++ b/SimpleStateMachineNodeEditor/Helpers/Commands/Command.cs @@ -6,35 +6,13 @@ namespace SimpleStateMachineNodeEditor.Helpers.Commands { public class Command : ICommandWithUndoRedo, ICommand, ICloneable { - private readonly Func _execute; - - /// - /// Функция отмены команды - /// private readonly Func _unExecute; - public Action OnExecute { get; set; } - - /// - /// Параметр, который был передан в команду при выполнении - /// public TParameter Parameters { get; set; } - - /// - /// Результат выполнения команды - /// Например здесь может храниться список объектов, которые были изменены public TResult Result { get; set; } - /// - - - /// - /// Клонирование текущей команды, для записи в стек выполненных или отмененных команд - /// - /// public object Clone() - { - + { return new Command(_execute, _unExecute, OnExecute) { Parameters = this.Parameters, @@ -42,91 +20,56 @@ public object Clone() }; } - /// - /// Требуется интерфейсом ICloneable, не используется - /// + public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } - /// - /// Требуется интерфейсом ICloneable, не используется - /// - /// - /// Всегда возвращает true public bool CanExecute(object parameter) { return true; } - /// - /// Выполнение команды - /// - /// Параметр команды public void Execute(object parameter) { - //Запоминаем параметр ( чтобы можно было егоже передать в отмену) Parameters = parameter.Cast(); - //Выполняем команду и запоминаем результат ( чтобы можно было выполнить отмену именно для этого результата) Result = this._execute(Parameters, Result).Cast(); - //Добавляем копию команды в стек команд, которые можно отменить ICommandWithUndoRedo.AddInUndo(this.Clone() as ICommandWithUndoRedo); - //Очищаем список отмененнных команд ( началась новая ветка изменений) ICommandWithUndoRedo.StackRedo.Clear(); - //Очищаем результат ( чтобы не передавать его при повторном выполнении) Result = default(TResult); - //Очищаем параметр ( чтобы не передавать его при повторном выполнении) Parameters = default(TParameter); OnExecute?.Invoke(); } - /// - /// Отмена команды - /// public void UnExecute() { - //Выполняем отмену команду this._unExecute(Parameters, Result); - //Добавляем копию команды в стек команд, которые можно выполнить повторно ICommandWithUndoRedo.AddInRedo(this.Clone() as ICommandWithUndoRedo); } - /// - /// Повторное выполнения команды - /// public void ExecuteWithSubscribe() { - //Выполянем команду this.Result = this._execute(this.Parameters, this.Result); - //Добавляем копию команды в стек команд, которые можно отменить ICommandWithUndoRedo.AddInUndo(this.Clone() as ICommandWithUndoRedo); } - /// - /// Создать отменяемую команду - /// - /// Объкт, которому принадлежит команда - /// Функция, которая будет вызвана при выполнении команды - /// Функция, которая будет вызвана при отмене команды public Command(Func ExecuteWithSubscribe, Func unExecute, Action onExecute = null) { _execute = ExecuteWithSubscribe; _unExecute = unExecute; - OnExecute += onExecute; - - + OnExecute += onExecute; } } } diff --git a/SimpleStateMachineNodeEditor/Helpers/MyPoint.cs b/SimpleStateMachineNodeEditor/Helpers/MyPoint.cs index 8e6ac5e..77d3df0 100644 --- a/SimpleStateMachineNodeEditor/Helpers/MyPoint.cs +++ b/SimpleStateMachineNodeEditor/Helpers/MyPoint.cs @@ -49,11 +49,6 @@ public void Clear() Value = new Point(); } - /// - /// Отразить координаты - /// - /// Отразить по X (По умолчанию true) - /// Отразить по Y (По умолчанию true) public void Mirror(bool onX = true, bool onY = true) { Value = new Point(onX ? -this.X : this.X, onY ? -this.Y : this.Y); diff --git a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj index 13a07c0..0a7e087 100644 --- a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj +++ b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj @@ -44,7 +44,6 @@ - diff --git a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs index 2fcf504..5c6ba7a 100644 --- a/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs @@ -15,18 +15,9 @@ using System.Windows.Markup; using SimpleStateMachineNodeEditor.ViewModel; using SimpleStateMachineNodeEditor.Helpers.Enums; -using System.Windows.Forms; using System.IO; -using SimpleStateMachineNodeEditor.Helpers; -using Newtonsoft.Json; using System.Linq; -using SimpleStateMachineNodeEditor.Helpers.Commands; using SimpleStateMachineNodeEditor.Helpers.Extensions; -using System.Reactive.Concurrency; -using System.Threading.Tasks; -using System.Threading; -using System.Reactive; -using System.Collections.Generic; namespace SimpleStateMachineNodeEditor.View { diff --git a/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs index e36f0d7..e2066fc 100644 --- a/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs @@ -41,7 +41,6 @@ public ViewConnect() { InitializeComponent(); SetupBinding(); - SetupEvents(); } #region SetupBinding @@ -49,19 +48,14 @@ private void SetupBinding() { this.WhenActivated(disposable => { - // Цвет линии this.OneWayBind(this.ViewModel, x => x.Stroke, x => x.PathElement.Stroke).DisposeWith(disposable); - // Точка, из которой выходит линия this.OneWayBind(this.ViewModel, x => x.StartPoint.Value, x => x.PathFigureElement.StartPoint).DisposeWith(disposable); - // Первая промежуточная точка линии this.OneWayBind(this.ViewModel, x => x.Point1.Value, x => x.BezierSegmentElement.Point1).DisposeWith(disposable); - // Вторая промежуточная точка линии this.OneWayBind(this.ViewModel, x => x.Point2.Value, x => x.BezierSegmentElement.Point2).DisposeWith(disposable); - // Точка, в которую приходит линия this.OneWayBind(this.ViewModel, x => x.EndPoint.Value, x => x.BezierSegmentElement.Point3).DisposeWith(disposable); this.OneWayBind(this.ViewModel, x => x.StrokeDashArray, x => x.PathElement.StrokeDashArray).DisposeWith(disposable); @@ -74,22 +68,12 @@ private void SetupBinding() }); } - #endregion SetupBinding - - #region SetupEvents - private void SetupEvents() - { - this.WhenActivated(disposable => - { - }); - } private void UpdateZindex() { - if(this.ViewModel.FromConnector.Node!=this.ViewModel.ToConnector.Node) + if (this.ViewModel.FromConnector.Node != this.ViewModel.ToConnector.Node) Canvas.SetZIndex((UIElement)this.VisualParent, this.ViewModel.ToConnector.Node.Zindex); } - - #endregion SetupEvents + #endregion SetupBinding } } diff --git a/SimpleStateMachineNodeEditor/View/ViewCutter.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewCutter.xaml.cs index 6e4cd4f..87f12b9 100644 --- a/SimpleStateMachineNodeEditor/View/ViewCutter.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewCutter.xaml.cs @@ -66,26 +66,24 @@ private void SetupBinding() }); } - - #endregion Setup Binding - - #region Setup Events - private void Update() { Mouse.Capture(this); Keyboard.Focus(this); } + + #endregion Setup Binding + + #region Setup Events + private void SetupEvents() { this.WhenActivated(disposable => { this.Events().MouseMove.Subscribe(e => OnMouseMoves(e)).DisposeWith(disposable); this.Events().MouseLeftButtonUp.Subscribe(e => OnMouseLeftButtonUp(e)).DisposeWith(disposable); - }); } - private void OnMouseMoves(MouseEventArgs e) { ViewNodesCanvas NodesCanvas = MyUtils.FindParent(this); @@ -99,17 +97,8 @@ private void OnMouseLeftButtonUp(MouseEventArgs e) { this.ViewModel.Visible = null; } - #endregion Setup Events - - #region Setup Commands - private void SetupCommands() - { - this.WhenActivated(disposable => - { + #endregion Setup Events - }); - } - #endregion Setup Commands } } diff --git a/SimpleStateMachineNodeEditor/View/ViewMessage.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewMessage.xaml.cs index 732b1a8..4c4df69 100644 --- a/SimpleStateMachineNodeEditor/View/ViewMessage.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewMessage.xaml.cs @@ -68,12 +68,6 @@ private void SetupSubscriptions() private void UpdateIcon(TypeMessage type) { this.RectangleElement.Fill = Application.Current.Resources["Icon" + type.Name()] as DrawingBrush; - //{ - // TypeMessage.Error => "IconError", - // TypeMessage.Warning => new RGBColor(0x00, 0x00, 0xFF), - // TypeMessage.Information => new RGBColor(0xFF, 0x7F, 0x00), - // TypeMessage.Debug => new RGBColor(0xFF, 0x7F, 0x00), - //}] as DrawingBrush; } #endregion Setup Subscriptions } diff --git a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml deleted file mode 100644 index fe2bf04..0000000 --- a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml +++ /dev/null @@ -1,8 +0,0 @@ - - - diff --git a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs deleted file mode 100644 index 0a2d72e..0000000 --- a/SimpleStateMachineNodeEditor/View/ViewModalDialog.xaml.cs +++ /dev/null @@ -1,44 +0,0 @@ -using ReactiveUI; -using SimpleStateMachineNodeEditor.ViewModel; -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SimpleStateMachineNodeEditor.View -{ - /// - /// Interaction logic for ViewModalDialog.xaml - /// - public partial class ViewModalDialog : UserControl, IViewFor - { - #region ViewModel - public static readonly DependencyProperty ViewModelProperty = DependencyProperty.Register(nameof(ViewModel), typeof(ViewModelModalDialog), typeof(ViewModalDialog), new PropertyMetadata(null)); - - public ViewModelModalDialog ViewModel - { - get { return (ViewModelModalDialog)GetValue(ViewModelProperty); } - set { SetValue(ViewModelProperty, value); } - } - - object IViewFor.ViewModel - { - get { return ViewModel; } - set { ViewModel = (ViewModelModalDialog)value; } - } - #endregion ViewModel - - public ViewModalDialog() - { - InitializeComponent(); - } - } -} diff --git a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs index 6a5a83b..bd1d179 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs @@ -102,9 +102,9 @@ private void SetupEvents() { this.WhenAnyValue(x=>x.IsMouseOver).Subscribe(value=> OnEventMouseOver(value)).DisposeWith(disposable); this.Events().MouseLeftButtonDown.Subscribe(e => OnEventMouseLeftDowns(e)).DisposeWith(disposable); - this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)).DisposeWith(disposable); - this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); - this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); + //this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)).DisposeWith(disposable); + //this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); + //this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); this.Events().MouseDown.Subscribe(e => OnEventMouseDown(e)).DisposeWith(disposable); this.Events().MouseUp.Subscribe(e => OnEventMouseUp(e)).DisposeWith(disposable); this.Events().MouseMove.Subscribe(e => OnMouseMove(e)).DisposeWith(disposable); diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs index b782416..3028ffd 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs @@ -70,11 +70,8 @@ private void SetupBinding() { this.OneWayBind(this.ViewModel, x => x.Nodes, x => x.Nodes.Collection).DisposeWith(disposable); - this.OneWayBind(this.ViewModel, x => x.Connects, x => x.Connects.Collection).DisposeWith(disposable); - - //this.OneWayBind(this.ViewModel, x => x.Nodes, x => x.Nodes.ItemsSource).DisposeWith(disposable); - //this.OneWayBind(this.ViewModel, x => x.Connects, x => x.Connects.ItemsSource).DisposeWith(disposable); + this.OneWayBind(this.ViewModel, x => x.Connects, x => x.Connects.Collection).DisposeWith(disposable); this.OneWayBind(this.ViewModel, x => x.Scale.Scales.Value.X, x => x.Scale.ScaleX).DisposeWith(disposable); @@ -111,9 +108,6 @@ private void SetupCommands() this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedElements, x => x.BindingDeleteSelectedElements).DisposeWith(disposable); - //this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedNodes, x => x.BindingDeleteSelected).DisposeWith(disposable); - //this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedConnectors, x => x.BindingDeleteSelected).DisposeWith(disposable); - this.BindCommand(this.ViewModel, x => x.CommandCollapseUpSelected, x => x.ItemCollapsUp).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandExpandDownSelected, x => x.ItemExpandDown).DisposeWith(disposable); @@ -137,14 +131,14 @@ private void SetupEvents() this.Events().MouseLeftButtonDown.Subscribe(e => OnEventMouseLeftDown(e)).DisposeWith(disposable); this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)); this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); - this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); - this.Events().MouseDown.Subscribe(e => OnEventMouseDown(e)).DisposeWith(disposable); + //this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); + //this.Events().MouseDown.Subscribe(e => OnEventMouseDown(e)).DisposeWith(disposable); this.Events().MouseUp.Subscribe(e => OnEventMouseUp(e)).DisposeWith(disposable); this.Events().MouseMove.Subscribe(e => OnEventMouseMove(e)).DisposeWith(disposable); this.Events().MouseWheel.Subscribe(e => OnEventMouseWheel(e)).DisposeWith(disposable); this.Events().DragOver.Subscribe(e => OnEventDragOver(e)).DisposeWith(disposable); - this.Events().DragEnter.Subscribe(e => OnEventDragEnter(e)).DisposeWith(disposable); - this.Events().DragLeave.Subscribe(e => OnEventDragLeave(e)).DisposeWith(disposable); + //this.Events().DragEnter.Subscribe(e => OnEventDragEnter(e)).DisposeWith(disposable); + //this.Events().DragLeave.Subscribe(e => OnEventDragLeave(e)).DisposeWith(disposable); //Эти события срабатывают раньше команд this.Events().PreviewMouseLeftButtonDown.Subscribe(e => OnEventPreviewMouseLeftButtonDown(e)).DisposeWith(disposable); this.Events().PreviewMouseRightButtonDown.Subscribe(e => OnEventPreviewMouseRightButtonDown(e)).DisposeWith(disposable); @@ -164,11 +158,7 @@ private void OnEventMouseLeftDown(MouseButtonEventArgs e) this.ViewModel.CommandUnSelectAll.ExecuteWithSubscribe(); } } - private void UpdateConnector() - { - //this.Connector.Visibility = (this.ViewModel.DraggedConnector == null) ? Visibility.Collapsed : Visibility.Visible; - } private void OnEventMouseLeftUp(MouseButtonEventArgs e) { if (Move == TypeMove.None) @@ -206,11 +196,9 @@ private void OnEventMouseUp(MouseButtonEventArgs e) private void OnEventMouseMove(MouseEventArgs e) { - //if ((Mouse.Captured == null)||(!(Mouse.Captured is CanBeMove))) if (!(Mouse.Captured is CanBeMove)) return; - MyPoint delta = GetDeltaMove(); if (delta.IsClear) @@ -219,13 +207,11 @@ private void OnEventMouseMove(MouseEventArgs e) SumMove += delta; if (this.IsMouseCaptured) { - //ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta).Subscribe(); ViewModel.CommandPartMoveAllNode.ExecuteWithSubscribe(delta); Move = TypeMove.MoveAll; } else { - //ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); Move = TypeMove.MoveSelected; } @@ -270,24 +256,11 @@ private MyPoint GetDeltaMove() PositionMove = CurrentPosition; return result; } - private MyPoint GetDeltaDragOver(DragEventArgs e) - { - MyPoint CurrentPosition = new MyPoint(e.GetPosition(this)); - - MyPoint result = new MyPoint(); - - if (!PositionDragOver.IsClear) - { - result = CurrentPosition - PositionDragOver; - } - PositionDragOver = CurrentPosition; - - return result; - } private void SaveCanvasToImage(string filename, ImageFormats format) { MyUtils.PanelToImage(this.Canvas, filename, format); + ViewModel.CommandLogDebug.ExecuteWithSubscribe(String.Format("Scheme was exported to \"{0}\"", filename)); } } diff --git a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs index 1e7388d..ba2f339 100644 --- a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs @@ -44,7 +44,6 @@ object IViewFor.ViewModel public ViewRightConnector() { InitializeComponent(); - SetupCommands(); SetupBinding(); SetupEvents(); } @@ -80,16 +79,6 @@ private void SetupBinding() } #endregion SetupBinding - #region Setup Commands - private void SetupCommands() - { - this.WhenActivated(disposable => - { - //this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelectWithCtrl).DisposeWith(disposable); - //this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelectWithShift).DisposeWith(disposable); - }); - } - #endregion Setup Commands #region SetupEvents private void SetupEvents() @@ -184,9 +173,7 @@ private void ConnectorDrop(DragEventArgs e) #endregion SetupEvents - /// - /// Обновить координату центра круга - /// + void UpdatePositionConnectPoin() { Point positionConnectPoint; @@ -213,21 +200,5 @@ void UpdatePositionConnectPoin() this.ViewModel.PositionConnectPoint.Set(Position); } - //void UpdatePosition() - //{ - // if (!this.IsVisible) - // return; - - // Point position = new Point(); - - // //Ищем Canvas - // ViewNodesCanvas NodesCanvas = MyUtils.FindParent(this); - - // position = this.TransformToAncestor(NodesCanvas).Transform(position); - - // this.ViewModel.Position.Set(position); - - // this.ViewModel.NodesCanvas.Text = "UpdatePosition for " + this.ViewModel.Name; - //} } } diff --git a/SimpleStateMachineNodeEditor/View/ViewSelector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewSelector.xaml.cs index 0fe0c4a..456442d 100644 --- a/SimpleStateMachineNodeEditor/View/ViewSelector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewSelector.xaml.cs @@ -44,7 +44,6 @@ public ViewSelector() InitializeComponent(); SetupBinding(); SetupEvents(); - SetupCommands(); } protected override void OnMouseMove(MouseEventArgs e) { @@ -109,16 +108,6 @@ private void OnMouseLeftButtonUp(MouseEventArgs e) #endregion Setup Events - #region Setup Commands - private void SetupCommands() - { - this.WhenActivated(disposable => - { - - - }); - } - #endregion Setup Commands } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs index ca85ff1..29db154 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs @@ -8,6 +8,7 @@ using SimpleStateMachineNodeEditor.Helpers.Enums; using System.Windows.Data; using System.IO; +using Splat; namespace SimpleStateMachineNodeEditor.ViewModel.NodesCanvas { @@ -48,24 +49,6 @@ public ViewModelNodesCanvas() SetupStartState(); Cutter = new ViewModelCutter(this); this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); - - //for (int i = 1; i <= 5; i++) - //{ - // LogError("Error " + i.ToString()); - //} - //for (int i = 1; i <= 5; i++) - //{ - // LogInformation("Information " + i.ToString()); - //} - //for (int i = 1; i <= 5; i++) - //{ - // LogWarning("Warning " + i.ToString()); - //} - //for (int i = 1; i <= 5; i++) - //{ - // LogDebug("Debug " + i.ToString()); - //} - } public readonly object lockNodes = new object(); public readonly object lockConnects = new object(); @@ -104,21 +87,21 @@ private void SetAsStart(ViewModelNode node) #region Logging - public void LogDebug(string message) + public void LogDebug(string message, params object[] args) { - Messages.Add(new ViewModelMessage(TypeMessage.Debug, message)); + Messages.Add(new ViewModelMessage(TypeMessage.Debug, string.Format(message, args))); } - public void LogError(string message) + public void LogError(string message, params object[] args) { - Messages.Add(new ViewModelMessage(TypeMessage.Error, message)); + Messages.Add(new ViewModelMessage(TypeMessage.Error, string.Format(message, args))); } - public void LogInformation(string message) + public void LogInformation(string message, params object[] args) { - Messages.Add(new ViewModelMessage(TypeMessage.Information, message)); + Messages.Add(new ViewModelMessage(TypeMessage.Information, string.Format(message, args))); } - public void LogWarning(string message) + public void LogWarning(string message, params object[] args) { - Messages.Add(new ViewModelMessage(TypeMessage.Warning, message)); + Messages.Add(new ViewModelMessage(TypeMessage.Warning, string.Format(message, args))); } #endregion Logging diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index 5cbb573..fd3827c 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -4,16 +4,13 @@ using SimpleStateMachineNodeEditor.Helpers.Commands; using SimpleStateMachineNodeEditor.Helpers.Enums; using SimpleStateMachineNodeEditor.Helpers.Extensions; +using SimpleStateMachineNodeEditor.Icons; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reactive; using System.Reactive.Linq; -using System.Threading; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Data; using System.Windows.Input; using System.Xml.Linq; @@ -107,10 +104,10 @@ private void SetupCommands() CommandAddConnect = ReactiveCommand.Create(AddConnect); CommandDeleteConnect = ReactiveCommand.Create(DeleteConnect); CommandZoom = ReactiveCommand.Create(Zoom); - CommandLogDebug = ReactiveCommand.Create(LogDebug); - CommandLogError = ReactiveCommand.Create(LogError); - CommandLogInformation = ReactiveCommand.Create(LogInformation); - CommandLogWarning = ReactiveCommand.Create(LogWarning); + CommandLogDebug = ReactiveCommand.Create((message)=>LogDebug(message)); + CommandLogError = ReactiveCommand.Create((message) => LogError(message)); + CommandLogInformation = ReactiveCommand.Create((message) => LogInformation(message)); + CommandLogWarning = ReactiveCommand.Create((message) => LogWarning(message)); CommandSelect = ReactiveCommand.Create(StartSelect); CommandCut = ReactiveCommand.Create(StartCut); CommandAddDraggedConnect = ReactiveCommand.Create(AddDraggedConnect); @@ -222,7 +219,7 @@ private void SelectNodes() } private void ExportToJPEG() { - Dialog.ShowSaveFileDialog("JPEG Image (.jpeg)|*.jpeg", SchemeName(), "Export scheme"); + Dialog.ShowSaveFileDialog("JPEG Image (.jpeg)|*.jpeg", SchemeName(), "Export scheme to JPEG"); if (Dialog.Result != DialogResult.Ok) return; //"Png Image (.png)|*.png"; @@ -238,6 +235,7 @@ private void ClearScheme() { this.Nodes.Clear(); this.Connects.Clear(); + this.SchemePath = ""; this.SetupStartState(); } @@ -246,12 +244,11 @@ private void Open() if (!WithoutSaving()) return; - Dialog.ShowOpenFileDialog("XML-File | *.xml", SchemeName(), "Import scheme"); + Dialog.ShowOpenFileDialog("XML-File | *.xml", SchemeName(), "Import scheme from xml file"); if (Dialog.Result != DialogResult.Ok) return; string fileName = Dialog.FileName; - //string fileName = @"C:\Users\roman\Downloads\100 States.xml"; this.Nodes.Clear(); this.Connects.Clear(); @@ -297,6 +294,7 @@ private void Open() return; } SchemePath = fileName; + LogDebug("Scheme was imported from file \"{0}\"", SchemePath); #endregion setup Transitions/connects @@ -317,7 +315,7 @@ bool WithError(string errorMessage, Action action, T obj) } void Error(string errorMessage) { - LogError("File is not valid: " + errorMessage); + LogError("File is not valid. " + errorMessage); ClearScheme(); } } @@ -340,7 +338,7 @@ private void Exit() } private void SaveAs() { - Dialog.ShowSaveFileDialog("XML-File | *.xml", SchemeName(), "Save scheme"); + Dialog.ShowSaveFileDialog("XML-File | *.xml", SchemeName(), "Save scheme as..."); if (Dialog.Result != DialogResult.Ok) return; @@ -373,6 +371,8 @@ private void Save(string fileName) xDocument.Save(fileName); ItSaved = true; SchemePath = fileName; + + LogDebug("Scheme was saved as \"{0}\"", SchemePath); } @@ -430,9 +430,19 @@ private void ValidateNodeName((ViewModelNode objectForValidate, string newValue) { if (!NodesExist(obj.newValue)) { + LogDebug("Node \"{0}\" has been renamed . New name is \"{1}\"", obj.objectForValidate.Name, obj.newValue); obj.objectForValidate.Name = obj.newValue; + + } + else + { + LogError("Name for node doesn't set, because node with name \"{0}\" already exist", obj.newValue); } } + else + { + LogError("Name for node doesn't set, name off node should not be empty", obj.newValue); + } } private void ValidateConnectName((ViewModelConnector objectForValidate, string newValue) obj) { @@ -440,8 +450,17 @@ private void ValidateConnectName((ViewModelConnector objectForValidate, string n { if (!ConnectsExist(obj.newValue)) { + LogDebug("Transition \"{0}\" has been renamed . New name is \"{1}\"", obj.objectForValidate.Name, obj.newValue); obj.objectForValidate.Name = obj.newValue; } + else + { + LogError("Name for transition doesn't set, because transition with name \"{0}\" already exist", obj.newValue); + } + } + else + { + LogError("Name for transition doesn't set, name off transition should not be empty", obj.newValue); } } @@ -455,8 +474,6 @@ private List FullMoveAllNode(MyPoint delta, List n myPoint.Clear(); } nodes.ForEach(node => node.CommandMove.ExecuteWithSubscribe(myPoint)); - - LogInformation(Messages.Count.ToString()); return nodes; } private List UnFullMoveAllNode(MyPoint delta, List nodes = null) diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs index 05e5ef9..d8959e6 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnect.cs @@ -8,39 +8,18 @@ using ReactiveUI.Fody.Helpers; using SimpleStateMachineNodeEditor.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Enums; -using System.Xml.Linq; using SimpleStateMachineNodeEditor.Helpers.Extensions; -using SimpleStateMachineNodeEditor.Helpers.Commands; using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel { public class ViewModelConnect : ReactiveObject { - /// - /// Точка, из которой выходит линия ( совпадает с центром элемента, из которого выходит линия) - /// [Reactive] public MyPoint StartPoint { get; set; } = new MyPoint(); - - /// - /// Точка, в которую приходит линия ( совпадает с центром элемента, в который приходит линия) - /// [Reactive] public MyPoint EndPoint { get; set; } = new MyPoint(); - - /// - /// Первая промежуточная точка линии - /// [Reactive] public MyPoint Point1 { get; set; } = new MyPoint(); - - /// - /// Вторая промежуточная точка линии - /// [Reactive] public MyPoint Point2 { get; set; } = new MyPoint(); - /// - /// Цвет линии - /// [Reactive] public Brush Stroke { get; set; } = Application.Current.Resources["ColorConnect"] as SolidColorBrush; [Reactive] public ViewModelConnector FromConnector { get; set; } @@ -62,7 +41,6 @@ public ViewModelConnect(ViewModelNodesCanvas viewModelNodesCanvas, ViewModelConn NodesCanvas = viewModelNodesCanvas; FromConnector = fromConnector; FromConnector.Connect = this; - //SetupCommands(); } #region Setup Subscriptions diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs index daee983..ada928b 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelConnector.cs @@ -5,7 +5,6 @@ using ReactiveUI; using SimpleStateMachineNodeEditor.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Commands; using System; using System.Xml.Linq; using System.Linq; @@ -13,66 +12,24 @@ using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; -using System.Windows.Documents; -using System.Collections.Generic; namespace SimpleStateMachineNodeEditor.ViewModel { public class ViewModelConnector : ReactiveObject { - /// - /// Координата перехода ( нужна для создания соединения ) - /// [Reactive] public MyPoint PositionConnectPoint { get; set; } = new MyPoint(); - - /// - /// Имя перехода ( вводится в узле) - /// [Reactive] public string Name { get; set; } - - /// - /// Доступно ли имя перехода для редактирования - /// [Reactive] public bool TextEnable { get; set; } = false; - - /// - /// Отображается ли переход - /// [Reactive] public bool? Visible { get; set; } = true; - - /// - /// Ellipse enable - /// [Reactive] public bool FormEnable { get; set; } = true; - - /// - /// Ellipse stroke color - /// [Reactive] public Brush FormStroke { get; set; } = Application.Current.Resources["ColorNodesCanvasBackground"] as SolidColorBrush; - - /// - /// Ellipse fill color - /// [Reactive] public Brush FormFill { get; set; } = Application.Current.Resources["ColorConnector"] as SolidColorBrush; - [Reactive] public Brush Foreground { get; set; } = Application.Current.Resources["ColorConnectorForeground"] as SolidColorBrush; - [Reactive] public double FormStrokeThickness { get; set; } = 1; - - /// - /// Узел, которому принадлежит переход - /// [Reactive] public ViewModelNode Node { get; set; } - - /// - /// Соединение, которое связанно с этим переходом - /// [Reactive] public ViewModelConnect Connect { get; set; } - [Reactive] public bool ItsLoop { get; set; } = false; - [Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; } - [Reactive] public bool Selected { get; set; } public ViewModelConnector(ViewModelNodesCanvas nodesCanvas, ViewModelNode viewModelNode) @@ -99,10 +56,6 @@ private void SetupBinding() public ReactiveCommand CommandConnectorDragEnter { get; set; } public ReactiveCommand CommandConnectorDrop { get; set; } public ReactiveCommand CommandSetAsLoop { get; set; } - //public ReactiveCommand CommandAdd { get; set; } - //public ReactiveCommand CommandDelete { get; set; } - //public ReactiveCommand CommandAddWithConnect { get; set; } - //public ReactiveCommand CommandDeleteWithConnect { get; set; } public ReactiveCommand CommandSelect { get; set; } public ReactiveCommand CommandValidateName { get; set; } @@ -118,18 +71,11 @@ private void SetupCommands() CommandConnectorDragEnter = ReactiveCommand.Create(ConnectorDragEnter); CommandConnectorDrop = ReactiveCommand.Create(ConnectorDrop); - //CommandAdd = ReactiveCommand.Create(Add); - //CommandDelete = ReactiveCommand.Create(Delete); - //CommandAddWithConnect = ReactiveCommand.Create(AddWithConnect); - //CommandDeleteWithConnect = ReactiveCommand.Create(DeleteWithConnect); - CommandValidateName = ReactiveCommand.Create(ValidateName); CommandSelect = ReactiveCommand.Create(Select); - //SimpleCommandWithResult> t = new SimpleCommandWithResult>() - NotSavedSubscribe(); } private void NotSavedSubscribe() @@ -152,9 +98,7 @@ private void Select(SelectMode selectMode) { if(!this.Selected) { - //this.Node.CommandUnSelectedAllConnectorsExecuteWithSubscribe(); - this.Node.CommandSetConnectorAsStartSelect.ExecuteWithSubscribe(this); - //this.Selected = true; + this.Node.CommandSetConnectorAsStartSelect.ExecuteWithSubscribe(this); } break; @@ -187,32 +131,10 @@ private void SetAsLoop() Node.CommandAddEmptyConnector.ExecuteWithSubscribe(); } - //private void Add() - //{ - // Node.CommandAddConnector.ExecuteWithSubscribe((0, this)); - //} - //private void Delete() - //{ - // Node.CommandDeleteConnector.ExecuteWithSubscribe(this); - //} - //private void AddWithConnect() - //{ - // this.Add(); - // this.Connect?.CommandAddExecuteWithSubscribe(); - //} - //private void DeleteWithConnect() - //{ - // this.Delete(); - // this.Connect?.CommandDeleteExecuteWithSubscribe(); - //} private void ConnectPointDrag() { NodesCanvas.CommandAddDraggedConnect.ExecuteWithSubscribe(Node.CurrentConnector); } - private void DragConnector(ViewModelConnector draggedConnector) - { - - } private void ConnectPointDrop() { @@ -234,8 +156,6 @@ private void CheckConnectPointDrop() { NodesCanvas.CommandAddConnectorWithConnect.Execute(Node.CurrentConnector); Node.CommandAddEmptyConnector.ExecuteWithSubscribe(); - - //NodesCanvas.CommandAddConnectWithUndoRedo.ExecuteWithSubscribe(Node.NodesCanvas.DraggedConnect); NodesCanvas.DraggedConnect = null; } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs index b8cf614..a4d4ab1 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelCutter.cs @@ -35,20 +35,26 @@ public class ViewModelCutter : ReactiveObject public ViewModelCutter(ViewModelNodesCanvas nodesCanvas) { + NodesCanvas = nodesCanvas; SetupCommands(); + SetupSubscriptions(); + + } + #region Setup Subscriptions + private void SetupSubscriptions() + { this.WhenAnyValue(x => x.NodesCanvas.Scale.Value).Subscribe(value => StrokeThickness = value); - - NodesCanvas = nodesCanvas; } + + #endregion Setup Subscriptions + #region Setup Commands public ReactiveCommand CommandStartCut { get; set; } - public ReactiveCommand CommandEndCut { get; set; } private void SetupCommands() { CommandStartCut = ReactiveCommand.Create(StartCut); - CommandEndCut = ReactiveCommand.Create(EndCut); } private void StartCut(MyPoint point) @@ -56,10 +62,6 @@ private void StartCut(MyPoint point) Visible = true; StartPoint.Set(point); } - private void EndCut() - { - - } #endregion Setup Commands } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs index 5fb5a6a..088de9d 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMainWindow.cs @@ -2,15 +2,10 @@ using DynamicData.Binding; using ReactiveUI; using ReactiveUI.Fody.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Commands; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows; using SimpleStateMachineNodeEditor.Helpers.Enums; using System.Reactive.Linq; -using System.Collections.ObjectModel; using System.Reactive; using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMessage.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMessage.cs index de2d28c..42728c9 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelMessage.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelMessage.cs @@ -1,14 +1,5 @@ -using System; -using System.Windows; -using System.Reactive.Linq; - -using ReactiveUI; +using ReactiveUI; using ReactiveUI.Fody.Helpers; - -using SimpleStateMachineNodeEditor.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Commands; -using SimpleStateMachineNodeEditor.Helpers.Transformations; -using SimpleStateMachineNodeEditor.Helpers.Logging; using SimpleStateMachineNodeEditor.Helpers.Enums; namespace SimpleStateMachineNodeEditor.ViewModel diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs deleted file mode 100644 index 7770fa2..0000000 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelModalDialog.cs +++ /dev/null @@ -1,33 +0,0 @@ -using MvvmDialogs; -using ReactiveUI.Validation.Helpers; -using SimpleStateMachineNodeEditor.View; -using System; -using System.Collections.Generic; -using System.Text; - -namespace SimpleStateMachineNodeEditor.ViewModel -{ - public class ViewModelModalDialog : ReactiveValidationObject - { - - private readonly IDialogService dialogService; - - public ViewModelModalDialog(IDialogService dialogService) - { - this.dialogService = dialogService; - } - - private void ShowDialog() - { - //dialogService.ShowMessageBox() - //var dialogViewModel = new AddTextDialogViewModel(); - - - //bool? success = dialogService.ShowDialog(this, dialogViewModel); - //if (success == true) - //{ - // Texts.Add(dialogViewModel.Text); - //} - } -} -} diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index 93b3b74..22295b7 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -10,14 +10,12 @@ using DynamicData.Binding; using SimpleStateMachineNodeEditor.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Commands; using System.Linq; using System.Xml.Linq; using SimpleStateMachineNodeEditor.Helpers.Enums; using DynamicData; using System.Reactive; using SimpleStateMachineNodeEditor.Helpers.Extensions; -using System.Threading.Tasks; using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas; namespace SimpleStateMachineNodeEditor.ViewModel @@ -50,7 +48,7 @@ public class ViewModelNode : ReactiveValidationObject private ViewModelNode() { SetupCommands(); - //SetupBinding(); + SetupBinding(); } @@ -98,7 +96,6 @@ private void SetupConnectors() public ReactiveCommand CommandAddEmptyConnector { get; set; } public ReactiveCommand CommandSelect { get; set; } public ReactiveCommand CommandMove { get; set; } - //public ReactiveCommand CommandCollapse { get; set; } public ReactiveCommand<(int index, ViewModelConnector connector), Unit> CommandAddConnectorWithConnect { get; set; } public ReactiveCommand CommandDeleteConnectorWithConnect { get; set; } public ReactiveCommand CommandValidateName { get; set; } @@ -111,24 +108,21 @@ private void SetupCommands() CommandSelect = ReactiveCommand.Create(Select); CommandMove = ReactiveCommand.Create(Move); CommandAddEmptyConnector = ReactiveCommand.Create(AddEmptyConnector); - //CommandCollapse = ReactiveCommand.Create(Collapse); CommandSelectWithShiftForConnectors = ReactiveCommand.Create(SelectWithShiftForConnectors); CommandSetConnectorAsStartSelect = ReactiveCommand.Create(SetConnectorAsStartSelect); CommandUnSelectedAllConnectors = ReactiveCommand.Create(UnSelectedAllConnectors); CommandAddConnectorWithConnect = ReactiveCommand.Create<(int index, ViewModelConnector connector)>(AddConnectorWithConnect); CommandDeleteConnectorWithConnect = ReactiveCommand.Create(DeleteConnectorWithConnec); CommandValidateName = ReactiveCommand.Create(ValidateName); + + NotSavedSubscrube(); } private void NotSavedSubscrube() { CommandMove.Subscribe(_ => NotSaved()); - //CommandCollapse.Subscribe(_ => NotSaved()); CommandAddConnectorWithConnect.Subscribe(_ => NotSaved()); CommandDeleteConnectorWithConnect.Subscribe(_ => NotSaved()); CommandValidateName.Subscribe(_ => NotSaved()); - - - } private void NotSaved() { @@ -287,67 +281,5 @@ public static ViewModelNode FromXElement(ViewModelNodesCanvas nodesCanvas, XElem return viewModelNode; } - public static ViewModelNode FromXElement(XElement node) - { - //errorMessage = null; - ViewModelNode viewModelNode = null; - string name = node.Attribute("Name")?.Value; - - //if (string.IsNullOrEmpty(name)) - //{ - // errorMessage = "Node without name"; - // return viewModelNode; - //} - - //if (actionForCheck(name)) - //{ - // errorMessage = String.Format("Contains more than one node with name \"{0}\"", name); - // return viewModelNode; - //} - - viewModelNode = new ViewModelNode(); - viewModelNode.Name = name; - - var position = node.Attribute("Position")?.Value; - if (position != null) - viewModelNode.Point1 = MyPoint.Parse(position); - - var isCollapse = node.Attribute("IsCollapse")?.Value; - if (isCollapse != null) - viewModelNode.IsCollapse = bool.Parse(isCollapse); - - return viewModelNode; - } - //public static async Task<(ViewModelNode node, string message)> FromXElement(ViewModelNodesCanvas nodesCanvas, XElement node, Func actionForCheck) - //{ - // string errorMessage = null; - // ViewModelNode viewModelNode = null; - // string name = node.Attribute("Name")?.Value; - - // if (string.IsNullOrEmpty(name)) - // { - // errorMessage = "Node without name"; - // return (viewModelNode, errorMessage); - // } - - // if (actionForCheck(name)) - // { - // errorMessage = String.Format("Contains more than one node with name \"{0}\"", name); - // return (viewModelNode, errorMessage); - // } - - // viewModelNode = new ViewModelNode(nodesCanvas); - // viewModelNode.Name = name; - - // var position = node.Attribute("Position")?.Value; - // if (position != null) - // viewModelNode.Point1 = MyPoint.Parse(position); - - // var isCollapse = node.Attribute("IsCollapse")?.Value; - // if (isCollapse != null) - // viewModelNode.Collapse(!bool.Parse(isCollapse)); - - // return (viewModelNode, errorMessage); - //} } } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs index 88c78a8..d3673c9 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelSelector.cs @@ -6,7 +6,6 @@ using ReactiveUI.Fody.Helpers; using SimpleStateMachineNodeEditor.Helpers; -using SimpleStateMachineNodeEditor.Helpers.Commands; using SimpleStateMachineNodeEditor.Helpers.Transformations; using System.Reactive; @@ -52,11 +51,17 @@ public MyPoint Point2WithScale } - public ViewModelSelector() + { + SetupCommands(); + SetupSubscriptions(); + } + + #region Setup Subscriptions + + private void SetupSubscriptions() { this.WhenAnyValue(x => x.Point1.Value, x => x.Point2.Value).Subscribe(_ => UpdateSize()); - SetupCommands(); } private void UpdateSize() { @@ -65,14 +70,14 @@ private void UpdateSize() Scale.Scales.Set(((different.X > 0) ? 1 : -1), ((different.Y > 0) ? 1 : -1)); } + #endregion Setup Subscriptions + #region Setup Commands public ReactiveCommand CommandStartSelect { get; set; } - public ReactiveCommand CommandEndSelect { get; set; } private void SetupCommands() { CommandStartSelect = ReactiveCommand.Create(StartSelect); - CommandEndSelect = ReactiveCommand.Create(EndSelect); } private void StartSelect(MyPoint point) @@ -80,10 +85,6 @@ private void StartSelect(MyPoint point) Visible = true; Point1.Set(point); } - private void EndSelect() - { - - } #endregion Setup Commands } From 649396295be7d53cdbd6bfa0340d62ad7cbe080b Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 21:11:41 +0300 Subject: [PATCH 08/17] some fix --- .../SimpleStateMachineNodeEditor.csproj | 2 +- .../{StateMachine_16x.ico => StateMachine.ico} | Bin SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs | 3 ++- .../View/ViewRightConnector.xaml.cs | 3 ++- .../NodesCanvas/ViewModelNodesCanvasCommands.cs | 1 + .../ViewModel/ViewModelNode.cs | 3 ++- 6 files changed, 8 insertions(+), 4 deletions(-) rename SimpleStateMachineNodeEditor/{StateMachine_16x.ico => StateMachine.ico} (100%) diff --git a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj index 0a7e087..36ca6eb 100644 --- a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj +++ b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj @@ -5,7 +5,7 @@ netcoreapp3.1 true SimpleStateMachineNodeEditor.App - StateMachine_16x.ico + StateMachine.ico diff --git a/SimpleStateMachineNodeEditor/StateMachine_16x.ico b/SimpleStateMachineNodeEditor/StateMachine.ico similarity index 100% rename from SimpleStateMachineNodeEditor/StateMachine_16x.ico rename to SimpleStateMachineNodeEditor/StateMachine.ico diff --git a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs index bd1d179..d51bb61 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs @@ -129,7 +129,8 @@ private void OnEventMouseLeftDowns(MouseButtonEventArgs e) } private void Validate(RoutedEventArgs e) { - ViewModel.CommandValidateName.ExecuteWithSubscribe(NodeHeaderElement.TextBox.Text); + if (NodeHeaderElement.TextBox.Text != ViewModel.Name) + ViewModel.CommandValidateName.ExecuteWithSubscribe(NodeHeaderElement.TextBox.Text); if (NodeHeaderElement.TextBox.Text != ViewModel.Name) NodeHeaderElement.TextBox.Text = ViewModel.Name; } diff --git a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs index ba2f339..c1015c5 100644 --- a/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs @@ -99,7 +99,8 @@ private void OnEventMouseOver(bool value) } private void Validate(RoutedEventArgs e) { - ViewModel.CommandValidateName.ExecuteWithSubscribe(TextBoxElement.Text); + if (TextBoxElement.Text != ViewModel.Name) + ViewModel.CommandValidateName.ExecuteWithSubscribe(TextBoxElement.Text); if (TextBoxElement.Text != ViewModel.Name) TextBoxElement.Text = ViewModel.Name; } diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index fd3827c..615edcb 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -236,6 +236,7 @@ private void ClearScheme() this.Nodes.Clear(); this.Connects.Clear(); this.SchemePath = ""; + this.NodesCount = 0; this.SetupStartState(); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index 22295b7..197b787 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -190,7 +190,8 @@ private void Move(MyPoint delta) } private void ValidateName(string newName) { - NodesCanvas.CommandValidateNodeName.ExecuteWithSubscribe((this, newName)); + + NodesCanvas.CommandValidateNodeName.ExecuteWithSubscribe((this, newName)); } private void UpdatePoint2() { From f44425baa67d155de84994ced1dfebc501911f56 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Sun, 24 May 2020 23:09:04 +0300 Subject: [PATCH 09/17] some fix --- .../View/ViewNode.xaml.cs | 29 ----------------- .../View/ViewNodesCanvas.xaml | 2 +- .../View/ViewNodesCanvas.xaml.cs | 24 +++----------- .../NodesCanvas/ViewModelNodesCanvas.cs | 21 ++++++++----- .../ViewModelNodesCanvasCommands.cs | 17 ++++++++-- .../ViewModel/ViewModelNode.cs | 31 +++++++++++-------- 6 files changed, 50 insertions(+), 74 deletions(-) diff --git a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs index d51bb61..13b1dbd 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs @@ -102,14 +102,9 @@ private void SetupEvents() { this.WhenAnyValue(x=>x.IsMouseOver).Subscribe(value=> OnEventMouseOver(value)).DisposeWith(disposable); this.Events().MouseLeftButtonDown.Subscribe(e => OnEventMouseLeftDowns(e)).DisposeWith(disposable); - //this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)).DisposeWith(disposable); - //this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); - //this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); this.Events().MouseDown.Subscribe(e => OnEventMouseDown(e)).DisposeWith(disposable); this.Events().MouseUp.Subscribe(e => OnEventMouseUp(e)).DisposeWith(disposable); this.Events().MouseMove.Subscribe(e => OnMouseMove(e)).DisposeWith(disposable); - //this.Events().MouseEnter.Subscribe(e => OnEventMouseEnter(e)).DisposeWith(disposable); - //this.Events().MouseLeave.Subscribe(e => OnEventMouseMouseLeave(e)).DisposeWith(disposable); this.NodeHeaderElement.ButtonCollapse.Events().Click.Subscribe(_ => ViewModel.IsCollapse=!ViewModel.IsCollapse).DisposeWith(disposable); this.NodeHeaderElement.Events().LostFocus.Subscribe(e => Validate(e)).DisposeWith(disposable); @@ -135,17 +130,6 @@ private void Validate(RoutedEventArgs e) NodeHeaderElement.TextBox.Text = ViewModel.Name; } - private void OnEventMouseLeftUp(MouseButtonEventArgs e) - { - } - private void OnEventMouseRightDown(MouseButtonEventArgs e) - { - - } - private void OnEventMouseRightUp(MouseButtonEventArgs e) - { - } - private void OnEventMouseDown(MouseButtonEventArgs e) { if (Mouse.Captured == null) @@ -160,19 +144,6 @@ private void OnEventMouseUp(MouseButtonEventArgs e) { this.ReleaseMouseCapture(); } - - private void OnEventMouseEnter(MouseEventArgs e) - { - if (this.ViewModel.Selected != true) - this.ViewModel.BorderBrush = Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush; - } - private void OnEventMouseMouseLeave(MouseEventArgs e) - { - if (this.ViewModel.Selected != true) - this.ViewModel.BorderBrush = Application.Current.Resources["ColorNodeBorderBrush"] as SolidColorBrush; - } - - private void OnEventCollapse(bool isCollapse) { //bool visible = (this.NodeHeaderElement.ButtonRotate.Angle != 0); diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml index d9c9343..f8ac6a5 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml @@ -59,7 +59,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs index 3028ffd..bd3c4db 100644 --- a/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs +++ b/SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs @@ -107,7 +107,7 @@ private void SetupCommands() this.BindCommand(this.ViewModel, x => x.CommandSelectAll, x => x.ItemExpandDown).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedElements, x => x.BindingDeleteSelectedElements).DisposeWith(disposable); - + this.BindCommand(this.ViewModel, x => x.CommandDeleteSelectedElements, x => x.ItemDelete).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandCollapseUpSelected, x => x.ItemCollapsUp).DisposeWith(disposable); this.BindCommand(this.ViewModel, x => x.CommandExpandDownSelected, x => x.ItemExpandDown).DisposeWith(disposable); @@ -119,6 +119,8 @@ private void SetupCommands() this.WhenAnyValue(x => x.ViewModel.JPEGPath).Where(x=>!string.IsNullOrEmpty(x)).Subscribe(value=> SaveCanvasToImage(value, ImageFormats.JPEG)).DisposeWith(disposable); + + }); } #endregion Setup Commands @@ -131,15 +133,11 @@ private void SetupEvents() this.Events().MouseLeftButtonDown.Subscribe(e => OnEventMouseLeftDown(e)).DisposeWith(disposable); this.Events().MouseLeftButtonUp.Subscribe(e => OnEventMouseLeftUp(e)); this.Events().MouseRightButtonDown.Subscribe(e => OnEventMouseRightDown(e)).DisposeWith(disposable); - //this.Events().MouseRightButtonUp.Subscribe(e => OnEventMouseRightUp(e)).DisposeWith(disposable); - //this.Events().MouseDown.Subscribe(e => OnEventMouseDown(e)).DisposeWith(disposable); this.Events().MouseUp.Subscribe(e => OnEventMouseUp(e)).DisposeWith(disposable); this.Events().MouseMove.Subscribe(e => OnEventMouseMove(e)).DisposeWith(disposable); this.Events().MouseWheel.Subscribe(e => OnEventMouseWheel(e)).DisposeWith(disposable); this.Events().DragOver.Subscribe(e => OnEventDragOver(e)).DisposeWith(disposable); - //this.Events().DragEnter.Subscribe(e => OnEventDragEnter(e)).DisposeWith(disposable); - //this.Events().DragLeave.Subscribe(e => OnEventDragLeave(e)).DisposeWith(disposable); - //Эти события срабатывают раньше команд + this.Cutter.Events().MouseLeftButtonUp.InvokeCommand(this.ViewModel.CommandDeleteSelectedConnectors).DisposeWith(disposable); this.Events().PreviewMouseLeftButtonDown.Subscribe(e => OnEventPreviewMouseLeftButtonDown(e)).DisposeWith(disposable); this.Events().PreviewMouseRightButtonDown.Subscribe(e => OnEventPreviewMouseRightButtonDown(e)).DisposeWith(disposable); this.WhenAnyValue(x => x.ViewModel.Scale.Value).Subscribe(value => { this.Canvas.Height /= value; this.Canvas.Width /= value; }).DisposeWith(disposable); @@ -176,12 +174,6 @@ private void OnEventMouseRightDown(MouseButtonEventArgs e) { Keyboard.Focus(this); - } - private void OnEventMouseRightUp(MouseButtonEventArgs e) - { - } - private void OnEventMouseDown(MouseButtonEventArgs e) - { } private void OnEventMouseWheel(MouseWheelEventArgs e) { @@ -215,10 +207,6 @@ private void OnEventMouseMove(MouseEventArgs e) ViewModel.CommandPartMoveAllSelectedNode.ExecuteWithSubscribe(delta); Move = TypeMove.MoveSelected; } - } - private void OnEventDragEnter(DragEventArgs e) - { - } private void OnEventDragOver(DragEventArgs e) { @@ -228,10 +216,6 @@ private void OnEventDragOver(DragEventArgs e) point -= 2; this.ViewModel.DraggedConnect.EndPoint.Set(point / this.ViewModel.Scale.Value); } - } - private void OnEventDragLeave(DragEventArgs e) - { - } private void OnEventPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs index 29db154..98b39f9 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs @@ -38,6 +38,7 @@ public partial class ViewModelNodesCanvas : ReactiveObject [Reactive] public string JPEGPath{ get; set; } public int NodesCount = 0; + public int TransitionsCount = 0; public double ScaleMax = 5; public double ScaleMin = 0.1; public double Scales { get; set; } = 0.05; @@ -45,14 +46,19 @@ public partial class ViewModelNodesCanvas : ReactiveObject public ViewModelNodesCanvas() { + Cutter = new ViewModelCutter(this); SetupCommands(); + SetupSubscriptions(); SetupStartState(); - Cutter = new ViewModelCutter(this); - this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value)); } - public readonly object lockNodes = new object(); - public readonly object lockConnects = new object(); + #region Setup Subscriptions + + private void SetupSubscriptions() + { + this.WhenAnyValue(x => x.Nodes.Count).Buffer(2, 1).Select(x => (Previous: x[0], Current: x[1])).Subscribe(x => UpdateCount(x.Previous, x.Current)); + } + #endregion Setup Subscriptions #region Setup Nodes private void SetupStartState() @@ -105,12 +111,11 @@ public void LogWarning(string message, params object[] args) } #endregion Logging - - private void UpdateCount(int count) + private void UpdateCount(int oldValue, int newValue) { - if (count > NodesCount) + if (newValue > oldValue) { - NodesCount = count; + NodesCount++; } } private string SchemeName() diff --git a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs index 615edcb..12f9084 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs @@ -205,7 +205,7 @@ private void SelectConnects() { connect.FromConnector.Selected = MyUtils.CheckIntersectCubicBezierCurveAndLine(connect.StartPoint, connect.Point1, connect.Point2, connect.EndPoint, cutterStartPoint, cutterEndPoint); } - + } private void SelectNodes() { @@ -235,9 +235,10 @@ private void ClearScheme() { this.Nodes.Clear(); this.Connects.Clear(); - this.SchemePath = ""; this.NodesCount = 0; - + this.TransitionsCount = 0; + this.SchemePath = ""; + this.SetupStartState(); } private void Open() @@ -515,6 +516,10 @@ private ViewModelNode AddNodeWithUndoRedo(MyPoint parameter, ViewModelNode resul Point1 = new MyPoint(myPoint) }; } + else + { + NodesCount--; + } Nodes.Add(newNode); return newNode; } @@ -527,6 +532,9 @@ private ViewModelConnector AddConnectorWithConnect(ViewModelConnector parameter, { if (result == null) return parameter; + else + TransitionsCount--; + result.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((1, result)); return result; } @@ -607,6 +615,7 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res { foreach (var element in result) { + TransitionsCount--; element.connector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((element.index, element.connector)); } @@ -645,11 +654,13 @@ private ElementsForDelete DeleteSelectedNodes(ElementsForDelete parameter, Eleme } private ElementsForDelete UnDeleteSelectedNodes(ElementsForDelete parameter, ElementsForDelete result) { + NodesCount -= result.NodesToDelete.Count; Nodes.AddRange(result.NodesToDelete); Connects.AddRange(result.ConnectsToDelete); result.ConnectsToDeleteWithConnectors.Sort(ElementsForDelete.Sort); foreach (var element in result.ConnectsToDeleteWithConnectors) { + TransitionsCount--; element.connect.FromConnector.Node.CommandAddConnectorWithConnect.ExecuteWithSubscribe((element.connectorIndex, element.connect.FromConnector)); } diff --git a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs index 197b787..55b2d6d 100644 --- a/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs +++ b/SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs @@ -41,9 +41,6 @@ public class ViewModelNode : ReactiveValidationObject public IObservableCollection Transitions { get; set; } = new ObservableCollectionExtended(); public int Zindex { get; private set; } - - public int TransitionsCount = -1; - private ViewModelNode() { @@ -56,24 +53,30 @@ public ViewModelNode(ViewModelNodesCanvas nodesCanvas) { NodesCanvas = nodesCanvas; Zindex = nodesCanvas.Nodes.Count; - + SetupConnectors(); SetupCommands(); - SetupBinding(); - + SetupBinding(); + SetupSubscriptions(); } #region SetupBinding private void SetupBinding() + { + } + #endregion SetupBinding + + #region Setup Subscriptions + + private void SetupSubscriptions() { this.WhenAnyValue(x => x.Selected).Subscribe(value => { this.BorderBrush = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Brushes.LightGray; }); - this.WhenAnyValue(x => x.Transitions.Count).Subscribe(value => UpdateCount(value)); + this.WhenAnyValue(x => x.Transitions.Count).Buffer(2, 1).Select(x => (Previous: x[0], Current: x[1])).Subscribe(x => UpdateCount(x.Previous, x.Current)); this.WhenAnyValue(x => x.Point1.Value, x => x.Size).Subscribe(_ => UpdatePoint2()); this.WhenAnyValue(x => x.IsCollapse).Subscribe(value => Collapse(value)); } - #endregion SetupBinding - + #endregion Setup Subscriptions #region Connectors private void SetupConnectors() { @@ -128,10 +131,12 @@ private void NotSaved() { NodesCanvas.ItSaved = false; } - private void UpdateCount(int count) + private void UpdateCount(int oldValue, int newValue) { - if (count > TransitionsCount) - TransitionsCount = count; + if (newValue > oldValue) + { + NodesCanvas.TransitionsCount++; + } } #endregion Setup Commands @@ -205,7 +210,7 @@ private void AddEmptyConnector() CurrentConnector.TextEnable = true; CurrentConnector.FormEnable = false; if (string.IsNullOrEmpty(CurrentConnector.Name)) - CurrentConnector.Name = "Transition " + TransitionsCount.ToString(); + CurrentConnector.Name = "Transition " + NodesCanvas.TransitionsCount.ToString(); } CurrentConnector = new ViewModelConnector(NodesCanvas, this) { From 3389781451038229bcad49153de9621637730ca1 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Mon, 25 May 2020 01:06:17 +0300 Subject: [PATCH 10/17] fix for light theme --- SimpleStateMachineNodeEditor/App.xaml | 13 ++++---- .../Icons/AddNode.xaml | 2 +- SimpleStateMachineNodeEditor/Icons/Close.xaml | 2 +- .../Icons/CollapseUp.xaml | 2 +- .../Icons/CollapseUpAll.xaml | 2 +- SimpleStateMachineNodeEditor/Icons/Copy.xaml | 2 +- .../Icons/DeleteScheme.xaml | 2 +- .../Icons/ErrorList.xaml | 2 +- .../Icons/ExpandDown.xaml | 2 +- .../Icons/ExpandDownAll.xaml | 2 +- .../Icons/ExportScheme.xaml | 4 +-- SimpleStateMachineNodeEditor/Icons/Icons.xaml | 5 +-- .../Icons/ImportScheme.xaml | 2 +- .../Icons/Maximize.xaml | 2 +- .../Icons/Minimize.xaml | 5 ++- .../Icons/NewSheme.xaml | 2 +- SimpleStateMachineNodeEditor/Icons/Redo.xaml | 4 +-- .../Icons/Relationship.xaml | 15 --------- .../Icons/Restore.xaml | 2 +- SimpleStateMachineNodeEditor/Icons/Save.xaml | 2 +- .../Icons/SaveAs.xaml | 8 ++--- .../Icons/SelectAll.xaml | 4 +-- SimpleStateMachineNodeEditor/Icons/Test.xaml | 33 ------------------- .../Icons/Test.xaml.cs | 26 --------------- SimpleStateMachineNodeEditor/Icons/Undo.xaml | 6 ++-- .../Icons/Update.xaml | 2 +- .../Icons/ZoomIn.xaml | 4 +-- .../Icons/ZoomOriginalSize.xaml | 5 ++- .../Icons/ZoomOut.xaml | 6 ++-- .../SimpleStateMachineNodeEditor.csproj | 6 ---- .../Header/StyleHeaderButtonClosePath.xaml | 15 --------- .../MainWindow/ToolBar/TemplateSeparator.xaml | 4 +-- .../Styles/Themes/Dark.xaml | 13 ++++---- .../Styles/Themes/Light.xaml | 15 ++++----- .../View/MainWindow.xaml | 12 +++---- .../NodesCanvas/ViewModelNodesCanvas.cs | 2 +- 36 files changed, 65 insertions(+), 170 deletions(-) delete mode 100644 SimpleStateMachineNodeEditor/Icons/Relationship.xaml delete mode 100644 SimpleStateMachineNodeEditor/Icons/Test.xaml delete mode 100644 SimpleStateMachineNodeEditor/Icons/Test.xaml.cs delete mode 100644 SimpleStateMachineNodeEditor/Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml diff --git a/SimpleStateMachineNodeEditor/App.xaml b/SimpleStateMachineNodeEditor/App.xaml index 0301c99..60ab671 100644 --- a/SimpleStateMachineNodeEditor/App.xaml +++ b/SimpleStateMachineNodeEditor/App.xaml @@ -6,9 +6,11 @@ + + - - + + @@ -46,12 +48,11 @@ - + - + - - + diff --git a/SimpleStateMachineNodeEditor/Icons/AddNode.xaml b/SimpleStateMachineNodeEditor/Icons/AddNode.xaml index 0feff5a..49909d8 100644 --- a/SimpleStateMachineNodeEditor/Icons/AddNode.xaml +++ b/SimpleStateMachineNodeEditor/Icons/AddNode.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Close.xaml b/SimpleStateMachineNodeEditor/Icons/Close.xaml index 69330c2..96a2972 100644 --- a/SimpleStateMachineNodeEditor/Icons/Close.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Close.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/CollapseUp.xaml b/SimpleStateMachineNodeEditor/Icons/CollapseUp.xaml index 29015f4..ac799cc 100644 --- a/SimpleStateMachineNodeEditor/Icons/CollapseUp.xaml +++ b/SimpleStateMachineNodeEditor/Icons/CollapseUp.xaml @@ -5,7 +5,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml b/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml index 535f979..aa0dd70 100644 --- a/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml +++ b/SimpleStateMachineNodeEditor/Icons/CollapseUpAll.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Copy.xaml b/SimpleStateMachineNodeEditor/Icons/Copy.xaml index 7f4aecb..c71148e 100644 --- a/SimpleStateMachineNodeEditor/Icons/Copy.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Copy.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/DeleteScheme.xaml b/SimpleStateMachineNodeEditor/Icons/DeleteScheme.xaml index a415675..be561d2 100644 --- a/SimpleStateMachineNodeEditor/Icons/DeleteScheme.xaml +++ b/SimpleStateMachineNodeEditor/Icons/DeleteScheme.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/ErrorList.xaml b/SimpleStateMachineNodeEditor/Icons/ErrorList.xaml index bfe780f..ef2c1d6 100644 --- a/SimpleStateMachineNodeEditor/Icons/ErrorList.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ErrorList.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/ExpandDown.xaml b/SimpleStateMachineNodeEditor/Icons/ExpandDown.xaml index 2a34f2a..65cfb86 100644 --- a/SimpleStateMachineNodeEditor/Icons/ExpandDown.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ExpandDown.xaml @@ -5,7 +5,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml b/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml index f16cf41..bd8a395 100644 --- a/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ExpandDownAll.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/ExportScheme.xaml b/SimpleStateMachineNodeEditor/Icons/ExportScheme.xaml index 9730577..7156a2e 100644 --- a/SimpleStateMachineNodeEditor/Icons/ExportScheme.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ExportScheme.xaml @@ -5,9 +5,9 @@ - + - + diff --git a/SimpleStateMachineNodeEditor/Icons/Icons.xaml b/SimpleStateMachineNodeEditor/Icons/Icons.xaml index 081fc85..27aba44 100644 --- a/SimpleStateMachineNodeEditor/Icons/Icons.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Icons.xaml @@ -1,8 +1,10 @@  - + + + @@ -25,7 +27,6 @@ - diff --git a/SimpleStateMachineNodeEditor/Icons/ImportScheme.xaml b/SimpleStateMachineNodeEditor/Icons/ImportScheme.xaml index f2e82fb..4e5f66d 100644 --- a/SimpleStateMachineNodeEditor/Icons/ImportScheme.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ImportScheme.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Maximize.xaml b/SimpleStateMachineNodeEditor/Icons/Maximize.xaml index 6f06a35..571c812 100644 --- a/SimpleStateMachineNodeEditor/Icons/Maximize.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Maximize.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Minimize.xaml b/SimpleStateMachineNodeEditor/Icons/Minimize.xaml index 344f078..37b89bb 100644 --- a/SimpleStateMachineNodeEditor/Icons/Minimize.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Minimize.xaml @@ -3,9 +3,8 @@ - - - + + diff --git a/SimpleStateMachineNodeEditor/Icons/NewSheme.xaml b/SimpleStateMachineNodeEditor/Icons/NewSheme.xaml index 2964243..20e6543 100644 --- a/SimpleStateMachineNodeEditor/Icons/NewSheme.xaml +++ b/SimpleStateMachineNodeEditor/Icons/NewSheme.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Redo.xaml b/SimpleStateMachineNodeEditor/Icons/Redo.xaml index c488049..76decd5 100644 --- a/SimpleStateMachineNodeEditor/Icons/Redo.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Redo.xaml @@ -4,9 +4,7 @@ - - + diff --git a/SimpleStateMachineNodeEditor/Icons/Relationship.xaml b/SimpleStateMachineNodeEditor/Icons/Relationship.xaml deleted file mode 100644 index 4ab5c71..0000000 --- a/SimpleStateMachineNodeEditor/Icons/Relationship.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/SimpleStateMachineNodeEditor/Icons/Restore.xaml b/SimpleStateMachineNodeEditor/Icons/Restore.xaml index 8e1f079..e40577d 100644 --- a/SimpleStateMachineNodeEditor/Icons/Restore.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Restore.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/Save.xaml b/SimpleStateMachineNodeEditor/Icons/Save.xaml index 9015f5d..400018d 100644 --- a/SimpleStateMachineNodeEditor/Icons/Save.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Save.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/SaveAs.xaml b/SimpleStateMachineNodeEditor/Icons/SaveAs.xaml index 47b3213..af997c1 100644 --- a/SimpleStateMachineNodeEditor/Icons/SaveAs.xaml +++ b/SimpleStateMachineNodeEditor/Icons/SaveAs.xaml @@ -4,12 +4,8 @@ - - - + + diff --git a/SimpleStateMachineNodeEditor/Icons/SelectAll.xaml b/SimpleStateMachineNodeEditor/Icons/SelectAll.xaml index 519cf5e..f162acd 100644 --- a/SimpleStateMachineNodeEditor/Icons/SelectAll.xaml +++ b/SimpleStateMachineNodeEditor/Icons/SelectAll.xaml @@ -4,8 +4,8 @@ - - + + diff --git a/SimpleStateMachineNodeEditor/Icons/Test.xaml b/SimpleStateMachineNodeEditor/Icons/Test.xaml deleted file mode 100644 index 4ab47a0..0000000 --- a/SimpleStateMachineNodeEditor/Icons/Test.xaml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - diff --git a/SimpleStateMachineNodeEditor/Icons/Test.xaml.cs b/SimpleStateMachineNodeEditor/Icons/Test.xaml.cs deleted file mode 100644 index 7ec8c66..0000000 --- a/SimpleStateMachineNodeEditor/Icons/Test.xaml.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SimpleStateMachineNodeEditor.Icons -{ - /// - /// Interaction logic for Test.xaml - /// - public partial class Test : UserControl - { - public Test() - { - InitializeComponent(); - } - } -} diff --git a/SimpleStateMachineNodeEditor/Icons/Undo.xaml b/SimpleStateMachineNodeEditor/Icons/Undo.xaml index a424894..3efeca0 100644 --- a/SimpleStateMachineNodeEditor/Icons/Undo.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Undo.xaml @@ -1,12 +1,14 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + > - + + diff --git a/SimpleStateMachineNodeEditor/Icons/Update.xaml b/SimpleStateMachineNodeEditor/Icons/Update.xaml index 4ce5c1c..176c74e 100644 --- a/SimpleStateMachineNodeEditor/Icons/Update.xaml +++ b/SimpleStateMachineNodeEditor/Icons/Update.xaml @@ -4,7 +4,7 @@ - + diff --git a/SimpleStateMachineNodeEditor/Icons/ZoomIn.xaml b/SimpleStateMachineNodeEditor/Icons/ZoomIn.xaml index 2f3fe5a..73c16b8 100644 --- a/SimpleStateMachineNodeEditor/Icons/ZoomIn.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ZoomIn.xaml @@ -4,8 +4,8 @@ - - + + diff --git a/SimpleStateMachineNodeEditor/Icons/ZoomOriginalSize.xaml b/SimpleStateMachineNodeEditor/Icons/ZoomOriginalSize.xaml index 538ddab..c0c176a 100644 --- a/SimpleStateMachineNodeEditor/Icons/ZoomOriginalSize.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ZoomOriginalSize.xaml @@ -4,9 +4,8 @@ - - - + + diff --git a/SimpleStateMachineNodeEditor/Icons/ZoomOut.xaml b/SimpleStateMachineNodeEditor/Icons/ZoomOut.xaml index 26425ba..b82ec7c 100644 --- a/SimpleStateMachineNodeEditor/Icons/ZoomOut.xaml +++ b/SimpleStateMachineNodeEditor/Icons/ZoomOut.xaml @@ -4,10 +4,8 @@ - - - + + diff --git a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj index 36ca6eb..b0ffaf3 100644 --- a/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj +++ b/SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj @@ -54,10 +54,4 @@ - - - Designer - - - \ No newline at end of file diff --git a/SimpleStateMachineNodeEditor/Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml b/SimpleStateMachineNodeEditor/Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml deleted file mode 100644 index ac79c57..0000000 --- a/SimpleStateMachineNodeEditor/Styles/MainWindow/Header/StyleHeaderButtonClosePath.xaml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/SimpleStateMachineNodeEditor/Styles/MainWindow/ToolBar/TemplateSeparator.xaml b/SimpleStateMachineNodeEditor/Styles/MainWindow/ToolBar/TemplateSeparator.xaml index 2ada62d..d30ff05 100644 --- a/SimpleStateMachineNodeEditor/Styles/MainWindow/ToolBar/TemplateSeparator.xaml +++ b/SimpleStateMachineNodeEditor/Styles/MainWindow/ToolBar/TemplateSeparator.xaml @@ -3,8 +3,8 @@ xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Styles.MainWindow.ToolBar">