Skip to content

Commit 57f88d2

Browse files
committed
fix for name
1 parent e61e034 commit 57f88d2

File tree

6 files changed

+91
-88
lines changed

6 files changed

+91
-88
lines changed

SimpleStateMachineNodeEditor/View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
<Label Grid.Column="6" x:Name="LabelInformation" Style="{DynamicResource StyleLabelWithIcon}" BorderBrush="{StaticResource IconInformation}" OpacityMask="{StaticResource ColorElementMouseOver}">Messages</Label>
187187
<Separator Grid.Column="7" Visibility="{Binding ElementName=LabelDebug, Path=Visibility}" Style="{DynamicResource TemplateSeparator}" Height="Auto" BorderThickness="0,0,1,0" />
188188
<Label Grid.Column="8" x:Name="LabelDebug" Visibility="Hidden" Style="{DynamicResource StyleLabelWithIcon}" BorderBrush="{StaticResource IconDebug}" OpacityMask="{StaticResource ColorElementMouseOver}">Debug</Label>
189-
<Label Grid.Column="9" x:Name="LabelUpdate" Style="{DynamicResource StyleLabelWithIcon}" BorderBrush="{StaticResource IconUpdate}" OpacityMask="{StaticResource ColorElementMouseOver}" HorizontalAlignment="Right" Margin="0,0,5,0">Update</Label>
189+
<Label Grid.Column="9" x:Name="LabelErrorListUpdate" Style="{DynamicResource StyleLabelWithIcon}" BorderBrush="{StaticResource IconUpdate}" OpacityMask="{StaticResource ColorElementMouseOver}" HorizontalAlignment="Right" Margin="0,0,5,0">Update/Clear</Label>
190190
</Grid>
191191
</Expander.Header>
192192
<Expander.Content>

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Threading.Tasks;
2727
using System.Threading;
2828
using System.Reactive;
29+
using System.Collections.Generic;
2930

3031
namespace SimpleStateMachineNodeEditor.View
3132
{
@@ -49,10 +50,26 @@ object IViewFor.ViewModel
4950
set { ViewModel = (ViewModelMainWindow)value; }
5051
}
5152
#endregion ViewModel
53+
Dictionary<TypeMessage, System.Windows.Controls.Label> messagesLabels;
54+
static Dictionary<TypeMessage, string> labelPostfix = new Dictionary<TypeMessage, string>()
55+
{
56+
{TypeMessage.Error, "Error" },
57+
{TypeMessage.Information, "Information" },
58+
{TypeMessage.Warning, "Warning" },
59+
{TypeMessage.Debug, "Debug" },
60+
};
5261

5362
public MainWindow()
5463
{
5564
InitializeComponent();
65+
messagesLabels = new Dictionary<TypeMessage, System.Windows.Controls.Label>()
66+
{
67+
{TypeMessage.Error, LabelError },
68+
{TypeMessage.Information, LabelInformation },
69+
{TypeMessage.Warning, LabelWarning },
70+
{TypeMessage.Debug, LabelDebug },
71+
};
72+
5673
ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel);
5774
SetupCommands();
5875
SetupSubscriptions();
@@ -90,6 +107,19 @@ private void SetupBinding()
90107
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
91108

92109

110+
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_=> UpdateLabels());
111+
//var informationCount = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.Value.Where(x=>x.TypeMessage==TypeMessage.Information).Count().ToString());
112+
////var SelectedItem = this.ObservableForProperty(x => x.NodesCanvas.ViewModel.Messages).Select(x=>x.);
113+
//this.OneWayBind(this.ViewModel, x => informationCount, x => x.LabelError.Content).DisposeWith(disposable);
114+
115+
//informationCount.WhenAnyValue().Sub
116+
//this.LabelError.Content.
117+
//this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable);
118+
//this.LabelInformation.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable);
119+
//this.LabelWarning.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable);
120+
//this.LabelDebug.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable);
121+
122+
93123
//ItemSave.Command = CommandSave;
94124
//this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable);
95125

@@ -152,35 +182,40 @@ private void SetupEvents()
152182
{
153183
this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable);
154184
this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable);
155-
//this.ButtonImportScheme
156-
157185

158-
159-
//this.ItemSave.InputBindings.Bin
160186
this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable);
161187
this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
162188
this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable);
163189
this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable);
164-
165190

166-
//this.ItemSave.Events().Click.Subscribe(_=> Save()).DisposeWith(disposable);
191+
this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable);
167192
this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable);
168193
this.ItemOpen.Events().Click.Subscribe(async _ => await WithoutSavingAsync(OpenAsync)).DisposeWith(disposable);
169194
this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
170195
this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable);
171196
this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable);
172197
this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable);
173198

