Add Log Saving

This commit is contained in:
TheBrokenRail 2022-09-30 23:12:13 -04:00
parent 27cd9e88a7
commit 0016f68829
5 changed files with 101 additions and 17 deletions

View File

@ -103,8 +103,9 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
if (data->extra_label) {
gint i = 0;
while (data->extra_label[i] != NULL) {
gtk_dialog_add_button (
GTK_DIALOG (dialog), data->extra_label[i], i);
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
i++;
}
}
@ -227,8 +228,10 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) {
default:
if (zen_data->extra_label &&
response < g_strv_length (zen_data->extra_label))
printf ("%s\n", zen_data->extra_label[response]);
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}

View File

@ -176,11 +176,14 @@ 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) {
gtk_dialog_add_button (
GTK_DIALOG (dialog), data->extra_label[i], i);
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
i++;
}
}
@ -217,6 +220,56 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) {
gtk_main ();
}
static void
zenity_save (GtkWidget *widget, GtkWindow *parent_window) {
GtkFileChooserNative *dialog;
GtkFileChooser *chooser;
GtkFileFilter *filter;
gint res;
dialog = gtk_file_chooser_native_new ("Save File",
parent_window,
GTK_FILE_CHOOSER_ACTION_SAVE,
"Cancel",
"Save");
chooser = GTK_FILE_CHOOSER (dialog);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Log Files");
gtk_file_filter_add_pattern (filter, "*.log");
gtk_file_chooser_add_filter (chooser, filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "All Files");
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (chooser, filter);
gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
gtk_file_chooser_set_current_name (
chooser, "minecraft-pi-reborn-crash.log");
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT) {
char *filename;
GtkTextBuffer *buffer;
GtkTextIter start;
GtkTextIter end;
char *text;
filename = gtk_file_chooser_get_filename (chooser);
buffer = GTK_TEXT_BUFFER (
g_object_get_data (G_OBJECT (widget), "text_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);
gtk_text_buffer_set_modified (buffer, FALSE);
g_file_set_contents (filename, text, -1, NULL);
g_free (filename);
}
g_object_unref (dialog);
}
static void
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) {
ZenityData *zen_data = data;
@ -230,10 +283,16 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) {
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
case ZENITY_SAVE_BUTTON:
zenity_save (widget, GTK_WINDOW (gtk_widget_get_toplevel (widget)));
break;
default:
if (zen_data->extra_label &&
response < g_strv_length (zen_data->extra_label))
printf ("%s\n", zen_data->extra_label[response]);
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
zenity_util_exit_code_with_data (ZENITY_ESC, zen_data);
break;
}

View File

@ -415,8 +415,9 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
if (data->extra_label) {
gint i = 0;
while (data->extra_label[i] != NULL) {
gtk_dialog_add_button (
GTK_DIALOG (dialog), data->extra_label[i], i);
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
i++;
}
}
@ -785,8 +786,10 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) {
default:
if (zen_data->extra_label &&
response < g_strv_length (zen_data->extra_label))
printf ("%s\n", zen_data->extra_label[response]);
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}

View File

@ -18,12 +18,14 @@ typedef struct {
} ZenityData;
typedef enum {
ZENITY_OK,
ZENITY_OK = 0,
ZENITY_CANCEL,
ZENITY_ESC,
ZENITY_ERROR,
ZENITY_EXTRA,
ZENITY_TIMEOUT
ZENITY_TIMEOUT,
ZENITY_SAVE_BUTTON,
ZENITY_EXIT_CODE_LAST
} ZenityExitCode;
typedef struct {

View File

@ -72,7 +72,7 @@
<object class="GtkLabel" id="zenity_entry_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">_Enter new text:</property>
<property name="label">Enter new text:</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
</object>
@ -237,11 +237,27 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="zenity_text_save_button">
<property name="label">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="image_position">right</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="zenity_text_close_button">
<property name="label">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="image_position">right</property>
@ -250,7 +266,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
</object>
@ -276,7 +292,7 @@
<object class="GtkLabel" id="zenity_text_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">_Text information:</property>
<property name="label">Text information:</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
</object>
@ -340,6 +356,7 @@
</child>
<action-widgets>
<action-widget response="-7">zenity_text_close_button</action-widget>
<action-widget response="6">zenity_text_save_button</action-widget>
</action-widgets>
</object>
</interface>