Skip to content

Commit 93c343e

Browse files
committed
work with dialog
1 parent abe3c27 commit 93c343e

File tree

7 files changed

+250
-260
lines changed

7 files changed

+250
-260
lines changed

SimpleStateMachineNodeEditor/View/MainWindow.xaml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<MenuItem.Icon>
4545
<Rectangle Fill="{StaticResource IconExportScheme}" Height="15" Width="15"/>
4646
</MenuItem.Icon>
47-
<MenuItem Header="Export to PNG" x:Name="ItemExportToPNG" Style="{StaticResource StyleMenuItem}"/>
47+
<!--<MenuItem Header="Export to PNG" x:Name="ItemExportToPNG" Style="{StaticResource StyleMenuItem}"/>-->
4848
<MenuItem Header="Export to JPEG" x:Name="ItemExportToJPEG" Style="{StaticResource StyleMenuItem}"/>
4949
</MenuItem>
5050
<Separator Background="{StaticResource ColorMenuSeparator}"/>
@@ -104,10 +104,10 @@
104104
</DockPanel>
105105
<ToolBarTray Grid.Row="1" IsLocked="True" Background="{x:Null}">
106106
<ToolBar Style="{StaticResource ToolBarTemplate}" Background="{x:Null}" Foreground="{x:Null}" >
107-
<Button x:Name="ButtonNewScheme" ToolTip="New (Ctrl+N)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
107+
<Button x:Name="ButtonNew" ToolTip="New (Ctrl+N)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
108108
<Rectangle Fill="{StaticResource IconNewSheme}" Height="15" Width="15"/>
109109
</Button>
110-
<Button x:Name="ButtonImportScheme" ToolTip="Open (Ctrl+O)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
110+
<Button x:Name="ButtonOpen" ToolTip="Open (Ctrl+O)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
111111
<Rectangle Fill="{StaticResource IconImportScheme}" Height="15" Width="15"/>
112112
</Button>
113113
<Button x:Name="ButtonSave" ToolTip="Save (Ctrl+S)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
@@ -116,7 +116,7 @@
116116
<Button x:Name="ButtonSaveAs" ToolTip="Save As... (Ctrl+Shift+S)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
117117
<Rectangle Fill="{StaticResource IconSaveAs}" Height="15" Width="15"/>
118118
</Button>
119-
<Button x:Name="ButtonHeaderButton" ToolTip="Export To Jpeg... (Ctrl+Shift+Alt+J)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
119+
<Button x:Name="ButtonExportToJPEG" ToolTip="Export To Jpeg... (Ctrl+Shift+Alt+J)" Style="{StaticResource StyleHeaderButton}" Background="{StaticResource ColorWindowHeader}" BorderBrush="{StaticResource ColorWindowHeaderButtonBackgroundMouseOver}">
120120
<Rectangle Fill="{StaticResource IconExportScheme}" Height="15" Width="15"/>
121121
</Button>
122122
<Separator Grid.Column="5" Style="{DynamicResource TemplateSeparator}" Height="Auto" BorderThickness="0,0,1,0" />
@@ -144,16 +144,6 @@
144144
<Rectangle Fill="{StaticResource IconExpandDownAll}" Height="13" Width="13"/>
145145
</Button>
146146
</ToolBar>
147-
148-
<!--<Separator />
149-
<Button>
150-
<Image Source="icon2.png" />
151-
</Button>
152-
<Separator />
153-
<Button>
154-
<Image Source="icon3.png" />
155-
</Button>
156-
<TextBox Foreground="LightGray" Width="100">Поиск...</TextBox>-->
157147
</ToolBarTray>
158148
<!--BorderBrush - it's color on IsMouseOver, OpacityMask - it's color on IsPressed-->
159149
<TabControl Grid.Row="2" Background="{x:Null}" BorderBrush="{x:Null}" TabStripPlacement="Top" Padding="2,2,2,0" >
@@ -222,17 +212,11 @@
222212
<Window.InputBindings>
223213
<!--<KeyBinding x:Name="BindingUndo" Key="Z" Modifiers="Control" />
224214
<KeyBinding x:Name="BindingRedo" Key="Y" Modifiers="Control" />-->
225-
<KeyBinding x:Name="BindingSave" Command="{Binding ElementName=ItemSave, Path=Command}" Key="S" Modifiers="Control" />
215+
<KeyBinding x:Name="BindingSave" Gesture="Ctrl+S"/>
226216
<KeyBinding x:Name="BindingSaveAs" Gesture="Ctrl+Shift+S"/>
227217
<KeyBinding x:Name="BindingOpen" Gesture="Ctrl+Shift+O" />
228-
<KeyBinding x:Name="BindingNew" Gesture="Ctrl+Shift+N"/>
229-
<KeyBinding x:Name="BindingExit" Key="F4" Modifiers="Alt"/>
230-
<KeyBinding x:Name="BindingExportToJpeg" Key="F4" Modifiers="Alt"/>
231-
<!--<KeyBinding x:Name="BindingSelectAll" Key="A" Modifiers="Control" />
232-
<KeyBinding x:Name="BindingAddNode" Key="N" Modifiers="Control" />
233-
<KeyBinding x:Name="BindingDeleteSelectedElements" Key="Delete" />
234-
<MouseBinding x:Name="BindingSelect" Gesture="Ctrl+LeftClick"/>
235-
<MouseBinding x:Name="BindingCut" Gesture="Alt+LeftClick" />-->
236-
<!--<MouseBinding x:Name="BindingZoom" Gesture="WheelClick"/>-->
218+
<KeyBinding x:Name="BindingNew" Gesture="Ctrl+Shift+N"/>
219+
<KeyBinding x:Name="BindingExit" Gesture="Alt+F4"/>
220+
<!--<KeyBinding x:Name="BindingExportToJpeg" Key="F4" Modifiers="Alt"/>-->
237221
</Window.InputBindings>
238222
</Window>

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 51 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,46 @@ private void SetupBinding()
9191