174-
this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable);
175-
this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable);
176-
this.LabelInformation.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable);
177-
this.LabelWarning.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable);
178-
this.LabelDebug.Events().MouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable);
199+
foreach(var label in messagesLabels)
200+
{
201+
label.Value.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, label.Key)).DisposeWith(disposable);
202+
}
179203

180-
//this.LabelUpdate.Events().PreviewMouseLeftButtonDown.Subscribe(_ => this.ViewModel.Messages.Cle).DisposeWith(disposable);
181-
//this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable);
204+
this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable);
205+
this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable);
182206
});
183207
}
208+
209+
void UpdateLabels()
210+
{
211+
var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count());
212+
213+
foreach(var lable in messagesLabels)
214+
{
215+
lable.Value.Content = (counts.Keys.Contains(lable.Key) ? counts[lable.Key].ToString() : "0") +" "+ labelPostfix[lable.Key];
216+
}
217+
218+
}
184219
void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage)
185220
{
186221
if ((ErrorListExpander.IsExpanded)&&(this.ViewModel.NodesCanvas.DisplayMessageType != typeMessage))

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
<local:ViewSelector x:Name="Selector" Panel.ZIndex="999"/>
1515
<local:ViewCutter x:Name="Cutter" Panel.ZIndex="999"/>
1616

17-
<ItemsControl x:Name="ElementItemControl"
18-
Panel.ZIndex="0"
17+
<ItemsControl x:Name="ElementItemControl" Panel.ZIndex="0"
1918
VirtualizingPanel.IsVirtualizing="True"
2019
VirtualizingPanel.VirtualizationMode="Recycling"
2120
VirtualizingPanel.CacheLength="1"
2221
VirtualizingPanel.CacheLengthUnit="Page"
2322
VirtualizingPanel.ScrollUnit="Pixel">
24-
23+
2524
<ItemsControl.RenderTransform>
2625
<TransformGroup x:Name="TransformGroup">
2726
<ScaleTransform x:Name="Scale" ScaleX="1" ScaleY="1" />
@@ -51,46 +50,6 @@
5150
</CompositeCollection>
5251
</ItemsControl.ItemsSource>
5352
</ItemsControl>
54-
55-
56-
<!--<ItemsControl x:Name="Nodes" >
57-
<ItemsControl.RenderTransform>
58-
<TransformGroup x:Name="TransformGroup">
59-
<ScaleTransform x:Name="Scale" ScaleX="1" ScaleY="1" />
60-
<SkewTransform/>
61-
<RotateTransform Angle="0" />
62-
<TranslateTransform x:Name="Translate"/>
63-
</TransformGroup>
64-
</ItemsControl.RenderTransform>
65-
<ItemsControl.ItemsPanel>
66-
<ItemsPanelTemplate>
67-
<Grid Background="{x:Null}">
68-
</Grid>
69-
</ItemsPanelTemplate>
70-
</ItemsControl.ItemsPanel>
71-
<ItemsControl.ItemTemplate>
72-
<DataTemplate>
73-
<View:ViewNode ViewModel="{Binding}" />
74-
</DataTemplate>
75-
</ItemsControl.ItemTemplate>
76-
</ItemsControl>
77-
78-
79-
80-
<ItemsControl x:Name="Connects" >
81-
<ItemsControl.ItemsPanel>
82-
<ItemsPanelTemplate>
83-
<Grid Background="{x:Null}">
84-
</Grid>
85-
</ItemsPanelTemplate>
86-
</ItemsControl.ItemsPanel>
87-
<ItemsControl.ItemTemplate>
88-
<DataTemplate>
89-
<View:ViewConnect ViewModel="{Binding}"/>
90-
</DataTemplate>
91-
</ItemsControl.ItemTemplate>
92-
</ItemsControl>-->
93-
9453
</Canvas>
9554
<UserControl.ContextMenu >
9655
<ContextMenu Template="{StaticResource TemplateContextMenu}" Background="{StaticResource ColorMenuBackground}" Foreground="{StaticResource ColorMenuForeground}" BorderBrush="{StaticResource ColorMenuBorder}" OpacityMask="{StaticResource ColorMenuBackgroundMouseOver}" BorderThickness="1" HorizontalAlignment="Left" VerticalAlignment="Center" >
@@ -117,21 +76,13 @@
11776
</MenuItem>
11877
</ContextMenu>
11978
</UserControl.ContextMenu>
120-
121-
<UserControl.CommandBindings>
122-
<!--<CommandBinding Command="Zoom" Executed="Zoom" />-->
123-
<CommandBinding Command="Redo" x:Name="RedoCommand"/>
124-
125-
</UserControl.CommandBindings>
12679
<UserControl.InputBindings>
127-
<KeyBinding x:Name="BindingUndo" Key="Z" Modifiers="Control" />
128-
<KeyBinding x:Name="BindingRedo" Key="Y" Modifiers="Control" />
129-
<!--<KeyBinding x:Name="BindingSave" Key="S" Modifiers="Control" />-->
130-
<KeyBinding x:Name="BindingSelectAll" Key="A" Modifiers="Control" />
131-
<KeyBinding x:Name="BindingAddNode" Key="N" Modifiers="Control" />
80+
<KeyBinding x:Name="BindingUndo" Key="Z" Modifiers="Control" />
81+
<KeyBinding x:Name="BindingRedo" Key="Y" Modifiers="Control" />
82+
<KeyBinding x:Name="BindingSelectAll" Key="A" Modifiers="Control" />
83+
<KeyBinding x:Name="BindingAddNode" Key="N" Modifiers="Control" />
13284
<KeyBinding x:Name="BindingDeleteSelectedElements" Key="Delete" />
133-
<MouseBinding x:Name="BindingSelect" Gesture="Ctrl+LeftClick"/>
134-
<MouseBinding x:Name="BindingCut" Gesture="Alt+LeftClick" />
135-
<!--<MouseBinding x:Name="BindingZoom" Gesture="WheelClick"/>-->
85+
<MouseBinding x:Name="BindingSelect" Gesture="Ctrl+LeftClick"/>
86+
<MouseBinding x:Name="BindingCut" Gesture="Alt+LeftClick" />
13687
</UserControl.InputBindings>
13788
</UserControl>

SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ private void ConnectDrag(MouseButtonEventArgs e)
121121
{
122122
this.ViewModel.CommandSetAsLoop.ExecuteWithSubscribe();
123123
this.ViewModel.NodesCanvas.CommandAddConnectorWithConnect.Execute(this.ViewModel);
124-
125-
this.ViewModel.NodesCanvas.LogDebug("Зашел 2 ");
126124
}
127125
else
128126
{
@@ -132,8 +130,6 @@ private void ConnectDrag(MouseButtonEventArgs e)
132130
DragDrop.DoDragDrop(this, data, DragDropEffects.Link);
133131
this.ViewModel.CommandCheckConnectPointDrop.ExecuteWithSubscribe();
134132
e.Handled = true;
135-
136-
this.ViewModel.NodesCanvas.LogDebug("Зашел 1 ");
137133
}
138134
}
139135

