Skip to content

Commit 11e51da

Browse files
committed
Some fix
Some optimization Feature with opacity Custom for drag and drop textbox Undo - Redo for renaming
1 parent 1d0436b commit 11e51da

10 files changed

+146
-33
lines changed

Diff for: SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
<Description>Node editor for SimpleStateMachine</Description>
1818
<AssemblyVersion>1.0.3.0</AssemblyVersion>
1919
<FileVersion>1.0.3.0</FileVersion>
20-
<PackageReleaseNotes>some fix
21-
some optimization
22-
feature with opacity</PackageReleaseNotes>
20+
<PackageReleaseNotes>Some fix
21+
Some optimization
22+
Feature with opacity
23+
Custom for drag and drop textbox
24+
Undo - Redo for renaming</PackageReleaseNotes>
2325
</PropertyGroup>
2426

2527
<ItemGroup>

Diff for: SimpleStateMachineNodeEditor/Styles/MyTextBox.xaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<TextBox x:Class="SimpleStateMachineNodeEditor.Styles.MyTextBox"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Styles"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800" AllowDrop="True" IsUndoEnabled="True" TextWrapping="NoWrap" BorderThickness="0,0,0,0" Background="{x:Null}" BorderBrush="{x:Null}" Style="{DynamicResource StyleEmptyTextBox}">
9+
</TextBox>
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Data;
7+
using System.Windows.Documents;
8+
using System.Windows.Input;
9+
using System.Windows.Media;
10+
using System.Windows.Media.Imaging;
11+
using System.Windows.Navigation;
12+
using System.Windows.Shapes;
13+
14+
namespace SimpleStateMachineNodeEditor.Styles
15+
{
16+
/// <summary>
17+
/// Логика взаимодействия для TestBox.xaml
18+
/// </summary>
19+
public partial class MyTextBox : TextBox
20+
{
21+
public MyTextBox()
22+
{
23+
InitializeComponent();
24+
this.ContextMenu = null;
25+
}
26+
27+
protected override void OnDragEnter(DragEventArgs e)
28+
{
29+
if(e.Effects != DragDropEffects.Move)
30+
{
31+
base.OnDragEnter(e);
32+
}
33+
}
34+
35+
36+
protected override void OnDragOver(DragEventArgs e)
37+
{
38+
if (e.Effects != DragDropEffects.Move)
39+
{
40+
base.OnDragOver(e);
41+
}
42+
}
43+
}
44+
}

Diff for: SimpleStateMachineNodeEditor/Styles/Node/ElementNodeHeader.xaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Styles.Node"
7-
mc:Ignorable="d"
8-
>
6+
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.Styles.Node"
7+
xmlns:styles="clr-namespace:SimpleStateMachineNodeEditor.Styles"
8+
mc:Ignorable="d" >
99
<Border CornerRadius="5,5,0,0" VerticalAlignment="Stretch" >
1010
<Border.Background>
1111
<SolidColorBrush Color="{DynamicResource ColorNodeHeader}" />
1212
</Border.Background>
13-
<Grid>
13+
<Grid >
1414
<Grid.ColumnDefinitions>
1515
<ColumnDefinition Width="*" />
1616
<ColumnDefinition Width="*" />
1717
</Grid.ColumnDefinitions>
1818
<Grid.RowDefinitions>
1919
<RowDefinition />
2020
</Grid.RowDefinitions>
21-
<TextBox Name="TextBox" Grid.Column="0" VerticalAlignment="Center" VerticalContentAlignment="Center" Style="{DynamicResource StyleEmptyTextBox}" HorizontalContentAlignment="Center" BorderThickness="0,0,0,0" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{DynamicResource ColorNodeHeaderForeground}" Padding="10,2,0,2" ScrollViewer.CanContentScroll="True" HorizontalAlignment="Center" />
22-
<Button Name ="ButtonCollapse" Grid.Column="1" Style="{DynamicResource StyleNodeCollapseButton}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5">
21+
<styles:MyTextBox x:Name="TextBoxElement" Grid.Column="0" VerticalAlignment="Center" ScrollViewer.CanContentScroll="True" HorizontalAlignment="Center" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="{DynamicResource ColorNodeHeaderForeground}" Padding="10,2,0,2" />
22+
<Button Name ="ButtonCollapse" Grid.Column="1" Style="{DynamicResource StyleNodeCollapseButton}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5" >
2323
<Button.RenderTransform>
2424
<TransformGroup>
2525
<RotateTransform x:Name="ButtonRotate" Angle="0" CenterX="4" CenterY="2" />

