Exemplo n.º 1
0
        private void InitializeKeyCommands()
        {
            EscCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenuVisibility = Visibility.Collapsed;
                }
                else
                {
                    MainWindowVisibility = Visibility.Collapsed;
                }
            });

            SelectNextItemCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenu.SelectNextResult();
                }
                else
                {
                    Results.SelectNextResult();
                }
            });

            SelectPrevItemCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenu.SelectPrevResult();
                }
                else
                {
                    Results.SelectPrevResult();
                }
            });



            DisplayNextQueryCommand = new RelayCommand(_ =>
            {
                var nextQuery = _queryHistory.Next();
                DisplayQueryHistory(nextQuery);
            });

            DisplayPrevQueryCommand = new RelayCommand(_ =>
            {
                var prev = _queryHistory.Previous();
                DisplayQueryHistory(prev);
            });

            SelectNextPageCommand = new RelayCommand(_ =>
            {
                Results.SelectNextPage();
            });

            SelectPrevPageCommand = new RelayCommand(_ =>
            {
                Results.SelectPrevPage();
            });

            StartHelpCommand = new RelayCommand(_ =>
            {
                Process.Start("http://doc.getwox.com");
            });

            OpenResultCommand = new RelayCommand(index =>
            {
                var results = ContextMenuVisibility.IsVisible() ? ContextMenu : Results;

                if (index != null)
                {
                    results.SelectedIndex = int.Parse(index.ToString());
                }

                var result = results.SelectedItem?.RawResult;
                if (result != null) // SelectedItem returns null if selection is empty.
                {
                    bool hideWindow = result.Action != null && result.Action(new ActionContext
                    {
                        SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
                    });

                    if (hideWindow)
                    {
                        MainWindowVisibility = Visibility.Collapsed;
                    }

                    if (!ContextMenuVisibility.IsVisible())
                    {
                        _userSelectedRecord.Add(result);
                        _queryHistory.Add(result.OriginQuery.RawQuery);
                    }
                }
            });

            LoadContextMenuCommand = new RelayCommand(_ =>
            {
                if (!ContextMenuVisibility.IsVisible())
                {
                    var result = Results.SelectedItem?.RawResult;

                    if (result != null) // SelectedItem returns null if selection is empty.
                    {
                        var id = result.PluginID;

                        var menus = PluginManager.GetContextMenusForPlugin(result);
                        menus.Add(ContextMenuTopMost(result));
                        menus.Add(ContextMenuPluginInfo(id));

                        ContextMenu.Clear();
                        Task.Run(() =>
                        {
                            ContextMenu.AddResults(menus, id);
                        }, _updateToken);
                        ContextMenuVisibility = Visibility.Visible;
                    }
                }
                else
                {
                    ContextMenuVisibility = Visibility.Collapsed;
                }
            });
        }
Exemplo n.º 2
0
        private void InitializeKeyCommands()
        {
            EscCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenuVisibility = Visibility.Collapsed;
                }
                else
                {
                    MainWindowVisibility = Visibility.Collapsed;
                }
            });

            SelectNextItemCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenu.SelectNextResult();
                }
                else
                {
                    Results.SelectNextResult();
                }
            });

            SelectPrevItemCommand = new RelayCommand(_ =>
            {
                if (ContextMenuVisibility.IsVisible())
                {
                    ContextMenu.SelectPrevResult();
                }
                else
                {
                    Results.SelectPrevResult();
                }
            });



            DisplayNextQueryCommand = new RelayCommand(_ =>
            {
                var nextQuery = _queryHistory.Next();
                DisplayQueryHistory(nextQuery);
            });

            DisplayPrevQueryCommand = new RelayCommand(_ =>
            {
                var prev = _queryHistory.Previous();
                DisplayQueryHistory(prev);
            });

            SelectNextPageCommand = new RelayCommand(_ =>
            {
                Results.SelectNextPage();
            });

            SelectPrevPageCommand = new RelayCommand(_ =>
            {
                Results.SelectPrevPage();
            });

            StartHelpCommand = new RelayCommand(_ =>
            {
                Process.Start("http://doc.getwox.com");
            });

            OpenResultCommand = new RelayCommand(o =>
            {
                var results = ContextMenuVisibility.IsVisible() ? ContextMenu : Results;

                if (o != null)
                {
                    var index = int.Parse(o.ToString());
                    results.SelectResult(index);
                }

                var result      = results.SelectedResult.RawResult;
                bool hideWindow = result.Action(new ActionContext
                {
                    SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
                });
                if (hideWindow)
                {
                    MainWindowVisibility = Visibility.Collapsed;
                }

                if (!ContextMenuVisibility.IsVisible())
                {
                    _userSelectedRecord.Add(result);
                    _queryHistory.Add(result.OriginQuery.RawQuery);
                }
            });

            LoadContextMenuCommand = new RelayCommand(_ =>
            {
                if (!ContextMenuVisibility.IsVisible())
                {
                    var result = Results.SelectedResult.RawResult;
                    var id     = result.PluginID;

                    var menus = PluginManager.GetContextMenusForPlugin(result);
                    menus.Add(ContextMenuTopMost(result));
                    menus.Add(ContextMenuPluginInfo(id));

                    ContextMenu.Clear();
                    ContextMenu.AddResults(menus, id);
                    ContextMenuVisibility = Visibility.Visible;
                }
                else
                {
                    ContextMenuVisibility = Visibility.Collapsed;
                }
            });

            BackCommand = new RelayCommand(_ =>
            {
                ListeningKeyPressed?.Invoke(this, new ListeningKeyPressedEventArgs(_ as KeyEventArgs));
            });
        }