SimpleStateMachineNodeEditor/ViewModel/ViewModelNode.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ public class ViewModelNode : ReactiveValidationObject<ViewModelNode>
3838
[Reactive] public ViewModelConnector Output { get; set; }
3939
[Reactive] public ViewModelConnector CurrentConnector { get; set; }
4040
[Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; }
41+
[Reactive] public int IndexStartSelectConnectors { get; set; } = 0;
4142

43+
public IObservableCollection<ViewModelConnector> Transitions { get; set; } = new ObservableCollectionExtended<ViewModelConnector>();
4244
public int Zindex { get; private set; }
4345

44-
[Reactive] public int IndexStartSelectConnectors { get; set; } = 0;
45-
public IObservableCollection<ViewModelConnector> Transitions { get; set; } = new ObservableCollectionExtended<ViewModelConnector>();
46+
public int TransitionsCount = -1;
47+
48+
4649

4750

4851

@@ -61,6 +64,8 @@ public ViewModelNode(ViewModelNodesCanvas nodesCanvas)
6164
private void SetupBinding()
6265
{
6366
this.WhenAnyValue(x => x.Selected).Subscribe(value => { this.BorderBrush = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Brushes.LightGray; });
67+
this.WhenAnyValue(x => x.Transitions.Count).Subscribe(value => UpdateCount(value));
68+
6469
this.WhenAnyValue(x => x.Point1.Value, x => x.Size).Subscribe(_ => UpdatePoint2());
6570
this.WhenAnyValue(x => x.IsCollapse).Subscribe(value => Collapse(value));
6671
}
@@ -124,6 +129,11 @@ private void NotSaved()
124129
{
125130
NodesCanvas.ItSaved = false;
126131
}
132+
private void UpdateCount(int count)
133+
{
134+
if (count > TransitionsCount)
135+
TransitionsCount = count;
136+
}
127137
#endregion Setup Commands
128138

