public void LoadContextMenu() { var results = PluginManager.GetContextMenusForPlugin(Result); ContextMenuItems.Clear(); foreach (var r in results) { ContextMenuItems.Add(new ContextMenuItemViewModel() { PluginName = r.PluginName, Title = r.Title, Glyph = r.Glyph, FontFamily = r.FontFamily, AcceleratorKey = r.AcceleratorKey, AcceleratorModifiers = r.AcceleratorModifiers, Command = new RelayCommand(_ => { bool hideWindow = r.Action != null && r.Action( new ActionContext { SpecialKeyState = KeyboardHelper.CheckModifiers(), }); if (hideWindow) { // TODO - Do we hide the window // MainWindowVisibility = Visibility.Collapsed; } }), }); } }
private void OpenResultsEvent(object index, bool isMouseClick) { var results = SelectedResults; if (index != null) { // Using InvariantCulture since this is internal results.SelectedIndex = int.Parse(index.ToString(), CultureInfo.InvariantCulture); } if (results.SelectedItem != null) { bool executeResultRequired = false; if (isMouseClick) { executeResultRequired = true; } else { // If there is a context button selected fire the action for that button instead, and the main command will not be executed executeResultRequired = !results.SelectedItem.ExecuteSelectedContextButton(); } if (executeResultRequired) { var result = results.SelectedItem.Result; // SelectedItem returns null if selection is empty. if (result != null && result.Action != null) { MainWindowVisibility = Visibility.Collapsed; Application.Current.Dispatcher.Invoke(() => { result.Action(new ActionContext { SpecialKeyState = KeyboardHelper.CheckModifiers(), }); }); if (SelectedIsFromQueryResults()) { // todo: revert _userSelectedRecordStorage.Save() and _historyItemsStorage.Save() after https://github.com/microsoft/PowerToys/issues/9164 is done _userSelectedRecord.Add(result); _userSelectedRecordStorage.Save(); _history.Add(result.OriginQuery.RawQuery); _historyItemsStorage.Save(); } else { SelectedResults = Results; } } } } }
private void OpenResultsEvent(object index, bool isMouseClick) { var results = SelectedResults; if (index != null) { // Using InvariantCulture since this is internal results.SelectedIndex = int.Parse(index.ToString(), CultureInfo.InvariantCulture); } if (results.SelectedItem != null) { bool executeResultRequired = false; if (isMouseClick) { executeResultRequired = true; } else { // If there is a context button selected fire the action for that button instead, and the main command will not be executed executeResultRequired = !results.SelectedItem.ExecuteSelectedContextButton(); } if (executeResultRequired) { var result = results.SelectedItem.Result; // SelectedItem returns null if selection is empty. if (result != null && result.Action != null) { Hide(); Application.Current.Dispatcher.Invoke(() => { result.Action(new ActionContext { SpecialKeyState = KeyboardHelper.CheckModifiers(), }); }); if (SelectedIsFromQueryResults()) { _userSelectedRecord.Add(result); _history.Add(result.OriginQuery.RawQuery); } else { SelectedResults = Results; } } } } }
private void InitializeKeyCommands() { IgnoreCommand = new RelayCommand(_ => { }); EscCommand = new RelayCommand(_ => { if (!SelectedIsFromQueryResults()) { SelectedResults = Results; } else { MainWindowVisibility = Visibility.Collapsed; } }); SelectNextItemCommand = new RelayCommand(_ => { SelectedResults.SelectNextResult(); }); SelectPrevItemCommand = new RelayCommand(_ => { SelectedResults.SelectPrevResult(); }); SelectNextTabItemCommand = new RelayCommand(_ => { SelectedResults.SelectNextTabItem(); }); SelectPrevTabItemCommand = new RelayCommand(_ => { SelectedResults.SelectPrevTabItem(); }); SelectNextContextMenuItemCommand = new RelayCommand(_ => { SelectedResults.SelectNextContextMenuItem(); }); SelectPreviousContextMenuItemCommand = new RelayCommand(_ => { SelectedResults.SelectPreviousContextMenuItem(); }); SelectNextPageCommand = new RelayCommand(_ => { SelectedResults.SelectNextPage(); }); SelectPrevPageCommand = new RelayCommand(_ => { SelectedResults.SelectPrevPage(); }); SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult()); StartHelpCommand = new RelayCommand(_ => { Process.Start("http://doc.wox.one/"); }); OpenResultCommand = new RelayCommand(index => { var results = SelectedResults; if (index != null) { results.SelectedIndex = int.Parse(index.ToString(), CultureInfo.InvariantCulture); } if (results.SelectedItem != null) { //If there is a context button selected fire the action for that button before the main command. bool didExecuteContextButton = results.SelectedItem.ExecuteSelectedContextButton(); if (!didExecuteContextButton) { var result = results.SelectedItem.Result; if (result != null && result.Action != null) // SelectedItem returns null if selection is empty. { MainWindowVisibility = Visibility.Collapsed; Application.Current.Dispatcher.Invoke(() => { result.Action(new ActionContext { SpecialKeyState = KeyboardHelper.CheckModifiers() }); }); if (SelectedIsFromQueryResults()) { _userSelectedRecord.Add(result); _history.Add(result.OriginQuery.RawQuery); } else { SelectedResults = Results; } } } } }); LoadContextMenuCommand = new RelayCommand(_ => { if (SelectedIsFromQueryResults()) { SelectedResults = ContextMenu; } else { SelectedResults = Results; } }); LoadHistoryCommand = new RelayCommand(_ => { if (SelectedIsFromQueryResults()) { SelectedResults = History; History.SelectedIndex = _history.Items.Count - 1; } else { SelectedResults = Results; } }); ClearQueryCommand = new RelayCommand(_ => { if (!string.IsNullOrEmpty(QueryText)) { ChangeQueryText(string.Empty, true); //Push Event to UI SystemQuery has changed OnPropertyChanged(nameof(SystemQueryText)); } }); }