Fixed Image Errors + Handing Bad ShellRun

This commit is contained in:
Aaron Campf 2014-05-08 15:58:38 -07:00
parent 0b70c5225d
commit 7c2e2a01c2
7 changed files with 144 additions and 150 deletions

View File

@ -5,8 +5,8 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Default.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="Themes/Default.xaml"></ResourceDictionary>-->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -57,7 +57,7 @@ namespace Wox
{
// First time app is launched
app = new App();
app.InitializeComponent();
//app.InitializeComponent();
app.Run();
return true;
}

View File

@ -24,7 +24,7 @@ namespace Wox.Helper
static FontStyleConverter fontStyleConverter = new FontStyleConverter();
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value)
{
{
try
{
return (FontStyle)fontStyleConverter.ConvertFromInvariantString(value);
@ -37,7 +37,7 @@ namespace Wox.Helper
static FontStretchConverter fontStretchConverter = new FontStretchConverter();
public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value)
{
{
try
{
return (FontStretch)fontStretchConverter.ConvertFromInvariantString(value);

View File

@ -455,6 +455,12 @@ namespace Wox {
}
public void SetTheme(string themeName) {
//Uri uri = new Uri("Themes/Default.xaml", UriKind.Relative);
//System.Windows.Resources.StreamResourceInfo info = Application.GetResourceStream(uri);
//System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
var dict = new ResourceDictionary {
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
};

View File

@ -15,70 +15,65 @@ using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Timer = System.Threading.Timer;
namespace Wox
{
public partial class Msg : Window
{
Storyboard fadeOutStoryboard = new Storyboard();
private bool closing = false;
namespace Wox {
public partial class Msg : Window {
Storyboard fadeOutStoryboard = new Storyboard();
private bool closing = false;
public Msg()
{
InitializeComponent();
public Msg() {
InitializeComponent();
Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
Top = Screen.PrimaryScreen.Bounds.Bottom;
showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom;
showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height;
Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
Top = Screen.PrimaryScreen.Bounds.Bottom;
showAnimation.From = Screen.PrimaryScreen.Bounds.Bottom;
showAnimation.To = Screen.PrimaryScreen.WorkingArea.Bottom - Height;
// Create the fade out storyboard
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3)))
{
AccelerationRatio = 0.2
};
Storyboard.SetTarget(fadeOutAnimation, this);
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
fadeOutStoryboard.Children.Add(fadeOutAnimation);
// Create the fade out storyboard
fadeOutStoryboard.Completed += new EventHandler(fadeOutStoryboard_Completed);
DoubleAnimation fadeOutAnimation = new DoubleAnimation(Screen.PrimaryScreen.WorkingArea.Bottom - Height, Screen.PrimaryScreen.Bounds.Bottom, new Duration(TimeSpan.FromSeconds(0.3))) {
AccelerationRatio = 0.2
};
Storyboard.SetTarget(fadeOutAnimation, this);
Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(TopProperty));
fadeOutStoryboard.Children.Add(fadeOutAnimation);
imgClose.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\close.png")));
imgClose.MouseUp += imgClose_MouseUp;
}
void imgClose_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!closing)
{
closing = true;
fadeOutStoryboard.Begin();
}
}
imgClose.Source = new BitmapImage(new Uri("Images\\close.pn", UriKind.Relative));
//imgClose.Source = new BitmapImage(new Uri(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\close.png")));
imgClose.MouseUp += imgClose_MouseUp;
}
private void fadeOutStoryboard_Completed(object sender, EventArgs e)
{
Close();
}
void imgClose_MouseUp(object sender, MouseButtonEventArgs e) {
if (!closing) {
closing = true;
fadeOutStoryboard.Begin();
}
}
public void Show(string title, string subTitle, string icopath)
{
tbTitle.Text = title;
tbSubTitle.Text = subTitle;
if (!File.Exists(icopath))
{
icopath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\app.png");
}
imgIco.Source = new BitmapImage(new Uri(icopath));
Show();
private void fadeOutStoryboard_Completed(object sender, EventArgs e) {
Close();
}
Dispatcher.DelayInvoke("ShowMsg",
o =>
{
if (!closing)
{
closing = true;
Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin));
}
}, TimeSpan.FromSeconds(3));
}
}
public void Show(string title, string subTitle, string icopath) {
tbTitle.Text = title;
tbSubTitle.Text = subTitle;
if (!File.Exists(icopath)) {
//icopath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Images\\app.png");
imgIco.Source = new BitmapImage(new Uri("Images\\app.png", UriKind.Relative));
}
else {
imgIco.Source = new BitmapImage(new Uri(icopath));
}
Show();
Dispatcher.DelayInvoke("ShowMsg",
o => {
if (!closing) {
closing = true;
Dispatcher.Invoke(new Action(fadeOutStoryboard.Begin));
}
}, TimeSpan.FromSeconds(3));
}
}
}

View File

