From c9ff7f17aa81d9d1566d426c87a184831ce4f7d9 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 6 Oct 2022 23:12:30 -0400 Subject: [PATCH] Move Code Around --- src/main.c | 2 +- src/option.c | 12 ++++++++++++ src/text.c | 11 +++++------ src/zenity.h | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index b49a28b..401ede5 100644 --- a/src/main.c +++ b/src/main.c @@ -35,7 +35,7 @@ gint main (gint argc, gchar **argv) { ZenityParsingOptions *results; - gint retval; + gint retval; #ifdef HAVE_LOCALE_H setlocale (LC_ALL, ""); diff --git a/src/option.c b/src/option.c index 9e82da7..7ef7238 100644 --- a/src/option.c +++ b/src/option.c @@ -64,6 +64,7 @@ static gboolean zenity_list_mid_search; /* Text Dialog Options */ static gboolean zenity_text_active; static gchar *zenity_text_font; +static gchar *zenity_text_save_filename; static GOptionEntry general_options[] = {{"title", '\0', @@ -292,6 +293,13 @@ static GOptionEntry text_options[] = {{"text-info", &zenity_general_dialog_no_wrap, "Do not enable text wrapping", NULL}, + {"save-filename", + '\0', + 0, + G_OPTION_ARG_STRING, + &zenity_text_save_filename, + "Set the initial filename for text save dialog", + "TEXT"}, {NULL}}; static ZenityParsingOptions *results; @@ -338,6 +346,8 @@ zenity_option_free (void) { if (zenity_text_font) g_free (zenity_text_font); + if (zenity_text_save_filename) + g_free (zenity_text_save_filename); g_option_context_free (ctx); } @@ -426,6 +436,7 @@ zenity_text_pre_callback (GOptionContext *context, GOptionGroup *group, gpointer data, GError **error) { zenity_text_active = FALSE; zenity_text_font = NULL; + zenity_text_save_filename = NULL; return TRUE; } @@ -561,6 +572,7 @@ zenity_text_post_callback (GOptionContext *context, GOptionGroup *group, results->text_data->uri = zenity_general_uri; results->text_data->no_wrap = zenity_general_dialog_no_wrap; results->text_data->font = zenity_text_font; + results->text_data->save_filename = zenity_text_save_filename; } else { if (zenity_text_font) zenity_option_error ( diff --git a/src/text.c b/src/text.c index 9644878..d3eb9ab 100644 --- a/src/text.c +++ b/src/text.c @@ -174,8 +174,6 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) { } else zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW (text_view)); - g_object_set_data (G_OBJECT (dialog), "text_buffer", text_buffer); - if (data->extra_label) { gint i = 0; while (data->extra_label[i] != NULL) { @@ -243,8 +241,10 @@ zenity_save (GtkWidget *widget, GtkWindow *parent_window) { gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE); - gtk_file_chooser_set_current_name ( - chooser, "minecraft-pi-reborn-crash.log"); + if (zen_text_data->save_filename) { + gtk_file_chooser_set_current_name ( + chooser, zen_text_data->save_filename); + } res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)); if (res == GTK_RESPONSE_ACCEPT) { @@ -255,8 +255,7 @@ zenity_save (GtkWidget *widget, GtkWindow *parent_window) { char *text; filename = gtk_file_chooser_get_filename (chooser); - buffer = GTK_TEXT_BUFFER ( - g_object_get_data (G_OBJECT (widget), "text_buffer")); + buffer = zen_text_data->buffer; gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_end_iter (buffer, &end); text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); diff --git a/src/zenity.h b/src/zenity.h index 2e8f99c..7827529 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -41,6 +41,7 @@ typedef struct { gchar *uri; gboolean no_wrap; gchar *font; + gchar *save_filename; GtkTextBuffer *buffer; } ZenityTextData;