Skip to content

Commit 5b2e69a

Browse files
committed
show error
1 parent 9f6f6e7 commit 5b2e69a

File tree

8 files changed

+98
-66
lines changed

8 files changed

+98
-66
lines changed

SimpleStateMachineNodeEditor/Helpers/Extensions/PointExtensition.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,16 @@ public static Point Multiply(this Point point1, Size size)
318318
{
319319
return new Point(point1.X * size.Width, point1.Y * size.Height);
320320
}
321+
322+
public static string PointToString(Point point)
323+
{
324+
return string.Format("{0}, {1}", point.X.ToString(System.Globalization.CultureInfo.InvariantCulture), point.Y.ToString(System.Globalization.CultureInfo.InvariantCulture));
325+
}
326+
327+
public static Point StringToPoint(string str)
328+
{
329+
string[] parts = str.Split(",");
330+
return new Point(double.Parse(parts[0], System.Globalization.CultureInfo.InvariantCulture), double.Parse(parts[1], System.Globalization.CultureInfo.InvariantCulture));
331+
}
321332
}
322333
}

SimpleStateMachineNodeEditor/Helpers/Transformations/Translate.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ private void SetupBinding()
6767
this.OneWayBind(this.ViewModel, x => x.Messages, x => x.MessageList.ItemsSource).DisposeWith(disposable);
6868
this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable);
6969

70-
70+
this.OneWayBind(this.ViewModel, x => x.CountError, x => x.LabelError.Content, value=>value.ToString()+" Error").DisposeWith(disposable);
71+
this.OneWayBind(this.ViewModel, x => x.CountWarning, x => x.LabelWarning.Content, value => value.ToString() + " Warning").DisposeWith(disposable);
72+
this.OneWayBind(this.ViewModel, x => x.CountInformation, x => x.LabelInformation.Content, value => value.ToString() + " Information").DisposeWith(disposable);
73+
this.OneWayBind(this.ViewModel, x => x.CountDebug, x => x.LabelDebug.Content, value => value.ToString() + " Debug").DisposeWith(disposable);
7174

7275
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
7376
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomIn, x => x.ButtonZoomIn).DisposeWith(disposable);
@@ -115,9 +118,9 @@ private void SetupSubscriptions()
115118
{
116119
this.WhenActivated(disposable =>
117120
{
118-
this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
119-
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels()).DisposeWith(disposable);
121+
this.WhenAnyValue(x => x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
120122
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.NeedExit).Where(x=>x).Subscribe(_ => this.Close()).DisposeWith(disposable);
123+
this.WhenAnyValue(x => x.ViewModel.CountError).Buffer(2, 1).Where(x => x[1] > x[0]).Subscribe(_ => ShowError()).DisposeWith(disposable);
121124
});
122125
}
123126
private void UpdateSchemeName(string newName)
@@ -148,23 +151,10 @@ private void SetupEvents()
148151
this.LabelInformation.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Information)).DisposeWith(disposable);
149152
this.LabelDebug.Events().PreviewMouseLeftButtonDown.Subscribe(e => SetDisplayMessageType(e, TypeMessage.Debug)).DisposeWith(disposable);
150153
this.LabelErrorList.Events().PreviewMouseLeftButtonDown.Subscribe(e=> SetDisplayMessageType(e, TypeMessage.All)).DisposeWith(disposable);
151-
this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable);
154+
this.LabelErrorListUpdate.Events().MouseLeftButtonDown.WithoutParameter().InvokeCommand(NodesCanvas.ViewModel.CommandErrorListUpdate).DisposeWith(disposable);
152155
});
153156
}
154157

