Move Code Around

This commit is contained in:
TheBrokenRail 2022-10-06 23:12:30 -04:00
parent 58787016ce
commit c9ff7f17aa
4 changed files with 19 additions and 7 deletions

View File

@ -64,6 +64,7 @@ static gboolean zenity_list_mid_search;
/* Text Dialog Options */ /* Text Dialog Options */
static gboolean zenity_text_active; static gboolean zenity_text_active;
static gchar *zenity_text_font; static gchar *zenity_text_font;
static gchar *zenity_text_save_filename;
static GOptionEntry general_options[] = {{"title", static GOptionEntry general_options[] = {{"title",
'\0', '\0',
@ -292,6 +293,13 @@ static GOptionEntry text_options[] = {{"text-info",
&zenity_general_dialog_no_wrap, &zenity_general_dialog_no_wrap,
"Do not enable text wrapping", "Do not enable text wrapping",
NULL}, NULL},
{"save-filename",
'\0',
0,
G_OPTION_ARG_STRING,
&zenity_text_save_filename,
"Set the initial filename for text save dialog",
"TEXT"},
{NULL}}; {NULL}};
static ZenityParsingOptions *results; static ZenityParsingOptions *results;
@ -338,6 +346,8 @@ zenity_option_free (void) {
if (zenity_text_font) if (zenity_text_font)
g_free (zenity_text_font); g_free (zenity_text_font);
if (zenity_text_save_filename)
g_free (zenity_text_save_filename);
g_option_context_free (ctx); g_option_context_free (ctx);
} }
@ -426,6 +436,7 @@ zenity_text_pre_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) { gpointer data, GError **error) {
zenity_text_active = FALSE; zenity_text_active = FALSE;
zenity_text_font = NULL; zenity_text_font = NULL;
zenity_text_save_filename = NULL;
return TRUE; return TRUE;
} }
@ -561,6 +572,7 @@ zenity_text_post_callback (GOptionContext *context, GOptionGroup *group,
results->text_data->uri = zenity_general_uri; results->text_data->uri = zenity_general_uri;
results->text_data->no_wrap = zenity_general_dialog_no_wrap; results->text_data->no_wrap = zenity_general_dialog_no_wrap;
results->text_data->font = zenity_text_font; results->text_data->font = zenity_text_font;
results->text_data->save_filename = zenity_text_save_filename;
} else { } else {
if (zenity_text_font) if (zenity_text_font)
zenity_option_error ( zenity_option_error (

View File

@ -174,8 +174,6 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) {
} else } else
zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW (text_view)); 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) { if (data->extra_label) {
gint i = 0; gint i = 0;
while (data->extra_label[i] != NULL) { 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_do_overwrite_confirmation (chooser, TRUE);
if (zen_text_data->save_filename) {
gtk_file_chooser_set_current_name ( gtk_file_chooser_set_current_name (
chooser, "minecraft-pi-reborn-crash.log"); chooser, zen_text_data->save_filename);
}
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)); res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT) { if (res == GTK_RESPONSE_ACCEPT) {
@ -255,8 +255,7 @@ zenity_save (GtkWidget *widget, GtkWindow *parent_window) {
char *text; char *text;
filename = gtk_file_chooser_get_filename (chooser); filename = gtk_file_chooser_get_filename (chooser);
buffer = GTK_TEXT_BUFFER ( buffer = zen_text_data->buffer;
g_object_get_data (G_OBJECT (widget), "text_buffer"));
gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end); gtk_text_buffer_get_end_iter (buffer, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

View File

@ -41,6 +41,7 @@ typedef struct {
gchar *uri; gchar *uri;
gboolean no_wrap; gboolean no_wrap;
gchar *font; gchar *font;
gchar *save_filename;
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
} ZenityTextData; } ZenityTextData;