Пример #1
0
 /// <summary>
 /// Initializes the ViewModel with the specified clipboard access.
 /// </summary>
 public PasswordGenViewModel(IPasswordGenerationService passwordService, ISensitiveClipboardService clipboardService)
 {
     ClipboardCopyCommand = new ActionCommand(
         async() =>
     {
         clipboardService.CopyCredential(
             await passwordService.Generate(GetCurrentRecipe()),
             ClipboardOperationType.Password
             );
     }
         );
 }
Пример #2
0
        /// <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));
                }
            };
        }