X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=plugins%2FVimish.cs;h=51c2cfcb769b016c5fa5a0d2648967188ce4db4c;hb=11835c28c3407f9bbd4aa68b875a528d13ff0d73;hp=968fae901eff31a325468e02a88389e9db63b38a;hpb=84890340eccbe66e303780a992fe152356974394;p=WebThing.git diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 968fae9..51c2cfc 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -106,18 +106,28 @@ public class Vimish : WebThingPlugin { private void command_Activate(object o, EventArgs e) { string[] args = Regex.Split(commandline.Text, @"\s+"); - switch(args[0]) { + if (args.Length == 0) return; + string cmd = args[0]; + string[] tmp = new string[args.Length - 1]; + Array.Copy(args, 1, tmp, 0, tmp.Length); + args = tmp; + string query = Regex.Replace(commandline.Text, String.Format(@"^{0}\s+", cmd), ""); + + switch(cmd) { case "close": wt.CloseTab(); break; case "open": - if (args.Length < 2) return; - wt.OpenUri(args[1]); + if (args.Length < 1) return; + if (!wt.Open(query)) + Error("Could not open query"); break; case "tabopen": - if (args.Length < 2) return; - wt.OpenUriTab(args[1]); - wt.Tabs.CurrentPage = wt.Tabs.NPages - 1; + if (args.Length < 1) return; + if (wt.OpenTab(query)) + wt.Tabs.CurrentPage = wt.Tabs.NPages - 1; + else + Error("Could not open query"); break; case "n": wt.Tabs.NextPage(); @@ -129,12 +139,29 @@ public class Vimish : WebThingPlugin { wt.Quit(); break; case "set": - if (args.Length == 2) - Options[args[1]] = null; + if (args.Length == 1) + Options[args[0]] = null; else - Options[args[1]] = args[2]; + Options[args[0]] = args[1]; ApplyOptions(); break; + case "save": + SaveConfig(); + break; + default: + bool found; + if (args.Length > 0) { + found = wt.Plugins.Call(cmd, args); + if (!found) + Error("No function {0}({1}) found", cmd, String.Join(", ", args)); + } else { + found = wt.Plugins.Call(cmd); + if (!found) + Error("No function {0}() found", cmd); + } + if (found) + Console.WriteLine("Plugin function {0} called successfully", cmd); + break; } CommandlineHide(); } @@ -143,7 +170,7 @@ public class Vimish : WebThingPlugin { foreach (string key in Options.Keys) { switch(key) { case "ShowTabs": - bool v = ParseBool(Options[key]); + bool v = Config.ParseBool(Options[key]); wt.Tabs.ShowTabs = v; break; default: @@ -153,18 +180,6 @@ public class Vimish : WebThingPlugin { } } - private bool ParseBool(string v) { - switch(v.ToLower()) { - case "true": - case "t": - case "1": - case "on": - case "yes": - return true; - } - return false; - } - private void Error(string format, params object[] values) { Console.WriteLine(format, values); }