protected override List<Result> DoQuery(Query query) { if (query.QueryText.Trim().Length <= 1) return new List<Result>(); if (!CheckExpressionValid(query.QueryText)) return new List<Result>(); ex = new ExpressionHelper() { expre = query.QueryText, }; ex.startCalculate(); double answer = ex.result; if (answer == -99999999) return new List<Result>(); Result result = new Result() { Title = answer.ToString(), SubTitle = query.QueryText, IconPath = "%windir%/system32/calc.exe", Score = 1000, Action = () => { Context.InvokeMethodInMainWindow("HideApp", null); Context.InvokeMethodInMainWindow("ShellRun", new object[] { "%windir%/system32/calc.exe", false }); return true; } }; return new List<Result>() { result }; }
public static void Dispatch(Query query) { foreach (Component component in allComponents) { Component tempComponent = component; ThreadPool.QueueUserWorkItem(state => { List<Result> results = tempComponent.Query(query); App.Current.Dispatcher.Invoke(new Action(() => { (App.Current.MainWindow as MainWindow).PushResult(results); })); }); } }
protected override List<Result> DoQuery(Query query) { if (query.QueryText.Trim().Length <= 1) return new List<Result>(); FuzzyMatcher fuzzyMatcher = FuzzyMatcher.Create(query.QueryText); List<Program> results = programs.Where(o => MatchProgram(o, fuzzyMatcher)).ToList(); // 筛选出匹配的程序 results = results.OrderByDescending(o => o.Score).ToList(); // 按分数排序 return results.Select(o => new Result() { Title = o.Title, SubTitle = o.ExecutePath, IconPath = o.IcoPath, Score = o.Score, Action = () => { Context.InvokeMethodInMainWindow("HideApp", null); Context.InvokeMethodInMainWindow("ShellRun", new object[] { o.ExecutePath, false }); return true; } }).ToList(); }
private void InputTextBox_OnTextChanged(object sender, TextChangedEventArgs e) { lastQuery = inputTextBox.Text; toolTip.IsOpen = false; resultListBox.Dirty = true; Dispatcher.DelayInvoke("UpdateSearch", o => { Dispatcher.DelayInvoke("ClearResults", i => { // first try to use clear method inside pnlResult, which is more closer to the add new results // and this will not bring splash issues.After waiting 30ms, if there still no results added, we // must clear the result. otherwise, it will be confused why the query changed, but the results // didn't. if (resultListBox.Dirty) resultListBox.Clear(); }, TimeSpan.FromMilliseconds(100), null); queryHasReturn = false; var q = new Query(lastQuery); CommandDispatcher.Dispatch(q); if (Components.MatchComponentActionName(q)) { Console.WriteLine("Match Component Action Name '{0}'", q); } }, TimeSpan.FromMilliseconds(150)); }