[latexila] Build tools prefs: select only one row in the two treeviews



commit 4493847a6a02f01c48cdfb160aeb947120b8b9ba
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Tue Jul 17 22:13:00 2012 +0200

    Build tools prefs: select only one row in the two treeviews

 src/build_tools_preferences.vala |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/src/build_tools_preferences.vala b/src/build_tools_preferences.vala
index 10d7077..cf343f2 100644
--- a/src/build_tools_preferences.vala
+++ b/src/build_tools_preferences.vala
@@ -48,11 +48,7 @@ public class BuildToolsPreferences : GLib.Object
         update_default_store ();
         update_personal_store ();
 
-        _default_view = get_new_view (_default_store,
-            DefaultBuildTools.get_default ());
-
-        _personal_view = get_new_view (_personal_store,
-            PersonalBuildTools.get_default ());
+        init_views ();
 
         _dialog = new Dialog.with_buttons (_("Build Tools"), main_window,
             DialogFlags.DESTROY_WITH_PARENT,
@@ -73,6 +69,30 @@ public class BuildToolsPreferences : GLib.Object
         _dialog.destroy ();
     }
 
+    private void init_views ()
+    {
+        _default_view = get_new_view (_default_store,
+            DefaultBuildTools.get_default ());
+
+        _personal_view = get_new_view (_personal_store,
+            PersonalBuildTools.get_default ());
+
+        // Only one item of the two views can be selected at once.
+
+        TreeSelection default_select = _default_view.get_selection ();
+        TreeSelection personal_select = _personal_view.get_selection ();
+
+        default_select.changed.connect (() =>
+        {
+            on_view_selection_changed (default_select, personal_select);
+        });
+
+        personal_select.changed.connect (() =>
+        {
+            on_view_selection_changed (personal_select, default_select);
+        });
+    }
+
     private Grid get_default_grid ()
     {
         BuildTools default_build_tools = DefaultBuildTools.get_default ();
@@ -207,6 +227,14 @@ public class BuildToolsPreferences : GLib.Object
         return view;
     }
 
+    private void on_view_selection_changed (TreeSelection select,
+        TreeSelection other_select)
+    {
+        List<TreePath> selected_items = select.get_selected_rows (null);
+        if (selected_items.length () > 0)
+            other_select.unselect_all ();
+    }
+
     private ToolButton get_properties_button (TreeView view, BuildTools build_tools)
     {
         ToolButton properties_button = new ToolButton (null, null);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]