129139
private void Collapse(bool value)
@@ -195,7 +205,7 @@ private void AddEmptyConnector()
195205
CurrentConnector.TextEnable = true;
196206
CurrentConnector.FormEnable = false;
197207
if (string.IsNullOrEmpty(CurrentConnector.Name))
198-
CurrentConnector.Name = "Transition " + NodesCanvas.Nodes.Sum(x => x.Transitions.Count - 1).ToString();
208+
CurrentConnector.Name = "Transition " + TransitionsCount.ToString();
199209
}
200210
CurrentConnector = new ViewModelConnector(NodesCanvas, this)
201211
{

SimpleStateMachineNodeEditor/ViewModel/ViewModelNodesCanvas.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,23 @@ public class ViewModelNodesCanvas : ReactiveObject
3939
[Reactive] public ViewModelNode StartState { get; set; }
4040
[Reactive] public bool ItSaved { get; set; } = true;
4141
[Reactive] public string Path { get; set; }
42+
4243
[Reactive] public TypeMessage DisplayMessageType { get; set; }
43-
4444

45+
46+
public int NodesCount = 0;
47+
public double ScaleMax = 5;
48+
public double ScaleMin = 0.1;
49+
public double Scales { get; set; } = 0.05;
4550
[Reactive] public Scale Scale { get; set; } = new Scale();
4651

4752
public ViewModelNodesCanvas()
4853
{
4954
SetupCommands();
5055
SetupStartState();
5156
Cutter = new ViewModelCutter(this);
57+
this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value));
58+
5259
for (int i = 1; i <= 5; i++)
5360
{
5461
LogError("Error " + i.ToString());
@@ -114,7 +121,7 @@ private void SetAsStart(ViewModelNode node)
114121
public ReactiveCommand<Unit, Unit> CommandExpandDownAll { get; set; }
115122
public ReactiveCommand<Unit, Unit> CommandCollapseUpSelected { get; set; }
116123
public ReactiveCommand<Unit, Unit> CommandExpandDownSelected { get; set; }
117-
124+
public ReactiveCommand<Unit, Unit> CommandErrorListUpdate { get; set; }
118125

119126

120127

@@ -154,13 +161,6 @@ private void SetAsStart(ViewModelNode node)
154161
public Command<List<(int index, ViewModelConnector element)>, List<(int index, ViewModelConnector element)>> CommandDeleteSelectedConnectors { get; set; }
155162
public Command<DeleteMode, DeleteMode> CommandDeleteSelectedElements { get; set; }
156163

157-
158-
159-
160-
public double ScaleMax = 5;
161-
public double ScaleMin = 0.1;
162-
public double Scales { get; set; } = 0.05;
163-
164164
private void SetupCommands()
165165
{
166166
CommandRedo = ReactiveCommand.Create(ICommandWithUndoRedo.Redo);
@@ -177,6 +177,8 @@ private void SetupCommands()
177177
CommandExpandDownAll = ReactiveCommand.Create(ExpandDownAll);
178178
CommandCollapseUpSelected = ReactiveCommand.Create(CollapseUpSelected);
179179
CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected);
180+
CommandErrorListUpdate = ReactiveCommand.Create(ErrosUpdaate);
181+
180182

181183
CommandValidateNodeName = ReactiveCommand.Create<(ViewModelNode objectForValidate, string newValue)>(ValidateNodeName);
182184
CommandValidateConnectName = ReactiveCommand.Create<(ViewModelConnector objectForValidate, string newValue)>(ValidateConnectName);
@@ -249,6 +251,11 @@ public void LogWarning(string message)
249251

250252
#endregion Logging
251253

254+
private void UpdateCount(int count)
255+
{
256+
if (count > NodesCount)
257+
NodesCount = count;
258+
}
252259
private void CollapseUpAll()
253260
{
254261
foreach(var node in Nodes)
@@ -263,6 +270,10 @@ private void ExpandDownAll()
263270
node.IsCollapse = false;
264271
}
265272
}
273+
private void ErrosUpdaate()
274+
{
275+
Messages.RemoveMany(Messages.Where(x => x.TypeMessage == DisplayMessageType || DisplayMessageType==TypeMessage.All));
276+
}
266277
private void CollapseUpSelected()
267278
{
268279
foreach (var node in Nodes.Where(x=>x.Selected))
@@ -348,7 +359,7 @@ private void PartMoveAllSelectedNode(MyPoint delta)
348359
}
349360
private string GetNameForNewNode()
350361
{
351-
return "State " + Nodes.Count.ToString();
362+
return "State " + NodesCount.ToString();
352363
}
353364
private ViewModelNode AddNodeWithUndoRedo(MyPoint parameter, ViewModelNode result)
354365
{

0 commit comments

Comments
 (0)