Beispiel #1
0
 public QueryHandler(MainWindow mainWindow)
 {
     ShownResults    = new UIResults();
     IconCache       = new Dictionary <IntPtr, ImageSource>();
     MainWindow      = mainWindow;
     MaxResultsShown = 32;
 }
Beispiel #2
0
        protected override void OnQuery(string text)
        {
            UIResults results = new UIResults();

            //TODO: implement query
            results.Add(new UIResultItem(Environment.CurrentDirectory + "/Images/WebIcon.png", "Internet Search", "Not implemented yet"));


            QueryEnd(results, text);
        }
Beispiel #3
0
        protected override void OnQuery(string text)
        {
            UIResults results = new UIResults();

            foreach (KeyValuePair <string, Command> cmd in _commands)
            {
                results.Add(new UIResultItem("Images/CommandIcon.png", cmd.Key, cmd.Value.Description));
            }

            ShowResults(results, text);
            QueryEnd(results, text);
        }
Beispiel #4
0
        protected override void OnQuery(string query)
        {
            if (IsScanning)
            {
                return;
            }

            string lowerCaseQuery = query.ToLower();
            int    closestIndex   = -1;

            if (_queryWorker.IsBusy)
            {
                _queryWorker.CancelAsync();
                _queryWorker.Dispose();
                _queryWorker = new BackgroundWorker();
                _queryWorker.WorkerSupportsCancellation = true;
            }

            _queryWorker.DoWork += (sender, args) =>
            {
                closestIndex = FindClosestResultIndex(lowerCaseQuery); // heavy CPU
            };
            _queryWorker.RunWorkerCompleted += (sender, args) =>
            {
                if (closestIndex != -1)
                {
                    UIResults results = new UIResults();
                    Log.Message(string.Format("Last query result: {0}", Path.GetFileName(BigResultList[closestIndex].GetPathString())));
                    for (int i = 0; i < MaxResultsShown; i++)
                    {
                        int index = (closestIndex + i);
                        if (index < BigResultList.Count && index > 0)
                        {
                            string       path   = BigResultList[index].GetPathString();
                            string       file   = Path.GetFileName(path);
                            UIResultItem uiItem = new UIResultItem(true, file, path);
                            results.Add(uiItem);
                        }
                    }

                    ShowResults(results, lowerCaseQuery);
                    QueryEnd(results, query);
                }
                else
                {
                    QueryEnd(null, query);
                }
            };
            _queryWorker.RunWorkerAsync();
        }
Beispiel #5
0
        public void ShowResults(UIResults results, string query)
        {
            IOrderedEnumerable <UIResultItem> ordered = results.SortByNameRelevance(query);

            ordered = OrderResults(results, query);

            if (ordered != null)
            {
                UIResults sortedResults = new UIResults();
                int       resultCount   = 0;
                foreach (UIResultItem result in ordered)
                {
                    if (resultCount >= MaxResultsShown)
                    {
                        break;
                    }
                    sortedResults.Add(result);
                    resultCount++;
                }

                ShownResults = sortedResults;
                OnResultItemsAddedForShow(sortedResults, MainWindow.ListBoxResults);
                MainWindow.ListBoxResults.ItemsSource = sortedResults;
            }
            else
            {
                ShownResults = results;
                OnResultItemsAddedForShow(results, MainWindow.ListBoxResults);
                MainWindow.ListBoxResults.ItemsSource = results;
            }

            if (MainWindow.ListBoxResults.HasItems)
            {
                MainWindow.ListBoxResults.Visibility = Visibility.Visible;
            }

            OnResultsShown(results);
        }
Beispiel #6
0
 protected virtual void OnResultsShown(UIResults shownResults)
 {
 }
Beispiel #7
0
 protected virtual IOrderedEnumerable <UIResultItem> OrderResults(UIResults currentOrder, string query)
 {
     return(null);
 }
Beispiel #8
0
 protected void QueryEnd(UIResults results, string query)
 {
     OnQueryEnd(results, query);
 }
Beispiel #9
0
 protected override IOrderedEnumerable <UIResultItem> OrderResults(UIResults currentOrder, string query)
 {
     //IOrderedEnumerable<QueryResultItem> sortedByDiscLength = currentOrder.OrderBy(x => x.ResultDesc.Length);
     return(null);
 }