Skip to content

Commit abe3c27

Browse files
committed
before start dialog
1 parent 57f88d2 commit abe3c27

26 files changed

+741
-417
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace SimpleStateMachineNodeEditor.Helpers.Enums
2+
{
3+
public enum DialogResult
4+
{
5+
noCorrect = 0,
6+
Yes,
7+
No,
8+
Ok,
9+
Cancel,
10+
None,
11+
Abort,
12+
Retry,
13+
Ignore
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SimpleStateMachineNodeEditor.Helpers.Enums
2+
{
3+
public enum DialogType
4+
{
5+
noCorrect = 0,
6+
MessageBox,
7+
SaveFileDialog,
8+
OpenFileDialog,
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace SimpleStateMachineNodeEditor.Helpers.Enums
6+
{
7+
public enum TypeMove
8+
{
9+
None = 0,
10+
MoveAll,
11+
MoveSelected,
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace SimpleStateMachineNodeEditor.Helpers.Extensions
4+
{
5+
public static class FileDialogResultExtension
6+
{
7+
public static Enums.DialogResult ToDialogResult(this System.Windows.Forms.DialogResult fileDialogResult)
8+
{
9+
return fileDialogResult switch
10+
{
11+
System.Windows.Forms.DialogResult.Yes => Helpers.Enums.DialogResult.None,
12+
System.Windows.Forms.DialogResult.No => Helpers.Enums.DialogResult.No,
13+
System.Windows.Forms.DialogResult.OK => Helpers.Enums.DialogResult.Ok,
14+
System.Windows.Forms.DialogResult.Cancel => Helpers.Enums.DialogResult.Cancel,
15+
System.Windows.Forms.DialogResult.None => Helpers.Enums.DialogResult.None,
16+
System.Windows.Forms.DialogResult.Abort => Helpers.Enums.DialogResult.Abort,
17+
System.Windows.Forms.DialogResult.Retry => Helpers.Enums.DialogResult.Retry,
18+
System.Windows.Forms.DialogResult.Ignore => Helpers.Enums.DialogResult.Ignore,
19+
_ => throw new NotImplementedException(),
20+
};
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Windows;
3+
4+
namespace SimpleStateMachineNodeEditor.Helpers.Extensions
5+
{
6+
public static class MessageBoxResultExtension
7+
{
8+
public static Helpers.Enums.DialogResult ToDialogResult(this MessageBoxResult messageBoxResult)
9+
{
10+
return messageBoxResult switch
11+
{
12+
MessageBoxResult.Yes => Helpers.Enums.DialogResult.Yes,
13+
MessageBoxResult.No => Helpers.Enums.DialogResult.No,
14+
MessageBoxResult.OK => Helpers.Enums.DialogResult.Ok,
15+
MessageBoxResult.Cancel => Helpers.Enums.DialogResult.Cancel,
16+
MessageBoxResult.None => Helpers.Enums.DialogResult.None,
17+
_ => throw new NotImplementedException()
18+
};
19+
}
20+
}
21+
}

SimpleStateMachineNodeEditor/SimpleStateMachineNodeEditor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</ItemGroup>
4545

4646
<ItemGroup>
47+
<PackageReference Include="MvvmDialogs" Version="7.0.0" />
4748
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
4849
<PackageReference Include="ReactiveUI" Version="11.4.1" />
4950
<PackageReference Include="ReactiveUI.Events.WPF" Version="11.4.1" />

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ object IViewFor.ViewModel
5050
set { ViewModel = (ViewModelMainWindow)value; }
5151
}
5252
#endregion ViewModel
53+
5354
Dictionary<TypeMessage, System.Windows.Controls.Label> messagesLabels;
5455
static Dictionary<TypeMessage, string> labelPostfix = new Dictionary<TypeMessage, string>()
5556
{
@@ -71,7 +72,6 @@ public MainWindow()
7172
};
7273

7374
ViewModel = new ViewModelMainWindow(this.NodesCanvas.ViewModel);
74-
SetupCommands();
7575
SetupSubscriptions();
7676
SetupBinding();
7777
SetupEvents();
@@ -106,34 +106,6 @@ private void SetupBinding()
106106
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable);
107107
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
108108

109-
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-
123-
//ItemSave.Command = CommandSave;
124-
//this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable);
125-
126-
//this.OneWayBind(this, x => x.CommandSave, x => x.BindingSave.Command).DisposeWith(disposable);
127-
128-
//this.OneWayBind(this.ViewModel, x=>x.CommandCopyError, x=>x.BindingSave.Command)
129-
130-
131-
//this.ItemSave.Inp
132-
133-
//this.OneWayBind(this.NodesCanvas.ViewModel, x => x.CommandSave, x => x.BindingSave.Command);
134-
//this.OneWayBind(this.NodesCanvas.ViewModel, x => x.CommandSave, x => x.BindingSave.Command);
135-
136-
137109
});
138110
}
139111
#endregion Setup Binding
@@ -144,8 +116,8 @@ private void SetupSubscriptions()
144116
{
145117
this.WhenActivated(disposable =>
146118
{
147-
this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.Path).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
148-
119+
this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
120+
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels());
149121

150122
});
151123
}
@@ -160,39 +132,28 @@ private void UpdateSchemeName(string newName)
160132
}
161133
#endregion Setup Subscriptions
162134

163-
#region Setup Commands
164-
165-
public ReactiveCommand<Unit,Unit> CommandSave { get; set; }
166-
private void SetupCommands()
167-
{
168-
this.WhenActivated(disposable =>
169-
{
170-
CommandSave = ReactiveCommand.Create(Save);
171-
172-
//this.Events().KeyUp.Where(x => x.Key == Key.S && (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))).Subscribe(_ => Save()).DisposeWith(disposable);
173-
//this.Events().KeyUp.Where(x => x.Key == Key.F4 && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))).Subscribe(_ => Close()).DisposeWith(disposable);
174-
});
175-
}
176-
#endregion Setup Commands
177135

178136
#region SetupEvents
179137
private void SetupEvents()
180138
{
181139
this.WhenActivated(disposable =>
182140
{
141+
183142
this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable);
184143
this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable);
185144

145+
186146
this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable);
187147
this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
188148
this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable);
189149
this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable);
190150