@ -10,97 +10,90 @@ using Wox.Infrastructure.Storage;
using Wox.Infrastructure.Storage.UserSettings;
using Wox.Plugin;
namespace Wox.PluginLoader
{
public static class Plugins
{
private static string debuggerMode = null;
private static List<PluginPair> plugins = new List<PluginPair>();
private static ManualResetEvent initializing = null;
namespace Wox.PluginLoader {
public static class Plugins {
//private static string debuggerMode = null;
public static String DebuggerMode { get; private set; }
public static void Init()
{
if (initializing != null) return;
private static List<PluginPair> plugins = new List<PluginPair>();
private static ManualResetEvent initializing = null;
initializing = new ManualResetEvent(false);
plugins.Clear();
BasePluginLoader.ParsePluginsConfig();
public static void Init() {
if (initializing != null) return;
if (UserSettingStorage.Instance.EnablePythonPlugins)
{
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
}
initializing = new ManualResetEvent(false);
plugins.Clear();
BasePluginLoader.ParsePluginsConfig();
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
Forker forker = new Forker();
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
{
IPlugin plugin1 = plugin;
PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1);
if (pluginPair != null)
{
PluginMetadata metadata = pluginPair.Metadata;
pluginPair.InitContext = new PluginInitContext()
{
Plugins = plugins,
CurrentPluginMetadata = metadata,
ChangeQuery = s => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ChangeQuery(s))),
CloseApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.CloseApp())),
HideApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.HideApp())),
ShowApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowApp())),
ShowMsg = (title, subTitle, iconPath) => App.Window.Dispatcher.Invoke(new Action(() =>
App.Window.ShowMsg(title, subTitle, iconPath))),
OpenSettingDialog = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.OpenSettingDialog())),
ShowCurrentResultItemTooltip = (msg) => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowCurrentResultItemTooltip(msg))),
ReloadPlugins = () => App.Window.Dispatcher.Invoke(new Action(() => Init())),
InstallPlugin = (filePath) => App.Window.Dispatcher.Invoke(new Action(() =>
{
PluginInstaller.Install(filePath);
})),
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<bool>(() => App.Window.ShellRun(cmd))),
};
forker.Fork(() => plugin1.Init(pluginPair.InitContext));
}
}
if (UserSettingStorage.Instance.EnablePythonPlugins) {
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
}
ThreadPool.QueueUserWorkItem(o =>
{
forker.Join();
initializing.Set();
initializing = null;
});
}
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
Forker forker = new Forker();
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin)) {
IPlugin plugin1 = plugin;
PluginPair pluginPair = plugins.FirstOrDefault(o => o.Plugin == plugin1);
if (pluginPair != null) {
PluginMetadata metadata = pluginPair.Metadata;
pluginPair.InitContext = new PluginInitContext() {
Plugins = plugins,
CurrentPluginMetadata = metadata,
ChangeQuery = s => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ChangeQuery(s))),
CloseApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.CloseApp())),
HideApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.HideApp())),
ShowApp = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowApp())),
ShowMsg = (title, subTitle, iconPath) => App.Window.Dispatcher.Invoke(new Action(() =>
App.Window.ShowMsg(title, subTitle, iconPath))),
OpenSettingDialog = () => App.Window.Dispatcher.Invoke(new Action(() => App.Window.OpenSettingDialog())),
ShowCurrentResultItemTooltip = (msg) => App.Window.Dispatcher.Invoke(new Action(() => App.Window.ShowCurrentResultItemTooltip(msg))),
ReloadPlugins = () => App.Window.Dispatcher.Invoke(new Action(() => Init())),
InstallPlugin = (filePath) => App.Window.Dispatcher.Invoke(new Action(() => {
PluginInstaller.Install(filePath);
})),
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<bool>(() => App.Window.ShellRun(cmd)))
};
public static List<PluginPair> AllPlugins
{
get
{
var init = initializing;
if (init != null)
{
init.WaitOne();
}
return plugins;
}
}
pluginPair.InitContext.ShellRun = (cmd) => {
try {
return (bool)App.Window.Dispatcher.Invoke(new Func<bool>(() => App.Window.ShellRun(cmd)));
}
catch (Exception) {
return false;
}
};
public static bool HitThirdpartyKeyword(Query query)
{
if (string.IsNullOrEmpty(query.ActionName)) return false;
forker.Fork(() => plugin1.Init(pluginPair.InitContext));
}
}
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
ThreadPool.QueueUserWorkItem(o => {
forker.Join();
initializing.Set();
initializing = null;
});
}
public static void ActivatePluginDebugger(string path)
{
debuggerMode = path;
}
public static List<PluginPair> AllPlugins {
get {
var init = initializing;
if (init != null) {
init.WaitOne();
}
return plugins;
}
}
public static String DebuggerMode
{
get { return debuggerMode; }
}
}
public static bool HitThirdpartyKeyword(Query query) {
if (string.IsNullOrEmpty(query.ActionName)) return false;
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
public static void ActivatePluginDebugger(string path) {
DebuggerMode = path;
}
}
}

View File

@ -197,21 +197,21 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="Themes\Dark.xaml">
<None Include="Themes\Dark.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
</None>
<None Include="Themes\Light.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="Themes\Default.xaml">
<None Include="Themes\Default.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
</None>
<None Include="Themes\Pink.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>