Commit 63f1469f2310f1362b4eb3616c4ed841b676c735
1 parent
7a750bff
Exists in
master
and in
1 other branch
Fixing bugs on the new save dialog.
Showing
1 changed file
with
64 additions
and
38 deletions
Show diff stats
src/dialogs/save/save.c
@@ -101,19 +101,16 @@ | @@ -101,19 +101,16 @@ | ||
101 | } | 101 | } |
102 | 102 | ||
103 | /* | 103 | /* |
104 | - static GtkFileChooserConfirmation confirm_overwrite(GtkFileChooser *chooser, GObject *action) | 104 | + static GtkFileChooserConfirmation confirm_overwrite(GtkFileChooser *chooser, V3270SaveDialog G_GNUC_UNUSED(*widget)) |
105 | { | 105 | { |
106 | - const gchar * attr = g_object_get_data(action,"overwrite"); | ||
107 | - GtkFileChooserConfirmation ret = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; | ||
108 | - GtkWidget * dialog; | 106 | + GtkFileChooserConfirmation ret = GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME; |
109 | 107 | ||
110 | - if(attr && !g_ascii_strcasecmp(attr,"yes")) | ||
111 | - return ret; | ||
112 | - | ||
113 | - dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(chooser), | ||
114 | - GTK_DIALOG_DESTROY_WITH_PARENT, | ||
115 | - GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL, | ||
116 | - "%s",_("The file already exists. Replace it?")); | 108 | + GtkWidget * dialog = gtk_message_dialog_new_with_markup( |
109 | + GTK_WINDOW(chooser), | ||
110 | + GTK_DIALOG_DESTROY_WITH_PARENT, | ||
111 | + GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL, | ||
112 | + "%s",_("The file already exists. Replace it?") | ||
113 | + ); | ||
117 | 114 | ||
118 | 115 | ||
119 | if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) | 116 | if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) |
@@ -127,37 +124,44 @@ | @@ -127,37 +124,44 @@ | ||
127 | */ | 124 | */ |
128 | 125 | ||
129 | #ifdef WIN32 | 126 | #ifdef WIN32 |
130 | -static void select_local_file(GtkButton G_GNUC_UNUSED(*button), v3270ft *dialog) { | 127 | +static void select_local_file(GtkButton G_GNUC_UNUSED(*button), V3270SaveDialog *widget) { |
131 | #else | 128 | #else |
132 | -static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270SaveDialog *dialog) { | 129 | +static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_pos, G_GNUC_UNUSED GdkEvent *event, V3270SaveDialog *widget) { |
133 | #endif // WIN32 | 130 | #endif // WIN32 |
134 | 131 | ||
135 | - gint format = gtk_combo_box_get_active(GTK_COMBO_BOX(dialog->format)); | ||
136 | - g_autofree gchar * extension = g_strconcat("*",formats[format].extension,NULL); | 132 | + //gint format = gtk_combo_box_get_active(GTK_COMBO_BOX(widget->format)); |
133 | + //g_autofree gchar * extension = g_strconcat("*",formats[format].extension,NULL); | ||
137 | 134 | ||
138 | - g_autofree gchar *filename = | ||
139 | - v3270_select_file( | ||
140 | - GTK_WIDGET(dialog), | ||
141 | - _("Select file to save"), | ||
142 | - _("Select"), | ||
143 | - GTK_FILE_CHOOSER_ACTION_SAVE, | ||
144 | - gtk_entry_get_text(GTK_ENTRY(dialog->filename)), | ||
145 | - gettext(formats[format].name), extension, | ||
146 | - NULL | ||
147 | - ); | 135 | + GtkWidget * dialog = |
136 | + gtk_file_chooser_dialog_new( | ||
137 | + _( "Select destination file"), | ||
138 | + GTK_WINDOW(widget), | ||
139 | + GTK_FILE_CHOOSER_ACTION_SAVE, | ||
140 | + _("Cancel"), GTK_RESPONSE_CANCEL, | ||
141 | + _("Select"), GTK_RESPONSE_ACCEPT, | ||
142 | + NULL ); | ||
148 | 143 | ||
149 | - // g_signal_connect(GTK_FILE_CHOOSER(dialog), "confirm-overwrite", G_CALLBACK(confirm_overwrite), G_OBJECT(action)); | ||
150 | 144 | ||
145 | + const gchar *filename = gtk_entry_get_text(GTK_ENTRY(widget->filename)); | ||
146 | + | ||
147 | + if(filename && *filename) | ||
148 | + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),filename); | ||
149 | + else | ||
150 | + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS)); | ||
151 | + | ||
152 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | ||
153 | + gtk_entry_set_text(GTK_ENTRY(widget->filename),gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog))); | ||
154 | + | ||
155 | + gtk_widget_destroy(dialog); | ||
151 | 156 | ||
152 | - if(filename) | ||
153 | - gtk_entry_set_text(GTK_ENTRY(dialog->filename),filename); | ||
154 | 157 | ||
155 | } | 158 | } |
156 | 159 | ||
160 | + | ||
157 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) | 161 | static void V3270SaveDialog_init(V3270SaveDialog *dialog) |
158 | { | 162 | { |
159 | - // 0--------1---------------------2-------3------------------ | ||
160 | - // 0 - Filename xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx. | 163 | + // 0--------1---------------------2-------3--------------------4 |
164 | + // 0 - Filename xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx.xxxxxxxxx. x | ||
161 | // 1 - Charset xxxxxxxxx.xxxxxxxxx. Format: xxxxxxxxx.xxxxxxxxx. | 165 | // 1 - Charset xxxxxxxxx.xxxxxxxxx. Format: xxxxxxxxx.xxxxxxxxx. |
162 | 166 | ||
163 | 167 | ||
@@ -193,7 +197,7 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | @@ -193,7 +197,7 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | ||
193 | #ifdef WIN32 | 197 | #ifdef WIN32 |
194 | widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); | 198 | widget = gtk_button_new_from_icon_name("document-open",GTK_ICON_SIZE_BUTTON); |
195 | g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); | 199 | g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(select_local_file),dialog); |
196 | - gtk_grid_attach(grid,widget,6,0,1,1); | 200 | + gtk_grid_attach(grid,widget,4,0,1,1); |
197 | #else | 201 | #else |
198 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); | 202 | gtk_entry_set_icon_from_icon_name(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,"document-open"); |
199 | gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); | 203 | gtk_entry_set_icon_activatable(GTK_ENTRY(dialog->filename),GTK_ENTRY_ICON_SECONDARY,TRUE); |
@@ -364,16 +368,19 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | @@ -364,16 +368,19 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | ||
364 | switch(dialog->mode) | 368 | switch(dialog->mode) |
365 | { | 369 | { |
366 | case LIB3270_CONTENT_ALL: | 370 | case LIB3270_CONTENT_ALL: |
371 | + debug("%s","LIB3270_CONTENT_ALL"); | ||
367 | dynamic = g_new0(GList,1); | 372 | dynamic = g_new0(GList,1); |
368 | dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,1); | 373 | dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,1); |
369 | selection = dynamic; | 374 | selection = dynamic; |
370 | break; | 375 | break; |
371 | 376 | ||
372 | case LIB3270_CONTENT_COPY: | 377 | case LIB3270_CONTENT_COPY: |
378 | + debug("%s","LIB3270_CONTENT_COPY"); | ||
373 | selection = v3270_get_selection_blocks(dialog->terminal); | 379 | selection = v3270_get_selection_blocks(dialog->terminal); |
374 | break; | 380 | break; |
375 | 381 | ||
376 | case LIB3270_CONTENT_SELECTED: | 382 | case LIB3270_CONTENT_SELECTED: |
383 | + debug("%s","LIB3270_CONTENT_SELECTED"); | ||
377 | dynamic = g_new0(GList,1); | 384 | dynamic = g_new0(GList,1); |
378 | dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,0); | 385 | dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,0); |
379 | selection = dynamic; | 386 | selection = dynamic; |
@@ -415,14 +422,33 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | @@ -415,14 +422,33 @@ static void icon_press(G_GNUC_UNUSED GtkEntry *entry, G_GNUC_UNUSED GtkEntryIcon | ||
415 | 422 | ||
416 | if(text) | 423 | if(text) |
417 | { | 424 | { |
418 | - debug("%s",text); | 425 | + const gchar * filename = gtk_entry_get_text(GTK_ENTRY(dialog->filename)); |
426 | + gint response = GTK_RESPONSE_OK; | ||
419 | 427 | ||
420 | - g_file_set_contents( | ||
421 | - gtk_entry_get_text(GTK_ENTRY(dialog->filename)), | ||
422 | - text, | ||
423 | - -1, | ||
424 | - error | ||
425 | - ); | 428 | + if(g_file_test(filename,G_FILE_TEST_EXISTS)) |
429 | + { | ||
430 | + GtkWidget * confirmation = | ||
431 | + gtk_message_dialog_new_with_markup( | ||
432 | + GTK_WINDOW(widget), | ||
433 | + GTK_DIALOG_DESTROY_WITH_PARENT, | ||
434 | + GTK_MESSAGE_QUESTION,GTK_BUTTONS_OK_CANCEL, | ||
435 | + _("The file \"%s\" already exists. Replace it?"), | ||
436 | + filename | ||
437 | + ); | ||
438 | + | ||
439 | + response = gtk_dialog_run(GTK_DIALOG(confirmation)); | ||
440 | + gtk_widget_destroy(confirmation); | ||
441 | + } | ||
442 | + | ||
443 | + if(response == GTK_RESPONSE_OK) | ||
444 | + { | ||
445 | + g_file_set_contents( | ||
446 | + gtk_entry_get_text(GTK_ENTRY(dialog->filename)), | ||
447 | + text, | ||
448 | + -1, | ||
449 | + error | ||
450 | + ); | ||
451 | + } | ||
426 | 452 | ||
427 | } | 453 | } |
428 | 454 |