add AutoAjustScore option for results

This commit is contained in:
qianlifeng
2014-01-15 22:45:02 +08:00
parent 93d8f66afc
commit 56118a7142
15 changed files with 106 additions and 147 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WinAlfred.Plugin.System
{
public abstract class BaseSystemPlugin :ISystemPlugin
{
protected abstract List<Result> QueryInternal(Query query);
protected abstract void InitInternal(PluginInitContext context);
public List<Result> Query(Query query)
{
return QueryInternal(query);
}
public void Init(PluginInitContext context)
{
InitInternal(context);
}
public string Name
{
get
{
return "System workflow";
}
}
public string Description
{
get
{
return "System workflow";
}
}
}
}

View File

@@ -12,7 +12,7 @@ using WinAlfred.Plugin.System.Common;
namespace WinAlfred.Plugin.System
{
public class BrowserBookmarks : ISystemPlugin
public class BrowserBookmarks : BaseSystemPlugin
{
private List<Bookmark> bookmarks = new List<Bookmark>();
@@ -21,7 +21,7 @@ namespace WinAlfred.Plugin.System
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
const int CSIDL_LOCAL_APPDATA = 0x001c;
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
@@ -55,7 +55,7 @@ namespace WinAlfred.Plugin.System
return false;
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
LoadChromeBookmarks();
}
@@ -114,22 +114,6 @@ namespace WinAlfred.Plugin.System
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
return reg.Replace(dataStr, m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
}
public string Name
{
get
{
return "BrowserBookmark";
}
}
public string Description
{
get
{
return "BrowserBookmark";
}
}
}
public class Bookmark

View File

@@ -7,9 +7,9 @@ using System.Windows.Forms;
namespace WinAlfred.Plugin.System
{
public class CMD : ISystemPlugin
public class CMD : BaseSystemPlugin
{
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
List<Result> results = new List<Result>();
if (query.RawQuery.StartsWith(">") && query.RawQuery.Length > 1)
@@ -38,24 +38,9 @@ namespace WinAlfred.Plugin.System
return results;
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
}
public string Name
{
get
{
return "CMD";
}
}
public string Description
{
get
{
return "Execute shell commands.";
}
}
}
}

View File

@@ -7,14 +7,14 @@ using System.Text;
namespace WinAlfred.Plugin.System
{
public class DirectoryIndicator : ISystemPlugin
public class DirectoryIndicator : BaseSystemPlugin
{
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
List<Result> results = new List<Result>();
if (string.IsNullOrEmpty(query.RawQuery)) return results;
if (CheckIfDirectory(query.RawQuery))
if (Directory.Exists(query.RawQuery))
{
Result result = new Result
{
@@ -30,29 +30,9 @@ namespace WinAlfred.Plugin.System
return results;
}
private bool CheckIfDirectory(string path)
{
return Directory.Exists(path);
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
}
public string Name
{
get
{
return "DirectoryIndicator";
}
}
public string Description
{
get
{
return "DirectoryIndicator";
}
}
}
}

View File

@@ -19,7 +19,7 @@ namespace WinAlfred.Plugin.System
public int Score { get; set; }
}
public class Programs : ISystemPlugin
public class Programs : BaseSystemPlugin
{
private List<string> indexDirectory = new List<string>();
private List<string> indexPostfix = new List<string> { "lnk", "exe" };
@@ -32,7 +32,7 @@ namespace WinAlfred.Plugin.System
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
const int CSIDL_COMMON_PROGRAMS = 0x17;
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
@@ -66,7 +66,7 @@ namespace WinAlfred.Plugin.System
return false;
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
@@ -126,21 +126,5 @@ namespace WinAlfred.Plugin.System
string name = temp.Substring(0, temp.LastIndexOf('.'));
return name;
}
public string Name
{
get
{
return "Programs";
}
}
public string Description
{
get
{
return "get system programs";
}
}
}
}

View File

@@ -8,7 +8,7 @@ using System.Windows.Forms;
namespace WinAlfred.Plugin.System
{
public class Sys : ISystemPlugin
public class Sys : BaseSystemPlugin
{
List<Result> availableResults = new List<Result>();
@@ -23,7 +23,7 @@ namespace WinAlfred.Plugin.System
[DllImport("user32")]
public static extern void LockWorkStation();
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
@@ -39,7 +39,7 @@ namespace WinAlfred.Plugin.System
return results;
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
availableResults.Add(new Result
{
@@ -74,21 +74,5 @@ namespace WinAlfred.Plugin.System
Action = () => context.CloseApp()
});
}
public string Name
{
get
{
return "sys";
}
}
public string Description
{
get
{
return "provide system commands";
}
}
}
}

View File

@@ -5,12 +5,12 @@ using System.Text;
namespace WinAlfred.Plugin.System
{
public class ThirdpartyPluginIndicator : ISystemPlugin
public class ThirdpartyPluginIndicator : BaseSystemPlugin
{
private List<PluginPair> allPlugins = new List<PluginPair>();
private Action<string> changeQuery;
public List<Result> Query(Query query)
protected override List<Result> QueryInternal(Query query)
{
List<Result> results = new List<Result>();
if (string.IsNullOrEmpty(query.RawQuery)) return results;
@@ -27,7 +27,7 @@ namespace WinAlfred.Plugin.System
Score = 50,
IcoPath = "Images/work.png",
Action = () => changeQuery(metadataCopy.ActionKeyword + " "),
DontHideWinAlfredAfterAction = true
DontHideWinAlfredAfterSelect = true
};
results.Add(result);
}
@@ -35,27 +35,12 @@ namespace WinAlfred.Plugin.System
return results;
}
public void Init(PluginInitContext context)
protected override void InitInternal(PluginInitContext context)
{
allPlugins = context.Plugins;
changeQuery = context.ChangeQuery;
}
public string Name {
get
{
return "ThirdpartyPluginIndicator";
}
}
public string Description
{
get
{
return "ThirdpartyPluginIndicator";
}
}
}
}

View File

@@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BaseSystemPlugin.cs" />
<Compile Include="BrowserBookmarks.cs" />
<Compile Include="CMD.cs" />
<Compile Include="Common\ChineseToPinYin.cs" />