[latexila] Build Tools preferences: buttons's sensitivity
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] Build Tools preferences: buttons's sensitivity
- Date: Sat, 7 Jul 2012 03:49:06 +0000 (UTC)
commit c9fbe802b4cfcf04739e194008ea0cda8ebcc3fa
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Sat Jul 7 05:48:29 2012 +0200
Build Tools preferences: buttons's sensitivity
src/build_tools_preferences.vala | 76 ++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/src/build_tools_preferences.vala b/src/build_tools_preferences.vala
index 6ff2334..9b82d91 100644
--- a/src/build_tools_preferences.vala
+++ b/src/build_tools_preferences.vala
@@ -159,6 +159,8 @@ public class BuildToolsPreferences : Grid
properties_button.set_icon_name ("document-properties-symbolic");
properties_button.set_tooltip_text ("Edit the properties");
+ set_sensitivity_on_selection (properties_button);
+
properties_button.clicked.connect (() =>
{
int num = Utils.get_selected_row (_tree_view);
@@ -175,6 +177,8 @@ public class BuildToolsPreferences : Grid
copy_button.set_icon_name ("edit-copy-symbolic");
copy_button.set_tooltip_text ("Create a copy");
+ set_sensitivity_on_selection (copy_button);
+
copy_button.clicked.connect (() =>
{
int selected_row = Utils.get_selected_row (_tree_view);
@@ -215,6 +219,8 @@ public class BuildToolsPreferences : Grid
remove_button.set_icon_name ("list-remove-symbolic");
remove_button.set_tooltip_text (_("Remove"));
+ set_sensitivity_on_selection (remove_button);
+
remove_button.clicked.connect (() =>
{
TreeIter iter;
@@ -255,6 +261,29 @@ public class BuildToolsPreferences : Grid
up_button.set_icon_name ("go-up-symbolic");
up_button.set_tooltip_text (_("Move up"));
+ /* Sensitivity */
+
+ up_button.set_sensitive (false);
+
+ unowned TreeSelection select = _tree_view.get_selection ();
+ select.changed.connect (() =>
+ {
+ List<TreePath> selected_rows = select.get_selected_rows (null);
+
+ if (selected_rows.length () == 0)
+ {
+ up_button.set_sensitive (false);
+ return;
+ }
+
+ TreePath path_selected = selected_rows.nth_data (0);
+ int row_num = path_selected.get_indices ()[0];
+
+ up_button.set_sensitive (row_num > 0);
+ });
+
+ /* Behavior */
+
up_button.clicked.connect (() =>
{
TreeIter iter_selected;
@@ -269,6 +298,9 @@ public class BuildToolsPreferences : Grid
{
_list_store.swap (iter_selected, iter_up);
BuildTools.get_default ().move_up (selected_row);
+
+ // Force the 'changed' signal on the selection to be emitted
+ select.changed ();
}
}
});
@@ -282,6 +314,32 @@ public class BuildToolsPreferences : Grid
down_button.set_icon_name ("go-down-symbolic");
down_button.set_tooltip_text (_("Move down"));
+ /* Sensitivity */
+
+ down_button.set_sensitive (false);
+
+ unowned TreeSelection select = _tree_view.get_selection ();
+ select.changed.connect (() =>
+ {
+ List<TreePath> selected_rows = select.get_selected_rows (null);
+
+ if (selected_rows.length () == 0)
+ {
+ down_button.set_sensitive (false);
+ return;
+ }
+
+ TreePath path_selected = selected_rows.nth_data (0);
+ int row_num = path_selected.get_indices ()[0];
+
+ TreeModel model = _list_store as TreeModel;
+ int nb_rows = model.iter_n_children (null);
+
+ down_button.set_sensitive (row_num < nb_rows - 1);
+ });
+
+ /* Behavior */
+
down_button.clicked.connect (() =>
{
TreeIter iter_selected;
@@ -296,6 +354,9 @@ public class BuildToolsPreferences : Grid
{
_list_store.swap (iter_selected, iter_down);
BuildTools.get_default ().move_down (selected_row);
+
+ // Force the 'changed' signal on the selection to be emitted
+ select.changed ();
}
}
});
@@ -357,4 +418,19 @@ public class BuildToolsPreferences : Grid
if (accepted)
update_list_store ();
}
+
+ // Set 'widget' as sensitive when there is a selection in the TreeView.
+ // If no elements are selected (this is the case by default),
+ // the widget is insensitive.
+ private void set_sensitivity_on_selection (Widget widget)
+ {
+ widget.set_sensitive (false);
+
+ unowned TreeSelection select = _tree_view.get_selection ();
+ select.changed.connect (() =>
+ {
+ bool row_selected = select.count_selected_rows () > 0;
+ widget.set_sensitive (row_selected);
+ });
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]