69
static gboolean handle_save_as(const gchar *utf8_filename, gboolean open_new_tab,
70
gboolean rename_file);
73
static GtkWidget *add_file_open_extra_widget(void);
77
on_file_open_dialog_response (GtkDialog *dialog,
81
gtk_widget_hide(ui_widgets.open_filesel);
69
static struct FileSelState
77
gboolean more_options_visible;
81
gboolean open_in_new_tab;
87
GEANY_ENCODINGS_MAX, /* default encoding is detect from file */
98
/* gets the ID of the current file filter */
99
static guint file_chooser_get_filter_idx(GtkFileChooser *chooser)
102
GtkFileFilter *current;
103
GSList *filters, *item;
105
current = gtk_file_chooser_get_filter(chooser);
106
filters = gtk_file_chooser_list_filters(chooser);
107
foreach_slist(item, filters)
109
if (item->data == current)
113
g_slist_free(filters);
118
/* sets the current file filter from its ID */
119
static void file_chooser_set_filter_idx(GtkFileChooser *chooser, guint idx)
121
GtkFileFilter *current;
124
filters = gtk_file_chooser_list_filters(chooser);
125
current = g_slist_nth_data(filters, idx);
126
g_slist_free(filters);
127
gtk_file_chooser_set_filter(chooser, current);
131
static void open_file_dialog_handle_response(GtkWidget *dialog, gint response)
83
133
if (response == GTK_RESPONSE_ACCEPT || response == GEANY_RESPONSE_VIEW)
86
gint filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(
87
ui_lookup_widget(GTK_WIDGET(dialog), "filetype_combo")));
89
136
GtkTreeModel *encoding_model;
90
137
GtkTreeIter encoding_iter;
91
138
GeanyFiletype *ft = NULL;
92
139
const gchar *charset = NULL;
140
GtkWidget *expander = ui_lookup_widget(dialog, "more_options_expander");
141
GtkWidget *filetype_combo = ui_lookup_widget(dialog, "filetype_combo");
142
GtkWidget *encoding_combo = ui_lookup_widget(dialog, "encoding_combo");
93
143
gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */
145
filesel_state.open.more_options_visible = gtk_expander_get_expanded(GTK_EXPANDER(expander));
146
filesel_state.open.filter_idx = file_chooser_get_filter_idx(GTK_FILE_CHOOSER(dialog));
147
filesel_state.open.filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(filetype_combo));
95
149
/* ignore detect from file item */
97
ft = g_slist_nth_data(filetypes_by_title, filetype_idx);
99
encoding_model = gtk_combo_box_get_model(GTK_COMBO_BOX(
100
ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo")));
101
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(
102
ui_lookup_widget(GTK_WIDGET(dialog), "encoding_combo")), &encoding_iter);
103
gtk_tree_model_get(encoding_model, &encoding_iter, 0, &encoding_idx, -1);
104
if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX)
105
charset = encodings[encoding_idx].charset;
107
filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(ui_widgets.open_filesel));
150
if (filesel_state.open.filetype_idx > 0)
151
ft = g_slist_nth_data(filetypes_by_title, filesel_state.open.filetype_idx);
153
encoding_model = gtk_combo_box_get_model(GTK_COMBO_BOX(encoding_combo));
154
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(encoding_combo), &encoding_iter);
155
gtk_tree_model_get(encoding_model, &encoding_iter, 0, &filesel_state.open.encoding_idx, -1);
156
if (filesel_state.open.encoding_idx >= 0 && filesel_state.open.encoding_idx < GEANY_ENCODINGS_MAX)
157
charset = encodings[filesel_state.open.encoding_idx].charset;
159
filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
108
160
if (filelist != NULL)
110
162
document_open_files(filelist, ro, ft, charset);
231
static void create_open_file_dialog(void)
285
static GtkWidget *add_file_open_extra_widget(GtkWidget *dialog)
287
GtkWidget *expander, *vbox, *table, *check_hidden;
288
GtkWidget *filetype_ebox, *filetype_label, *filetype_combo;
289
GtkWidget *encoding_ebox, *encoding_label, *encoding_combo;
291
expander = gtk_expander_new_with_mnemonic(_("_More Options"));
292
vbox = gtk_vbox_new(FALSE, 6);
293
gtk_container_add(GTK_CONTAINER(expander), vbox);
295
table = gtk_table_new(2, 4, FALSE);
297
/* line 1 with checkbox and encoding combo */
298
check_hidden = gtk_check_button_new_with_mnemonic(_("Show _hidden files"));
299
gtk_widget_show(check_hidden);
300
gtk_table_attach(GTK_TABLE(table), check_hidden, 0, 1, 0, 1,
301
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
302
(GtkAttachOptions) (0), 0, 5);
305
gtk_table_attach(GTK_TABLE(table), gtk_label_new(""), 1, 2, 0, 1,
306
(GtkAttachOptions) (GTK_FILL),
307
(GtkAttachOptions) (0), 5, 5);
309
encoding_label = gtk_label_new(_("Set encoding:"));
310
gtk_misc_set_alignment(GTK_MISC(encoding_label), 1, 0);
311
gtk_table_attach(GTK_TABLE(table), encoding_label, 2, 3, 0, 1,
312
(GtkAttachOptions) (GTK_FILL),
313
(GtkAttachOptions) (0), 4, 5);
314
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
315
encoding_ebox = gtk_event_box_new();
316
encoding_combo = gtk_combo_box_new();
317
gtk_widget_set_tooltip_text(encoding_ebox,
318
_("Explicitly defines an encoding for the file, if it would not be detected. This is useful when you know that the encoding of a file cannot be detected correctly by Geany.\nNote if you choose multiple files, they will all be opened with the chosen encoding."));
319
gtk_container_add(GTK_CONTAINER(encoding_ebox), encoding_combo);
320
gtk_table_attach(GTK_TABLE(table), encoding_ebox, 3, 4, 0, 1,
321
(GtkAttachOptions) (GTK_FILL),
322
(GtkAttachOptions) (0), 0, 5);
324
/* line 2 with filetype combo */
325
filetype_label = gtk_label_new(_("Set filetype:"));
326
gtk_misc_set_alignment(GTK_MISC(filetype_label), 1, 0);
327
gtk_table_attach(GTK_TABLE(table), filetype_label, 2, 3, 1, 2,
328
(GtkAttachOptions) (GTK_FILL),
329
(GtkAttachOptions) (0), 4, 5);
330
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
331
filetype_ebox = gtk_event_box_new();
332
filetype_combo = gtk_combo_box_new_text();
333
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(filetype_combo), 2);
334
gtk_widget_set_tooltip_text(filetype_ebox,
335
_("Explicitly defines a filetype for the file, if it would not be detected by filename extension.\nNote if you choose multiple files, they will all be opened with the chosen filetype."));
336
gtk_container_add(GTK_CONTAINER(filetype_ebox), filetype_combo);
337
gtk_table_attach(GTK_TABLE(table), filetype_ebox, 3, 4, 1, 2,
338
(GtkAttachOptions) (GTK_FILL),
339
(GtkAttachOptions) (0), 0, 5);
341
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
342
gtk_widget_show_all(vbox);
344
g_signal_connect(check_hidden, "toggled", G_CALLBACK(on_file_open_check_hidden_toggled), dialog);
346
ui_hookup_widget(dialog, expander, "more_options_expander");
347
ui_hookup_widget(dialog, check_hidden, "check_hidden");
348
ui_hookup_widget(dialog, filetype_combo, "filetype_combo");
349
ui_hookup_widget(dialog, encoding_combo, "encoding_combo");
355
static GtkWidget *create_open_file_dialog(void)
233
358
GtkWidget *filetype_combo, *encoding_combo;
234
359
GtkWidget *viewbtn;
235
360
GtkCellRenderer *encoding_renderer;
236
361
GtkTreeIter encoding_iter;
239
ui_widgets.open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(main_widgets.window),
364
dialog = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(main_widgets.window),
240
365
GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
241
gtk_widget_set_name(ui_widgets.open_filesel, "GeanyDialog");
366
gtk_widget_set_name(dialog, "GeanyDialog");
243
viewbtn = gtk_dialog_add_button(GTK_DIALOG(ui_widgets.open_filesel), _("_View"),
244
GEANY_RESPONSE_VIEW);
245
ui_widget_set_tooltip_text(viewbtn,
368
viewbtn = gtk_dialog_add_button(GTK_DIALOG(dialog), _("_View"), GEANY_RESPONSE_VIEW);
369
gtk_widget_set_tooltip_text(viewbtn,
246
370
_("Opens the file in read-only mode. If you choose more than one file to open, all files will be opened read-only."));
248
gtk_dialog_add_buttons(GTK_DIALOG(ui_widgets.open_filesel),
372
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
249
373
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
250
374
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
251
gtk_dialog_set_default_response(GTK_DIALOG(ui_widgets.open_filesel), GTK_RESPONSE_ACCEPT);
375
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
253
gtk_widget_set_size_request(ui_widgets.open_filesel, -1, 460);
254
gtk_window_set_modal(GTK_WINDOW(ui_widgets.open_filesel), TRUE);
255
gtk_window_set_destroy_with_parent(GTK_WINDOW(ui_widgets.open_filesel), TRUE);
256
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(ui_widgets.open_filesel), FALSE);
257
gtk_window_set_type_hint(GTK_WINDOW(ui_widgets.open_filesel), GDK_WINDOW_TYPE_HINT_DIALOG);
258
gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.open_filesel), GTK_WINDOW(main_widgets.window));
259
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(ui_widgets.open_filesel), TRUE);
377
gtk_widget_set_size_request(dialog, -1, 460);
378
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
379
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
380
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
381
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
382
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
383
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
260
384
if (gtk_check_version(2, 14, 0) == NULL)
261
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(ui_widgets.open_filesel), FALSE);
385
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE);
263
387
/* add checkboxes and filename entry */
264
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(ui_widgets.open_filesel),
265
add_file_open_extra_widget());
266
filetype_combo = ui_lookup_widget(ui_widgets.open_filesel, "filetype_combo");
388
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), add_file_open_extra_widget(dialog));
389
filetype_combo = ui_lookup_widget(dialog, "filetype_combo");
268
391
gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), _("Detect by file extension"));
269
392
/* add FileFilters(start with "All Files") */
270
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel),
393
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),
271
394
filetypes_create_file_filter(filetypes[GEANY_FILETYPES_NONE]));
272
395
/* now create meta filter "All Source" */
273
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel),
396
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),
274
397
filetypes_create_file_filter_all_source());
275
398
foreach_slist(node, filetypes_by_title)
279
402
if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE))
281
404
gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), ft->title);
282
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel),
283
filetypes_create_file_filter(ft));
405
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filetypes_create_file_filter(ft));
285
407
gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), 0);
287
409
/* fill encoding combo box */
288
encoding_combo = ui_lookup_widget(ui_widgets.open_filesel, "encoding_combo");
410
encoding_combo = ui_lookup_widget(dialog, "encoding_combo");
289
411
gtk_combo_box_set_model(GTK_COMBO_BOX(encoding_combo), GTK_TREE_MODEL(
290
create_encoding_combo_store(&encoding_iter)));
412
create_encoding_combo_store(&encoding_iter)));
291
413
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(encoding_combo), &encoding_iter);
292
414
encoding_renderer = gtk_cell_renderer_text_new();
293
415
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer, TRUE);
294
416
gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer, "text", 1);
295
417
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(encoding_combo), encoding_renderer,
296
encoding_combo_cell_data_func, NULL, NULL);
298
g_signal_connect(ui_widgets.open_filesel, "notify::show-hidden",
299
G_CALLBACK(on_file_open_notify), NULL);
300
g_signal_connect(ui_widgets.open_filesel, "delete-event",
301
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
302
g_signal_connect(ui_widgets.open_filesel, "response",
303
G_CALLBACK(on_file_open_dialog_response), NULL);
418
encoding_combo_cell_data_func, NULL, NULL);
420
g_signal_connect(dialog, "notify::show-hidden", G_CALLBACK(on_file_open_notify), NULL);
426
static void open_file_dialog_apply_settings(GtkWidget *dialog)
428
static gboolean initialized = FALSE;
429
GtkWidget *check_hidden = ui_lookup_widget(dialog, "check_hidden");
430
GtkWidget *filetype_combo = ui_lookup_widget(dialog, "filetype_combo");
431
GtkWidget *expander = ui_lookup_widget(dialog, "more_options_expander");
433
/* we can't know the initial position of combo boxes, so retreive it the first time */
436
filesel_state.open.filter_idx = file_chooser_get_filter_idx(GTK_FILE_CHOOSER(dialog));
437
filesel_state.open.filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(filetype_combo));
443
file_chooser_set_filter_idx(GTK_FILE_CHOOSER(dialog), filesel_state.open.filter_idx);
444
gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), filesel_state.open.filetype_idx);
446
gtk_expander_set_expanded(GTK_EXPANDER(expander), filesel_state.open.more_options_visible);
447
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_hidden), filesel_state.open.show_hidden);
448
/* encoding combo is restored at creating time, see create_encoding_combo_store() */
307
452
/* This shows the file selection dialog to open a file. */
308
void dialogs_show_open_file()
453
void dialogs_show_open_file(void)
328
/* We use the same file selection widget each time, so first of all we create it
329
* if it hasn't already been created. */
330
if (ui_widgets.open_filesel == NULL)
331
create_open_file_dialog();
335
if (g_path_is_absolute(initdir))
336
gtk_file_chooser_set_current_folder(
337
GTK_FILE_CHOOSER(ui_widgets.open_filesel), initdir);
473
GtkWidget *dialog = create_open_file_dialog();
476
open_file_dialog_apply_settings(dialog);
478
if (initdir != NULL && g_path_is_absolute(initdir))
479
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), initdir);
340
481
if (app->project && NZV(app->project->base_path))
341
gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(ui_widgets.open_filesel),
342
app->project->base_path, NULL);
482
gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),
483
app->project->base_path, NULL);
344
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.open_filesel));
345
gtk_window_present(GTK_WINDOW(ui_widgets.open_filesel));
485
response = gtk_dialog_run(GTK_DIALOG(dialog));
486
open_file_dialog_handle_response(dialog, response);
487
gtk_widget_destroy(dialog);
351
static GtkWidget *add_file_open_extra_widget()
353
GtkWidget *expander, *vbox, *table, *check_hidden;
354
GtkWidget *filetype_ebox, *filetype_label, *filetype_combo;
355
GtkWidget *encoding_ebox, *encoding_label, *encoding_combo;
357
expander = gtk_expander_new_with_mnemonic(_("_More Options"));
358
vbox = gtk_vbox_new(FALSE, 6);
359
gtk_container_add(GTK_CONTAINER(expander), vbox);
361
table = gtk_table_new(2, 4, FALSE);
363
/* line 1 with checkbox and encoding combo */
364
check_hidden = gtk_check_button_new_with_mnemonic(_("Show _hidden files"));
365
gtk_widget_show(check_hidden);
366
gtk_table_attach(GTK_TABLE(table), check_hidden, 0, 1, 0, 1,
367
(GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
368
(GtkAttachOptions) (0), 0, 5);
371
gtk_table_attach(GTK_TABLE(table), gtk_label_new(""), 1, 2, 0, 1,
372
(GtkAttachOptions) (GTK_FILL),
373
(GtkAttachOptions) (0), 5, 5);
375
encoding_label = gtk_label_new(_("Set encoding:"));
376
gtk_misc_set_alignment(GTK_MISC(encoding_label), 1, 0);
377
gtk_table_attach(GTK_TABLE(table), encoding_label, 2, 3, 0, 1,
378
(GtkAttachOptions) (GTK_FILL),
379
(GtkAttachOptions) (0), 4, 5);
380
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
381
encoding_ebox = gtk_event_box_new();
382
encoding_combo = gtk_combo_box_new();
383
ui_widget_set_tooltip_text(encoding_ebox,
384
_("Explicitly defines an encoding for the file, if it would not be detected. This is useful when you know that the encoding of a file cannot be detected correctly by Geany.\nNote if you choose multiple files, they will all be opened with the chosen encoding."));
385
gtk_container_add(GTK_CONTAINER(encoding_ebox), encoding_combo);
386
gtk_table_attach(GTK_TABLE(table), encoding_ebox, 3, 4, 0, 1,
387
(GtkAttachOptions) (GTK_FILL),
388
(GtkAttachOptions) (0), 0, 5);
390
/* line 2 with filetype combo */
391
filetype_label = gtk_label_new(_("Set filetype:"));
392
gtk_misc_set_alignment(GTK_MISC(filetype_label), 1, 0);
393
gtk_table_attach(GTK_TABLE(table), filetype_label, 2, 3, 1, 2,
394
(GtkAttachOptions) (GTK_FILL),
395
(GtkAttachOptions) (0), 4, 5);
396
/* the ebox is for the tooltip, because gtk_combo_box can't show tooltips */
397
filetype_ebox = gtk_event_box_new();
398
filetype_combo = gtk_combo_box_new_text();
399
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(filetype_combo), 2);
400
ui_widget_set_tooltip_text(filetype_ebox,
401
_("Explicitly defines a filetype for the file, if it would not be detected by filename extension.\nNote if you choose multiple files, they will all be opened with the chosen filetype."));
402
gtk_container_add(GTK_CONTAINER(filetype_ebox), filetype_combo);
403
gtk_table_attach(GTK_TABLE(table), filetype_ebox, 3, 4, 1, 2,
404
(GtkAttachOptions) (GTK_FILL),
405
(GtkAttachOptions) (0), 0, 5);
407
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
408
gtk_widget_show_all(vbox);
410
g_signal_connect(check_hidden, "toggled",
411
G_CALLBACK(on_file_open_check_hidden_toggled), NULL);
413
ui_hookup_widget(ui_widgets.open_filesel, check_hidden, "check_hidden");
414
ui_hookup_widget(ui_widgets.open_filesel, filetype_combo, "filetype_combo");
415
ui_hookup_widget(ui_widgets.open_filesel, encoding_combo, "encoding_combo");
421
493
static void on_save_as_new_tab_toggled(GtkToggleButton *togglebutton, gpointer user_data)
423
gtk_widget_set_sensitive(GTK_WIDGET(user_data),
424
! gtk_toggle_button_get_active(togglebutton));
495
gtk_widget_set_sensitive(GTK_WIDGET(user_data), ! gtk_toggle_button_get_active(togglebutton));
485
553
case GTK_RESPONSE_ACCEPT:
487
555
gboolean open_new_tab = gtk_toggle_button_get_active(
488
GTK_TOGGLE_BUTTON(ui_lookup_widget(ui_widgets.save_filesel, "check_open_new_tab")));
556
GTK_TOGGLE_BUTTON(ui_lookup_widget(dialog, "check_open_new_tab")));
489
557
gchar *utf8_filename;
491
559
utf8_filename = utils_get_utf8_from_locale(new_filename);
492
560
success = handle_save_as(utf8_filename, open_new_tab, rename_file);
563
filesel_state.save.open_in_new_tab = open_new_tab;
494
565
g_free(utf8_filename);
568
case GTK_RESPONSE_DELETE_EVENT:
497
569
case GTK_RESPONSE_CANCEL:
501
573
g_free(new_filename);
504
gtk_widget_hide(ui_widgets.save_filesel);
508
static void create_save_file_dialog(void)
579
static GtkWidget *create_save_file_dialog(void)
510
GtkWidget *vbox, *check_open_new_tab, *rename_btn;
581
GtkWidget *dialog, *vbox, *check_open_new_tab, *rename_btn;
511
582
const gchar *initdir;
513
ui_widgets.save_filesel = gtk_file_chooser_dialog_new(_("Save File"), GTK_WINDOW(main_widgets.window),
584
dialog = gtk_file_chooser_dialog_new(_("Save File"), GTK_WINDOW(main_widgets.window),
514
585
GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL);
515
gtk_window_set_modal(GTK_WINDOW(ui_widgets.save_filesel), TRUE);
516
gtk_window_set_destroy_with_parent(GTK_WINDOW(ui_widgets.save_filesel), TRUE);
517
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(ui_widgets.save_filesel), FALSE);
518
gtk_window_set_type_hint(GTK_WINDOW(ui_widgets.save_filesel), GDK_WINDOW_TYPE_HINT_DIALOG);
519
gtk_widget_set_name(ui_widgets.save_filesel, "GeanyDialog");
521
rename_btn = gtk_dialog_add_button(GTK_DIALOG(ui_widgets.save_filesel), _("R_ename"),
522
GEANY_RESPONSE_RENAME);
523
ui_widget_set_tooltip_text(rename_btn, _("Save the file and rename it"));
525
gtk_dialog_add_buttons(GTK_DIALOG(ui_widgets.save_filesel),
586
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
587
gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE);
588
gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
589
gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
590
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(main_widgets.window));
591
gtk_widget_set_name(dialog, "GeanyDialog");
593
rename_btn = gtk_dialog_add_button(GTK_DIALOG(dialog), _("R_ename"), GEANY_RESPONSE_RENAME);
594
gtk_widget_set_tooltip_text(rename_btn, _("Save the file and rename it"));
596
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
526
597
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
527
598
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
528
gtk_dialog_set_default_response(GTK_DIALOG(ui_widgets.save_filesel), GTK_RESPONSE_ACCEPT);
599
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
530
601
vbox = gtk_vbox_new(FALSE, 0);
531
602
check_open_new_tab = gtk_check_button_new_with_mnemonic(_("_Open file in a new tab"));
532
ui_widget_set_tooltip_text(check_open_new_tab,
603
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check_open_new_tab), filesel_state.save.open_in_new_tab);
604
gtk_widget_set_tooltip_text(check_open_new_tab,
533
605
_("Keep the current unsaved document open"
534
606
" and open the newly saved file in a new tab"));
535
607
gtk_box_pack_start(GTK_BOX(vbox), check_open_new_tab, FALSE, FALSE, 0);
536
608
gtk_widget_show_all(vbox);
537
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(ui_widgets.save_filesel), vbox);
538
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(ui_widgets.save_filesel), TRUE);
609
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), vbox);
610
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
539
611
if (gtk_check_version(2, 14, 0) == NULL)
540
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(ui_widgets.save_filesel), FALSE);
612
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), FALSE);
542
614
/* set the folder by default to the project base dir or the global pref for opening files */
543
615
initdir = utils_get_default_dir_utf8();
546
618
gchar *linitdir = utils_get_locale_from_utf8(initdir);
547
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(ui_widgets.save_filesel), linitdir);
619
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), linitdir);
548
620
g_free(linitdir);
551
623
g_signal_connect(check_open_new_tab, "toggled",
552
624
G_CALLBACK(on_save_as_new_tab_toggled), rename_btn);
554
ui_hookup_widget(ui_widgets.save_filesel, check_open_new_tab, "check_open_new_tab");
556
g_signal_connect(ui_widgets.save_filesel, "delete-event",
557
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
558
g_signal_connect(ui_widgets.save_filesel, "response",
559
G_CALLBACK(on_file_save_dialog_response), NULL);
561
gtk_window_set_transient_for(GTK_WINDOW(ui_widgets.save_filesel), GTK_WINDOW(main_widgets.window));
626
ui_hookup_widget(dialog, check_open_new_tab, "check_open_new_tab");
565
static gboolean gtk_show_save_as(void)
632
static gboolean show_save_as_gtk(void)
567
635
GeanyDocument *doc = document_get_current();
570
638
g_return_val_if_fail(doc != NULL, FALSE);
572
if (G_UNLIKELY(ui_widgets.save_filesel == NULL))
573
create_save_file_dialog();
575
gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(ui_widgets.save_filesel));
640
dialog = create_save_file_dialog();
577
642
if (doc->file_name != NULL)