Refactoring FolderLink and URL plugin.

This commit is contained in:
qianlifeng
2014-07-19 10:12:11 +08:00
parent f1697313c0
commit fc66fba577
10 changed files with 231 additions and 169 deletions

View File

@@ -1,29 +1,47 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security.Policy;
using System.Text.RegularExpressions;
using System.Windows;
namespace Wox.Plugin.SystemPlugins
{
public class UrlPlugin : BaseSystemPlugin
{
const string pattern = @"^(http|https|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
protected override List<Result> QueryInternal(Query query)
{
var raw = query.RawQuery;
Uri uri;
if (Uri.TryCreate(raw, UriKind.Absolute, out uri))
if (reg.IsMatch(raw))
{
return new List<Result>
{
new Result
{
Title = raw,
SubTitle = "Open the typed URL...",
IcoPath = "Images/url1.png",
SubTitle = "Open " + raw,
IcoPath = "Images/url.png",
Score = 8,
Action = _ =>
{
Process.Start(uri.AbsoluteUri);
return true;
if (!raw.ToLower().StartsWith("http"))
{
raw = "http://" + raw;
}
try
{
Process.Start(raw);
return true;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Could not open " + raw);
return false;
}
}
}
};
@@ -38,7 +56,7 @@ namespace Wox.Plugin.SystemPlugins
public override string Name { get { return "URL handler"; } }
public override string Description { get { return "Provide Opening the typed URL from Wox."; } }
public override string IcoPath { get { return "Images/url2.png"; } }
public override string IcoPath { get { return "Images/url.png"; } }
protected override void InitInternal(PluginInitContext context)
{