9292

9393
this.OneWayBind(this.ViewModel, x => x.Messages, x => x.MessageList.ItemsSource).DisposeWith(disposable);
94-
this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable);
94+
this.OneWayBind(this.ViewModel, x => x.DebugEnable, x => x.LabelDebug.Visibility).DisposeWith(disposable);
9595

9696

97-
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo, x => x.ButtonUndo).DisposeWith(disposable);
98-
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable);
97+
98+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
9999
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomIn, x => x.ButtonZoomIn).DisposeWith(disposable);
100100
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOut, x => x.ButtonZoomOut).DisposeWith(disposable);
101101
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandZoomOriginalSize, x => x.ButtonZoomOriginalSize).DisposeWith(disposable);
102102
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandCollapseUpAll, x => x.ButtonCollapseUpAll).DisposeWith(disposable);
103103
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExpandDownAll, x => x.ButtonExpandDownAll).DisposeWith(disposable);
104104

105-
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo , x => x.ItemUndo).DisposeWith(disposable);
106-
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable);
107-
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
105+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo , x => x.ItemUndo).DisposeWith(disposable);
106+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandUndo, x => x.ButtonUndo).DisposeWith(disposable);
107+
108+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ItemRedo).DisposeWith(disposable);
109+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandRedo, x => x.ButtonRedo).DisposeWith(disposable);
110+
111+
112+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ButtonExportToJPEG).DisposeWith(disposable);
113+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExportToJPEG, x => x.ItemExportToJPEG).DisposeWith(disposable);
114+
115+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.BindingNew).DisposeWith(disposable);
116+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.ItemNew).DisposeWith(disposable);
117+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandNew, x => x.ButtonNew).DisposeWith(disposable);
108118

119+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.BindingOpen).DisposeWith(disposable);
120+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.ItemOpen).DisposeWith(disposable);
121+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandOpen, x => x.ButtonOpen).DisposeWith(disposable);
122+
123+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.BindingSave).DisposeWith(disposable);
124+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.ItemSave).DisposeWith(disposable);
125+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSave, x => x.ButtonSave).DisposeWith(disposable);
126+
127+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.BindingSaveAs).DisposeWith(disposable);
128+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.ItemSaveAs).DisposeWith(disposable);
129+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSaveAs, x => x.ButtonSaveAs).DisposeWith(disposable);
130+
131+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.BindingExit).DisposeWith(disposable);
132+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.ItemExit).DisposeWith(disposable);
133+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandExit, x => x.ButtonClose).DisposeWith(disposable);
109134
});
110135
}
111136
#endregion Setup Binding
@@ -117,8 +142,8 @@ private void SetupSubscriptions()
117142
this.WhenActivated(disposable =>
118143
{
119144
this.WhenAnyValue(x=>x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
120-
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels());
121-
145+
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.Messages.Count).Subscribe(_ => UpdateLabels()).DisposeWith(disposable);
146+
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.NeedExit).Where(x=>x).Subscribe(_ => this.Close()).DisposeWith(disposable);
122147
});
123148
}
124149
private void UpdateSchemeName(string newName)
@@ -132,28 +157,15 @@ private void UpdateSchemeName(string newName)
132157
}
133158
#endregion Setup Subscriptions
134159

