diff --git a/Plugins/Wox.Plugin.Everything/Main.cs b/Plugins/Wox.Plugin.Everything/Main.cs
index c29b3a530c..dc8abe93ab 100644
--- a/Plugins/Wox.Plugin.Everything/Main.cs
+++ b/Plugins/Wox.Plugin.Everything/Main.cs
@@ -30,17 +30,7 @@ namespace Wox.Plugin.Everything
r.Action = (c) =>
{
context.HideApp();
- System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
- info.UseShellExecute = true;
- info.FileName = path;
- try
- {
- System.Diagnostics.Process.Start(info);
- }
- catch (Exception ex)
- {
- context.ShowMsg("Could not start " + r.Title, ex.Message, null);
- }
+ context.ShellRun(path);
return true;
};
results.Add(r);
diff --git a/Wox.Plugin.System/WindowsShellRun.cs b/Wox.Infrastructure/WindowsShellRun.cs
similarity index 99%
rename from Wox.Plugin.System/WindowsShellRun.cs
rename to Wox.Infrastructure/WindowsShellRun.cs
index fbdaa6a504..6dd21f43a6 100644
--- a/Wox.Plugin.System/WindowsShellRun.cs
+++ b/Wox.Infrastructure/WindowsShellRun.cs
@@ -5,7 +5,7 @@ using System.Text;
using System.Runtime.InteropServices;
using System.IO;
-namespace Wox.Plugin.System
+namespace Wox.Infrastructure
{
/*
* http://undoc.airesoft.co.uk/shell32.dll/ShellExecCmdLine.php
@@ -205,7 +205,7 @@ namespace Wox.Plugin.System
// there might be args in that command
args = PathGetArgs(cmd);
if (args != null)
- cmd = cmd.Substring(0, cmd.Length - args.Length);
+ cmd = cmd.Substring(0, cmd.Length - args.Length).Trim();
}
else
args = null;
diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj
index 4aab17fbe5..a807ea39a8 100644
--- a/Wox.Infrastructure/Wox.Infrastructure.csproj
+++ b/Wox.Infrastructure/Wox.Infrastructure.csproj
@@ -60,6 +60,7 @@
+
diff --git a/Wox.Plugin.System/BrowserBookmarks.cs b/Wox.Plugin.System/BrowserBookmarks.cs
index 42be68a777..32965762db 100644
--- a/Wox.Plugin.System/BrowserBookmarks.cs
+++ b/Wox.Plugin.System/BrowserBookmarks.cs
@@ -14,7 +14,7 @@ namespace Wox.Plugin.System
{
public class BrowserBookmarks : BaseSystemPlugin
{
-
+ private PluginInitContext context;
private List bookmarks = new List();
protected override List QueryInternal(Query query)
@@ -29,16 +29,10 @@ namespace Wox.Plugin.System
SubTitle = "Bookmark: " + c.Url,
IcoPath = Directory.GetCurrentDirectory() + @"\Images\bookmark.png",
Score = 5,
- Action = (context) =>
+ Action = (e) =>
{
- try
- {
- Process.Start(c.Url);
- }
- catch (Exception)
- {
- MessageBox.Show("open url failed:" + c.Url);
- }
+ context.HideApp();
+ context.ShellRun(c.Url);
return true;
}
}).ToList();
@@ -57,6 +51,7 @@ namespace Wox.Plugin.System
LoadChromeBookmarks();
bookmarks = bookmarks.Distinct().ToList();
+ this.context = context;
}
private void ParseChromeBookmarks(String path, string source)
diff --git a/Wox.Plugin.System/CMD.cs b/Wox.Plugin.System/CMD.cs
index 7142ada54f..d8c7b6ff34 100644
--- a/Wox.Plugin.System/CMD.cs
+++ b/Wox.Plugin.System/CMD.cs
@@ -137,15 +137,8 @@ namespace Wox.Plugin.System
private void ExecuteCmd(string cmd)
{
- try
- {
- WindowsShellRun.Start(cmd);
+ if (context.ShellRun(cmd))
AddCmdHistory(cmd);
- }
- catch (Exception e)
- {
- MessageBox.Show("Wox cound't execute this command. \n\n" + e.Message);
- }
}
protected override void InitInternal(PluginInitContext context)
diff --git a/Wox.Plugin.System/AppPathsProgramSource.cs b/Wox.Plugin.System/ProgramSources/AppPathsProgramSource.cs
similarity index 97%
rename from Wox.Plugin.System/AppPathsProgramSource.cs
rename to Wox.Plugin.System/ProgramSources/AppPathsProgramSource.cs
index 6b645c9720..96f66c860b 100644
--- a/Wox.Plugin.System/AppPathsProgramSource.cs
+++ b/Wox.Plugin.System/ProgramSources/AppPathsProgramSource.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace Wox.Plugin.System
+namespace Wox.Plugin.System.ProgramSources
{
[global::System.ComponentModel.Browsable(false)]
public class AppPathsProgramSource: AbstractProgramSource
diff --git a/Wox.Plugin.System/CommonStartMenuProgramSource.cs b/Wox.Plugin.System/ProgramSources/CommonStartMenuProgramSource.cs
similarity index 96%
rename from Wox.Plugin.System/CommonStartMenuProgramSource.cs
rename to Wox.Plugin.System/ProgramSources/CommonStartMenuProgramSource.cs
index 37169e008c..c0e8ca4dab 100644
--- a/Wox.Plugin.System/CommonStartMenuProgramSource.cs
+++ b/Wox.Plugin.System/ProgramSources/CommonStartMenuProgramSource.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
-namespace Wox.Plugin.System
+namespace Wox.Plugin.System.ProgramSources
{
[global::System.ComponentModel.Browsable(false)]
public class CommonStartMenuProgramSource : FileSystemProgramSource
diff --git a/Wox.Plugin.System/FileSystemProgramSource.cs b/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs
similarity index 97%
rename from Wox.Plugin.System/FileSystemProgramSource.cs
rename to Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs
index 5f3a142f4b..57440ed1f2 100644
--- a/Wox.Plugin.System/FileSystemProgramSource.cs
+++ b/Wox.Plugin.System/ProgramSources/FileSystemProgramSource.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.IO;
-namespace Wox.Plugin.System
+namespace Wox.Plugin.System.ProgramSources
{
public class FileSystemProgramSource : AbstractProgramSource
{
diff --git a/Wox.Plugin.System/PortableAppsProgramSource.cs b/Wox.Plugin.System/ProgramSources/PortableAppsProgramSource.cs
similarity index 99%
rename from Wox.Plugin.System/PortableAppsProgramSource.cs
rename to Wox.Plugin.System/ProgramSources/PortableAppsProgramSource.cs
index a2600116c3..41a6d7ce92 100644
--- a/Wox.Plugin.System/PortableAppsProgramSource.cs
+++ b/Wox.Plugin.System/ProgramSources/PortableAppsProgramSource.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.IO;
using IniParser;
-namespace Wox.Plugin.System
+namespace Wox.Plugin.System.ProgramSources
{
public class PortableAppsProgramSource : AbstractProgramSource
{
diff --git a/Wox.Plugin.System/UserStartMenuProgramSource.cs b/Wox.Plugin.System/ProgramSources/UserStartMenuProgramSource.cs
similarity index 94%
rename from Wox.Plugin.System/UserStartMenuProgramSource.cs
rename to Wox.Plugin.System/ProgramSources/UserStartMenuProgramSource.cs
index bdb902d569..e4976797e7 100644
--- a/Wox.Plugin.System/UserStartMenuProgramSource.cs
+++ b/Wox.Plugin.System/ProgramSources/UserStartMenuProgramSource.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace Wox.Plugin.System
+namespace Wox.Plugin.System.ProgramSources
{
[global::System.ComponentModel.Browsable(false)]
public class UserStartMenuProgramSource : FileSystemProgramSource
diff --git a/Wox.Plugin.System/Programs.cs b/Wox.Plugin.System/Programs.cs
index 5d05bff18e..9d61401325 100644
--- a/Wox.Plugin.System/Programs.cs
+++ b/Wox.Plugin.System/Programs.cs
@@ -9,6 +9,7 @@ using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using Wox.Infrastructure;
+using Wox.Plugin.System.ProgramSources;
namespace Wox.Plugin.System
{
@@ -45,12 +46,13 @@ namespace Wox.Plugin.System
List installedList = new List();
List sources = new List();
public static Dictionary SourceTypes = new Dictionary() {
+ {"FileSystemProgramSource", typeof(FileSystemProgramSource)},
+ {"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
{"AppPathsProgramSource", typeof(AppPathsProgramSource)},
- {"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
- {"FileSystemProgramSource", typeof(FileSystemProgramSource)},
};
+ private PluginInitContext context;
protected override List QueryInternal(Query query)
{
@@ -69,28 +71,10 @@ namespace Wox.Plugin.System
SubTitle = c.ExecutePath,
IcoPath = c.IcoPath,
Score = 0,
- Action = (context) =>
+ Action = (e) =>
{
- if (string.IsNullOrEmpty(c.ExecutePath))
- {
- MessageBox.Show("couldn't start" + c.Title);
- }
- else
- {
- try
- {
- Process.Start(c.ExecutePath);
- }
- catch (Win32Exception)
- {
- //Do nothing.
- //It may be caused if UAC blocks the program.
- }
- catch (Exception e)
- {
- throw e;
- }
- }
+ context.HideApp();
+ context.ShellRun(c.ExecutePath);
return true;
}
}).ToList();
@@ -108,6 +92,8 @@ namespace Wox.Plugin.System
protected override void InitInternal(PluginInitContext context)
{
+ this.context = context;
+
if (CommonStorage.Instance.UserSetting.ProgramSources == null)
CommonStorage.Instance.UserSetting.ProgramSources = CommonStorage.Instance.UserSetting.LoadDefaultProgramSources();
diff --git a/Wox.Plugin.System/Wox.Plugin.System.csproj b/Wox.Plugin.System/Wox.Plugin.System.csproj
index d6984b650e..34611c97bd 100644
--- a/Wox.Plugin.System/Wox.Plugin.System.csproj
+++ b/Wox.Plugin.System/Wox.Plugin.System.csproj
@@ -51,17 +51,16 @@
-
-
-
+
+
+
-
-
+
+
-
diff --git a/Wox.Plugin/PluginInitContext.cs b/Wox.Plugin/PluginInitContext.cs
index fae6d758d9..a29448ba35 100644
--- a/Wox.Plugin/PluginInitContext.cs
+++ b/Wox.Plugin/PluginInitContext.cs
@@ -29,5 +29,7 @@ namespace Wox.Plugin
public Action StartLoadingBar { get; set; }
public Action StopLoadingBar { get; set; }
+
+ public Func ShellRun { get; set; }
}
}
diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs
index 3eb3e35561..c11ebf1a44 100644
--- a/Wox/MainWindow.xaml.cs
+++ b/Wox/MainWindow.xaml.cs
@@ -305,12 +305,14 @@ namespace Wox
private void OnWinRPressed()
{
ShowWox(false);
- if (tbQuery.Text != ">")
+ if (!tbQuery.Text.StartsWith(">"))
{
resultCtrl.Clear();
ChangeQuery(">");
}
tbQuery.CaretIndex = tbQuery.Text.Length;
+ tbQuery.SelectionStart = 1;
+ tbQuery.SelectionLength = tbQuery.Text.Length - 1;
}
private void updateCmdMode()
@@ -506,6 +508,21 @@ namespace Wox
#endregion
+ public bool ShellRun(string cmd)
+ {
+ try
+ {
+ if (string.IsNullOrEmpty(cmd))
+ throw new ArgumentNullException();
+ Wox.Infrastructure.WindowsShellRun.Start(cmd);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ ShowMsg("Could not start " + cmd, ex.Message, null);
+ }
+ return false;
+ }
}
}
\ No newline at end of file
diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs
index d1fe4b118d..72accc6109 100644
--- a/Wox/PluginLoader/Plugins.cs
+++ b/Wox/PluginLoader/Plugins.cs
@@ -51,6 +51,7 @@ namespace Wox.PluginLoader
})),
StartLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StartLoadingBar())),
StopLoadingBar = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.StopLoadingBar())),
+ ShellRun = (cmd) => (bool) App.Window.Dispatcher.Invoke(new Func(() => App.Window.ShellRun(cmd))),
}));
}
}