191151
this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable);
192152
this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable);
193-
this.ItemOpen.Events().Click.Subscribe(async _ => await WithoutSavingAsync(OpenAsync)).DisposeWith(disposable);
153+
this.ItemOpen.Events().Click.Subscribe(_ => WithoutSaving(Open)).DisposeWith(disposable);
194154
this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
195155
this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable);
156+
196157
this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable);
197158
this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable);
198159

@@ -300,7 +261,7 @@ void ExportToImage(ImageFormats format)
300261
dlg.FileName = SchemeName();
301262
dlg.Filter = (format == ImageFormats.JPEG)? "JPEG Image (.jpeg)|*.jpeg":"Png Image (.png)|*.png";
302263

303-
DialogResult dialogResult = dlg.ShowDialog();
264+
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
304265
if(dialogResult==System.Windows.Forms.DialogResult.OK)
305266
{
306267
this.NodesCanvas.SaveCanvasToImage(dlg.FileName, format);
@@ -321,62 +282,55 @@ void WithoutSaving(Action action)
321282
if (result == MessageBoxResult.Yes)
322283
action.Invoke();
323284
}
324-
async Task WithoutSavingAsync(Func<Task> action)
325-
{
326-
var result = MessageBoxResult.Yes;
327-
if (!this.NodesCanvas.ViewModel.ItSaved)
328-
{
329-
result = System.Windows.MessageBox.Show("Exit without saving ?", "Test", MessageBoxButton.YesNo);
330-
}
331285

332-
if (result == MessageBoxResult.Yes)
333-
await action.Invoke();
334-
}
335286
void Save()
336287
{
337-
if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.Path))
288+
if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath))
338289
{
339290
SaveAs();
340291
}
341292
else
342293
{
343-
this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.Path);
294+
this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.SchemePath);
344295
}
345296
}
346297
void SaveAs()
347298
{
348299
SaveFileDialog dlg = new SaveFileDialog();
349300
dlg.FileName = SchemeName();
350301
dlg.Filter = "XML-File | *.xml";
351-
352-
DialogResult dialogResult = dlg.ShowDialog();
302+
303+
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
353304
if (dialogResult == System.Windows.Forms.DialogResult.OK)
354305
{
306+
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
355307
this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(dlg.FileName);
308+
Mouse.OverrideCursor = null;
356309
}
357310
}
358311
private string SchemeName()
359312
{
360-
if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.Path))
313+
if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath))
361314
{
362-
return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.Path);
315+
return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.SchemePath);
363316
}
364317
else
365318
{
366319
return "SimpleStateMachine";
367320
}
368321
}
369-
async Task OpenAsync()
322+
private void Open()
370323
{
371324
OpenFileDialog dlg = new OpenFileDialog();
372325
dlg.FileName = SchemeName();
373326
dlg.Filter = "XML-File | *.xml";
374327

375-
DialogResult dialogResult = dlg.ShowDialog();
328+
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
376329
if (dialogResult == System.Windows.Forms.DialogResult.OK)
377330
{
378-
//this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName);
379-
await this.NodesCanvas.ViewModel.CommandOpen.Execute(dlg.FileName);
331+
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
332+
this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName);
333+
Mouse.OverrideCursor = null;
380334
}
381335

382336
}

SimpleStateMachineNodeEditor/View/ViewConnect.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ private void SetupBinding()
4949
{
5050
this.WhenActivated(disposable =>
5151
{
52-
5352
// Цвет линии
5453
this.OneWayBind(this.ViewModel, x => x.Stroke, x => x.PathElement.Stroke).DisposeWith(disposable);
5554

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<UserControl x:Class="SimpleStateMachineNodeEditor.View.ViewDialog"
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.View"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
</UserControl>

0 commit comments

Comments
 (0)