135-
136160
#region SetupEvents
137161
private void SetupEvents()
138162
{
139163
this.WhenActivated(disposable =>
140164
{
141-
142-
this.ItemExportToJPEG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.JPEG)).DisposeWith(disposable);
143-
this.ItemExportToPNG.Events().Click.Subscribe(_ => ExportToImage(ImageFormats.PNG)).DisposeWith(disposable);
144-
145-
146-
this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable);
147-
this.ButtonClose.Events().Click.Subscribe(_ => WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
165+
this.Header.Events().PreviewMouseLeftButtonDown.Subscribe(e => HeaderClick(e)).DisposeWith(disposable);
148166
this.ButtonMin.Events().Click.Subscribe(e => ButtonMinClick(e)).DisposeWith(disposable);
149167
this.ButtonMax.Events().Click.Subscribe(e => ButtonMaxClick(e)).DisposeWith(disposable);
150168

151-
this.ItemSave.Events().Click.Subscribe(_ => Save()).DisposeWith(disposable);
152-
this.ItemSaveAs.Events().Click.Subscribe(_ => SaveAs()).DisposeWith(disposable);
153-
this.ItemOpen.Events().Click.Subscribe(_ => WithoutSaving(Open)).DisposeWith(disposable);
154-
this.ItemExit.Events().Click.Subscribe(_=> WithoutSaving(ButtonCloseClick)).DisposeWith(disposable);
155-
this.ItemNew.Events().Click.Subscribe(_ => WithoutSaving(New)).DisposeWith(disposable);
156-
157169
this.ErrorListExpander.Events().Collapsed.Subscribe(_=> ErrorListCollapse()).DisposeWith(disposable);
158170
this.ErrorListExpander.Events().Expanded.Subscribe(_ => ErrorListExpanded()).DisposeWith(disposable);
159171

@@ -166,8 +178,8 @@ private void SetupEvents()
166178
this.LabelErrorListUpdate.Events().MouseLeftButtonDown.Subscribe(_ => NodesCanvas.ViewModel.CommandErrorListUpdate.ExecuteWithSubscribe()).DisposeWith(disposable);
167179
});
168180
}
169-
170-
void UpdateLabels()
181+
182+
private void UpdateLabels()
171183
{
172184
var counts = this.NodesCanvas.ViewModel.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x=>x.Key,x=>x.Count());
173185

@@ -177,26 +189,36 @@ void UpdateLabels()
177189
}
178190

179191
}
180-
void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage)
192+
private void SetDisplayMessageType(MouseButtonEventArgs e, TypeMessage typeMessage)
181193
{
182194
if ((ErrorListExpander.IsExpanded)&&(this.ViewModel.NodesCanvas.DisplayMessageType != typeMessage))
183195
e.Handled = true;
184196

185197
this.ViewModel.NodesCanvas.DisplayMessageType = typeMessage;
186198
}
187-
void ErrorListCollapse()
199+
private void ErrorListCollapse()
188200
{
189201
this.ErrorListSplitter.IsEnabled = false;
190202
this.Fotter.Height = new GridLength();
191203
}
192-
void ErrorListExpanded()
204+
private void ErrorListExpanded()
193205
{
194206
this.ErrorListSplitter.IsEnabled = true;
195207
this.Fotter.Height = new GridLength(this.ViewModel.MaxHeightMessagePanel);
196208
}
197-
void StateNormalMaximaze()
209+
210+
211+
private void ButtonMinClick(RoutedEventArgs e)
198212
{
199-
if(this.WindowState == WindowState.Normal)
213+
this.WindowState = WindowState.Minimized;
214+
}
215+
private void ButtonMaxClick(RoutedEventArgs e)
216+
{
217+
StateNormalMaximaze();
218+
}
219+
private void StateNormalMaximaze()
220+
{
221+
if (this.WindowState == WindowState.Normal)
200222
{
201223
this.WindowState = WindowState.Maximized;
202224
this.ButtonMaxRectangle.Fill = System.Windows.Application.Current.Resources["IconRestore"] as DrawingBrush;
@@ -209,19 +231,6 @@ void StateNormalMaximaze()
209231
this.ButtonMaxRectangle.ToolTip = "Restore down";
210232
}
211233
}
212-
void ButtonCloseClick()
213-
{
214-
this.Close();
215-
}
216-
void ButtonMinClick(RoutedEventArgs e)
217-
{
218-
this.WindowState = WindowState.Minimized;
219-
}
220-
void ButtonMaxClick(RoutedEventArgs e)
221-
{
222-
StateNormalMaximaze();
223-
}
224-
225234
private void HeaderClick(MouseButtonEventArgs e)
226235
{
227236
if (e.OriginalSource is DockPanel)
@@ -254,86 +263,6 @@ private void HeaderClick(MouseButtonEventArgs e)
254263
}
255264
}
256265

