Exemplo n.º 1
0
        private void TextChanged(object sender, TextChangedEventArgs args)
        {
            if (!tb.IsEnabled)
            {
                return;
            }

            var query = tb.Text;

            var context = new WindowFilterContext <AppWindowViewModel>
            {
                Windows = _unfilteredWindowList,
                ForegroundWindowProcessTitle = new AppWindow(_foregroundWindow.HWnd).ProcessTitle
            };

            var filterResults = new WindowFilterer().Filter(context, query).ToList();

            foreach (var filterResult in filterResults)
            {
                filterResult.AppWindow.FormattedTitle =
                    GetFormattedTitleFromBestResult(filterResult.WindowTitleMatchResults);
                filterResult.AppWindow.FormattedProcessTitle =
                    GetFormattedTitleFromBestResult(filterResult.ProcessTitleMatchResults);
            }

            _filteredWindowList = new ObservableCollection <AppWindowViewModel>(filterResults.Select(r => r.AppWindow));
            AddPrefixNumbersToFormattedTitle(_filteredWindowList);
            lb.DataContext = _filteredWindowList;
            if (lb.Items.Count > 0)
            {
                lb.SelectedItem = lb.Items[0];
            }
        }
Exemplo n.º 2
0
        public List <Result> Query(Query query)
        {
            var queryString = query.Search;

            var windowContext = new WindowFilterContext <AppWindowViewModel>
            {
                Windows = new WindowFinder().GetWindows().Select(w => new AppWindowViewModel(w)),
                ForegroundWindowProcessTitle = new AppWindow(SystemWindow.ForegroundWindow.HWnd).ProcessTitle
            };

            var filterResults =
                new WindowFilterer().Filter(windowContext, queryString).Select(o => o.AppWindow.AppWindow)
                .Where(window => window.ProcessTitle != "Wox")
                .ToList();


            return(filterResults.Select(o =>
            {
                return new Result
                {
                    Title = _settings.SwapTitleAndSubtitle? o.ProcessTitle : GetNormalTitleOrAppFirst(o.Title),
                    SubTitle = _settings.SwapTitleAndSubtitle ? GetNormalTitleOrAppFirst(o.Title) : o.ProcessTitle,
                    IcoPath = o.ExecutablePath,
                    ContextData = o,
                    Action = con =>
                    {
                        o.SwitchTo();
                        Context.API.HideApp();
                        return true;
                    }
                };
            }).ToList());
        }
Exemplo n.º 3
0
        private void TextChanged(object sender, TextChangedEventArgs args)
        {
            if (!tb.IsEnabled)
            {
                return;
            }

            var query = tb.Text;

            var context = new WindowFilterContext <AppWindowViewModel>
            {
                Windows = _unfilteredWindowList,
                ForegroundWindowProcessTitle = new AppWindow(_foregroundWindow.HWnd).ProcessTitle
            };

            var filterResults = new WindowFilterer().Filter(context, query);

            if (!string.IsNullOrEmpty(query) && Settings.Default.MaximumResultCountEnabled)
            {
                filterResults = filterResults.Take(Settings.Default.MaximumResultCount);
            }

            var collectedResult = filterResults.ToList();

            foreach (var filterResult in collectedResult)
            {
                filterResult.AppWindow.FormattedTitle =
                    GetFormattedTitleFromBestResult(filterResult.WindowTitleMatchResults);
                filterResult.AppWindow.FormattedProcessTitle =
                    GetFormattedTitleFromBestResult(filterResult.ProcessTitleMatchResults);
            }

            _filteredWindowList = new ObservableCollection <AppWindowViewModel>(collectedResult.Select(r => r.AppWindow));
            lb.DataContext      = _filteredWindowList;
            if (lb.Items.Count > 0)
            {
                lb.SelectedItem = lb.Items[0];
            }
        }
Exemplo n.º 4
0
        public List <Result> Query(Query query, Dictionary <string, int> historyHistorySources)
        {
            string queryString = query.Search;

            WindowFilterContext <AppWindowViewModel> windowContext = new WindowFilterContext <AppWindowViewModel> {
                Windows = new WindowFinder().GetWindows().Select(w => new AppWindowViewModel(w)),
                ForegroundWindowProcessTitle = new AppWindow(SystemWindow.ForegroundWindow.HWnd).ProcessTitle
            };
            List <AppWindowViewModel> filterResults = windowContext.Windows
                                                      .Where(r => { return(XinFuzzyMatcher.isMatch(r.ProcessTitle + " " + r.WindowTitle, queryString)); })
                                                      .OrderByDescending(r => - r.ProcessTitle.Length)
                                                      .ToList();

//            var filterResults =
//                new WindowFilterer().Filter(windowContext, queryString).Select(o => o.AppWindow.AppWindow)
//                    .Where(window => window.ProcessTitle != "Wox")
//                    .ToList();


            List <Result> results = filterResults.Select(o => {
                Result result = new Result {
                    Title       = o.ProcessTitle,
                    SubTitle    = o.WindowTitle,
                    IcoPath     = o.AppWindow.ExecutablePath,
                    ContextData = o,
                    Action      = con => {
                        o.AppWindow.SwitchTo();
                        Context.API.HideApp();
                        return(true);
                    }
                };
                return(result);
            }).ToList();

            return(results);
        }
Exemplo n.º 5
0
        private void TextChanged(object sender, TextChangedEventArgs args)
        {
            var query = tb.Text;

            var context = new WindowFilterContext<AppWindowViewModel>
            {
                Windows = _unfilteredWindowList,
                ForegroundWindowProcessTitle = new AppWindow(_foregroundWindow.HWnd).ProcessTitle
            };

            var filterResults = new WindowFilterer().Filter(context, query).ToList();

            foreach (var filterResult in filterResults)
            {
                filterResult.AppWindow.FormattedTitle =
                    GetFormattedTitleFromBestResult(filterResult.WindowTitleMatchResults);
                filterResult.AppWindow.FormattedProcessTitle =
                    GetFormattedTitleFromBestResult(filterResult.ProcessTitleMatchResults);
            }

            _filteredWindowList = new ObservableCollection<AppWindowViewModel>(filterResults.Select(r => r.AppWindow));
            lb.DataContext = _filteredWindowList;
            if (lb.Items.Count > 0)
            {
                lb.SelectedItem = lb.Items[0];
            }
        }