示例#1
0
        private void Menu_AddItem(ContextMenu c, CustomAction.Actions action)
        {
            MenuItem m = new MenuItem();

            m.Header = action.GetDescription();
            m.Click += delegate
            {
                if (action == CustomAction.Actions.RunExternalProgram)
                {
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Title       = Loc.GetString("cact_external_app_dialog_title");
                    dlg.Multiselect = false;
                    dlg.Filter      = "Executable Files|*.exe;*.bat;*.cmd;*.pif|" +
                                      "All Files (*.*)|*.*";

                    bool?result = dlg.ShowDialog();
                    if (result == true)
                    {
                        _action = new CustomAction(action, dlg.FileName);
                    }
                }
                else if (action == CustomAction.Actions.Hotkey)
                {
                    HotkeyRecorder dlg    = new HotkeyRecorder();
                    bool?          result = dlg.ShowDialog();
                    if (result == true)
                    {
                        _action = new CustomAction(action, dlg.HotkeyString + ";" + String.Join(",", dlg.HotKeysVirtualCodeRaw));
                    }
                }
                else
                {
                    _action = new CustomAction(action);
                }

                if (_action != null)
                {
                    Action.TextDetail = _action.ToLongString();
                }
            };
            m.Style = (Style)FindResource("MenuItemStyle");
            c.Items.Add(m);
        }
示例#2
0
        private async void ItemClicked(CustomAction action)
        {
            switch (action.Action)
            {
            case CustomAction.Actions.RunExternalProgram:
            {
                OpenFileDialog dlg = new OpenFileDialog
                {
                    Title         = Loc.Resolve("cact_external_app_dialog_title"),
                    AllowMultiple = false
                };

                string[]? result = await dlg.ShowAsync(MainWindow.Instance);

                if (result != null && result.Length > 0)
                {
                    _currentAction = new CustomAction(action.Action, result[0]);
                }

                break;
            }

            case CustomAction.Actions.TriggerHotkey:
                var recorder = new HotkeyRecorder();
                await recorder.ShowDialog(MainWindow.Instance);

                if (recorder.Result)
                {
                    _currentAction = new CustomAction(action.Action, string.Join(",", recorder.Hotkeys ?? new List <Key>()));
                }
                break;

            default:
                _currentAction = action;
                break;
            }

            if (_currentAction != null)
            {
                _menuDetail.Description = _currentAction.ToLongString();
            }
        }