From 80fda25498d47abf7dabcd46b08a211395ea4324 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Wed, 4 Dec 2013 23:45:45 +0100 Subject: [PATCH] More plugin loading progress --- Programs/GridProxyGUI/MainWindow.cs | 7 +- Programs/GridProxyGUI/PluginsScroller.cs | 136 +++++++++++++++++++++++ 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/Programs/GridProxyGUI/MainWindow.cs b/Programs/GridProxyGUI/MainWindow.cs index 25335aca..52198c27 100755 --- a/Programs/GridProxyGUI/MainWindow.cs +++ b/Programs/GridProxyGUI/MainWindow.cs @@ -597,7 +597,7 @@ public partial class MainWindow : Gtk.Window } } - List GetFileFilters() + List GetFileFilters() { List filters = new List(); @@ -664,7 +664,10 @@ public partial class MainWindow : Gtk.Window about.Destroy(); } - protected void OnBtnLoadPluginClicked (object sender, EventArgs e) + protected void OnBtnLoadPluginClicked(object sender, EventArgs e) { + if (proxy == null) return; + + plugins.LoadPlugin(proxy.Proxy); } } \ No newline at end of file diff --git a/Programs/GridProxyGUI/PluginsScroller.cs b/Programs/GridProxyGUI/PluginsScroller.cs index f6ab59b1..d81951e3 100755 --- a/Programs/GridProxyGUI/PluginsScroller.cs +++ b/Programs/GridProxyGUI/PluginsScroller.cs @@ -1,15 +1,151 @@ using System; using System.Collections.Generic; +using System.IO; using Gtk; +using GridProxy; using GridProxyGUI; namespace GridProxyGUI { + public class PluginInfo + { + public bool LoadOnStartup; + public string Path; + public string Name + { + get + { + if (string.IsNullOrEmpty(Path)) return string.Empty; + return System.IO.Path.GetFileName(Path); + } + } + public string Dir + { + get + { + if (string.IsNullOrEmpty(Path)) return string.Empty; + return System.IO.Path.GetDirectoryName(Path); + } + } + } + public class PluginsScroller : TreeView { + ListStore Store; + public PluginsScroller() { + TreeViewColumn col = new TreeViewColumn(); + col.Title = "Load on Starup"; + CellRendererToggle cell = new CellRendererToggle(); + cell.Toggled += new ToggledHandler((sender, e) => + { + TreeIter iter; + if (Store.GetIterFromString(out iter, e.Path)) + { + PluginInfo item = Store.GetValue(iter, 0) as PluginInfo; + if (null != item) + { + item.LoadOnStartup = !item.LoadOnStartup; + Store.SetValue(iter, 0, item); + } + } + }); + cell.Activatable = true; + col.PackStart(cell, true); + col.SetCellDataFunc(cell, (TreeViewColumn column, CellRenderer xcell, TreeModel model, TreeIter iter) => + { + var item = Store.GetValue(iter, 0) as PluginInfo; + if (item != null) + { + ((CellRendererToggle)cell).Active = item.LoadOnStartup; + } + }); + AppendColumn(col); + + col = new TreeViewColumn(); + col.Title = "Plugin"; + CellRendererText cellText = new CellRendererText(); + col.PackStart(cellText, true); + col.SetCellDataFunc(cellText, (TreeViewColumn column, CellRenderer xcell, TreeModel model, TreeIter iter) => + { + var item = Store.GetValue(iter, 0) as PluginInfo; + if (item != null) + { + ((CellRendererText)xcell).Text = item.Name; + } + }); + AppendColumn(col); + + col = new TreeViewColumn(); + col.Title = "Path"; + cellText = new CellRendererText(); + col.PackStart(cellText, true); + col.SetCellDataFunc(cellText, (TreeViewColumn column, CellRenderer xcell, TreeModel model, TreeIter iter) => + { + var item = Store.GetValue(iter, 0) as PluginInfo; + if (item != null) + { + ((CellRendererText)xcell).Text = item.Path; + } + }); + AppendColumn(col); + + Store = new ListStore(typeof(PluginInfo)); + Model = Store; + HeadersVisible = true; + ShowAll(); + } + + List GetFileFilters() + { + List filters = new List(); + + FileFilter filter = new FileFilter(); + filter.Name = "Grid Proxy Plugin (*.dll; *.exe)"; + filter.AddPattern("*.dll"); + filter.AddPattern("*.exe"); + filters.Add(filter); + + filter = new FileFilter(); + filter.Name = "All Files (*.*)"; + filter.AddPattern("*.*"); + filters.Add(filter); + + return filters; + } + + public void LoadPlugin(ProxyFrame proxy) + { + if (proxy == null) return; + + var od = new Gtk.FileChooserDialog(null, "Load Plugin", null, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); + foreach (var filter in GetFileFilters()) od.AddFilter(filter); + + if (od.Run() == (int)ResponseType.Accept) + { + PluginInfo plugin = new PluginInfo(); + plugin.Path = od.Filename; + bool found = false; + Store.Foreach((model, path, iter) => + { + var item = model.GetValue(iter, 0) as PluginInfo; + if (null != item && item.Path == plugin.Path) + { + return found = true; + } + + return false; + }); + + if (!found) + { + Store.AppendValues(plugin); + } + } + od.Destroy(); + } }