Diff for: SimpleStateMachineNodeEditor/Styles/StyleEmptyTextBox.xaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
<Setter.Value>
1313
<ControlTemplate TargetType="{x:Type TextBox}">
1414
<Border x:Name="border" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True" >
15-
<Border.ContextMenu>
16-
<ContextMenu Visibility="Collapsed"/>
17-
</Border.ContextMenu>
1815
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
16+
1917
</Border>
2018
</ControlTemplate>
2119
</Setter.Value>

Diff for: SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.View"
6+
xmlns:local="clr-namespace:SimpleStateMachineNodeEditor.View"
7+
xmlns:styles="clr-namespace:SimpleStateMachineNodeEditor.Styles"
78
x:Name="LeftConnector" HorizontalAlignment="Stretch" VerticalAlignment="Top" AllowDrop="True" >
89
<Grid x:Name="GridElement" Background="#00000000">
910
<Grid.ColumnDefinitions>
@@ -13,7 +14,7 @@
1314
<Grid.RowDefinitions>
1415
<RowDefinition />
1516
</Grid.RowDefinitions>
16-
<TextBox Name="TextBoxElement" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,5,3" TextWrapping="NoWrap" BorderThickness="0,0,0,0" Background="{x:Null}" BorderBrush="{x:Null}" Style="{DynamicResource StyleEmptyTextBox}"/>
17+
<styles:MyTextBox x:Name="TextBoxElement" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,5,3" />
1718
<Ellipse Name="EllipseElement" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="-7,0,0,0" Height="12" Width="12" AllowDrop="True" StrokeThickness="1" />
1819
</Grid>
1920

Diff for: SimpleStateMachineNodeEditor/View/ViewNode.xaml.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ private void SetupBinding()
6060

6161
this.OneWayBind(this.ViewModel, x => x.BorderBrush, x => x.BorderElement.BorderBrush).DisposeWith(disposable);
6262

63-
this.OneWayBind(this.ViewModel, x => x.Name, x => x.NodeHeaderElement.TextBox.Text).DisposeWith(disposable);
63+
this.OneWayBind(this.ViewModel, x => x.Name, x => x.NodeHeaderElement.TextBoxElement.Text).DisposeWith(disposable);
6464

65-
this.Bind(this.ViewModel, x => x.NameEnable, x => x.NodeHeaderElement.TextBox.IsEnabled).DisposeWith(disposable);
65+
this.Bind(this.ViewModel, x => x.NameEnable, x => x.NodeHeaderElement.TextBoxElement.IsEnabled).DisposeWith(disposable);
6666

6767
this.OneWayBind(this.ViewModel, x => x.Point1.X, x => x.TranslateTransformElement.X).DisposeWith(disposable);
6868

@@ -126,10 +126,10 @@ private void OnEventMouseLeftDowns(MouseButtonEventArgs e)
126126
}
127127
private void Validate(RoutedEventArgs e)
128128
{
129-
if (NodeHeaderElement.TextBox.Text != ViewModel.Name)
130-
ViewModel.CommandValidateName.ExecuteWithSubscribe(NodeHeaderElement.TextBox.Text);
131-
if (NodeHeaderElement.TextBox.Text != ViewModel.Name)
132-
NodeHeaderElement.TextBox.Text = ViewModel.Name;
129+
if (NodeHeaderElement.TextBoxElement.Text != ViewModel.Name)
130+
ViewModel.CommandValidateName.ExecuteWithSubscribe(NodeHeaderElement.TextBoxElement.Text);
131+
if (NodeHeaderElement.TextBoxElement.Text != ViewModel.Name)
132+
NodeHeaderElement.TextBoxElement.Text = ViewModel.Name;
133133
}
134134

135135
private void OnEventMouseDown(MouseButtonEventArgs e)

