Skip to content

Commit b8c3b8e

Browse files
committed
fix for exit command
1 parent 23c8d10 commit b8c3b8e

File tree

3 files changed

+39
-47
lines changed

3 files changed

+39
-47
lines changed

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,9 @@ object IViewFor.ViewModel
5151
}
5252
#endregion ViewModel
5353

54-
Dictionary<TypeMessage, System.Windows.Controls.Label> messagesLabels;
55-
static Dictionary<TypeMessage, string> labelPostfix = new Dictionary<TypeMessage, string>()
56-
{
57-
{TypeMessage.Error, "Error" },
58-
{TypeMessage.Information, "Information" },
59-
{TypeMessage.Warning, "Warning" },
60-
{TypeMessage.Debug, "Debug" },
61-
};
62-
6354
public MainWindow()
6455
{
6556
InitializeComponent();
66-
messagesLabels = new Dictionary<TypeMessage, System.Windows.Controls.Label>()
67-
{
68-
{TypeMessage.Error, LabelError },
69-
{TypeMessage.Information, LabelInformation },
70-
{TypeMessage.Warning, LabelWarning },
71-
{TypeMessage.Debug, LabelDebug },
72-
};
73-
7457
ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel);
7558
SetupSubscriptions();
7659
SetupBinding();
@@ -169,11 +152,10 @@ private void SetupEvents()
169152
this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable);
170153
this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable);
171154

172-
foreach(var label in messagesLabels)
173-
{
174-
label.Value.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, label.Key)).DisposeWith(disposable);
175-
}
176-
155+
this.LabelError.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Error)).DisposeWith(disposable);
156+
this.LabelWarning.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Warning)).DisposeWith(disposable);
157+
this.LabelInformation.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable);
158+
this.LabelDebug.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable);
177159
this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable);
178160
this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable);
179161
});
@@ -182,12 +164,15 @@ private void SetupEvents()
182164
private void UpdateLabels()
183165
{
184166
var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count());
185-
186-
foreach(var lable in messagesLabels)
187-
{
188-
lable.Value.Content = (counts.Keys.Contains(lable.Key) ? counts[lable.Key].ToString() : "0") +" "+ labelPostfix[lable.Key];
189-
}
190-
167+
var countError = counts.Keys.Contains(TypeMessage.Error) ? counts[TypeMessage.Error].ToString() : "0";
168+
var countWarning = counts.Keys.Contains(TypeMessage.Warning) ? counts[TypeMessage.Warning].ToString() : "0";
169+
var countInformation = counts.Keys.Contains(TypeMessage.Information) ? counts[TypeMessage.Information].ToString() : "0";
170+
var countDebug = counts.Keys.Contains(TypeMessage.Debug) ? counts[TypeMessage.Debug].ToString() : "0";
171+
172+
LabelError.Content = countError + " Error";
173+
LabelWarning.Content = countWarning + " Warning";
174+
LabelInformation.Content = countInformation + " Information";
175+
LabelDebug.Content = countDebug + " Debug";
191176
}
192177
private void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage)
193178
{

SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ public ViewModelNodesCanvas()
4949
Cutter = new ViewModelCutter(this);
5050
this.WhenAnyValue(x => x.Nodes.Count).Subscribe(value => UpdateCount(value));
5151

52-
for (int i = 1; i <= 5; i++)
53-
{
54-
LogError("Error " + i.ToString());
55-
}
56-
for (int i = 1; i <= 5; i++)
57-
{
58-
LogInformation("Information " + i.ToString());
59-
}
60-
for (int i = 1; i <= 5; i++)
61-
{
62-
LogWarning("Warning " + i.ToString());
63-
}
64-
for (int i = 1; i <= 5; i++)
65-
{
66-
LogDebug("Debug " + i.ToString());
67-
}
52+
//for (int i = 1; i <= 5; i++)
53+
//{
54+
// LogError("Error " + i.ToString());
55+
//}
56+
//for (int i = 1; i <= 5; i++)
57+
//{
58+
// LogInformation("Information " + i.ToString());
59+
//}
60+
//for (int i = 1; i <= 5; i++)
61+
//{
62+
// LogWarning("Warning " + i.ToString());
63+
//}
64+
//for (int i = 1; i <= 5; i++)
65+
//{
66+
// LogDebug("Debug " + i.ToString());
67+
//}
6868

6969
}
7070
public readonly object lockNodes = new object();

SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvasCommands.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private void SetupCommands()
9595
CommandExpandDownSelected = ReactiveCommand.Create(ExpandDownSelected);
9696
CommandErrorListUpdate = ReactiveCommand.Create(ErrosUpdaate);
9797
CommandExportToJPEG = ReactiveCommand.Create(ExportToJPEG);
98+
CommandNew = ReactiveCommand.Create(New);
9899
CommandOpen = ReactiveCommand.Create(Open);
99100
CommandSave = ReactiveCommand.Create(Save);
100101
CommandSaveAs = ReactiveCommand.Create(SaveAs);
@@ -115,7 +116,7 @@ private void SetupCommands()
115116
CommandAddDraggedConnect = ReactiveCommand.Create<ViewModelConnector>(AddDraggedConnect);
116117
CommandDeleteDraggedConnect = ReactiveCommand.Create(DeleteDraggedConnect);
117118

118-
CommandNew = ReactiveCommand.Create(NewScheme);
119+
119120
CommandPartMoveAllNode = ReactiveCommand.Create<MyPoint>(PartMoveAllNode);
120121
CommandPartMoveAllSelectedNode = ReactiveCommand.Create<MyPoint>(PartMoveAllSelectedNode);
121122

@@ -227,7 +228,13 @@ private void ExportToJPEG()
227228
//"Png Image (.png)|*.png";
228229
JPEGPath = Dialog.FileName;
229230
}
230-
private void NewScheme()
231+
private void New()
232+
{
233+
if (!WithoutSaving())
234+
return;
235+
ClearScheme();
236+
}
237+
private void ClearScheme()
231238
{
232239
this.Nodes.Clear();
233240
this.Connects.Clear();
@@ -311,7 +318,7 @@ bool WithError<T>(string errorMessage, Action<T> action, T obj)
311318
void Error(string errorMessage)
312319
{
313320
LogError("File is not valid: " + errorMessage);
314-
NewScheme();
321+
ClearScheme();
315322
}
316323
}
317324
private void Save()

0 commit comments

Comments
 (0)