Add PushResults for push results before Query results return

This commit is contained in:
Yeechan Lu
2014-03-27 14:50:42 +08:00
parent 9bc4b74888
commit ac81d38acc
6 changed files with 33 additions and 19 deletions

View File

@@ -31,8 +31,7 @@ namespace Wox.Plugin.System.CMD
results.AddRange(history); results.AddRange(history);
} }
else
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
{ {
string cmd = query.RawQuery.Substring(1); string cmd = query.RawQuery.Substring(1);
Result result = new Result Result result = new Result
@@ -57,7 +56,7 @@ namespace Wox.Plugin.System.CMD
} }
catch (Exception) { } catch (Exception) { }
results.Add(result); context.PushResults(new List<Result>() { result });
IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd)) IEnumerable<Result> history = CMDStorage.Instance.CMDHistory.Where(o => o.Key.Contains(cmd))
.OrderByDescending(o => o.Value) .OrderByDescending(o => o.Value)
@@ -92,7 +91,8 @@ namespace Wox.Plugin.System.CMD
return ret; return ret;
}).Where(o => o != null).Take(4); }).Where(o => o != null).Take(4);
results.AddRange(history); context.PushResults(history.ToList());
try try
{ {
string basedir = null; string basedir = null;

View File

@@ -31,5 +31,7 @@ namespace Wox.Plugin
public Action StopLoadingBar { get; set; } public Action StopLoadingBar { get; set; }
public Func<string, bool> ShellRun { get; set; } public Func<string, bool> ShellRun { get; set; }
public Action<List<Result>> PushResults { get; set; }
} }
} }

View File

@@ -9,5 +9,6 @@ namespace Wox.Plugin
{ {
public IPlugin Plugin { get; set; } public IPlugin Plugin { get; set; }
public PluginMetadata Metadata { get; set; } public PluginMetadata Metadata { get; set; }
public PluginInitContext InitContext { get; set; }
} }
} }

View File

@@ -27,13 +27,17 @@ namespace Wox.Commands
{ {
try try
{ {
List<Result> r = thirdPlugin.Plugin.Query(q) ?? new List<Result>(); thirdPlugin.InitContext.PushResults = r =>
r.ForEach(o =>
{ {
o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry; r.ForEach(o =>
o.OriginQuery = q; {
}); o.PluginDirectory = thirdPlugin.Metadata.PluginDirecotry;
UpdateResultView(r); o.OriginQuery = q;
});
UpdateResultView(r);
};
List<Result> results = thirdPlugin.Plugin.Query(q) ?? new List<Result>();
thirdPlugin.InitContext.PushResults(results);
} }
catch (Exception queryException) catch (Exception queryException)
{ {

View File

@@ -17,14 +17,20 @@ namespace Wox.Commands
PluginPair pair1 = pair; PluginPair pair1 = pair;
ThreadPool.QueueUserWorkItem(state => ThreadPool.QueueUserWorkItem(state =>
{ {
List<Result> results = pair1.Plugin.Query(query); pair1.InitContext.PushResults = r =>
foreach (Result result in results)
{ {
result.PluginDirectory = pair1.Metadata.PluginDirecotry; if (r == null || r.Count == 0) return;
result.OriginQuery = query; foreach (Result result in r)
result.AutoAjustScore = true; {
} result.PluginDirectory = pair1.Metadata.PluginDirecotry;
if(results.Count > 0) UpdateResultView(results); result.OriginQuery = query;
result.AutoAjustScore = true;
}
UpdateResultView(r);
};
List<Result> results = pair1.Plugin.Query(query);
pair1.InitContext.PushResults(results);
}); });
} }
} }

View File

@@ -40,7 +40,7 @@ namespace Wox.PluginLoader
if (pluginPair != null) if (pluginPair != null)
{ {
PluginMetadata metadata = pluginPair.Metadata; PluginMetadata metadata = pluginPair.Metadata;
forker.Fork(() => plugin1.Init(new PluginInitContext() pluginPair.InitContext = new PluginInitContext()
{ {
Plugins = plugins, Plugins = plugins,
CurrentPluginMetadata = metadata, CurrentPluginMetadata = metadata,
@@ -60,7 +60,8 @@ namespace Wox.PluginLoader
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())), StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())), StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func<bool>(() => App.Window.ShellRun(cmd))), ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func<bool>(() => App.Window.ShellRun(cmd))),
})); };
forker.Fork(() => plugin1.Init(pluginPair.InitContext));
} }
} }