Diff for: SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:enums="clr-namespace:SimpleStateMachineNodeEditor.Helpers.Enums"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:styles="clr-namespace:SimpleStateMachineNodeEditor.Styles"
78
mc:Ignorable="d"
89
x:Name="RightConnector" HorizontalAlignment="Stretch" VerticalAlignment="Top" BorderThickness="0" AllowDrop="True">
910
<Grid x:Name="GridElement" Background="#00000000" >
@@ -14,7 +15,7 @@
1415
<Grid.RowDefinitions>
1516
<RowDefinition />
1617
</Grid.RowDefinitions>
17-
<TextBox Name="TextBoxElement" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,0,5,3" TextWrapping="NoWrap" BorderThickness="0,0,0,0" Background="{x:Null}" BorderBrush="{x:Null}" Style="{DynamicResource StyleEmptyTextBox}"/>
18+
<styles:MyTextBox x:Name="TextBoxElement" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,0,5,3" />
1819
<Ellipse Name="EllipseElement" Grid.Row="0" Grid.Column="1" Margin="0,0,-7,0" HorizontalAlignment="Right" VerticalAlignment="Center" Height="12" Width="12" AllowDrop="True" StrokeThickness="1" />
1920
</Grid>
2021
</UserControl>

Diff for: SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ private void SetupEvents()
100100
this.TextBoxElement.Events().LostFocus.Subscribe(e => Validate(e)).DisposeWith(disposable);
101101
this.GridElement.Events().PreviewMouseLeftButtonDown.Subscribe(e => ConnectorDrag(e)).DisposeWith(disposable);
102102
this.GridElement.Events().PreviewDragEnter.Subscribe(e => ConnectorDragEnter(e)).DisposeWith(disposable);
103-
this.GridElement.Events().PreviewDragOver.Subscribe(e => e.Handled = true).DisposeWith(disposable);
104103
this.GridElement.Events().PreviewDrop.Subscribe(e => ConnectorDrop(e)).DisposeWith(disposable);
105104
});
106105
}
@@ -129,7 +128,7 @@ private void ConnectDrag(MouseButtonEventArgs e)
129128
this.ViewModel.CommandConnectPointDrag.ExecuteWithSubscribe();
130129
DataObject data = new DataObject();
131130
data.SetData("Node", this.ViewModel.Node);
132-
DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
131+
DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
133132
this.ViewModel.CommandCheckConnectPointDrop.ExecuteWithSubscribe();
134133
e.Handled = true;
135134
}
@@ -144,7 +143,7 @@ private void ConnectorDrag(MouseButtonEventArgs e)
144143
this.ViewModel.CommandConnectorDrag.ExecuteWithSubscribe();
145144
DataObject data = new DataObject();
146145
data.SetData("Connector", this.ViewModel);
147-
DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
146+
DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
148147
}
149148
else if (Keyboard.IsKeyDown(Key.LeftShift))
150149
{

Diff for: SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs

+68-9
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public partial class ViewModelNodesCanvas
7474
public Command<List<(int index, ViewModelConnector element)>, List<(int index, ViewModelConnector element)>> CommandDeleteSelectedConnectors { get; set; }
7575
public Command<DeleteMode, DeleteMode> CommandDeleteSelectedElements { get; set; }
7676

77+
78+
public Command<(ViewModelNode node, string newName), (ViewModelNode node, string oldName)> CommandChangeNodeName { get; set; }
79+
public Command<(ViewModelConnector connector, string newName), (ViewModelConnector connector, string oldName)> CommandChangeConnectName { get; set; }
80+
7781
#endregion commands with undo-redo
7882

7983
private void SetupCommands()
@@ -130,8 +134,9 @@ private void SetupCommands()
130134
CommandDeleteSelectedNodes = new Command<ElementsForDelete, ElementsForDelete>(DeleteSelectedNodes, UnDeleteSelectedNodes, NotSaved);
131135
CommandDeleteSelectedConnectors = new Command<List<(int index, ViewModelConnector element)>, List<(int index, ViewModelConnector connector)>>(DeleteSelectedConnectors, UnDeleteSelectedConnectors, NotSaved);
132136
CommandDeleteSelectedElements = new Command<DeleteMode, DeleteMode>(DeleteSelectedElements, UnDeleteSelectedElements);
137+
CommandChangeNodeName = new Command<(ViewModelNode node, string newName), (ViewModelNode node, string oldName)>(ChangeNodeName, UnChangeNodeName);
138+
CommandChangeConnectName = new Command<(ViewModelConnector connector, string newName), (ViewModelConnector connector, string oldName)>(ChangeConnectName, UnChangeConnectName);
133139

134-
135140

136141
NotSavedSubscrube();
137142
}
@@ -376,7 +381,10 @@ private void Save()
376381
}
377382
else
378383
{
379-
Save(SchemePath);
384+
WithValidateScheme(() =>
385+
{
386+
Save(SchemePath);
387+
});
380388
}
381389
}
382390
private void Exit()
@@ -387,14 +395,18 @@ private void Exit()
387395
}
388396
private void SaveAs()
389397
{
390-
Dialog.ShowSaveFileDialog("XML-File | *.xml", SchemeName(), "Save scheme as...");
391-
if (Dialog.Result != DialogResult.Ok)
392-
return;
398+
WithValidateScheme(()=>
399+
{
400+
Dialog.ShowSaveFileDialog("XML-File | *.xml", SchemeName(), "Save scheme as...");
401+
if (Dialog.Result != DialogResult.Ok)
402+
return;
393403

394-
Save(Dialog.FileName);
404+
Save(Dialog.FileName);
405+
});
395406
}
396407
private void Save(string fileName)
397408
{
409+
398410
Mouse.OverrideCursor = Cursors.Wait;
399411
XDocument xDocument = new XDocument();
400412
XElement stateMachineXElement = new XElement("StateMachine");
@@ -424,7 +436,29 @@ private void Save(string fileName)
424436
Mouse.OverrideCursor = null;
425437
LogDebug("Scheme was saved as \"{0}\"", SchemePath);
426438
}
439+
private void WithValidateScheme(Action action)
440+
{
441+
var unReachable = ValidateScheme();
442+
if (unReachable.Count < 1)
443+
{
444+
action.Invoke();
445+
}
446+
else
447+
{
448+
LogError("Nodes without connects: {0}", string.Join(',', unReachable));
449+
}
450+
}
451+
private List<string> ValidateScheme()
452+
{
453+
Dictionary<string, bool> forValidate = Nodes.Where(x=>x!=StartState).ToDictionary(x => x.Name, x=>false);
427454

455+
foreach(var connect in Connects )
456+
{
457+
forValidate[connect.ToConnector.Node.Name] = true;
458+
}
459+
460+
return forValidate.Where(x => !x.Value).Select(x=>x.Key).ToList();
461+
}
428462

