Clean up some omitted type-forcing in set_option_from_ui_type() instances.

This commit is contained in:
John Ralls 2020-04-04 17:49:34 -07:00
parent 245a8fccc7
commit 6491c98563
4 changed files with 38 additions and 53 deletions

View File

@ -971,7 +971,7 @@ public:
void set_option_from_ui_item(GncOption& option) noexcept override void set_option_from_ui_item(GncOption& option) noexcept override
{ {
auto widget{GTK_ENTRY(get_widget())}; auto widget{GTK_ENTRY(get_widget())};
option.set_value(gtk_entry_get_text(widget)); option.set_value(std::string{gtk_entry_get_text(widget)});
} }
}; };
@ -2091,7 +2091,7 @@ public:
} }
void set_option_from_ui_item(GncOption& option) noexcept override void set_option_from_ui_item(GncOption& option) noexcept override
{ {
option.set_value(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget()))); option.set_value<double>(gtk_spin_button_get_value(GTK_SPIN_BUTTON(get_widget())));
} }
}; };
@ -2217,13 +2217,14 @@ public:
void set_ui_item_from_option(GncOption& option) noexcept override void set_ui_item_from_option(GncOption& option) noexcept override
{ {
GtkFontButton *font_button = GTK_FONT_BUTTON(get_widget()); GtkFontButton *font_button = GTK_FONT_BUTTON(get_widget());
gtk_font_button_set_font_name(font_button, option.get_value<std::string>().c_str()); gtk_font_button_set_font_name(font_button,
option.get_value<std::string>().c_str());
} }
void set_option_from_ui_item(GncOption& option) noexcept override void set_option_from_ui_item(GncOption& option) noexcept override
{ {
GtkFontButton *font_button = GTK_FONT_BUTTON(get_widget()); GtkFontButton *font_button = GTK_FONT_BUTTON(get_widget());
option.set_value(gtk_font_button_get_font_name(font_button)); option.set_value(std::string{gtk_font_button_get_font_name(font_button)});
} }
}; };
@ -2727,7 +2728,7 @@ create_option_widget<GncOptionUIType::BUDGET> (GncOption& option,
GtkGrid *page_box, GtkGrid *page_box,
GtkLabel *name_label, GtkLabel *name_label,
char *documentation, char *documentation,
/* Return values */ /* Return values */
GtkWidget **enclosing, GtkWidget **enclosing,
bool *packed) bool *packed)
{ {

View File

@ -60,12 +60,11 @@ struct gncp_column_view_edit
GtkTreeView * available; GtkTreeView * available;
GtkTreeView * contents; GtkTreeView * contents;
SCM options;
SCM view; SCM view;
GNCOptionDB * odb; GncOptionDB * odb;
SCM available_list; SCM available_list;
SCM contents_list; GList* contents_list;
int contents_selected; int contents_selected;
GtkWidget *add_button; GtkWidget *add_button;
@ -82,26 +81,16 @@ void gnc_edit_column_view_move_down_cb(GtkButton * button, gpointer user_data);
void gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data); void gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data);
static void static void
gnc_column_view_set_option(GNCOptionDB * odb, char * section, char * name, gnc_column_view_set_option(GncOptionDB * odb, char * section, char * name,
SCM new_value) GList* new_value)
{ {
GNCOption * option = gnc_option_db_set_glist_value(section, name, new_value);
gnc_option_db_get_option_by_name(odb, section, name);
if (option)
{
gnc_option_db_set_option(odb, section, name, new_value);
/* set_option doesn't do this */
gnc_option_set_changed (option, TRUE);
}
} }
static void static void
gnc_column_view_edit_destroy(gnc_column_view_edit * view) gnc_column_view_edit_destroy(gnc_column_view_edit * view)
{ {
gnc_options_dialog_destroy(view->optwin); gnc_options_dialog_destroy(view->optwin);
scm_gc_unprotect_object(view->options);
scm_gc_unprotect_object(view->view); scm_gc_unprotect_object(view->view);
gnc_option_db_destroy(view->odb); gnc_option_db_destroy(view->odb);
g_free(view); g_free(view);
@ -175,12 +164,11 @@ static void
update_contents_lists(gnc_column_view_edit * view) update_contents_lists(gnc_column_view_edit * view)
{ {
SCM report_menu_name = scm_c_eval_string("gnc:report-menu-name"); SCM report_menu_name = scm_c_eval_string("gnc:report-menu-name");
SCM contents = GList* contents = gnc_option_db_lookup_glist_option(view->odb,
gnc_option_db_lookup_option(view->odb, "__general", "report-list", "__general",
SCM_BOOL_F); "report-list");
SCM this_report; SCM this_report;
SCM selection; gchar* selection;
gchar *name;
GtkListStore *store; GtkListStore *store;
GtkTreeIter iter; GtkTreeIter iter;
@ -189,41 +177,38 @@ update_contents_lists(gnc_column_view_edit * view)
/* Update the list of selected reports (right selection box). */ /* Update the list of selected reports (right selection box). */
tree_selection = gtk_tree_view_get_selection(view->contents); tree_selection = gtk_tree_view_get_selection(view->contents);
if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list)) if (g_list_length(contents))
{ {
int row = view->contents_selected; int row = view->contents_selected;
row = MIN (row, scm_ilength (view->contents_list) - 1); row = MIN (row, g_list_length(view->contents_list) - 1);
selection = scm_list_ref (view->contents_list, scm_from_int (row)); selection = g_list_nth_value(view->contents_list, row);
} }
else else
selection = SCM_UNDEFINED; selection = NULL;
scm_gc_unprotect_object(view->contents_list);
view->contents_list = contents; view->contents_list = contents;
scm_gc_protect_object(view->contents_list);
store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents)); store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents));
gtk_list_store_clear(store); gtk_list_store_clear(store);
if (scm_is_list(contents)) for (GList* node = contents; node; g_list_next(node))
{ {
for (int i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++) gchar *name;
{ SCM contents_temp = SCM_CAR(node);
SCM contents_temp = SCM_CAR(contents); int id = scm_to_int(SCM_CAAR(node));
int id = scm_to_int(SCM_CAAR(contents)); this_report = gnc_report_find(id);
name = gnc_scm_to_utf8_string (scm_call_1(report_menu_name, this_report));
this_report = gnc_report_find(id); gtk_list_store_append(store, &iter);
name = gnc_scm_to_utf8_string (scm_call_1(report_menu_name, this_report)); gtk_list_store_set (store, &iter,
CONTENTS_COL_NAME, _(name),
gtk_list_store_append(store, &iter); CONTENTS_COL_ROW, i,
gtk_list_store_set CONTENTS_COL_REPORT_COLS,
(store, &iter, scm_to_int(SCM_CADR(contents_temp)),
CONTENTS_COL_NAME, _(name), CONTENTS_COL_REPORT_ROWS,
CONTENTS_COL_ROW, i, scm_to_int(SCM_CADDR(contents_temp)),
CONTENTS_COL_REPORT_COLS, scm_to_int(SCM_CADR(contents_temp)), -1);
CONTENTS_COL_REPORT_ROWS, scm_to_int(SCM_CADDR(contents_temp)),
-1);
if (scm_is_equal (contents_temp, selection)) if (scm_is_equal (contents_temp, selection))
gtk_tree_selection_select_iter (tree_selection, &iter); gtk_tree_selection_select_iter (tree_selection, &iter);
@ -324,7 +309,7 @@ gnc_column_view_edit_close_cb(GNCOptionWin * win, gpointer user_data)
********************************************************************/ ********************************************************************/
GtkWidget * GtkWidget *
gnc_column_view_edit_options(SCM options, SCM view) gnc_column_view_edit_options(GncOptionDB* odb, SCM view)
{ {
SCM get_editor = scm_c_eval_string("gnc:report-editor-widget"); SCM get_editor = scm_c_eval_string("gnc:report-editor-widget");
SCM ptr; SCM ptr;
@ -366,12 +351,11 @@ gnc_column_view_edit_options(SCM options, SCM view)
r->down_button = GTK_WIDGET(gtk_builder_get_object (builder, "down_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->size_button = GTK_WIDGET(gtk_builder_get_object (builder, "size_button1"));
r->options = options;
r->view = view; r->view = view;
r->available_list = SCM_EOL; r->available_list = SCM_EOL;
r->contents_selected = 0; r->contents_selected = 0;
r->contents_list = SCM_EOL; r->contents_list = SCM_EOL;
r->odb = gnc_option_db_new(r->options); r->odb = odb;
gnc_options_dialog_build_contents(r->optwin, r->odb); gnc_options_dialog_build_contents(r->optwin, r->odb);
@ -380,7 +364,6 @@ gnc_column_view_edit_options(SCM options, SCM view)
editor, editor,
gtk_label_new(_("Contents"))); gtk_label_new(_("Contents")));
scm_gc_protect_object(r->options);
scm_gc_protect_object(r->view); scm_gc_protect_object(r->view);
scm_gc_protect_object(r->available_list); scm_gc_protect_object(r->available_list);
scm_gc_protect_object(r->contents_list); scm_gc_protect_object(r->contents_list);

View File

@ -28,6 +28,6 @@
typedef struct gncp_column_view_edit gnc_column_view_edit; typedef struct gncp_column_view_edit gnc_column_view_edit;
GtkWidget * gnc_column_view_edit_options(SCM options, SCM view); GtkWidget * gnc_column_view_edit_options(GncOptionDB* odb, SCM view);
#endif #endif

View File

@ -53,6 +53,7 @@ enum GncOptionUIType
INVOICE, INVOICE,
TAX_TABLE, TAX_TABLE,
QUERY, QUERY,
REPORT_LIST,
MAX_VALUE, //Nake sure this one is always last MAX_VALUE, //Nake sure this one is always last
}; };