257-
void ExportToImage(ImageFormats format)
258-
{
259-
SaveFileDialog dlg = new SaveFileDialog();
260-
261-
dlg.FileName = SchemeName();
262-
dlg.Filter = (format == ImageFormats.JPEG)? "JPEG Image (.jpeg)|*.jpeg":"Png Image (.png)|*.png";
263-
264-
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
265-
if(dialogResult==System.Windows.Forms.DialogResult.OK)
266-
{
267-
this.NodesCanvas.SaveCanvasToImage(dlg.FileName, format);
268-
}
269-
}
270-
void New()
271-
{
272-
this.NodesCanvas.ViewModel.CommandNewScheme.ExecuteWithSubscribe();
273-
}
274-
void WithoutSaving(Action action)
275-
{
276-
var result = MessageBoxResult.Yes;
277-
if (!this.NodesCanvas.ViewModel.ItSaved)
278-
{
279-
result = System.Windows.MessageBox.Show("Exit without saving ?", "Test", MessageBoxButton.YesNo);
280-
}
281-
282-
if (result == MessageBoxResult.Yes)
283-
action.Invoke();
284-
}
285-
286-
void Save()
287-
{
288-
if (string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath))
289-
{
290-
SaveAs();
291-
}
292-
else
293-
{
294-
this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(this.ViewModel.NodesCanvas.SchemePath);
295-
}
296-
}
297-
void SaveAs()
298-
{
299-
SaveFileDialog dlg = new SaveFileDialog();
300-
dlg.FileName = SchemeName();
301-
dlg.Filter = "XML-File | *.xml";
302-
303-
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
304-
if (dialogResult == System.Windows.Forms.DialogResult.OK)
305-
{
306-
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
307-
this.NodesCanvas.ViewModel.CommandSave.ExecuteWithSubscribe(dlg.FileName);
308-
Mouse.OverrideCursor = null;
309-
}
310-
}
311-
private string SchemeName()
312-
{
313-
if (!string.IsNullOrEmpty(this.ViewModel.NodesCanvas.SchemePath))
314-
{
315-
return Path.GetFileNameWithoutExtension(this.ViewModel.NodesCanvas.SchemePath);
316-
}
317-
else
318-
{
319-
return "SimpleStateMachine";
320-
}
321-
}
322-
private void Open()
323-
{
324-
OpenFileDialog dlg = new OpenFileDialog();
325-
dlg.FileName = SchemeName();
326-
dlg.Filter = "XML-File | *.xml";
327-
328-
System.Windows.Forms.DialogResult dialogResult = dlg.ShowDialog();
329-
if (dialogResult == System.Windows.Forms.DialogResult.OK)
330-
{
331-
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
332-
this.NodesCanvas.ViewModel.CommandOpen.ExecuteWithSubscribe(dlg.FileName);
333-
Mouse.OverrideCursor = null;
334-
}
335-
336-
}
337266
#endregion SetupEvents
338267

339268

SimpleStateMachineNodeEditor/View/ViewDialog.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ private void SetupSubcriptions()
4747
{
4848
this.WhenActivated(disposable =>
4949
{
50-
this.WhenAnyValue(x => x.Visibility).ObserveOn(RxApp.MainThreadScheduler).
51-
Where(x => x == Visibility.Visible).Subscribe(_ => Show()).DisposeWith(disposable);
50+
this.WhenAnyValue(x => x.Visibility).Where(x => x == Visibility.Visible).Subscribe(_ => Show()).DisposeWith(disposable);
5251
});
5352
}
5453
private void Show()

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ private void SetupCommands()
123123
this.WhenAnyValue(x => x.ViewModel.Selector.Size).WithoutParameter().InvokeCommand(ViewModel,x=>x.CommandSelectorIntersect).DisposeWith(disposable);
124124
this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint.Value).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandCutterIntersect).DisposeWith(disposable);
125125

126+
this.WhenAnyValue(x => x.ViewModel.JPEGPath).Where(x=>!string.IsNullOrEmpty(x)).Subscribe(value=> SaveCanvasToImage(value, ImageFormats.JPEG)).DisposeWith(disposable);
127+
126128
});
127129
}
128130
#endregion Setup Commands
@@ -283,7 +285,7 @@ private MyPoint GetDeltaDragOver(DragEventArgs e)
283285
return result;
284286
}
285287

286-
public void SaveCanvasToImage(string filename, ImageFormats format)
288+
private void SaveCanvasToImage(string filename, ImageFormats format)
287289
{
288290
MyUtils.PanelToImage(this.Canvas, filename, format);
289291
}

0 commit comments

Comments
 (0)