@@ -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
0 commit comments