Пример #1
0
        public async Task EditCommandAsync(CommandViewModel viewModel)
        {
            switch (viewModel)
            {
            case UserCommandViewModel userCommandViewModel:
                var newCommand      = (Command)userCommandViewModel.Command.Clone();
                var dialogViewModel = new CommandSettingsViewModel(newCommand);
                var result          = await this.ShowDialogAsync(dialogViewModel);

                if (result != true)
                {
                    return;
                }

                foreach (var key in userCommandViewModel.Command.Keys)
                {
                    StorageService.Remove(key.Text);
                }
                foreach (var key in newCommand.Keys)
                {
                    StorageService[key.Text] = newCommand;
                }

                var index = UserCommands.IndexOf(userCommandViewModel);
                UserCommands.Remove(userCommandViewModel);
                UserCommands.Insert(index, new UserCommandViewModel(newCommand));

                break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #2
0
        public async Task AddAsync()
        {
            var command = new Command();

            command.Keys.Add(new SingleKey(string.Empty));
            command.Lines.Add(new SingleCommand(string.Empty));

            var viewModel = new CommandSettingsViewModel(command);
            var result    = await this.ShowDialogAsync(viewModel);

            if (result != true)
            {
                return;
            }

            UserCommands.Add(new UserCommandViewModel(command));
            foreach (var key in command.Keys)
            {
                StorageService[key.Text] = command;
            }
        }