Пример #1
0
        private void NewCommandMenuItem_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 newCommand = new Command
            {
                Name = LocalizationProvider.Instance.GetTextValue("Action.NewCommand")
            };

            Dispatcher.Invoke(() =>
            {
                lstAvailableActions.SelectedItem = null;
                var newAction = new GestureSign.Common.Applications.Action();
                newAction.AddCommand(newCommand);
                selectedApplication.AddAction(newAction);
                ApplicationManager.Instance.SaveApplications();
            }, DispatcherPriority.Input);
        }
Пример #2
0
        private void PasteToNewActionMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (_commandClipboard.Count == 0)
            {
                return;
            }

            var targetApplication = lstAvailableApplication.SelectedItem as IApplication;

            if (targetApplication == null)
            {
                return;
            }

            lstAvailableActions.SelectedItem = null;
            foreach (var actionGroup in _commandClipboard.GroupBy(ci => ci.Action))
            {
                var sourceAction = actionGroup.Key;
                var newAction    = new GestureSign.Common.Applications.Action()
                {
                    Condition         = sourceAction.Condition,
                    ContinuousGesture = sourceAction.ContinuousGesture,
                    GestureName       = sourceAction.GestureName,
                    Commands          = new List <ICommand>(),
                };
                targetApplication.AddAction(newAction);

                foreach (var info in actionGroup)
                {
                    if (_cutActionSource != null)
                    {
                        info.Action.RemoveCommand(info.Command);
                    }

                    var newCommand = ((Command)info.Command).Clone() as Command;
                    newCommand.Name = ApplicationManager.GetNextCommandName(newCommand.Name, info.Action);
                    newAction.AddCommand(newCommand);
                }
            }

            if (_cutActionSource != null)
            {
                _cutActionSource = null;
                _commandClipboard.Clear();
            }

            ApplicationManager.Instance.SaveApplications();
        }
Пример #3
0
        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;

            if (ci == null)
            {
                var newCommand = new Command
                {
                    Name = LocalizationProvider.Instance.GetTextValue("Action.NewCommand")
                };
                Dispatcher.Invoke(() =>
                {
                    lstAvailableActions.SelectedItem = null;
                    var newAction = new GestureSign.Common.Applications.Action();
                    newAction.AddCommand(newCommand);
                    selectedApplication.AddAction(newAction);
                    ApplicationManager.Instance.SaveApplications();
                }, DispatcherPriority.Input);
            }
            else
            {
                var element = (FrameworkElement)sender;
                element.ContextMenu.PlacementTarget = element;
                element.ContextMenu.Placement       = System.Windows.Controls.Primitives.PlacementMode.Top;
                element.ContextMenu.IsOpen          = true;
            }
        }
Пример #4
0
        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")
            };

            Dispatcher.Invoke(() =>
            {
                lstAvailableActions.SelectedItem = null;
                if (ci == null)
                {
                    var newAction = new GestureSign.Common.Applications.Action();
                    newAction.AddCommand(newCommand);
                    selectedApplication.AddAction(newAction);
                }
                else
                {
                    int commandIndex = ci.Action.Commands.ToList().IndexOf(ci.Command);
                    ci.Action.InsertCommand(commandIndex + 1, newCommand);
                }
                ApplicationManager.Instance.SaveApplications();
            }, DispatcherPriority.Input);
        }
Пример #5
0
        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);
            }
        }