public DocumentViewModel() { WindowTitle = new PropertyDelegateReadonlyModel <string>(() => ".NET Master Password - " + FilePathName.Value + " " + (HasChanges.Value ? "*" : "")); HasChanges = new PropertyReadonlyModel <bool>(); FilePathValid = new PropertyReadonlyModel <bool>(); FilePathName = new PropertyReadonlyModel <string>(FileNameNew); WindowTitle.MonitorForChanges(HasChanges, FilePathName); Open = new DelegateCommand(() => DoOpen()); ImportForMerge = new DelegateCommand(DoImportMerge); Save = new DelegateCommand(() => DoSave()); SaveAs = new DelegateCommand(() => DoSaveAs()); New = new DelegateCommand(DoNew); // data Config = new ConfigurationViewModel(); Config.DetectChanges.DataChanged += () => HasChanges.SetValue(true); // try to load last file try { if (Settings.Default.HasMostRecentFile) { // we have an old path PerformOpen(Settings.Default.MostRecentFile); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } HasChanges.SetValue(false); }
public DocumentViewModel() { WindowTitle = new PropertyDelegateReadonlyModel<string>(() => ".NET Master Password - " + FilePathName.Value + " " + (HasChanges.Value ? "*" : "")); HasChanges = new PropertyReadonlyModel<bool>(); FilePathValid = new PropertyReadonlyModel<bool>(); FilePathName = new PropertyReadonlyModel<string>(FileNameNew); WindowTitle.MonitorForChanges(HasChanges, FilePathName); Open = new DelegateCommand(() => DoOpen()); Save = new DelegateCommand(() => DoSave()); SaveAs = new DelegateCommand(() => DoSaveAs()); New = new DelegateCommand(DoNew); // data Config = new ConfigurationViewModel(); Config.DetectChanges.DataChanged += () => HasChanges.SetValue(true); // try to load last file try { if (Settings.Default.HasMostRecentFile) { // we have an old path PerformOpen(Settings.Default.MostRecentFile); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } HasChanges.SetValue(false); }
public ConfigurationViewModel() { // Data UserName = new PropertyModel<string>(); Sites = new ObservableCollection<ConfigurationSiteViewModel>(); SelectedItem = new PropertyModel<ConfigurationSiteViewModel>(); SelectedItemScrollTo = new PropertyReadonlyModel<ConfigurationSiteViewModel>(); // helper to influence grid selection GeneratedForSite = new PropertyReadonlyModel<string>(); GeneratedPassword = new PropertyReadonlyModel<string>(); CurrentMasterPassword = new PropertyModel<SecureString>(); ResetMasterPassword = new PropertyReadonlyModel<bool>(); LastClipboardAction = new PropertyReadonlyModel<string>(); CurrentMasterPassword.PropertyChanged += delegate { ResetMasterPassword.SetValue(false); }; // Commands Add = new DelegateCommand(() => PerformAdd()); RemoveSelected = new DelegateCommand(() => { if (CanRemove(SelectedItem.Value)) Sites.Remove(SelectedItem.Value); }, () => SelectedItem.Value != null); GeneratePassword = new DelegateCommand(DoGeneratePassword, () => CurrentMasterPassword.Value != null && SelectedItem.Value != null); CopyToClipBoard = new DelegateCommand(DoCopyPassToClipboard, () => !string.IsNullOrEmpty(GeneratedPassword.Value) && CurrentMasterPassword.Value != null); CopyLoginToClipBoard = new DelegateCommand(DoCopyLoginToClipboard, () => SelectedItem.Value != null); // Change detection DetectChanges = new GenericChangeDetection(); DetectChanges.AddINotifyPropertyChanged(UserName); DetectChanges.AddCollectionOfIDetectChanges(Sites, item => item.DetectChanges); }
public ConfigurationViewModel() { // Data UserName = new PropertyModel <string>(); Sites = new ObservableCollection <ConfigurationSiteViewModel>(); SelectedItem = new PropertyModel <ConfigurationSiteViewModel>(); SelectedItemScrollTo = new PropertyReadonlyModel <ConfigurationSiteViewModel>(); // helper to influence grid selection GeneratedForSite = new PropertyReadonlyModel <string>(); GeneratedPassword = new PropertyReadonlyModel <string>(); CurrentMasterPassword = new PropertyModel <SecureString>(); ResetMasterPassword = new PropertyReadonlyModel <bool>(); LastClipboardAction = new PropertyReadonlyModel <string>(); CurrentMasterPassword.PropertyChanged += delegate { ResetMasterPassword.SetValue(false); }; // Commands Add = new DelegateCommand(() => PerformAdd()); RemoveSelected = new DelegateCommand(() => { if (CanRemove(SelectedItem.Value)) { Sites.Remove(SelectedItem.Value); } }, () => SelectedItem.Value != null); GeneratePassword = new DelegateCommand(DoGeneratePassword, () => CurrentMasterPassword.Value != null && SelectedItem.Value != null); CopyToClipBoard = new DelegateCommand(DoCopyPassToClipboard, () => !string.IsNullOrEmpty(GeneratedPassword.Value) && CurrentMasterPassword.Value != null); CopyLoginToClipBoard = new DelegateCommand(DoCopyLoginToClipboard, () => SelectedItem.Value != null); // Change detection DetectChanges = new GenericChangeDetection(); DetectChanges.AddINotifyPropertyChanged(UserName); DetectChanges.AddCollectionOfIDetectChanges(Sites, item => item.DetectChanges); }