155-
private void UpdateLabels()
156-
{
157-
var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count());
158-
var countError = counts.Keys.Contains(TypeMessage.Error) ? counts[TypeMessage.Error].ToString() : "0";
159-
var countWarning = counts.Keys.Contains(TypeMessage.Warning) ? counts[TypeMessage.Warning].ToString() : "0";
160-
var countInformation = counts.Keys.Contains(TypeMessage.Information) ? counts[TypeMessage.Information].ToString() : "0";
161-
var countDebug = counts.Keys.Contains(TypeMessage.Debug) ? counts[TypeMessage.Debug].ToString() : "0";
162-
163-
LabelError.Content = countError + " Error";
164-
LabelWarning.Content = countWarning + " Warning";
165-
LabelInformation.Content = countInformation + " Information";
166-
LabelDebug.Content = countDebug + " Debug";
167-
}
168158
private void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage)
169159
{
170160
if ((ErrorListExpander.IsExpanded)&&(this.ViewModel.NodesCanvas.DisplayMessageType != typeMessage))
@@ -182,7 +172,17 @@ private void ErrorListExpanded()
182172
this.ErrorListSplitter.IsEnabled = true;
183173
this.Fotter.Height = new GridLength(this.ViewModel.MaxHeightMessagePanel);
184174
}
175+
private void ShowError()
176+
{
177+
if (!this.ErrorListExpander.IsExpanded)
178+
{
179+
this.ErrorListExpander.IsExpanded = true;
180+
ErrorListExpanded();
181+
}
182+
//this.ErrorListExpander.RaiseEvent(new RoutedEventArgs(Expander.ExpandedEvent));
183+
//this.ErrorListExpander.IsExpanded = true;
185184

185+
}
186186

187187
private void ButtonMinClick(RoutedEventArgs e)
188188
{

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ object IViewFor.ViewModel
4343
set { ViewModel = (ViewModelNodesCanvas)value; }
4444
}
4545
#endregion ViewModel
46-
47-
private Point PositionDragOver { get; set; }
48-
private Point PositionRightClick { get; set; } = new Point();
49-
[Reactive] public Point PositionLeftClick { get; set; } = new Point();
5046
private Point PositionMove { get; set; }
5147

