Refactoring

This commit is contained in:
qianlifeng 2015-01-19 19:14:02 +08:00
parent b49209a0d9
commit c380049b21
2 changed files with 74 additions and 46 deletions

View File

@ -4,10 +4,13 @@ using System.Windows.Documents;
namespace Wox.Plugin namespace Wox.Plugin
{ {
/// <summary>
/// Public APIs that plugin can use
/// </summary>
public interface IPublicAPI public interface IPublicAPI
{ {
/// <summary> /// <summary>
/// Push result to query window /// Push result to query box
/// </summary> /// </summary>
/// <param name="query"></param> /// <param name="query"></param>
/// <param name="plugin"></param> /// <param name="plugin"></param>
@ -15,43 +18,106 @@ namespace Wox.Plugin
/// <param name="clearBeforeInsert"></param> /// <param name="clearBeforeInsert"></param>
void PushResults(Query query,PluginMetadata plugin, List<Result> results,bool clearBeforeInsert = false); void PushResults(Query query,PluginMetadata plugin, List<Result> results,bool clearBeforeInsert = false);
/// <summary>
/// Execute command
/// a replacement to RUN(win+r) function
/// </summary>
/// <param name="cmd">command that want to execute</param>
/// <param name="runAsAdministrator">run as administrator</param>
/// <returns></returns>
bool ShellRun(string cmd, bool runAsAdministrator = false); bool ShellRun(string cmd, bool runAsAdministrator = false);
/// <summary>
/// Change Wox query
/// </summary>
/// <param name="query">query text</param>
/// <param name="requery">
/// force requery By default, Wox will not fire query if your query is same with existing one.
/// Set this to true to force Wox requerying
/// </param>
void ChangeQuery(string query, bool requery = false); void ChangeQuery(string query, bool requery = false);
/// <summary>
/// Close Wox
/// </summary>
void CloseApp(); void CloseApp();
/// <summary>
/// Hide Wox
/// </summary>
void HideApp(); void HideApp();
/// <summary>
/// Show Wox
/// </summary>
void ShowApp(); void ShowApp();
/// <summary>
/// Show message box
/// </summary>
/// <param name="title">Message title</param>
/// <param name="subTitle">Message subtitle</param>
/// <param name="iconPath">Message icon path (relative path to your plugin folder)</param>
void ShowMsg(string title, string subTitle, string iconPath); void ShowMsg(string title, string subTitle, string iconPath);
/// <summary>
/// Open setting dialog
/// </summary>
void OpenSettingDialog(); void OpenSettingDialog();
/// <summary>
/// Show loading animation
/// </summary>
void StartLoadingBar(); void StartLoadingBar();
/// <summary>
/// Stop loading animation
/// </summary>
void StopLoadingBar(); void StopLoadingBar();
/// <summary>
/// Install Wox plugin
/// </summary>
/// <param name="path">Plugin path (ends with .wox)</param>
void InstallPlugin(string path); void InstallPlugin(string path);
/// <summary>
/// Reload all plugins
/// </summary>
void ReloadPlugins(); void ReloadPlugins();
/// <summary>
/// Get translation of current language
/// You need to implement IPluginI18n if you want to support multiple languages for your plugin
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
string GetTranslation(string key); string GetTranslation(string key);
/// <summary>
/// Get all loaded plugins
/// </summary>
/// <returns></returns>
List<PluginPair> GetAllPlugins(); List<PluginPair> GetAllPlugins();
/// <summary>
/// Fired after Back key down in the Wox query box
/// </summary>
event WoxKeyDownEventHandler BackKeyDownEvent; event WoxKeyDownEventHandler BackKeyDownEvent;
/// <summary>
/// Fired after global keyboard events
/// if you want to hook something like Ctrl+R, you should use this event
/// </summary>
event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent; event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
/// <summary> /// <summary>
/// fired after wox execute a query /// Fired after wox execute a query
/// </summary> /// </summary>
event AfterWoxQueryEventHandler AfterWoxQueryEvent; event AfterWoxQueryEventHandler AfterWoxQueryEvent;
/// <summary> /// <summary>
/// fired before wox start to execute a query /// Fired before wox start to execute a query
/// </summary> /// </summary>
event AfterWoxQueryEventHandler BeforeWoxQueryEvent; event AfterWoxQueryEventHandler BeforeWoxQueryEvent;
} }

View File

@ -364,7 +364,6 @@ namespace Wox
var q = new Query(lastQuery); var q = new Query(lastQuery);
FireBeforeWoxQueryEvent(q); FireBeforeWoxQueryEvent(q);
Query(q); Query(q);
BackToResultMode();
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{ {
if (!queryHasReturn && originQuery == lastQuery) if (!queryHasReturn && originQuery == lastQuery)
@ -373,7 +372,7 @@ namespace Wox
} }
}, TimeSpan.FromMilliseconds(150), lastQuery); }, TimeSpan.FromMilliseconds(150), lastQuery);
FireAfterWoxQueryEvent(q); FireAfterWoxQueryEvent(q);
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 200)); }, TimeSpan.FromMilliseconds(200));
} }
private void FireAfterWoxQueryEvent(Query q) private void FireAfterWoxQueryEvent(Query q)
@ -410,15 +409,9 @@ namespace Wox
private void Query(Query q) private void Query(Query q)
{ {
try PluginManager.Query(q);
{ StopProgress();
PluginManager.Query(q); BackToResultMode();
}
catch (Exception e)
{
StopProgress();
ErrorReporting.Report(e);
}
} }
private void BackToResultMode() private void BackToResultMode()
@ -427,22 +420,6 @@ namespace Wox
pnlContextMenu.Visibility = Visibility.Collapsed; pnlContextMenu.Visibility = Visibility.Collapsed;
} }
private bool ShouldNotDelayQuery
{
get
{
return IsCMDMode || IsWebSearchMode;
}
}
private bool IsCMDMode
{
get
{
return tbQuery.Text.StartsWith(">");
}
}
private bool IsWebSearchMode private bool IsWebSearchMode
{ {
get get
@ -500,17 +477,6 @@ namespace Wox
} }
} }
private void updateCmdMode()
{
var currentSelectedItem = pnlResult.GetActiveResult();
if (currentSelectedItem != null)
{
ignoreTextChange = true;
tbQuery.Text = ">" + currentSelectedItem.Title;
tbQuery.CaretIndex = tbQuery.Text.Length;
}
}
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
{ {
//when alt is pressed, the real key should be e.SystemKey //when alt is pressed, the real key should be e.SystemKey
@ -553,14 +519,12 @@ namespace Wox
case Key.PageDown: case Key.PageDown:
pnlResult.SelectNextPage(); pnlResult.SelectNextPage();
if (IsCMDMode) updateCmdMode();
toolTip.IsOpen = false; toolTip.IsOpen = false;
e.Handled = true; e.Handled = true;
break; break;
case Key.PageUp: case Key.PageUp:
pnlResult.SelectPrevPage(); pnlResult.SelectPrevPage();
if (IsCMDMode) updateCmdMode();
toolTip.IsOpen = false; toolTip.IsOpen = false;
e.Handled = true; e.Handled = true;
break; break;
@ -621,7 +585,6 @@ namespace Wox
else else
{ {
pnlResult.SelectPrev(); pnlResult.SelectPrev();
if (IsCMDMode) updateCmdMode();
} }
toolTip.IsOpen = false; toolTip.IsOpen = false;
} }
@ -635,7 +598,6 @@ namespace Wox
else else
{ {
pnlResult.SelectNext(); pnlResult.SelectNext();
if (IsCMDMode) updateCmdMode();
} }
toolTip.IsOpen = false; toolTip.IsOpen = false;
} }