Ejemplo n.º 1
0
        public void SearchResultUpdateHandler(object sender, WindowWalker.Components.Window.WindowListUpdateEventArgs e)
        {
            resultsListBox.Items.Clear();

            var windows = WindowSearchController.Instance.SearchMatches.Where(x => x.Hwnd != this.handleToMainWindow);

            foreach (var window in windows)
            {
                var tempStackPanel = new StackPanel();
                tempStackPanel.Orientation = Orientation.Horizontal;
                var image = new Image();
                image.Source = window.WindowIcon;
                image.Margin = new Thickness(0,0,5,0);
                tempStackPanel.Children.Add(image);
                var tempTextBlock = new TextBlockWindow();
                tempTextBlock.Text = window.Title;

                if (!window.ProcessName.ToUpper().Equals(string.Empty))
                {
                    tempTextBlock.Text += " (" + window.ProcessName.ToUpper() + ")" ;
                }

                tempTextBlock.Window = window;
                tempStackPanel.Children.Add(tempTextBlock);
                image.Height = 15;
                this.resultsListBox.Items.Add(tempStackPanel);
            }

            if (resultsListBox.Items.Count != 0)
            {
                resultsListBox.SelectedIndex = 0;
            }

            System.Diagnostics.Debug.Print("Search result updated in Main Window. There are now " + this.resultsListBox.Items.Count + " windows that match the search term");
        }
Ejemplo n.º 2
0
        public void SearchResultUpdateHandler(object sender, WindowWalker.Components.Window.WindowListUpdateEventArgs e)
        {
            this.Dispatcher.Invoke(() =>
            {
                resultsListBox.Items.Clear();

                var windowsResult = WindowSearchController.Instance.SearchMatches.Where(x => x.ResultWindow.Hwnd != this.handleToMainWindow);
                Dictionary<TextBlock, WindowSearchResult> highlightStack = new Dictionary<TextBlock, WindowSearchResult>();

                var windowResultsByType = new List<List<WindowSearchResult>>();

                var windowNoSearchTextResults = windowsResult.Where(x => x.SearchResultMatchType == WindowSearchResult.SearchType.Empty).OrderByDescending(x => x.Score);
                var windowsShortcutResults = windowsResult.Where(x => x.SearchResultMatchType == WindowSearchResult.SearchType.Shortcut).OrderByDescending(x => x.Score);
                var windowsFuzzyResults = windowsResult.Where(x => x.SearchResultMatchType == WindowSearchResult.SearchType.Fuzzy).OrderByDescending(x => x.Score);

                windowResultsByType.Add(windowNoSearchTextResults.ToList());
                windowResultsByType.Add(windowsShortcutResults.ToList());
                windowResultsByType.Add(windowsFuzzyResults.ToList());

                Dictionary<IntPtr, bool> windowsAlreadyDisplayed = new Dictionary<IntPtr, bool>();

                foreach (var windowsResultForType in windowResultsByType)
                {
                    foreach (WindowSearchResult windowResult in windowsResultForType)
                    {
                        if (windowsAlreadyDisplayed.ContainsKey(windowResult.ResultWindow.Hwnd))
                        {
                            continue;
                        }
                        else
                        {
                            windowsAlreadyDisplayed[windowResult.ResultWindow.Hwnd] = true;
                        }

                        /// Each window is shown in a horizontal stack panel
                        /// that contains an image object on the left and
                        /// a textblock with the window title on the right

                        var tempStackPanel = new StackPanel();
                        tempStackPanel.Orientation = Orientation.Horizontal;
                        var image = new Image();
                        image.Source = windowResult.ResultWindow.WindowIcon;
                        image.Margin = new Thickness(0, 0, 5, 0);
                        tempStackPanel.Children.Add(image);
                        var tempTextBlock = new TextBlockWindow();

                        tempTextBlock.Window = windowResult.ResultWindow;
                        tempStackPanel.Children.Add(tempTextBlock);
                        image.Height = 15;
                        this.resultsListBox.Items.Add(tempStackPanel);
                        highlightStack[tempTextBlock] = windowResult;
                    }
                }
                if (resultsListBox.Items.Count != 0)
                {
                    resultsListBox.SelectedIndex = 0;
                }

                this.UpdateTextWithHighlight(highlightStack);

                System.Diagnostics.Debug.Print("Search result updated in Main Window. There are now " + this.resultsListBox.Items.Count + " windows that match the search term");
            });
        }