429463
private void StartSelect(Point point)
430464
{
@@ -481,8 +515,8 @@ private void ValidateNodeName((ViewModelNode objectForValidate, string newValue)
481515
if (!NodesExist(obj.newValue))
482516
{
483517
LogDebug("Node \"{0}\" has been renamed . New name is \"{1}\"", obj.objectForValidate.Name, obj.newValue);
484-
obj.objectForValidate.Name = obj.newValue;
485-
518+
519+
CommandChangeNodeName.Execute((obj.objectForValidate, obj.newValue));
486520
}
487521
else
488522
{
@@ -501,7 +535,8 @@ private void ValidateConnectName((ViewModelConnector objectForValidate, string n
501535
if (!ConnectsExist(obj.newValue))
502536
{
503537
LogDebug("Transition \"{0}\" has been renamed . New name is \"{1}\"", obj.objectForValidate.Name, obj.newValue);
504-
obj.objectForValidate.Name = obj.newValue;
538+
539+
CommandChangeConnectName.Execute((obj.objectForValidate, obj.newValue));
505540
}
506541
else
507542
{
@@ -674,6 +709,30 @@ private DeleteMode UnDeleteSelectedElements(DeleteMode parameter, DeleteMode res
674709

675710
return result;
676711
}
712+
private (ViewModelConnector connector, string oldName) ChangeConnectName((ViewModelConnector connector, string newName) parameter, (ViewModelConnector connector, string oldName) result)
713+
{
714+
string oldName = parameter.connector.Name;
715+
parameter.connector.Name = parameter.newName;
716+
return (parameter.connector, oldName);
717+
}
718+
private (ViewModelConnector connector, string oldName) UnChangeConnectName((ViewModelConnector connector, string newName) parameter, (ViewModelConnector connector, string oldName) result)
719+
{
720+
result.connector.Name = result.oldName;
721+
return result;
722+
}
723+
724+
725+
private (ViewModelNode node, string oldName) ChangeNodeName((ViewModelNode node, string newName) parameter, (ViewModelNode node, string oldName) result)
726+
{
727+
string oldName = parameter.node.Name;
728+
parameter.node.Name = parameter.newName;
729+
return (parameter.node, oldName);
730+
}
731+
private (ViewModelNode node, string oldName) UnChangeNodeName((ViewModelNode node, string newName) parameter, (ViewModelNode node, string oldName) result)
732+
{
733+
result.node.Name = result.oldName;
734+
return result;
735+
}
677736
private ElementsForDelete DeleteSelectedNodes(ElementsForDelete parameter, ElementsForDelete result)
678737
{
679738
if (result == null)

0 commit comments

Comments
 (0)