2626using System . Threading . Tasks ;
2727using System . Threading ;
2828using System . Reactive ;
29+ using System . Collections . Generic ;
2930
3031namespace SimpleStateMachineNodeEditor . View
3132{
@@ -49,10 +50,26 @@ object IViewFor.ViewModel
4950 set { ViewModel = ( ViewModelMainWindow ) value ; }
5051 }
5152 #endregion ViewModel
53+ Dictionary < TypeMessage , System . Windows . Controls . Label > messagesLabels ;
54+ static Dictionary < TypeMessage , string > labelPostfix = new Dictionary < TypeMessage , string > ( )
55+ {
56+ { TypeMessage . Error , "Error" } ,
57+ { TypeMessage . Information , "Information" } ,
58+ { TypeMessage . Warning , "Warning" } ,
59+ { TypeMessage . Debug , "Debug" } ,
60+ } ;
5261
5362 public MainWindow ( )
5463 {
5564 InitializeComponent ( ) ;
65+ messagesLabels = new Dictionary < TypeMessage , System . Windows . Controls . Label > ( )
66+ {
67+ { TypeMessage . Error , LabelError } ,
68+ { TypeMessage . Information , LabelInformation } ,
69+ { TypeMessage . Warning , LabelWarning } ,
70+ { TypeMessage . Debug , LabelDebug } ,
71+ } ;
72+
5673 ViewModel = new ViewModelMainWindow ( this . NodesCanvas . ViewModel ) ;
5774 SetupCommands ( ) ;
5875 SetupSubscriptions ( ) ;
@@ -90,6 +107,19 @@ private void SetupBinding()
90107 this . BindCommand ( this . ViewModel , x => x . NodesCanvas . CommandSelectAll , x => x . ItemSelectAll ) . DisposeWith ( disposable ) ;
91108
92109
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+
93123 //ItemSave.Command = CommandSave;
94124 //this.OneWayBind(this, x => x.CommandSave, x => x.ItemSave.Command).DisposeWith(disposable);
95125
@@ -152,35 +182,40 @@ private void SetupEvents()
152182 {
153183 this . ItemExportToJPEG . Events ( ) . Click . Subscribe ( _ => ExportToImage ( ImageFormats . JPEG ) ) . DisposeWith ( disposable ) ;
154184 this . ItemExportToPNG . Events ( ) . Click . Subscribe ( _ => ExportToImage ( ImageFormats . PNG ) ) . DisposeWith ( disposable ) ;
155- //this.ButtonImportScheme
156-
157185
158-
159- //this.ItemSave.InputBindings.Bin
160186 this . Header . Events ( ) . PreviewMouseLeftButtonDown . Subscribe ( e => HeaderClick ( e ) ) . DisposeWith ( disposable ) ;
161187 this . ButtonClose . Events ( ) . Click . Subscribe ( _ => WithoutSaving ( ButtonCloseClick ) ) . DisposeWith ( disposable ) ;
162188 this . ButtonMin . Events ( ) . Click . Subscribe ( e => ButtonMinClick ( e ) ) . DisposeWith ( disposable ) ;
163189 this . ButtonMax . Events ( ) . Click . Subscribe ( e => ButtonMaxClick ( e ) ) . DisposeWith ( disposable ) ;
164-
165190
166- // this.ItemSave.Events().Click.Subscribe(_=> Save()).DisposeWith(disposable);
191+ this . ItemSave . Events ( ) . Click . Subscribe ( _ => Save ( ) ) . DisposeWith ( disposable ) ;
167192 this . ItemSaveAs . Events ( ) . Click . Subscribe ( _ => SaveAs ( ) ) . DisposeWith ( disposable ) ;
168193 this . ItemOpen . Events ( ) . Click . Subscribe ( async _ => await WithoutSavingAsync ( OpenAsync ) ) . DisposeWith ( disposable ) ;
169194 this . ItemExit . Events ( ) . Click . Subscribe ( _=> WithoutSaving ( ButtonCloseClick ) ) . DisposeWith ( disposable ) ;
170195 this . ItemNew . Events ( ) . Click . Subscribe ( _ => WithoutSaving ( New ) ) . DisposeWith ( disposable ) ;
171196 this . ErrorListExpander . Events ( ) . Collapsed . Subscribe ( _=> ErrorListCollapse ( ) ) . DisposeWith ( disposable ) ;
172197 this . ErrorListExpander . Events ( ) . Expanded . Subscribe ( _ => ErrorListExpanded ( ) ) . DisposeWith ( disposable ) ;
173198
174- this . LabelErrorList . Events ( ) . PreviewMouseLeftButtonDown . Subscribe ( e=> SetDisplayMessageType ( e , TypeMessage . All ) ) . DisposeWith ( disposable ) ;
175- this . LabelError . Events ( ) . PreviewMouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , TypeMessage . Error ) ) . DisposeWith ( disposable ) ;
176- this . LabelInformation . Events ( ) . MouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , TypeMessage . Information ) ) . DisposeWith ( disposable ) ;
177- this . LabelWarning . Events ( ) . MouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , TypeMessage . Warning ) ) . DisposeWith ( disposable ) ;
178- this . LabelDebug . Events ( ) . MouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , TypeMessage . Debug ) ) . DisposeWith ( disposable ) ;
199+ foreach ( var label in messagesLabels )
200+ {
201+ label . Value . Events ( ) . PreviewMouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , label . Key ) ) . DisposeWith ( disposable ) ;
202+ }
179203
180- // this.LabelUpdate .Events().PreviewMouseLeftButtonDown.Subscribe(_ => this.ViewModel.Messages.Cle ).DisposeWith(disposable);
181- // this.ErrorListExpander .Events().Expanded .Subscribe(_ => ErrorListExpanded ()).DisposeWith(disposable);
204+ this . LabelErrorList . Events ( ) . PreviewMouseLeftButtonDown . Subscribe ( e => SetDisplayMessageType ( e , TypeMessage . All ) ) . DisposeWith ( disposable ) ;
205+ this . LabelErrorListUpdate . Events ( ) . MouseLeftButtonDown . Subscribe ( _ => NodesCanvas . ViewModel . CommandErrorListUpdate . ExecuteWithSubscribe ( ) ) . DisposeWith ( disposable ) ;
182206 } ) ;
183207 }
208+
209+ void UpdateLabels ( )
210+ {
211+ var counts = this . NodesCanvas . ViewModel . Messages . GroupBy ( x => x . TypeMessage ) . ToDictionary ( x=> x . Key , x=> x . Count ( ) ) ;
212+
213+ foreach ( var lable in messagesLabels )
214+ {
215+ lable . Value . Content = ( counts . Keys . Contains ( lable . Key ) ? counts [ lable . Key ] . ToString ( ) : "0" ) + " " + labelPostfix [ lable . Key ] ;
216+ }
217+
218+ }
184219 void SetDisplayMessageType ( MouseButtonEventArgs e , TypeMessage typeMessage )
185220 {
186221 if ( ( ErrorListExpander . IsExpanded ) & & ( this . ViewModel . NodesCanvas . DisplayMessageType != typeMessage ) )
0 commit comments