diff --git a/Plugins/WinAlfred.Plugin.Fanyi/Main.cs b/Plugins/WinAlfred.Plugin.Fanyi/Main.cs
index cdbbc41677..986a9176ab 100644
--- a/Plugins/WinAlfred.Plugin.Fanyi/Main.cs
+++ b/Plugins/WinAlfred.Plugin.Fanyi/Main.cs
@@ -31,7 +31,7 @@ namespace WinAlfred.Plugin.Fanyi
private string translateURL = "http://openapi.baidu.com/public/2.0/bmt/translate";
private string baiduKey = "SnPcDY3iH5jDbklRewkG2D2v";
- static public string AssemblyDirectory
+ private static string AssemblyDirectory
{
get
{
@@ -89,23 +89,6 @@ namespace WinAlfred.Plugin.Fanyi
return results;
}
- public static string GetHtmlStr(string url)
- {
- try
- {
- WebRequest rGet = WebRequest.Create(url);
- WebResponse rSet = rGet.GetResponse();
- Stream s = rSet.GetResponseStream();
- StreamReader reader = new StreamReader(s, Encoding.UTF8);
- return reader.ReadToEnd();
- }
- catch (WebException)
- {
- //连接失败
- return null;
- }
- }
-
public void Init(PluginInitContext context)
{
this.context = context;
diff --git a/README.md b/README.md
index 509ce85cde..eb7809a29a 100644
--- a/README.md
+++ b/README.md
@@ -22,3 +22,8 @@ Create workflow
=========
Currently, WinAlfred support using C# and Python to write your workflows. Please refer to [Create-workflows](https://github.com/qianlifeng/WinAlfred/wiki/Create-workflows) page for more infomation.
+
+Share workflow
+=========
+
+Share your workflows through WinAlfredWorkflows. After you upload your workflow, other uses can download or search your workflow through `wf` command (this is a workflow for workflow management , which is one of the default workflows inside winalfred).
diff --git a/WinAlfred.Plugin.System/BaseSystemPlugin.cs b/WinAlfred.Plugin.System/BaseSystemPlugin.cs
new file mode 100644
index 0000000000..997261ca24
--- /dev/null
+++ b/WinAlfred.Plugin.System/BaseSystemPlugin.cs
@@ -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 QueryInternal(Query query);
+ protected abstract void InitInternal(PluginInitContext context);
+
+ public List 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";
+ }
+ }
+ }
+}
diff --git a/WinAlfred.Plugin.System/BrowserBookmarks.cs b/WinAlfred.Plugin.System/BrowserBookmarks.cs
index d7c86eeba4..1b288a7c65 100644
--- a/WinAlfred.Plugin.System/BrowserBookmarks.cs
+++ b/WinAlfred.Plugin.System/BrowserBookmarks.cs
@@ -12,7 +12,7 @@ using WinAlfred.Plugin.System.Common;
namespace WinAlfred.Plugin.System
{
- public class BrowserBookmarks : ISystemPlugin
+ public class BrowserBookmarks : BaseSystemPlugin
{
private List bookmarks = new List();
@@ -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 Query(Query query)
+ protected override List QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List();
@@ -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
diff --git a/WinAlfred.Plugin.System/CMD.cs b/WinAlfred.Plugin.System/CMD.cs
index fd16369cf1..659b9ed2e4 100644
--- a/WinAlfred.Plugin.System/CMD.cs
+++ b/WinAlfred.Plugin.System/CMD.cs
@@ -7,9 +7,9 @@ using System.Windows.Forms;
namespace WinAlfred.Plugin.System
{
- public class CMD : ISystemPlugin
+ public class CMD : BaseSystemPlugin
{
- public List Query(Query query)
+ protected override List QueryInternal(Query query)
{
List results = new List();
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.";
- }
- }
}
}
diff --git a/WinAlfred.Plugin.System/DirectoryIndicator.cs b/WinAlfred.Plugin.System/DirectoryIndicator.cs
index 79e4ae3f03..6b051980f2 100644
--- a/WinAlfred.Plugin.System/DirectoryIndicator.cs
+++ b/WinAlfred.Plugin.System/DirectoryIndicator.cs
@@ -7,14 +7,14 @@ using System.Text;
namespace WinAlfred.Plugin.System
{
- public class DirectoryIndicator : ISystemPlugin
+ public class DirectoryIndicator : BaseSystemPlugin
{
- public List Query(Query query)
+ protected override List QueryInternal(Query query)
{
List results = new List();
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";
- }
- }
}
}
diff --git a/WinAlfred.Plugin.System/Programs.cs b/WinAlfred.Plugin.System/Programs.cs
index 2b837b2dbf..9b45f9f115 100644
--- a/WinAlfred.Plugin.System/Programs.cs
+++ b/WinAlfred.Plugin.System/Programs.cs
@@ -19,7 +19,7 @@ namespace WinAlfred.Plugin.System
public int Score { get; set; }
}
- public class Programs : ISystemPlugin
+ public class Programs : BaseSystemPlugin
{
private List indexDirectory = new List();
private List indexPostfix = new List { "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 Query(Query query)
+ protected override List QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List();
@@ -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";
- }
- }
}
}
\ No newline at end of file
diff --git a/WinAlfred.Plugin.System/Sys.cs b/WinAlfred.Plugin.System/Sys.cs
index 69db348fe5..6b3b6fd2d0 100644
--- a/WinAlfred.Plugin.System/Sys.cs
+++ b/WinAlfred.Plugin.System/Sys.cs
@@ -8,7 +8,7 @@ using System.Windows.Forms;
namespace WinAlfred.Plugin.System
{
- public class Sys : ISystemPlugin
+ public class Sys : BaseSystemPlugin
{
List availableResults = new List();
@@ -23,7 +23,7 @@ namespace WinAlfred.Plugin.System
[DllImport("user32")]
public static extern void LockWorkStation();
- public List Query(Query query)
+ protected override List QueryInternal(Query query)
{
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List();
@@ -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";
- }
- }
}
}
diff --git a/WinAlfred.Plugin.System/ThirdpartyPluginIndicator.cs b/WinAlfred.Plugin.System/ThirdpartyPluginIndicator.cs
index ca10dfa486..a5a8712a32 100644
--- a/WinAlfred.Plugin.System/ThirdpartyPluginIndicator.cs
+++ b/WinAlfred.Plugin.System/ThirdpartyPluginIndicator.cs
@@ -5,12 +5,12 @@ using System.Text;
namespace WinAlfred.Plugin.System
{
- public class ThirdpartyPluginIndicator : ISystemPlugin
+ public class ThirdpartyPluginIndicator : BaseSystemPlugin
{
private List allPlugins = new List();
private Action changeQuery;
- public List Query(Query query)
+ protected override List QueryInternal(Query query)
{
List results = new List();
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";
- }
- }
-
}
}
diff --git a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
index 9119d543e2..14b1c7ec18 100644
--- a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
+++ b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj
@@ -44,6 +44,7 @@
+
diff --git a/WinAlfred.Plugin/PluginInitContext.cs b/WinAlfred.Plugin/PluginInitContext.cs
index 70025c2584..81d049961b 100644
--- a/WinAlfred.Plugin/PluginInitContext.cs
+++ b/WinAlfred.Plugin/PluginInitContext.cs
@@ -14,5 +14,7 @@ namespace WinAlfred.Plugin
public Action HideApp { get; set; }
public Action ShowApp { get; set; }
public Action ShowMsg { get; set; }
+
+
}
}
diff --git a/WinAlfred.Plugin/Result.cs b/WinAlfred.Plugin/Result.cs
index 784670c7c6..b1de820e1c 100644
--- a/WinAlfred.Plugin/Result.cs
+++ b/WinAlfred.Plugin/Result.cs
@@ -12,7 +12,12 @@ namespace WinAlfred.Plugin
public Action Action { get; set; }
public int Score { get; set; }
- public bool DontHideWinAlfredAfterAction { get; set; }
+ public bool DontHideWinAlfredAfterSelect { get; set; }
+
+ ///
+ /// Auto add scores for MRU items
+ ///
+ public bool AutoAjustScore { get; set; }
//todo: this should be controlled by system, not visible to users
///
diff --git a/WinAlfred/Commands/SystemCommand.cs b/WinAlfred/Commands/SystemCommand.cs
index f1e43e2acf..cec28c54d2 100644
--- a/WinAlfred/Commands/SystemCommand.cs
+++ b/WinAlfred/Commands/SystemCommand.cs
@@ -30,6 +30,7 @@ namespace WinAlfred.Commands
{
result.PluginDirectory = pair1.Metadata.PluginDirecotry;
result.OriginQuery = query;
+ result.AutoAjustScore = true;
}
if(results.Count > 0 && updateView) UpdateResultView(results);
});
diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs
index 83f2dc7365..2abe99c93e 100644
--- a/WinAlfred/MainWindow.xaml.cs
+++ b/WinAlfred/MainWindow.xaml.cs
@@ -231,7 +231,7 @@ namespace WinAlfred
if (result != null)
{
selectedRecords.AddSelect(result);
- if (!result.DontHideWinAlfredAfterAction)
+ if (!result.DontHideWinAlfredAfterSelect)
{
HideWinAlfred();
}
@@ -247,13 +247,14 @@ namespace WinAlfred
progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list.Count > 0)
{
+ //todo:this used be opened to users, it's they choise use it or not in thier workflows
list.ForEach(o =>
{
- o.Score += selectedRecords.GetSelectedCount(o);
+ if(o.AutoAjustScore) o.Score += selectedRecords.GetSelectedCount(o);
});
resultCtrl.Dispatcher.Invoke(new Action(() =>
{
- List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
+ List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList();
resultCtrl.AddResults(l);
}));
}
diff --git a/WinAlfred/PluginLoader/CSharpPluginLoader.cs b/WinAlfred/PluginLoader/CSharpPluginLoader.cs
index 836442e593..7fdd379f4b 100644
--- a/WinAlfred/PluginLoader/CSharpPluginLoader.cs
+++ b/WinAlfred/PluginLoader/CSharpPluginLoader.cs
@@ -20,9 +20,8 @@ namespace WinAlfred.PluginLoader
{
try
{
- byte[] buffer = System.IO.File.ReadAllBytes(metadata.ExecuteFilePath);
- Assembly asm = Assembly.Load(buffer);
- List types = asm.GetTypes().Where(o => o.IsClass && o.GetInterfaces().Contains(typeof(IPlugin)) || o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
+ Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
+ List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
if (types.Count == 0)
{
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
@@ -58,7 +57,7 @@ namespace WinAlfred.PluginLoader
private void InitPlugin(List plugins)
{
-
+
}
}
}
diff --git a/WinAlfred/PluginLoader/PythonPluginWrapper.cs b/WinAlfred/PluginLoader/PythonPluginWrapper.cs
index 1ecba68c8c..a2c13ff23e 100644
--- a/WinAlfred/PluginLoader/PythonPluginWrapper.cs
+++ b/WinAlfred/PluginLoader/PythonPluginWrapper.cs
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Documents;
using Newtonsoft.Json;
using Python.Runtime;
+using WinAlfred.Helper;
using WinAlfred.Plugin;
namespace WinAlfred.PluginLoader
@@ -12,17 +15,19 @@ namespace WinAlfred.PluginLoader
{
private PluginMetadata metadata;
+ private string moduleName;
public PythonPluginWrapper(PluginMetadata metadata)
{
this.metadata = metadata;
+ moduleName = metadata.ExecuteFileName.Replace(".py", "");
}
public List Query(Query query)
{
try
{
- string jsonResult = InvokeFunc(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), "query", query.RawQuery);
+ string jsonResult = InvokeFunc("query", query.RawQuery);
if (string.IsNullOrEmpty(jsonResult))
{
return new List();
@@ -35,7 +40,7 @@ namespace WinAlfred.PluginLoader
PythonResult ps = pythonResult;
if (!string.IsNullOrEmpty(ps.ActionName))
{
- ps.Action = () => InvokeFunc(metadata.PluginDirecotry, metadata.ExecuteFileName.Replace(".py", ""), ps.ActionName, ps.ActionPara);
+ ps.Action = () => InvokeFunc(ps.ActionName, ps.ActionPara);
}
r.Add(ps);
}
@@ -49,16 +54,37 @@ namespace WinAlfred.PluginLoader
}
#endif
}
-
}
- private string InvokeFunc(string path, string moduleName, string func, string para)
+ private string InvokeFunc(string func, params string[] para)
{
+ string json;
+
+ PyObject[] paras = { };
+ if (para != null && para.Length > 0)
+ {
+ paras = para.Select(o => new PyString(o)).ToArray();
+ }
+
IntPtr gs = PythonEngine.AcquireLock();
PyObject module = PythonEngine.ImportModule(moduleName);
- PyObject res = module.InvokeMethod(func, new PyString(para));
- string json = Runtime.GetManagedString(res.Handle);
+ if (module.HasAttr(func))
+ {
+ PyObject res = paras.Length > 0 ? module.InvokeMethod(func, paras) : module.InvokeMethod(func);
+ json = Runtime.GetManagedString(res.Handle);
+ }
+ else
+ {
+ string error = string.Format("Python Invoke failed: {0} doesn't has function {1}",
+ metadata.ExecuteFilePath, func);
+ Log.Error(error);
+#if (DEBUG)
+ {
+ throw new ArgumentException(error);
+ }
+#endif
+ }
PythonEngine.ReleaseLock(gs);
diff --git a/WinAlfred/ResultPanel.xaml.cs b/WinAlfred/ResultPanel.xaml.cs
index 26aa8f9598..0551a09425 100644
--- a/WinAlfred/ResultPanel.xaml.cs
+++ b/WinAlfred/ResultPanel.xaml.cs
@@ -74,7 +74,14 @@ namespace WinAlfred
{
if ((currentScore >= next.Result.Score && currentScore <= prev.Result.Score))
{
- location = index;
+ if (currentScore == next.Result.Score)
+ {
+ location = index + 1;
+ }
+ else
+ {
+ location = index;
+ }
}
}
}