5248
private Point SumMove { get; set; }
@@ -89,13 +85,6 @@ private void SetupCommands()
8985
{
9086
this.WhenActivated(disposable =>
9187
{
92-
//this.WhenAnyValue(x => x.PositionLeftClick).Subscribe(x => Test(x)).DisposeWith(disposable);
93-
var positionLeftClickObservable = this.WhenAnyValue(x => x.PositionLeftClick);
94-
var positionRightClickObservable = this.WhenAnyValue(x => x.PositionRightClick).Select(x => x);
95-
96-
97-
//IObservable<Point> positionLeftClickObservable = this.WhenAnyValue(x => x.PositionLeftClick).;
98-
//IObservable<Point> positionRightClickObservable = this.WhenAnyValue(x => x.PositionRightClick);
9988

10089
this.BindCommand(this.ViewModel, x => x.CommandSelect, x => x.BindingSelect, x => x.PositionRight).DisposeWith(disposable);
10190
this.BindCommand(this.ViewModel, x => x.CommandCut, x => x.BindingCut, x => x.PositionRight).DisposeWith(disposable);
@@ -225,13 +214,11 @@ private void OnEventDragOver(DragEventArgs e)
225214
}
226215
private void OnEventPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
227216
{
228-
PositionLeftClick = e.GetPosition(this.Canvas);
229-
this.ViewModel.PositionRight = PositionLeftClick;
217+
this.ViewModel.PositionRight = e.GetPosition(this.Canvas);
230218
}
231219
private void OnEventPreviewMouseRightButtonDown(MouseButtonEventArgs e)
232220
{
233-
PositionRightClick = e.GetPosition(this.Canvas);
234-
this.ViewModel.PositionLeft = PositionRightClick;
221+
this.ViewModel.PositionLeft = e.GetPosition(this.Canvas);
235222
}
236223

237224
#endregion Setup Events

SimpleStateMachineNodeEditor/ViewModel/MainWindow/ViewModelMainWindow.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@
88
using System.Reactive.Linq;
99
using System.Reactive;
1010
using SimpleStateMachineNodeEditor.ViewModel.NodesCanvas;
11+
using System.Linq;
1112

1213
namespace SimpleStateMachineNodeEditor.ViewModel
1314
{
14-
public class ViewModelMainWindow: ReactiveObject
15+
public class ViewModelMainWindow : ReactiveObject
1516
{
1617
public ObservableCollectionExtended<ViewModelMessage> Messages { get; set; } = new ObservableCollectionExtended<ViewModelMessage>();
1718

1819
[Reactive] public ViewModelNodesCanvas NodesCanvas { get; set; }
1920
[Reactive] public TypeMessage DisplayMessageType { get; set; }
2021
[Reactive] public bool? DebugEnable { get; set; } = true;
2122

23+
[Reactive] public int CountError { get; set; }
24+
[Reactive] public int CountWarning { get; set; }
25+
[Reactive] public int CountInformation { get; set; }
26+
[Reactive] public int CountDebug { get; set; }
27+
28+
2229
private IDisposable ConnectToMessages;
2330
public double MaxHeightMessagePanel = 150;
2431

@@ -28,14 +35,15 @@ public ViewModelMainWindow(ViewModelNodesCanvas viewModelNodesCanvas)
2835
{
2936
NodesCanvas = viewModelNodesCanvas;
3037
SetupCommands();
31-
SetupSubscriptions();
38+
SetupSubscriptions();
3239
}
3340

3441
#region Setup Subscriptions
3542

3643
private void SetupSubscriptions()
3744
{
38-
this.WhenAnyValue(x => x.NodesCanvas.DisplayMessageType).Subscribe(_ => UpdateMessages());
45+
this.WhenAnyValue(x => x.NodesCanvas.DisplayMessageType).Subscribe(_ => UpdateMessages());
46+
this.WhenAnyValue(x => x.NodesCanvas.Messages.Count).Subscribe(_ => UpdateCountMessages());
3947

4048
}
4149
private void UpdateMessages()
@@ -46,15 +54,15 @@ private void UpdateMessages()
4654
bool debugEnable = DebugEnable.HasValue && DebugEnable.Value;
4755
bool displayAll = this.NodesCanvas.DisplayMessageType == TypeMessage.All;
4856

49-
ConnectToMessages = this.NodesCanvas.Messages.ToObservableChangeSet().Filter(x=> CheckForDisplay(x.TypeMessage)).ObserveOnDispatcher().Bind(Messages).DisposeMany().Subscribe();
57+
ConnectToMessages = this.NodesCanvas.Messages.ToObservableChangeSet().Filter(x => CheckForDisplay(x.TypeMessage)).ObserveOnDispatcher().Bind(Messages).DisposeMany().Subscribe();
5058

5159
bool CheckForDisplay(TypeMessage typeMessage)
5260
{
5361
if (typeMessage == this.NodesCanvas.DisplayMessageType)
5462
{
5563
return true;
5664
}
57-
else if(typeMessage==TypeMessage.Debug)
65+
else if (typeMessage == TypeMessage.Debug)
5866
{
5967
return debugEnable && displayAll;
6068
}
@@ -66,7 +74,7 @@ bool CheckForDisplay(TypeMessage typeMessage)
6674
#region Setup Commands
6775

6876
public ReactiveCommand<string, Unit> CommandCopyError { get; set; }
69-
77+
public ReactiveCommand<Unit, Unit> CommandUpdateMessagesType { get; set; }
7078
private void SetupCommands()
7179
{
7280
CommandCopyError = ReactiveCommand.Create<string>(CopyError);
@@ -77,6 +85,14 @@ private void CopyError(string errrorText)
7785
{
7886
Clipboard.SetText(errrorText);
7987
}
88+
private void UpdateCountMessages()
89+
{
90+
var counts = NodesCanvas.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x => x.Key, x => x.Count());
91+
CountError = counts.Keys.Contains(TypeMessage.Error) ? counts[TypeMessage.Error] : 0;
92+
CountWarning = counts.Keys.Contains(TypeMessage.Warning) ? counts[TypeMessage.Warning] : 0;
93+
CountInformation = counts.Keys.Contains(TypeMessage.Information) ? counts[TypeMessage.Information] : 0;
94+
CountDebug = counts.Keys.Contains(TypeMessage.Debug) ? counts[TypeMessage.Debug] : 0;
95+
}
8096

8197
#endregion Setup Commands
8298

SimpleStateMachineNodeEditor/ViewModel/Node/ViewModelNode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ private void AddEmptyConnector()
215215
CurrentConnector.FormEnable = false;
216216
if (string.IsNullOrEmpty(CurrentConnector.Name))
217217
CurrentConnector.Name = "Transition " + NodesCanvas.TransitionsCount.ToString();
218+
NodesCanvas.LogDebug("Transition with name \"{0}\" was added", CurrentConnector.Name);
218219
}
219220
double width = Size.Width == 0 ? 80 : Size.Width;
220221
CurrentConnector = new ViewModelConnector(NodesCanvas, this,"", Point1.Addition(width, 54))
@@ -256,7 +257,7 @@ public XElement ToXElement()
256257
{
257258
XElement element = new XElement("State");
258259
element.Add(new XAttribute("Name", Name));
259-
element.Add(new XAttribute("Position", Point1.ToString()));
260+
element.Add(new XAttribute("Position", PointExtensition.PointToString(Point1)));
260261
element.Add(new XAttribute("IsCollapse", IsCollapse.ToString()));
261262
return element;
262263
}
@@ -280,7 +281,7 @@ public static ViewModelNode FromXElement(ViewModelNodesCanvas nodesCanvas, XElem
280281
}
281282

282283
var position = node.Attribute("Position")?.Value;
283-
Point point = string.IsNullOrEmpty(position) ? new Point() : Point.Parse(position);
284+
Point point = string.IsNullOrEmpty(position) ? new Point() : PointExtensition.StringToPoint(position);
284285
viewModelNode = new ViewModelNode(nodesCanvas, name, point);
285286
var isCollapse = node.Attribute("IsCollapse")?.Value;
286287
if (isCollapse != null)

SimpleStateMachineNodeEditor/ViewModel/NodesCanvas/ViewModelNodesCanvas.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public partial class ViewModelNodesCanvas : ReactiveObject
4040
/// Flag for close application
4141
/// </summary>
4242
[Reactive] public bool NeedExit { get; set; }
43-
4443
[Reactive] public string JPEGPath{ get; set; }
44+
[Reactive] public bool WithoutMessages { get; set; }
4545

4646
public int NodesCount = 0;
4747
public int TransitionsCount = 1;
@@ -63,6 +63,7 @@ public ViewModelNodesCanvas()
6363
private void SetupSubscriptions()
6464
{
6565
this.WhenAnyValue(x => x.Nodes.Count).Buffer(2, 1).Select(x => (Previous: x[0], Current: x[1])).Subscribe(x => UpdateCount(x.Previous, x.Current));
66+
//this.WhenAnyValue(x => x.CountError).Buffer(2, 1).Where(x => x[1] > x[0]).Subscribe(_ => DisplayMessageType = TypeMessage.Error).DisposeWith(disposable);
6667
}
6768

6869
#endregion Setup Subscriptions
@@ -90,19 +91,24 @@ private void SetAsStart(ViewModelNode node)
9091

9192
public void LogDebug(string message, params object[] args)
9293
{
93-
Messages.Add(new ViewModelMessage(TypeMessage.Debug, string.Format(message, args)));
94+
if(!WithoutMessages)
95+
Messages.Add(new ViewModelMessage(TypeMessage.Debug, string.Format(message, args)));
9496
}
9597
public void LogError(string message, params object[] args)
9698
{
97-
Messages.Add(new ViewModelMessage(TypeMessage.Error, string.Format(message, args)));
99+
DisplayMessageType = TypeMessage.Error;
100+
if (!WithoutMessages)
101+
Messages.Add(new ViewModelMessage(TypeMessage.Error, string.Format(message, args)));
98102
}
99103
public void LogInformation(string message, params object[] args)
100104
{
101-
Messages.Add(new ViewModelMessage(TypeMessage.Information, string.Format(message, args)));
105+
if (!WithoutMessages)
106+
Messages.Add(new ViewModelMessage(TypeMessage.Information, string.Format(message, args)));
102107
}
103108
public void LogWarning(string message, params object[] args)
104109
{
105-
Messages.Add(new ViewModelMessage(TypeMessage.Warning, string.Format(message, args)));
110+
if (!WithoutMessages)
111+
Messages.Add(new ViewModelMessage(TypeMessage.Warning, string.Format(message, args)));
106112
}
107113

108114
#endregion Logging

0 commit comments

Comments
 (0)