Remove triplicate versions of gnc_input_dialog

This commit is contained in:
jean 2021-10-05 20:51:23 -07:00
parent e95c694576
commit da8bc64e93
5 changed files with 65 additions and 200 deletions

View File

@ -315,3 +315,65 @@ gnc_choose_radio_option_dialog(GtkWidget *parent,
return radio_result;
}
/********************************************************************\
* gnc_input_dialog *
* simple convenience dialog to get a single value from the user *
* user may choose between "Ok" and "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent window or NULL *
* title - the title of the dialog *
* msg - the message to display *
* default_input - will be displayed as default input *
* Return: the input (text) the user entered, if pressed "Ok" *
* NULL, if pressed "Cancel" *
\********************************************************************/
gchar *
gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
{
GtkWidget *dialog, *label, *content_area;
gint result;
GtkWidget *view;
GtkTextBuffer *buffer;
gchar *user_input = NULL;
GtkTextIter start, end;
/* Create the widgets */
dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("_OK"), GTK_RESPONSE_ACCEPT,
_("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
// add a label
label = gtk_label_new (msg);
gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0);
// add a textview
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_set_text (buffer, default_input, -1);
gtk_box_pack_start(GTK_BOX(content_area), view, TRUE, TRUE, 0);
// run the dialog
gtk_widget_show_all (dialog);
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_REJECT)
user_input = 0;
else
{
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
user_input = gtk_text_buffer_get_text (buffer,
&start, &end, FALSE);
}
gtk_widget_destroy (dialog);
return user_input;
}

View File

@ -104,6 +104,8 @@ extern void
gnc_error_dialog (GtkWindow *parent,
const char *format, ...) G_GNUC_PRINTF (2, 3);
extern gchar *
gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
extern void
gnc_gnome_help (GtkWindow *parent, const char *file_name, const char *target_link);

View File

@ -75,7 +75,6 @@ void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data);
void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data);
// utils
static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
static void gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg);
#define UNUSED_VAR __attribute__ ((unused))
@ -392,70 +391,6 @@ void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data)
}
/********************************************************************\
* gnc_input_dialog *
* simple convenience dialog to get a single value from the user *
* user may choose between "Ok" and "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent window or NULL *
* title - the title of the dialog *
* msg - the message to display *
* default_input - will be displayed as default input *
* Return: the input (text) the user entered, if pressed "Ok" *
* NULL, if pressed "Cancel" *
\********************************************************************/
static gchar *
gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
{
GtkWidget *dialog, *label, *content_area;
gint result;
GtkWidget *view;
GtkTextBuffer *buffer;
gchar *user_input = NULL;
GtkTextIter start, end;
/* Create the widgets */
dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("_OK"), GTK_RESPONSE_ACCEPT,
_("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
// add a label
label = gtk_label_new (msg);
gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0);
// add a textview
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_set_text (buffer, default_input, -1);
gtk_box_pack_start(GTK_BOX(content_area), view, TRUE, TRUE, 0);
// run the dialog
gtk_widget_show_all (dialog);
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_REJECT)
user_input = 0;
else
{
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
user_input = gtk_text_buffer_get_text (buffer,
&start, &end, FALSE);
}
gtk_widget_destroy (dialog);
return user_input;
}
/********************************************************************\
* gnc_info2_dialog *
* displays an information dialog box (with scrollable text area) *
@ -503,3 +438,4 @@ gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg)
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}

View File

@ -65,8 +65,6 @@ void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data );
void csv_import_file_chooser_file_activated_cb (GtkFileChooser *chooser, CsvImportInfo *info);
void csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info);
static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
static const gchar *finish_tree_string = N_(
"The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
"You can verify your selections by clicking on 'Back' or 'Cancel' to Abort Import.\n");
@ -346,74 +344,6 @@ void load_settings (CsvImportInfo *info)
/* =============================================================== */
/********************************************************************\
* gnc_input_dialog *
* simple convenience dialog to get a single value from the user *
* user may choose between "Ok" and "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent window or NULL *
* title - the title of the dialog *
* msg - the message to display *
* default_input - will be displayed as default input *
* Return: the input (text) the user entered, if pressed "Ok" *
* NULL, if pressed "Cancel" *
\********************************************************************/
static gchar *
gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
{
GtkWidget *dialog, *label, *content_area;
gint result;
GtkWidget *view;
GtkTextBuffer *buffer;
gchar *user_input;
GtkTextIter start, end;
/* Create the widgets */
dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW(parent),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("_OK"), GTK_RESPONSE_ACCEPT,
_("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG(dialog));
// add a label
label = gtk_label_new (msg);
gtk_container_add (GTK_CONTAINER(content_area), label);
// add a textview
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(view), GTK_WRAP_WORD_CHAR);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(view));
gtk_text_buffer_set_text (buffer, default_input, -1);
gtk_container_add (GTK_CONTAINER(content_area), view);
// run the dialog
gtk_widget_show_all (dialog);
result = gtk_dialog_run (GTK_DIALOG(dialog));
if (result == GTK_RESPONSE_REJECT)
user_input = 0;
else
{
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
user_input = gtk_text_buffer_get_text (buffer,
&start, &end, FALSE);
}
gtk_widget_destroy (dialog);
return user_input;
}
/* =============================================================== */
/*******************************************************
* Assistant page prepare functions
*******************************************************/

View File

@ -69,7 +69,6 @@ void gnc_customer_import_gui_option5_cb (GtkWidget *widget, gpointer data);
void gnc_customer_import_gui_type_cb (GtkWidget *widget, gpointer data);
// utils
static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
static void gnc_info2_dialog (GtkWidget *parent, const gchar *title, const gchar *msg);
@ -354,70 +353,6 @@ void gnc_customer_import_gui_type_cb (GtkWidget *widget, gpointer data)
}
/********************************************************************\
* gnc_input_dialog *
* simple convenience dialog to get a single value from the user *
* user may choose between "Ok" and "Cancel" *
* *
* NOTE: This function does not return until the dialog is closed *
* *
* Args: parent - the parent window or NULL *
* title - the title of the dialog *
* msg - the message to display *
* default_input - will be displayed as default input *
* Return: the input (text) the user entered, if pressed "Ok" *
* NULL, if pressed "Cancel" *
\********************************************************************/
static gchar *
gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input)
{
GtkWidget *dialog, *label, *content_area;
gint result;
GtkWidget *view;
GtkTextBuffer *buffer;
gchar *user_input;
GtkTextIter start, end;
/* Create the widgets */
dialog = gtk_dialog_new_with_buttons (title, GTK_WINDOW (parent),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
_("_OK"), GTK_RESPONSE_ACCEPT,
_("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
// add a label
label = gtk_label_new (msg);
gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0);
// add a textview
view = gtk_text_view_new ();
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD_CHAR);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_set_text (buffer, default_input, -1);
gtk_box_pack_start(GTK_BOX(content_area), view, TRUE, TRUE, 0);
// run the dialog
gtk_widget_show_all (dialog);
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_REJECT)
user_input = 0;
else
{
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
user_input = gtk_text_buffer_get_text (buffer,
&start, &end, FALSE);
}
gtk_widget_destroy (dialog);
return user_input;
}
/********************************************************************\
* gnc_info2_dialog *
* displays an information dialog box (with scrollable text area) *