public DatabasePageViewModel( INavigator navigator, IDatabaseCache unlocker, IClipboard <string> clipboard, ICredentialProvider credentialProvider, INameProvider nameProvider, ILauncher launcher, IMessageDialogFactory dialogs, ILogger log) { _clipboard = clipboard; _unlocker = unlocker; _navigator = navigator; _credentialProvider = credentialProvider; _nameProvider = nameProvider; _launcher = launcher; _dialogs = dialogs; _log = log; ItemClickCommand = new DelegateCommand <IKeePassId>(item => GroupClicked(item as IKeePassGroup), item => (item as IKeePassGroup) != null); GoToParentCommand = new DelegateCommand <IKeePassGroup>(group => { if (_database != null) { _navigator.GoToDatabaseView(_database, group); } }); CopyCommand = new DelegateCommand <string>(text => _clipboard.Copy(text)); OpenUrlCommand = new DelegateCommand <IKeePassEntry>(async entry => { if (Uri.TryCreate(entry.Url, UriKind.Absolute, out Uri uri)) { await _launcher.LaunchUriAsync(uri); } }); AddEntryCommand = new DelegateCommand(async() => { var name = await _nameProvider.GetNameAsync(); if (!string.IsNullOrEmpty(name)) { Items.Add(_group.CreateEntry(name)); } NotifyAllCommands(); #if FEATURE_SAVE // This is disabled currently due to twsouthwick/KeePassWin 15 }, () => !_saving); #else }, () => !_activeSearch);
public MenuViewModel(INavigator navigator, IDatabaseCache cache, ICredentialProvider credentialProvider, IMessageDialogFactory messageDialogs, IFilePicker filePicker) { _navigator = navigator; _cache = cache; _credentialProvider = credentialProvider; _messageDialogs = messageDialogs; Databases = new ObservableCollection <MenuItemViewModel>(); SettingsCommand = new DelegateCommand(() => _navigator.GoToSettings()); OpenCommand = new DelegateCommand(async() => await _cache.AddDatabaseAsync(filePicker, false)); _subscription = cache.Databases .ObserveOn(SynchContext) .Subscribe(action => { switch (action.action) { case DatabaseAction.Add: AddDatabaseEntry(action.file); break; case DatabaseAction.Open: var entry = AddDatabaseEntry(action.file); entry.Command.Execute(null); break; case DatabaseAction.Remove: RemoveDatabaseEntry(action.file); break; } }); _cache.GetDatabaseFilesAsync().ContinueWith(r => { if (r.IsFaulted) { return; } foreach (var item in r.Result) { AddDatabaseEntry(item); } }); }
public MenuViewModel(INavigator navigator, IDatabaseCache cache, ICredentialProvider credentialProvider, IMessageDialogFactory messageDialogs) { _navigator = navigator; _cache = cache; _credentialProvider = credentialProvider; _messageDialogs = messageDialogs; Databases = new ObservableCollection <MenuItemViewModel>(); SettingsCommand = new DelegateCommand(() => _navigator.GoToSettings()); OpenCommand = new DelegateCommand(async() => { try { var db = await _cache.AddDatabaseAsync(); if (db != null) { AddDatabaseEntry(db); } } catch (DatabaseAlreadyExistsException) { await _messageDialogs.DatabaseAlreadyExistsAsync(); } }); _cache.GetDatabaseFilesAsync().ContinueWith(r => { if (r.IsFaulted) { return; } foreach (var item in r.Result) { AddDatabaseEntry(item); } }); }