コード例 #1
0
        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);