private void EditCommand() { // Make sure at least one item is selected if (lstAvailableActions.SelectedItems.Count == 0) { return; } // Get first item selected, associated action, and selected application CommandInfo selectedItem = (CommandInfo)lstAvailableActions.SelectedItem; var selectedCommand = selectedItem.Command; if (selectedCommand == null) { return; } CommandDialog commandDialog = new CommandDialog(selectedCommand, selectedItem.Action); var result = commandDialog.ShowDialog(); if (result != null && result.Value) { int index = CommandInfos.IndexOf(selectedItem); var newActionInfo = CommandInfo.FromCommand(selectedCommand, selectedItem.Action); CommandInfos[index] = newActionInfo; RefreshActionGroup(newActionInfo.Action); SelectCommands(newActionInfo); } }
private void RefreshAllActions() { var selectedApplication = lstAvailableApplication.SelectedItem as IApplication; if (selectedApplication == null) { return; } Action <object> refreshAction = (o) => { Dispatcher.Invoke(() => { CommandInfos.Clear(); }, DispatcherPriority.Loaded); foreach (var currentAction in selectedApplication.Actions) { if (currentAction.Commands == null) { continue; } foreach (var command in currentAction.Commands) { var info = CommandInfo.FromCommand(command, currentAction); try { Dispatcher.Invoke(() => { CommandInfos.Add(info); }, DispatcherPriority.Input); } catch { } } } }; _addCommandTask = _addCommandTask?.ContinueWith(refreshAction) ?? Task.Factory.StartNew(refreshAction, null); }
private void PasteActionMenuItem_Click(object sender, RoutedEventArgs e) { if (_commandClipboard.Count == 0) { return; } var targetApplication = lstAvailableApplication.SelectedItem as IApplication; if (targetApplication == null) { return; } CommandInfo commandInfo; foreach (var info in _commandClipboard) { var newCommand = ((Command)info.Command).Clone() as Command; if (targetApplication.Actions.Contains(info.Action)) { if (info.Action.Commands.Exists(c => c.Name == newCommand.Name)) { newCommand.Name = ApplicationManager.GetNextCommandName(newCommand.Name, info.Action); } info.Action.Commands.Add(newCommand); commandInfo = CommandInfo.FromCommand(newCommand, info.Action); } else { var newAction = ((GestureSign.Common.Applications.Action)info.Action).Clone() as GestureSign.Common.Applications.Action; newAction.Commands = new List <ICommand> { newCommand }; targetApplication.AddAction(newAction); commandInfo = CommandInfo.FromCommand(newCommand, newAction); } if (_cutActionSource != null) { _cutActionSource.RemoveAction(info.Action); if (_cutActionSource == targetApplication) { CommandInfos.Remove(info); } } CommandInfos.Add(commandInfo); } if (_cutActionSource != null) { _cutActionSource = null; _commandClipboard.Clear(); } ApplicationManager.Instance.SaveApplications(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var command = (ICommand)value; if (command == null) { return(null); } return(CommandInfo.FromCommand(command, null)); }
private void btnAddAction_Click(object sender, RoutedEventArgs e) { var selectedApplication = lstAvailableApplication.SelectedItem as IApplication; if (selectedApplication == null) { lstAvailableApplication.SelectedIndex = 0; selectedApplication = lstAvailableApplication.SelectedItem as IApplication; if (selectedApplication == null) { return; } } var ci = lstAvailableActions.SelectedItem as CommandInfo; var newCommand = new Command { Name = LocalizationProvider.Instance.GetTextValue("Action.NewCommand") }; Action <Task> addCommand = task => { Dispatcher.Invoke(() => { CommandInfo newInfo; if (ci == null) { var newAction = new GestureSign.Common.Applications.Action { Commands = new List <ICommand>() }; newAction.Commands.Add(newCommand); selectedApplication.AddAction(newAction); newInfo = CommandInfo.FromCommand(newCommand, newAction); CommandInfos.Add(newInfo); } else { newInfo = CommandInfo.FromCommand(newCommand, ci.Action); int infoIndex = CommandInfos.IndexOf(ci); int commandIndex = ci.Action.Commands.IndexOf(ci.Command); if (commandIndex + 1 == ci.Action.Commands.Count) { ci.Action.Commands.Add(newCommand); } else { ci.Action.Commands.Insert(commandIndex + 1, newCommand); } if (infoIndex + 1 == CommandInfos.Count) { CommandInfos.Add(newInfo); } else { CommandInfos.Insert(infoIndex + 1, newInfo); } } RefreshActionGroup(newInfo.Action); SelectCommands(newInfo); ApplicationManager.Instance.SaveApplications(); }, DispatcherPriority.Input); }; if (_addCommandTask != null && !_addCommandTask.IsCompleted) { _addCommandTask.ContinueWith(addCommand); } else { addCommand.Invoke(null); } }