Update buttons on Multicolumn report options

Change the sensitivity of the multicolumn report options based on the
selection in the two tree views using the select callback.
This commit is contained in:
Robert Fewell 2018-08-10 11:36:41 +01:00
parent 847766fc13
commit 5ff8d8daba
2 changed files with 94 additions and 7 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="col_adjustment">
@ -95,9 +95,10 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button85">
<object class="GtkButton" id="add_button1">
<property name="label" translatable="yes">A_dd &gt;&gt;</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@ -110,9 +111,10 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button86">
<object class="GtkButton" id="remove_button1">
<property name="label" translatable="yes">&lt;&lt; _Remove</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@ -137,9 +139,10 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button87">
<object class="GtkButton" id="up_button1">
<property name="label" translatable="yes">Move _up</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@ -152,9 +155,10 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button88">
<object class="GtkButton" id="down_button1">
<property name="label" translatable="yes">Move dow_n</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@ -179,9 +183,10 @@
</packing>
</child>
<child>
<object class="GtkButton" id="button89">
<object class="GtkButton" id="size_button1">
<property name="label" translatable="yes">Si_ze...</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
@ -241,9 +246,11 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
<object class="GtkDialog" id="html_style_sheet_dialog">
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">HTML Style Sheets</property>
<property name="type_hint">dialog</property>
@ -416,6 +423,9 @@
<action-widgets>
<action-widget response="-7">closebutton1</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
<object class="GtkAdjustment" id="row_adjustment">
<property name="upper">100</property>
@ -573,6 +583,9 @@
<action-widget response="-6">cancelbutton</action-widget>
<action-widget response="-5">okbutton</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
<object class="GtkDialog" id="select_style_sheet_dialog">
<property name="can_focus">False</property>
@ -690,6 +703,9 @@
<action-widget response="2">delete_button</action-widget>
<action-widget response="-7">close_button</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
<object class="GtkListStore" id="template_liststore">
<columns>
@ -849,5 +865,8 @@
<action-widget response="-6">cancelbutton1</action-widget>
<action-widget response="-5">okbutton1</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
</interface>

View File

@ -67,6 +67,12 @@ struct gncp_column_view_edit
SCM available_list;
SCM contents_list;
int contents_selected;
GtkWidget *add_button;
GtkWidget *remove_button;
GtkWidget *up_button;
GtkWidget *down_button;
GtkWidget *size_button;
};
void gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data);
@ -227,6 +233,50 @@ update_contents_lists(gnc_column_view_edit * view)
}
}
static void
gnc_column_view_update_buttons_cb (GtkTreeSelection *selection,
gnc_column_view_edit *r)
{
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeSelection *available_selection;
/* compare selection to establish which treeview selected */
available_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(r->available));
/* available treeview */
if (available_selection == selection)
{
if (gtk_tree_selection_get_selected(selection, &model, &iter))
gtk_widget_set_sensitive (r->add_button, TRUE);
else
gtk_widget_set_sensitive (r->add_button, FALSE);
return;
}
/* contents treeview */
if (gtk_tree_selection_get_selected(selection, &model, &iter))
{
int len = scm_ilength (r->contents_list);
gtk_widget_set_sensitive (r->size_button, TRUE);
gtk_widget_set_sensitive (r->remove_button, TRUE);
if (len > 1)
{
gtk_widget_set_sensitive (r->up_button, TRUE);
gtk_widget_set_sensitive (r->down_button, TRUE);
}
}
else
{
gtk_widget_set_sensitive (r->up_button, FALSE);
gtk_widget_set_sensitive (r->down_button, FALSE);
gtk_widget_set_sensitive (r->size_button, FALSE);
gtk_widget_set_sensitive (r->remove_button, FALSE);
}
}
static void
gnc_column_view_edit_apply_cb(GNCOptionWin * w, gpointer user_data)
{
@ -278,6 +328,7 @@ gnc_column_view_edit_options(SCM options, SCM view)
GtkListStore *store;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeSelection *selection;
ptr = scm_call_1(get_editor, view);
if (ptr != SCM_BOOL_F)
@ -304,6 +355,13 @@ gnc_column_view_edit_options(SCM options, SCM view)
editor = GTK_WIDGET(gtk_builder_get_object (builder, "view_contents_table"));
r->available = GTK_TREE_VIEW (gtk_builder_get_object (builder, "available_view"));
r->contents = GTK_TREE_VIEW (gtk_builder_get_object (builder, "contents_view"));
r->add_button = GTK_WIDGET(gtk_builder_get_object (builder, "add_button1"));
r->remove_button = GTK_WIDGET(gtk_builder_get_object (builder, "remove_button1"));
r->up_button = GTK_WIDGET(gtk_builder_get_object (builder, "up_button1"));
r->down_button = GTK_WIDGET(gtk_builder_get_object (builder, "down_button1"));
r->size_button = GTK_WIDGET(gtk_builder_get_object (builder, "size_button1"));
r->options = options;
r->view = view;
r->available_list = SCM_EOL;
@ -335,6 +393,11 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->available, column);
/* use the selection cb to update buttons */
selection = gtk_tree_view_get_selection(r->available);
g_signal_connect(selection, "changed",
G_CALLBACK(gnc_column_view_update_buttons_cb), r);
/* Build the 'contents' view */
store = gtk_list_store_new (NUM_CONTENTS_COLS, G_TYPE_STRING, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
@ -359,6 +422,11 @@ gnc_column_view_edit_options(SCM options, SCM view)
NULL);
gtk_tree_view_append_column(r->contents, column);
/* use the selection cb to update buttons */
selection = gtk_tree_view_get_selection(r->contents);
g_signal_connect(selection, "changed",
G_CALLBACK(gnc_column_view_update_buttons_cb), r);
update_available_lists(r);
update_contents_lists(r);