From ca8770374fa6798e92efe6b3cd865c674ae09ce9 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 5 Oct 2011 01:08:37 +0200 Subject: [PATCH] setup: move logic for new Add dialolog to controller --- SparkleShare/SparkleSetup.cs | 193 +++++++++++-------------- SparkleShare/SparkleSetupController.cs | 94 +++++++++++- data/plugins/Makefile.am | 4 +- data/plugins/own-server.png | Bin 0 -> 1363 bytes data/plugins/own-server.xml | 20 +++ data/plugins/redhat.xml | 20 +++ 6 files changed, 219 insertions(+), 112 deletions(-) create mode 100644 data/plugins/own-server.png create mode 100644 data/plugins/own-server.xml create mode 100644 data/plugins/redhat.xml diff --git a/SparkleShare/SparkleSetup.cs b/SparkleShare/SparkleSetup.cs index 3121f63d..ea1daf7f 100755 --- a/SparkleShare/SparkleSetup.cs +++ b/SparkleShare/SparkleSetup.cs @@ -37,8 +37,8 @@ namespace SparkleShare { private Entry NameEntry; private Entry EmailEntry; - private SparkleEntry ServerEntry; - private SparkleEntry FolderEntry; + private SparkleEntry AddressEntry; + private SparkleEntry PathEntry; private Button NextButton; private Button SyncButton; @@ -54,21 +54,6 @@ namespace SparkleShare { } - private void RenderServiceColumn (TreeViewColumn column, CellRenderer cell, - TreeModel model, TreeIter iter) - { - string markup = (string) model.GetValue (iter, 1); - TreeSelection selection = (column.TreeView as TreeView).Selection; - - if (selection.IterIsSelected (iter)) - markup = markup.Replace (SecondaryTextColor, SecondaryTextColorSelected); - else - markup = markup.Replace (SecondaryTextColorSelected, SecondaryTextColor); - - (cell as Gtk.CellRendererText).Markup = markup; - } - - public SparkleSetup () : base () { SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); @@ -153,6 +138,8 @@ namespace SparkleShare { typeof (string), typeof (SparklePlugin)); TreeView tree = new TreeView (store) { HeadersVisible = false }; + ScrolledWindow scrolled_window = new ScrolledWindow (); + scrolled_window.AddWithViewport (tree); // Icon column tree.AppendColumn ("Icon", new Gtk.CellRendererPixbuf (), "pixbuf", 0); @@ -164,33 +151,57 @@ namespace SparkleShare { service_column.PackStart (service_cell, true); service_column.SetCellDataFunc (service_cell, new TreeCellDataFunc (RenderServiceColumn)); - - store.AppendValues (new Gdk.Pixbuf ("/usr/share/icons/gnome/24x24/places/network-server.png"), - "On my own server\n" + - "Everything under my control", - null); - foreach (SparklePlugin plugin in Controller.Plugins) { store.AppendValues ( new Gdk.Pixbuf (plugin.ImagePath), "" + plugin.Name + "\n" + - "" + plugin.Description + "", + "" + + plugin.Description + "" + + "", plugin); } tree.AppendColumn (service_column); - // Select "On my own server" by default + PathEntry = new SparkleEntry (); + AddressEntry = new SparkleEntry (); + + // Select the first plugin by default TreeSelection default_selection = tree.Selection; TreePath default_path = new TreePath ("0"); default_selection.SelectPath (default_path); - ScrolledWindow scrolled_window = new ScrolledWindow (); - scrolled_window.AddWithViewport (tree); + Controller.SelectListPluginEvent += delegate (int index) { + TreeSelection selection = tree.Selection; + TreePath path = new TreePath (index.ToString ()); + selection.SelectPath (path); + }; - FolderEntry = new SparkleEntry (); - ServerEntry = new SparkleEntry (); + Controller.ChangeAddressFieldEvent += delegate (string text, + string example_text, FieldState state) { + Application.Invoke (delegate { + AddressEntry.Text = text; + AddressEntry.Sensitive = (state == FieldState.Enabled); + AddressEntry.ExampleText = example_text; + + if (!string.IsNullOrEmpty (text)) + AddressEntry.ExampleTextActive = true; + }); + }; + + Controller.ChangePathFieldEvent += delegate (string text, + string example_text, FieldState state) { + + Application.Invoke (delegate { + PathEntry.Text = text; + PathEntry.Sensitive = (state == FieldState.Enabled); + PathEntry.ExampleText = example_text; + + if (!string.IsNullOrEmpty (text)) + PathEntry.ExampleTextActive = true; + }); + }; // Update the address field text when the selection changes tree.CursorChanged += delegate (object sender, EventArgs e) { @@ -201,43 +212,11 @@ namespace SparkleShare { selection.GetSelected (out model, out iter); SparklePlugin plugin = (SparklePlugin) model.GetValue (iter, 2); + int selected_path = int.Parse (model.GetPath (iter).ToString ()); - ServerEntry.Sensitive = true; - FolderEntry.Sensitive = true; + Controller.SelectedPluginChanged (selected_path); - if (plugin != null) { - if (plugin.Path != null) { - FolderEntry.Text = plugin.Path; - FolderEntry.Sensitive = false; - FolderEntry.ExampleTextActive = false; - - } else if (plugin.PathExample != null) { - FolderEntry.Text = ""; - FolderEntry.ExampleText = plugin.PathExample; - FolderEntry.ExampleTextActive = true; - } - - if (plugin.Address != null) { - ServerEntry.Text = plugin.Address; - ServerEntry.Sensitive = false; - ServerEntry.ExampleTextActive = false; - - } else if (plugin.AddressExample != null) { - ServerEntry.Text = ""; - ServerEntry.ExampleText = plugin.AddressExample; - ServerEntry.ExampleTextActive = true; - } - - } else { - ServerEntry.Text = ""; - ServerEntry.ExampleTextActive = true; - ServerEntry.ExampleText = _("domain name or IP address"); - FolderEntry.Text = ""; - FolderEntry.ExampleTextActive = true; - FolderEntry.ExampleText = _("/path/to/project"); - } - - // TODO: Scroll along with the selection + // TODO: Scroll to selected row when using arrow keys }; tree.Model.Foreach (new TreeModelForeachFunc (delegate (TreeModel model, @@ -247,6 +226,7 @@ namespace SparkleShare { try { address = (model.GetValue (iter, 2) as SparklePlugin).Address; + } catch (NullReferenceException) { address = ""; } @@ -257,11 +237,11 @@ namespace SparkleShare { tree.SetCursor (path, service_column, false); SparklePlugin plugin = (SparklePlugin) model.GetValue (iter, 2); - if (plugin.Address != null) {Console.WriteLine ("DDDDDDDDD"); - ServerEntry.Sensitive = false;} + if (plugin.Address != null) { + AddressEntry.Sensitive = false;} if (plugin.Path != null) - FolderEntry.Sensitive = false; + PathEntry.Sensitive = false; // TODO: Scroll to the selection @@ -271,58 +251,43 @@ namespace SparkleShare { } })); - ServerEntry.Completion = new EntryCompletion(); + AddressEntry.Completion = new EntryCompletion(); ListStore server_store = new ListStore (typeof (string)); - foreach (string host in Program.Controller.PreviousHosts) - server_store.AppendValues (host); + foreach (string host in Program.Controller.PreviousHosts) + server_store.AppendValues (host); - ServerEntry.Completion.Model = server_store; - ServerEntry.Completion.TextColumn = 0; + AddressEntry.Completion.Model = server_store; + AddressEntry.Completion.TextColumn = 0; - if (!string.IsNullOrEmpty (Controller.PreviousServer)) { - ServerEntry.Text = Controller.PreviousServer; - ServerEntry.ExampleTextActive = false; - - } else { - ServerEntry.ExampleText = _("domain name or IP address"); - } - - ServerEntry.Changed += delegate { - CheckAddPage (); - }; + AddressEntry.Changed += delegate { + CheckAddPage (); + }; layout_address.PackStart (new Label () { - Markup = "" + _("Address") + "", - Xalign = 0 - }, true, true, 0); + Markup = "" + _("Address") + "", + Xalign = 0 + }, true, true, 0); - layout_address.PackStart (ServerEntry, true, true, 0); + layout_address.PackStart (AddressEntry, true, true, 0); - - FolderEntry.ExampleText = _("/path/to/project"); - FolderEntry.Completion = new EntryCompletion(); - - if (!string.IsNullOrEmpty (Controller.PreviousFolder)) { - FolderEntry.Text = Controller.PreviousFolder; - FolderEntry.ExampleTextActive = false; - } + PathEntry.Completion = new EntryCompletion(); ListStore folder_store = new ListStore (typeof (string)); //foreach (string host in Program.Controller.FolderPaths) // folder_store.AppendValues (host); - FolderEntry.Completion.Model = folder_store; - FolderEntry.Completion.TextColumn = 0; + PathEntry.Completion.Model = folder_store; + PathEntry.Completion.TextColumn = 0; - FolderEntry.Changed += delegate { + PathEntry.Changed += delegate { CheckAddPage (); }; layout_path.PackStart (new Label () { Markup = "" + _("Remote Path") + "", Xalign = 0 }, true, true, 0); - layout_path.PackStart (FolderEntry, true, true, 0); + layout_path.PackStart (PathEntry, true, true, 0); layout_fields.PackStart (layout_address); layout_fields.PackStart (layout_path); @@ -344,8 +309,8 @@ namespace SparkleShare { SyncButton = new Button (_("Add")); SyncButton.Clicked += delegate { - string server = ServerEntry.Text; - string folder_name = FolderEntry.Text; + string server = AddressEntry.Text; + string folder_name = PathEntry.Text; Controller.AddPageCompleted (server, folder_name); }; @@ -630,14 +595,14 @@ namespace SparkleShare { { SyncButton.Sensitive = false; - if (FolderEntry.ExampleTextActive || - (ServerEntry.Sensitive && ServerEntry.ExampleTextActive)) + if (PathEntry.ExampleTextActive || + (AddressEntry.Sensitive && AddressEntry.ExampleTextActive)) return; - bool IsFolder = !FolderEntry.Text.Trim ().Equals (""); - bool IsServer = !ServerEntry.Text.Trim ().Equals (""); + bool IsFolder = !PathEntry.Text.Trim ().Equals (""); + bool IsServer = !AddressEntry.Text.Trim ().Equals (""); - if (ServerEntry.Sensitive == true) { + if (AddressEntry.Sensitive == true) { if (IsServer && IsFolder) SyncButton.Sensitive = true; } else if (IsFolder) { @@ -645,6 +610,22 @@ namespace SparkleShare { } } + + private void RenderServiceColumn (TreeViewColumn column, CellRenderer cell, + TreeModel model, TreeIter iter) + { + string markup = (string) model.GetValue (iter, 1); + TreeSelection selection = (column.TreeView as TreeView).Selection; + + if (selection.IterIsSelected (iter)) + markup = markup.Replace (SecondaryTextColor, SecondaryTextColorSelected); + else + markup = markup.Replace (SecondaryTextColorSelected, SecondaryTextColor); + + (cell as CellRendererText).Markup = markup; + } + + private Gdk.Color MixColors (Gdk.Color first_color, Gdk.Color second_color, double ratio) { return new Gdk.Color ( diff --git a/SparkleShare/SparkleSetupController.cs b/SparkleShare/SparkleSetupController.cs index 4f1db890..5e4f23b9 100755 --- a/SparkleShare/SparkleSetupController.cs +++ b/SparkleShare/SparkleSetupController.cs @@ -41,7 +41,19 @@ namespace SparkleShare { public event UpdateProgressBarEventHandler UpdateProgressBarEvent; public delegate void UpdateProgressBarEventHandler (double percentage); + public event ChangeAddressFieldEventHandler ChangeAddressFieldEvent; + public delegate void ChangeAddressFieldEventHandler (string text, + string example_text, FieldState state); + + public event ChangePathFieldEventHandler ChangePathFieldEvent; + public delegate void ChangePathFieldEventHandler (string text, + string example_text, FieldState state); + + public event SelectListPluginEventHandler SelectListPluginEvent; + public delegate void SelectListPluginEventHandler (int index); + public readonly List Plugins = new List (); + public SparklePlugin SelectedPlugin; public int TutorialPageNumber { @@ -117,9 +129,14 @@ namespace SparkleShare { foreach (string xml_file_path in Directory.GetFiles (local_plugins_path, "*.xml")) Plugins.Add (new SparklePlugin (xml_file_path)); - if (Directory.Exists (plugins_path)) - foreach (string xml_file_path in Directory.GetFiles (plugins_path, "*.xml")) - Plugins.Add (new SparklePlugin (xml_file_path)); + if (Directory.Exists (plugins_path)) { + foreach (string xml_file_path in Directory.GetFiles (plugins_path, "*.xml")) { + if (xml_file_path.EndsWith ("own-server.xml")) + Plugins.Insert (0, new SparklePlugin (xml_file_path)); + else + Plugins.Add (new SparklePlugin (xml_file_path)); + } + } ChangePageEvent += delegate (PageType page) { this.previous_page = page; @@ -129,8 +146,20 @@ namespace SparkleShare { public void ShowAddPage () { - if (ChangePageEvent != null) - ChangePageEvent (PageType.Add); + if (ChangePageEvent != null) + ChangePageEvent (PageType.Add); + + int index; + if (SelectedPlugin == null) + index = 0; + else + index = Plugins.IndexOf (SelectedPlugin); + + if (SelectListPluginEvent != null) + SelectListPluginEvent (index); + + SelectedPluginChanged (index); + SelectedPlugin = null; } @@ -228,5 +257,60 @@ namespace SparkleShare { this.previous_folder = ""; Program.Controller.UpdateState (); } + + + public void SelectedPluginChanged (int plugin_index) + { + SelectedPlugin = Plugins [plugin_index]; + + if (SelectedPlugin.Address != null) { + if (ChangeAddressFieldEvent != null) + ChangeAddressFieldEvent (SelectedPlugin.Address, null, FieldState.Disabled); + + } else if (SelectedPlugin.AddressExample != null) { + if (ChangeAddressFieldEvent != null) + ChangeAddressFieldEvent (PreviousServer, SelectedPlugin.AddressExample, FieldState.Enabled); + } else { + if (ChangeAddressFieldEvent != null) + ChangeAddressFieldEvent (PreviousServer, SelectedPlugin.AddressExample, FieldState.Enabled); + } + + if (SelectedPlugin.Path != null) { + if (ChangePathFieldEvent != null) + ChangePathFieldEvent (SelectedPlugin.Path, null, FieldState.Disabled); + + } else if (SelectedPlugin.PathExample != null) { + if (ChangePathFieldEvent != null) + ChangePathFieldEvent (PreviousFolder, SelectedPlugin.PathExample, FieldState.Enabled); + + } else { + if (ChangePathFieldEvent != null) + ChangePathFieldEvent (PreviousFolder, SelectedPlugin.PathExample, FieldState.Enabled); + } + + // TODO: previous server/folder doesn't work yet + + /* + if (!string.IsNullOrEmpty (PreviousServer) && SelectedPlugin.Address == null) { + if (ChangeAddressFieldEvent != null) { + ChangeAddressFieldEvent (this.previous_server, + SelectedPlugin.AddressExample, FieldState.Enabled); + } + } + + if (!string.IsNullOrEmpty (PreviousFolder) && SelectedPlugin.Path == null) { + if (ChangePathFieldEvent != null) { + ChangeAddressFieldEvent (this.previous_folder, + SelectedPlugin.PathExample, FieldState.Enabled); + } + } + */ + } + } + + + public enum FieldState { + Enabled, + Disabled } } diff --git a/data/plugins/Makefile.am b/data/plugins/Makefile.am index 646cf71b..d87282b9 100644 --- a/data/plugins/Makefile.am +++ b/data/plugins/Makefile.am @@ -6,7 +6,9 @@ dist_plugins_DATA = \ bitbucket.xml \ bitbucket.png \ gnome.xml \ - gnome.png + gnome.png \ + own-server.xml \ + own-server.png pluginsdir = $(pkgdatadir)/plugins/ diff --git a/data/plugins/own-server.png b/data/plugins/own-server.png new file mode 100644 index 0000000000000000000000000000000000000000..59044df87130db9c78fc964371bc401068b049c1 GIT binary patch literal 1363 zcmV-Z1+4msP)loC6000D6 zNkl;+PZNT-+AjB2E|7P3+vp z7>q;5X&^W@k&VMvPK8q1(w1|90%POU7WNhjw54Y#K?axi^K8Qym-+6CzR8vMN%Oq- zb>H`OJ@?ZsTmG*nH81sri+R}t#ifO~e6u3RG17hO6bjqU3TB z@(QJfJlZchxI`k^dLiq4SByeEp_ z)aew;{1z0gjZn2Ipj6AD(J7(Uwh$D2-KKAawp|5XhZ^l&T9_=8tW6L_kRmyO@rgS~ zOFzp4vA3>Wjm+$HWMrm+^r7_wQDv-E z58IVrAjR;=5O0+zg0H?lf<>2;3q3`Zu>Q`?&vMK^fX!xwl^iArQ@ATk^Yg(79~m$- zH1z3^kdWtNV%`bcw?9$;#gW6XI~I89tPSjK9O~m4-WNEX)_);edI2s<=v?|4us9U& zITmx1AZpjH-8SdqP6H|YF;#d#wl z!WJDJ{oW>l$zn>P&AyL5PT2VQ%um>N;1k&G3s9<>F*G~?74`kr$RG+XNvVRgM~dtr zf|OGy8L5xKJY_z*Ne~(NR_v=`;ohj|s6P%KI)J^2doW5PLaSGk|J%^ssU@50(AnLN z?w(E*mlXa@{^xCyf#Z&8KA?Pd+BjMe)1i;2;e~$3`$QISS*T0VeY}dU`v# zqu6_D+Kd6Cfm~$4#Kb7gBQKJU9TiXDbUC<1`}%vi4Rv}A9j0lhHA$H99pnIx#sbFflqXFoS3pIsgCw8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuU Va%Y?FJQ@H1002ovPDHLkV1grQZ+ZX# literal 0 HcmV?d00001 diff --git a/data/plugins/own-server.xml b/data/plugins/own-server.xml new file mode 100644 index 00000000..5c74d131 --- /dev/null +++ b/data/plugins/own-server.xml @@ -0,0 +1,20 @@ + + + + + On my own server + Everything under my control + own-server.png + Git + +
+ + domain name or IP address +
+ + + /path/to/project + +
+
+ diff --git a/data/plugins/redhat.xml b/data/plugins/redhat.xml new file mode 100644 index 00000000..b96493cb --- /dev/null +++ b/data/plugins/redhat.xml @@ -0,0 +1,20 @@ + + + + + Red Hat UX Team Hub + Internal server for the UX team + redhat.png + Git + +
+ ssh://git@design.bos.lab.redhat.com/ + +
+ + + /project + +
+
+