public void TypeInCommand(char KeyDown) { switch ((int)KeyDown) { //enter case 10: ExecuteScript(TypedCommand.Trim()); TypedCommand = string.Empty; break; //backspace case 8: if (TypedCommand.Length > 0) { TypedCommand = TypedCommand.Substring(0, TypedCommand.Length - 1); PrintLine(CurrentLine, TypedCommand); Screen.Flush(); //CallPrintEvent(Screen); } break; default: TypedCommand = TypedCommand + KeyDown.ToString(); PrintLine(CurrentLine, TypedCommand); Screen.Flush(); //CallPrintEvent(Screen); break; } }
/// <summary> /// Initializes the mock data list. /// </summary> public DesignDashboardViewModel() { this.mockData = new ObservableCollection <StoredFileDescriptor>( new List <AccessListEntry> { new AccessListEntry { Token = Guid.NewGuid().ToString(), Metadata = "Sample Database" }, new AccessListEntry { Token = Guid.NewGuid().ToString(), Metadata = "My KeePass Vault" }, new AccessListEntry { Token = Guid.NewGuid().ToString(), Metadata = "Passwords" } }.Select(a => new StoredFileDescriptor(a)) ); this.readOnlyData = new ReadOnlyObservableCollection <StoredFileDescriptor>(this.mockData); ForgetCommand = new TypedCommand <StoredFileDescriptor>( (file) => { this.mockData.Remove(file); } ); }
/// <summary> /// Initializes the save command and localized strings. /// </summary> /// <param name="resourceProvider"></param> private FieldEditorViewModel(IResourceProvider resourceProvider) { if (resourceProvider == null) { throw new ArgumentNullException(nameof(resourceProvider)); } this.LocalizedMissingKey = resourceProvider.GetString(Error_MissingKeyLoc) ?? $"MISSING_STRING_FVEMK"; this.LocalizedReservedKey = resourceProvider.GetString(Error_ReservedKeyLoc) ?? $"MISSING_STRING_FVERK"; this.LocalizedDuplicateKey = resourceProvider.GetString(Error_DuplicateKeyLoc) ?? $"MISSING_STRING_FVEDK"; this.commitCommand = new TypedCommand <IKeePassEntry>(CanSave, DoSave); }
/// <summary> /// Passes provided parameters to the base constructor and initializes commands. /// </summary> /// <param name="resourceProvider">IResourceProvider for localizing strings.</param> /// <param name="navigationViewModel"></param> /// <param name="persistenceService"></param> /// <param name="clipboardService"></param> /// <param name="settingsService"></param> /// <param name="document"></param> /// <param name="entry"></param> /// <param name="isNew"></param> /// <param name="isReadOnly"></param> /// <param name="rng"></param> private EntryDetailsViewModel( IResourceProvider resourceProvider, IDatabaseNavigationViewModel navigationViewModel, IDatabasePersistenceService persistenceService, ISensitiveClipboardService clipboardService, IAppSettingsService settingsService, KdbxDocument document, IKeePassEntry entry, bool isNew, bool isReadOnly, IRandomNumberGenerator rng ) : base(navigationViewModel, persistenceService, document, entry, isNew, isReadOnly) { this.resourceProvider = resourceProvider; this.clipboardService = clipboardService; this.settingsService = settingsService; this.rng = rng; this.copyFieldValueCommand = new TypedCommand <IProtectedString>( str => { clipboardService.CopyCredential(str.ClearValue, ClipboardOperationType.Other); } ); this.deleteFieldCommand = new TypedCommand <IProtectedString>( str => !IsReadOnly && PersistenceService.CanSave, str => { DebugHelper.Assert(!IsReadOnly); WorkingCopy.Fields.Remove(str); } ); this.editFieldCommand = new AsyncTypedCommand <IProtectedString>( str => PersistenceService.CanSave, async str => { IsReadOnly = false; await UpdateFieldEditorViewModel(new FieldEditorViewModel(str, this.resourceProvider)); } ); this.newFieldCommand = new AsyncActionCommand( () => PersistenceService.CanSave, async() => { IsReadOnly = false; await UpdateFieldEditorViewModel(new FieldEditorViewModel(this.rng, this.resourceProvider)); } ); this.commitFieldCommand = new AsyncActionCommand( () => FieldEditorViewModel?.CommitCommand.CanExecute(WorkingCopy) ?? false, async() => { FieldEditorViewModel.CommitCommand.Execute(WorkingCopy); await UpdateFieldEditorViewModel(null); } ); PropertyChanged += (s, e) => { if (e.PropertyName == nameof(IsReadOnly)) { ((TypedCommand <IProtectedString>)DeleteFieldCommand).RaiseCanExecuteChanged(); } else if (e.PropertyName == nameof(WorkingCopy)) { OnPropertyChanged(nameof(WorkingCopyViewModel)); } }; }