Esempio n. 1
0
 public void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (ModelDataOb.Change && uiServices.WantToSave())
     {
         saveCommand.Execute(null);
     }
 }
Esempio n. 2
0
        public ViewM(IUIServises uiServices)
        {
            this.uiServices = uiServices;

            drawCommand = new RelayCommand(_ => uiServices.CanDraw(), _ => ModelView.Draw(chart, uiServices.SelectedItems()));

            deleteCommand = new RelayCommand(_ => { foreach (ModelData model in uiServices.SelectedItems())
                                                    {
                                                        if (!ModelDataOb.Contains(model))
                                                        {
                                                            return(false);
                                                        }
                                                    }
                                                    return(true); },
                                             _ => { foreach (ModelData model in uiServices.SelectedItems())
                                                    {
                                                        ModelDataOb.Remove(model);
                                                    }
                                             }
                                             );

            saveCommand = new RelayCommand(_ => ModelDataOb.Change,
                                           _ => {
                string path = uiServices.SavePath();
                if (path != null)
                {
                    ModelDataOb.Change = false;
                    ObservableModelData.Save(new SerializeAdapter(File.Create(path)), ModelDataOb);
                }
            }
                                           );

            addCommand = new RelayCommand(_ => uiServices.CanAdd(),
                                          _ => ModelDataOb.Add(new ModelData(model.N, model.P))
                                          );

            newCommand = new RelayCommand(_ => true,
                                          _ => {
                if (ModelDataOb.Change && uiServices.WantToSave())
                {
                    saveCommand.Execute(null);
                }
                ModelDataOb.Clear();
                ModelDataOb.Change = false;
            }
                                          );

            openCommand = new RelayCommand(_ => true,
                                           _ => {
                if (ModelDataOb.Change && uiServices.WantToSave())
                {
                    saveCommand.Execute(null);
                }
                string path = uiServices.OpenPath();
                if (path != null)
                {
                    ObservableModelData sample = new ObservableModelData();
                    ObservableModelData.Load(new DeserializeAdapter(File.OpenRead(path)), ref sample);
                    ModelDataOb.copy(sample);
                }
            }
                                           );
        }