From 1bff29702cf8ce8c1952d22243e4dc7a9df74105 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Wed, 3 Jun 2009 03:22:52 -0500 Subject: [PATCH] Re-tabinated C# files --- WebThing.cs | 372 ++++++++++++++++++++-------------------- main.cs | 14 +- plugins/DefaultPage.cs | 14 +- plugins/FFNav.cs | 46 ++--- plugins/LoadProgress.cs | 134 +++++++-------- plugins/Vimish.cs | 148 ++++++++-------- 6 files changed, 364 insertions(+), 364 deletions(-) diff --git a/WebThing.cs b/WebThing.cs index 4bccfbb..678194b 100644 --- a/WebThing.cs +++ b/WebThing.cs @@ -9,190 +9,190 @@ using GtkSharp; using WebKit; namespace bytex64.WebThing { - public enum CompassDirection { - N, E, S, W, Interior - } - - public class WebThing { - public Gtk.Window Window { - get { return _Window; } - } - - public Gtk.Window w { - get { return _Window; } - } - - public Gtk.ScrolledWindow ScrolledWindow { - get { return _ScrolledWindow; } - } - - public Gtk.ScrolledWindow sw { - get { return _ScrolledWindow; } - } - - public WebKit.WebView WebView { - get { return _WebView; } - } - - public WebKit.WebView wv { - get { return _WebView; } - } - - private Gtk.Window _Window; - private ScrolledWindow _ScrolledWindow; - private WebKit.WebView _WebView; - private Gtk.Table WidgetGrid; - private Gtk.Alignment InteriorOverlay; - - public Dictionary Plugins; - public Dictionary Options; - public string[] Arguments; - - [DllImport ("SoupSettings.dll")] - private static extern void soup_settings(); - - public void Run() { - Application.Init(); - - ParseArgs(); - - _Window = new Gtk.Window("WebThing"); - _Window.SetWmclass("webthing", "WebThing"); - _Window.Role = "browser"; - _Window.Destroyed += delegate { Quit(); }; - - WidgetGrid = new Gtk.Table(3, 3, false); - _Window.Add(WidgetGrid); - - _ScrolledWindow = new Gtk.ScrolledWindow(); - WidgetGrid.Attach(_ScrolledWindow, 1, 2, 1, 2); - - InteriorOverlay = new Gtk.Alignment(1, 0, 0, 0); - WidgetGrid.Attach(InteriorOverlay, 1, 2, 1, 2); - - _WebView = new WebKit.WebView(); - _WebView.TitleChanged += delegate(object o, TitleChangedArgs e) { - _Window.Title = e.Title + " - WebThing"; - }; - soup_settings(); - - _ScrolledWindow.Add(_WebView); - - _Window.ShowAll(); - - Plugins = new Dictionary(); - // TODO: Conf.Get("plugins") instead of hard-coded path? - using (TextReader f = new StreamReader("plugins.conf")) { - string line; - while ((line = f.ReadLine()) != null) { - line = line.Trim(); - LoadPlugin(line); - } - } - - Application.Run(); - } - - protected void ParseArgs() { - Options = new Dictionary(); - Queue q = new Queue(); - foreach (string s in System.Environment.GetCommandLineArgs()) { - q.Enqueue(s); - } - q.Dequeue(); // Remove self argument - - Regex SimpleOpt = new Regex(@"^-([a-zA-Z0-9]+)$"); - Regex LongOpt = new Regex(@"^--([\w-]+)$"); - string OptLast = null; - List args = new List(); - - while (q.Count > 0) { - string opt = q.Dequeue(); - Match m; - - m = SimpleOpt.Match(opt); - if (m.Success) { - string s = m.Groups[1].Value; - if (s.Length > 1) { - foreach (char c in s) { - Options[c.ToString()] = ""; - } - OptLast = null; - } else { - Options[s] = ""; - OptLast = s; - } - continue; - } - - m = LongOpt.Match(opt); - if (m.Success) { - string s = m.Groups[1].Value; - Options[s] = ""; - OptLast = s; - continue; - } - - // else - - if (OptLast != null) { - Options[OptLast] = opt; - OptLast = null; - } else { - args.Add(opt); - } - } - Arguments = args.ToArray(); - - /* - Console.WriteLine("Options:"); - foreach (string key in Options.Keys) - Console.WriteLine(" {0}\t{1}", key, Options[key]); - - Console.WriteLine("Arguments: {0}", String.Join(" ", Arguments)); - */ - } - - public void LoadPlugin(string assemblyname) { - Assembly a = Assembly.LoadFile("plugins/" + assemblyname + ".dll"); - object obj = a.CreateInstance("Plugin", false, BindingFlags.ExactBinding, null, new object[] { this }, null, null); - Plugins[assemblyname] = obj; - } - - public void AttachWidget(Gtk.Widget widget, CompassDirection direction, AttachOptions xoptions, AttachOptions yoptions) { - switch(direction) { - case CompassDirection.N: - WidgetGrid.Attach(widget, 0, 3, 0, 1, xoptions, yoptions, 0, 0); - break; - case CompassDirection.E: - WidgetGrid.Attach(widget, 2, 3, 1, 2, xoptions, yoptions, 0, 0); - break; - case CompassDirection.S: - WidgetGrid.Attach(widget, 0, 3, 2, 3, xoptions, yoptions, 0, 0); - break; - case CompassDirection.W: - WidgetGrid.Attach(widget, 0, 1, 1, 2, xoptions, yoptions, 0, 0); - break; - case CompassDirection.Interior: - InteriorOverlay.Add(widget); - break; - } - } - - public void AttachWidget(Gtk.Widget widget, CompassDirection direction) { - AttachWidget(widget, direction, 0, 0); - } - - public void OpenUri(string Uri) { - if (!Regex.IsMatch(Uri, @"://")) { - Uri = String.Format("http://{0}", Uri); - } - wv.Open(Uri); - } - - public void Quit() { - // TODO: Create a way of shutting down plugins - Application.Quit(); - } - } + public enum CompassDirection { + N, E, S, W, Interior + } + + public class WebThing { + public Gtk.Window Window { + get { return _Window; } + } + + public Gtk.Window w { + get { return _Window; } + } + + public Gtk.ScrolledWindow ScrolledWindow { + get { return _ScrolledWindow; } + } + + public Gtk.ScrolledWindow sw { + get { return _ScrolledWindow; } + } + + public WebKit.WebView WebView { + get { return _WebView; } + } + + public WebKit.WebView wv { + get { return _WebView; } + } + + private Gtk.Window _Window; + private ScrolledWindow _ScrolledWindow; + private WebKit.WebView _WebView; + private Gtk.Table WidgetGrid; + private Gtk.Alignment InteriorOverlay; + + public Dictionary Plugins; + public Dictionary Options; + public string[] Arguments; + + [DllImport ("SoupSettings.dll")] + private static extern void soup_settings(); + + public void Run() { + Application.Init(); + + ParseArgs(); + + _Window = new Gtk.Window("WebThing"); + _Window.SetWmclass("webthing", "WebThing"); + _Window.Role = "browser"; + _Window.Destroyed += delegate { Quit(); }; + + WidgetGrid = new Gtk.Table(3, 3, false); + _Window.Add(WidgetGrid); + + _ScrolledWindow = new Gtk.ScrolledWindow(); + WidgetGrid.Attach(_ScrolledWindow, 1, 2, 1, 2); + + InteriorOverlay = new Gtk.Alignment(1, 0, 0, 0); + WidgetGrid.Attach(InteriorOverlay, 1, 2, 1, 2); + + _WebView = new WebKit.WebView(); + _WebView.TitleChanged += delegate(object o, TitleChangedArgs e) { + _Window.Title = e.Title + " - WebThing"; + }; + soup_settings(); + + _ScrolledWindow.Add(_WebView); + + _Window.ShowAll(); + + Plugins = new Dictionary(); + // TODO: Conf.Get("plugins") instead of hard-coded path? + using (TextReader f = new StreamReader("plugins.conf")) { + string line; + while ((line = f.ReadLine()) != null) { + line = line.Trim(); + LoadPlugin(line); + } + } + + Application.Run(); + } + + protected void ParseArgs() { + Options = new Dictionary(); + Queue q = new Queue(); + foreach (string s in System.Environment.GetCommandLineArgs()) { + q.Enqueue(s); + } + q.Dequeue(); // Remove self argument + + Regex SimpleOpt = new Regex(@"^-([a-zA-Z0-9]+)$"); + Regex LongOpt = new Regex(@"^--([\w-]+)$"); + string OptLast = null; + List args = new List(); + + while (q.Count > 0) { + string opt = q.Dequeue(); + Match m; + + m = SimpleOpt.Match(opt); + if (m.Success) { + string s = m.Groups[1].Value; + if (s.Length > 1) { + foreach (char c in s) { + Options[c.ToString()] = ""; + } + OptLast = null; + } else { + Options[s] = ""; + OptLast = s; + } + continue; + } + + m = LongOpt.Match(opt); + if (m.Success) { + string s = m.Groups[1].Value; + Options[s] = ""; + OptLast = s; + continue; + } + + // else + + if (OptLast != null) { + Options[OptLast] = opt; + OptLast = null; + } else { + args.Add(opt); + } + } + Arguments = args.ToArray(); + + /* + Console.WriteLine("Options:"); + foreach (string key in Options.Keys) + Console.WriteLine(" {0}\t{1}", key, Options[key]); + + Console.WriteLine("Arguments: {0}", String.Join(" ", Arguments)); + */ + } + + public void LoadPlugin(string assemblyname) { + Assembly a = Assembly.LoadFile("plugins/" + assemblyname + ".dll"); + object obj = a.CreateInstance("Plugin", false, BindingFlags.ExactBinding, null, new object[] { this }, null, null); + Plugins[assemblyname] = obj; + } + + public void AttachWidget(Gtk.Widget widget, CompassDirection direction, AttachOptions xoptions, AttachOptions yoptions) { + switch(direction) { + case CompassDirection.N: + WidgetGrid.Attach(widget, 0, 3, 0, 1, xoptions, yoptions, 0, 0); + break; + case CompassDirection.E: + WidgetGrid.Attach(widget, 2, 3, 1, 2, xoptions, yoptions, 0, 0); + break; + case CompassDirection.S: + WidgetGrid.Attach(widget, 0, 3, 2, 3, xoptions, yoptions, 0, 0); + break; + case CompassDirection.W: + WidgetGrid.Attach(widget, 0, 1, 1, 2, xoptions, yoptions, 0, 0); + break; + case CompassDirection.Interior: + InteriorOverlay.Add(widget); + break; + } + } + + public void AttachWidget(Gtk.Widget widget, CompassDirection direction) { + AttachWidget(widget, direction, 0, 0); + } + + public void OpenUri(string Uri) { + if (!Regex.IsMatch(Uri, @"://")) { + Uri = String.Format("http://{0}", Uri); + } + wv.Open(Uri); + } + + public void Quit() { + // TODO: Create a way of shutting down plugins + Application.Quit(); + } + } } diff --git a/main.cs b/main.cs index 4633d6f..8861283 100644 --- a/main.cs +++ b/main.cs @@ -1,12 +1,12 @@ using System; namespace bytex64.WebThing { - public class WebThingMain { - static WebThing wt; + public class WebThingMain { + static WebThing wt; - public static void Main(string[] args) { - wt = new WebThing(); - wt.Run(); - } - } + public static void Main(string[] args) { + wt = new WebThing(); + wt.Run(); + } + } } diff --git a/plugins/DefaultPage.cs b/plugins/DefaultPage.cs index 9d8913d..3de2410 100644 --- a/plugins/DefaultPage.cs +++ b/plugins/DefaultPage.cs @@ -2,11 +2,11 @@ using System; using bytex64.WebThing; public class Plugin { - public Plugin(WebThing wt) { - if (wt.Arguments.Length > 0) { - wt.OpenUri(wt.Arguments[0]); - } else { - wt.OpenUri("http://dominionofawesome.com/"); - } - } + public Plugin(WebThing wt) { + if (wt.Arguments.Length > 0) { + wt.OpenUri(wt.Arguments[0]); + } else { + wt.OpenUri("http://dominionofawesome.com/"); + } + } } diff --git a/plugins/FFNav.cs b/plugins/FFNav.cs index 1a3145c..4f22b63 100644 --- a/plugins/FFNav.cs +++ b/plugins/FFNav.cs @@ -3,29 +3,29 @@ using Gtk; using bytex64.WebThing; public class Plugin { - WebThing wt; + WebThing wt; - public Plugin(WebThing wt) { - this.wt = wt; - wt.WebView.KeyPressEvent += WebView_KeyPress; - } + public Plugin(WebThing wt) { + this.wt = wt; + wt.WebView.KeyPressEvent += WebView_KeyPress; + } - private void WebView_KeyPress(object o, KeyPressEventArgs e) { - if ((e.Event.State & Gdk.ModifierType.Mod1Mask) != 0) { - switch(e.Event.Key) { - case Gdk.Key.Left: - wt.WebView.GoBack(); - break; - case Gdk.Key.Right: - wt.WebView.GoForward(); - break; - } - } else { - switch(e.Event.Key) { - case Gdk.Key.BackSpace: - wt.WebView.GoBack(); - break; - } - } - } + private void WebView_KeyPress(object o, KeyPressEventArgs e) { + if ((e.Event.State & Gdk.ModifierType.Mod1Mask) != 0) { + switch(e.Event.Key) { + case Gdk.Key.Left: + wt.WebView.GoBack(); + break; + case Gdk.Key.Right: + wt.WebView.GoForward(); + break; + } + } else { + switch(e.Event.Key) { + case Gdk.Key.BackSpace: + wt.WebView.GoBack(); + break; + } + } + } } diff --git a/plugins/LoadProgress.cs b/plugins/LoadProgress.cs index 3d5e59d..9dc6838 100644 --- a/plugins/LoadProgress.cs +++ b/plugins/LoadProgress.cs @@ -4,84 +4,84 @@ using WebKit; using bytex64.WebThing; public class LoadThrobber : Gtk.DrawingArea { - public enum Mode { - LoadStarted, - LoadInProgress, - LoadFinished - }; - public Mode LoadState; - int r; - uint idletimer; + public enum Mode { + LoadStarted, + LoadInProgress, + LoadFinished + }; + public Mode LoadState; + int r; + uint idletimer; - public LoadThrobber(WebThing wt) { - LoadState = Mode.LoadStarted; + public LoadThrobber(WebThing wt) { + LoadState = Mode.LoadStarted; - wt.WebView.LoadStarted += WebView_LoadStarted; - wt.WebView.LoadCommitted += WebView_LoadCommitted; - wt.WebView.LoadProgressChanged += WebView_LoadProgressChanged; - wt.WebView.LoadFinished += WebView_LoadFinished; + wt.WebView.LoadStarted += WebView_LoadStarted; + wt.WebView.LoadCommitted += WebView_LoadCommitted; + wt.WebView.LoadProgressChanged += WebView_LoadProgressChanged; + wt.WebView.LoadFinished += WebView_LoadFinished; - SetSizeRequest(64, 64); - } + SetSizeRequest(64, 64); + } - protected override bool OnExposeEvent(Gdk.EventExpose e) { - Gdk.Window w = e.Window; - Gdk.GC gc = new Gdk.GC(w); - int width, height; - w.GetSize(out width, out height); + protected override bool OnExposeEvent(Gdk.EventExpose e) { + Gdk.Window w = e.Window; + Gdk.GC gc = new Gdk.GC(w); + int width, height; + w.GetSize(out width, out height); - gc.Foreground = new Gdk.Color(0, 0, 0); - gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Butt, Gdk.JoinStyle.Round); - w.Clear(); + gc.Foreground = new Gdk.Color(0, 0, 0); + gc.SetLineAttributes(3, Gdk.LineStyle.Solid, Gdk.CapStyle.Butt, Gdk.JoinStyle.Round); + w.Clear(); - switch(LoadState) { - case Mode.LoadStarted: - w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64, 90*64); - w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64 + 180*64, 90*64); - r += 5; - break; - case Mode.LoadInProgress: - case Mode.LoadFinished: - w.DrawArc(gc, false, 4, 4, width-8, width-8, 90*64, -r*64); - break; - } - return true; - } + switch(LoadState) { + case Mode.LoadStarted: + w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64, 90*64); + w.DrawArc(gc, false, 4, 4, width-8, width-8, -r*64 + 180*64, 90*64); + r += 5; + break; + case Mode.LoadInProgress: + case Mode.LoadFinished: + w.DrawArc(gc, false, 4, 4, width-8, width-8, 90*64, -r*64); + break; + } + return true; + } - void WebView_LoadStarted(object o, LoadStartedArgs e) { - this.Show(); - Console.WriteLine("Loading Started"); - LoadState = Mode.LoadStarted; - idletimer = GLib.Timeout.Add(100, delegate { - QueueDraw(); - return true; - }); - } + void WebView_LoadStarted(object o, LoadStartedArgs e) { + this.Show(); + Console.WriteLine("Loading Started"); + LoadState = Mode.LoadStarted; + idletimer = GLib.Timeout.Add(100, delegate { + QueueDraw(); + return true; + }); + } - void WebView_LoadCommitted(object o, LoadCommittedArgs e) { - Console.WriteLine("Loading Committed"); - LoadState = Mode.LoadInProgress; - GLib.Source.Remove(idletimer); - r = 0; - QueueDraw(); - } + void WebView_LoadCommitted(object o, LoadCommittedArgs e) { + Console.WriteLine("Loading Committed"); + LoadState = Mode.LoadInProgress; + GLib.Source.Remove(idletimer); + r = 0; + QueueDraw(); + } - void WebView_LoadProgressChanged(object o, LoadProgressChangedArgs e) { - Console.WriteLine("Loading Progress: {0}", e.Progress); - r = (int) ((e.Progress / 100.0) * 360); - QueueDraw(); - } + void WebView_LoadProgressChanged(object o, LoadProgressChangedArgs e) { + Console.WriteLine("Loading Progress: {0}", e.Progress); + r = (int) ((e.Progress / 100.0) * 360); + QueueDraw(); + } - void WebView_LoadFinished(object o, LoadFinishedArgs e) { - Console.WriteLine("Loading Finished"); - LoadState = Mode.LoadFinished; - this.Hide(); - } + void WebView_LoadFinished(object o, LoadFinishedArgs e) { + Console.WriteLine("Loading Finished"); + LoadState = Mode.LoadFinished; + this.Hide(); + } } public class Plugin { - public Plugin(WebThing wt) { - LoadThrobber lt = new LoadThrobber(wt); - wt.AttachWidget(lt, CompassDirection.Interior); - } + public Plugin(WebThing wt) { + LoadThrobber lt = new LoadThrobber(wt); + wt.AttachWidget(lt, CompassDirection.Interior); + } } diff --git a/plugins/Vimish.cs b/plugins/Vimish.cs index 7ed071f..3b4089d 100644 --- a/plugins/Vimish.cs +++ b/plugins/Vimish.cs @@ -4,87 +4,87 @@ using Gtk; using bytex64.WebThing; public class Plugin { - WebThing wt; - Gtk.Entry commandline; + WebThing wt; + Gtk.Entry commandline; - public Plugin(WebThing wt) { - this.wt = wt; - wt.WebView.KeyPressEvent += WebView_KeyPress; + public Plugin(WebThing wt) { + this.wt = wt; + wt.WebView.KeyPressEvent += WebView_KeyPress; - commandline = new Gtk.Entry(); - commandline.Activated += command_Activate; - commandline.KeyPressEvent += command_KeyPress; - wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink); + commandline = new Gtk.Entry(); + commandline.Activated += command_Activate; + commandline.KeyPressEvent += command_KeyPress; + wt.AttachWidget(commandline, CompassDirection.S, AttachOptions.Fill, AttachOptions.Shrink); - commandline.Hide(); - } + commandline.Hide(); + } - private void WebView_KeyPress(object o, KeyPressEventArgs e) { - Console.WriteLine(e.Event.Key); - switch(e.Event.Key) { - case Gdk.Key.j: - wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement; - break; - case Gdk.Key.k: - wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement; - break; - case Gdk.Key.l: - wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement; - break; - case Gdk.Key.h: - wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement; - break; - case Gdk.Key.o: - CommandStart("open "); - break; - case Gdk.Key.r: - wt.WebView.Reload(); - break; - case Gdk.Key.t: - CommandStart("tabopen "); - break; - case Gdk.Key.colon: - CommandlineShow(); - break; - case Gdk.Key.Escape: - wt.WebView.ExecuteScript("document.activeElement.blur()"); - break; - } - } + private void WebView_KeyPress(object o, KeyPressEventArgs e) { + Console.WriteLine(e.Event.Key); + switch(e.Event.Key) { + case Gdk.Key.j: + wt.ScrolledWindow.Vadjustment.Value += wt.ScrolledWindow.Vadjustment.StepIncrement; + break; + case Gdk.Key.k: + wt.ScrolledWindow.Vadjustment.Value -= wt.ScrolledWindow.Vadjustment.StepIncrement; + break; + case Gdk.Key.l: + wt.ScrolledWindow.Hadjustment.Value += wt.ScrolledWindow.Hadjustment.StepIncrement; + break; + case Gdk.Key.h: + wt.ScrolledWindow.Hadjustment.Value -= wt.ScrolledWindow.Hadjustment.StepIncrement; + break; + case Gdk.Key.o: + CommandStart("open "); + break; + case Gdk.Key.r: + wt.WebView.Reload(); + break; + case Gdk.Key.t: + CommandStart("tabopen "); + break; + case Gdk.Key.colon: + CommandlineShow(); + break; + case Gdk.Key.Escape: + wt.WebView.ExecuteScript("document.activeElement.blur()"); + break; + } + } - public void CommandStart(string text) { - commandline.Text = text; - commandline.GrabFocus(); - commandline.Position = text.Length; - commandline.Show(); - } + public void CommandStart(string text) { + commandline.Text = text; + commandline.GrabFocus(); + commandline.Position = text.Length; + commandline.Show(); + } - public void CommandlineShow() { - commandline.Show(); - commandline.GrabFocus(); - } + public void CommandlineShow() { + commandline.Show(); + commandline.GrabFocus(); + } - public void CommandlineHide() { - commandline.Hide(); - wt.WebView.GrabFocus(); - } + public void CommandlineHide() { + commandline.Hide(); + wt.WebView.GrabFocus(); + } - private void command_Activate(object o, EventArgs e) { - string[] args = Regex.Split(commandline.Text, @"\s+"); - switch(args[0]) { - case "open": - if (args.Length < 2) return; - wt.OpenUri(args[1]); - break; - case "q": - wt.Quit(); - break; - } - CommandlineHide(); - } + private void command_Activate(object o, EventArgs e) { + string[] args = Regex.Split(commandline.Text, @"\s+"); + switch(args[0]) { + case "open": + if (args.Length < 2) return; + wt.OpenUri(args[1]); + break; + case "q": + wt.Quit(); + break; + } + CommandlineHide(); + } - private void command_KeyPress(object o, KeyPressEventArgs e) { - if (e.Event.Key == Gdk.Key.Escape) - CommandlineHide(); - } + private void command_KeyPress(object o, KeyPressEventArgs e) { + if (e.Event.Key == Gdk.Key.Escape) + CommandlineHide(); + } } -- 2.25.1