402
402
static void stop_loading_and_clear_list_model (GtkFileChooserDefault *impl,
403
403
gboolean remove_from_treeview);
405
static void search_setup_widgets (GtkFileChooserDefault *impl);
404
406
static void search_stop_searching (GtkFileChooserDefault *impl,
405
407
gboolean remove_query);
406
408
static void search_clear_model (GtkFileChooserDefault *impl,
407
409
gboolean remove_from_treeview);
408
410
static gboolean search_should_respond (GtkFileChooserDefault *impl);
409
static void search_switch_to_browse_mode (GtkFileChooserDefault *impl);
410
411
static GSList *search_get_selected_files (GtkFileChooserDefault *impl);
411
412
static void search_entry_activate_cb (GtkEntry *entry,
413
414
static void settings_load (GtkFileChooserDefault *impl);
416
static void recent_start_loading (GtkFileChooserDefault *impl);
415
417
static void recent_stop_loading (GtkFileChooserDefault *impl);
416
418
static void recent_clear_model (GtkFileChooserDefault *impl,
417
419
gboolean remove_from_treeview);
418
420
static gboolean recent_should_respond (GtkFileChooserDefault *impl);
419
static void recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
420
421
static GSList * recent_get_selected_files (GtkFileChooserDefault *impl);
421
422
static void set_file_system_backend (GtkFileChooserDefault *impl);
422
423
static void unset_file_system_backend (GtkFileChooserDefault *impl);
4360
location_entry_create (GtkFileChooserDefault *impl)
4362
if (!impl->location_entry)
4363
impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4365
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4367
_gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only);
4368
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
4369
gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
4370
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4357
4373
/* Creates the widgets specific to Save mode */
4359
4375
save_widgets_create (GtkFileChooserDefault *impl)
4387
4403
/* Location entry */
4389
impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4390
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4392
_gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only);
4393
gtk_entry_set_width_chars (GTK_ENTRY (impl->location_entry), 45);
4394
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4405
location_entry_create (impl);
4395
4406
gtk_table_attach (GTK_TABLE (impl->save_widgets_table), impl->location_entry,
4397
4408
GTK_EXPAND | GTK_FILL, 0,
4443
4454
gtk_widget_hide (impl->location_entry_box);
4446
/* Sets the full path of the current folder as the text in the location entry. */
4448
location_entry_set_initial_text (GtkFileChooserDefault *impl)
4450
gchar *text, *filename;
4452
if (!impl->current_folder)
4455
filename = g_file_get_path (impl->current_folder);
4459
text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
4463
text = g_file_get_uri (impl->current_folder);
4467
gboolean need_slash;
4470
len = strlen (text);
4471
need_slash = (text[len - 1] != G_DIR_SEPARATOR);
4477
slash_text = g_new (char, len + 2);
4478
strcpy (slash_text, text);
4479
slash_text[len] = G_DIR_SEPARATOR;
4480
slash_text[len + 1] = 0;
4486
_gtk_file_chooser_entry_set_file_part (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), text);
4493
4457
/* Turns on the location entry. Can be called even if we are already in that
4516
impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
4517
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
4519
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
4520
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
4483
location_entry_create (impl);
4522
4484
gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_entry, TRUE, TRUE, 0);
4523
4485
gtk_label_set_mnemonic_widget (GTK_LABEL (impl->location_label), impl->location_entry);
4525
4487
/* Configure the entry */
4527
4489
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
4528
_gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only);
4878
4839
GtkWidget *widget;
4879
4840
GtkSizeGroup *size_group;
4881
/* size group is used by the scrolled windows of the panes */
4882
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
4883
4842
impl->browse_widgets_box = gtk_vbox_new (FALSE, 12);
4843
gtk_box_pack_start (GTK_BOX (impl), impl->browse_widgets_box, TRUE, TRUE, 0);
4844
gtk_widget_show (impl->browse_widgets_box);
4846
impl->browse_header_box = gtk_vbox_new (FALSE, 12);
4847
gtk_box_pack_start (GTK_BOX (impl->browse_widgets_box), impl->browse_header_box, FALSE, FALSE, 0);
4848
gtk_widget_show (impl->browse_header_box);
4885
4850
/* Path bar, info bar, and their respective machinery - the browse_path_bar_hbox will get packed elsewhere */
4886
4851
path_bar_widgets_create (impl);
4888
4853
/* Box for the location label and entry */
4890
4855
impl->location_entry_box = gtk_hbox_new (FALSE, 12);
4891
gtk_box_pack_start (GTK_BOX (impl->browse_widgets_box), impl->location_entry_box, FALSE, FALSE, 0);
4856
gtk_box_pack_start (GTK_BOX (impl->browse_header_box), impl->location_entry_box, FALSE, FALSE, 0);
4893
4858
impl->location_label = gtk_label_new_with_mnemonic (_("_Location:"));
4894
4859
gtk_widget_show (impl->location_label);
4895
4860
gtk_box_pack_start (GTK_BOX (impl->location_entry_box), impl->location_label, FALSE, FALSE, 0);
4862
/* size group is used by the scrolled windows of the panes */
4863
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
4897
4865
/* Paned widget */
4898
4866
hpaned = gtk_hpaned_new ();
4899
4867
gtk_widget_show (hpaned);
5102
5069
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN
5103
5070
|| impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5105
gtk_box_pack_start (GTK_BOX (impl->browse_widgets_box), impl->browse_path_bar_hbox, FALSE, FALSE, 0);
5106
gtk_box_reorder_child (GTK_BOX (impl->browse_widgets_box), impl->browse_path_bar_hbox, 0);
5072
gtk_box_pack_start (GTK_BOX (impl->browse_header_box), impl->browse_path_bar_hbox, FALSE, FALSE, 0);
5073
gtk_box_reorder_child (GTK_BOX (impl->browse_header_box), impl->browse_path_bar_hbox, 0);
5108
5075
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE
5109
5076
|| impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
5185
5152
path_bar_set_mode (impl, mode);
5156
operation_mode_discard_search_widgets (GtkFileChooserDefault *impl)
5158
if (impl->search_hbox)
5160
gtk_widget_destroy (impl->search_hbox);
5162
impl->search_hbox = NULL;
5163
impl->search_entry = NULL;
5167
/* Stops running operations like populating the browse model, searches, and the recent-files model */
5169
operation_mode_stop (GtkFileChooserDefault *impl, OperationMode mode)
5173
case OPERATION_MODE_BROWSE:
5174
stop_loading_and_clear_list_model (impl, TRUE);
5177
case OPERATION_MODE_SEARCH:
5178
search_stop_searching (impl, FALSE);
5179
search_clear_model (impl, TRUE);
5181
operation_mode_discard_search_widgets (impl);
5184
case OPERATION_MODE_RECENT:
5185
recent_stop_loading (impl);
5186
recent_clear_model (impl, TRUE);
5190
g_assert_not_reached ();
5195
operation_mode_set_browse (GtkFileChooserDefault *impl)
5197
path_bar_update (impl);
5199
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5200
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5202
gtk_widget_show (impl->location_button);
5203
location_mode_set (impl, impl->location_mode, TRUE);
5205
if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
5206
gtk_widget_show (impl->location_entry_box);
5211
operation_mode_set_search (GtkFileChooserDefault *impl)
5213
g_assert (impl->search_hbox == NULL);
5214
g_assert (impl->search_entry == NULL);
5215
g_assert (impl->search_model == NULL);
5217
search_setup_widgets (impl);
5221
operation_mode_set_recent (GtkFileChooserDefault *impl)
5223
path_bar_update (impl);
5225
/* Hide the location widgets temporarily */
5226
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
5227
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
5229
gtk_widget_hide (impl->location_button);
5230
gtk_widget_hide (impl->location_entry_box);
5233
recent_start_loading (impl);
5236
/* Sometimes we need to frob the selection in the shortcuts list manually */
5238
shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos)
5240
GtkTreeSelection *selection;
5243
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
5245
g_signal_handlers_block_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
5247
path = gtk_tree_path_new_from_indices (pos, -1);
5248
gtk_tree_selection_select_path (selection, path);
5249
gtk_tree_path_free (path);
5251
g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
5255
operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode)
5257
ShortcutsIndex shortcut_to_select;
5259
operation_mode_stop (impl, impl->operation_mode);
5261
impl->operation_mode = mode;
5263
switch (impl->operation_mode)
5265
case OPERATION_MODE_BROWSE:
5266
operation_mode_set_browse (impl);
5267
shortcut_to_select = SHORTCUTS_CURRENT_FOLDER;
5270
case OPERATION_MODE_SEARCH:
5271
operation_mode_set_search (impl);
5272
shortcut_to_select = SHORTCUTS_SEARCH;
5275
case OPERATION_MODE_RECENT:
5276
operation_mode_set_recent (impl);
5277
shortcut_to_select = SHORTCUTS_RECENT;
5281
g_assert_not_reached ();
5285
if (shortcut_to_select != SHORTCUTS_CURRENT_FOLDER)
5286
shortcuts_select_item_without_activating (impl, shortcuts_get_index (impl, shortcut_to_select));
5188
5289
/* This function is basically a do_all function.
5190
5291
* It sets the visibility on all the widgets based on the current state, and
8924
/* Stops any pending searches, clears the file list, and switches back to OPERATION_MODE_BROWSE */
8926
search_switch_to_browse_mode (GtkFileChooserDefault *impl)
8928
g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
8930
search_stop_searching (impl, FALSE);
8931
search_clear_model (impl, TRUE);
8933
gtk_widget_destroy (impl->search_hbox);
8934
impl->search_hbox = NULL;
8935
impl->search_entry = NULL;
8937
impl->operation_mode = OPERATION_MODE_BROWSE;
8938
path_bar_update (impl);
8940
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
8941
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
8943
gtk_widget_show (impl->location_button);
8945
if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
8946
gtk_widget_show (impl->location_entry_box);
8949
file_list_set_sort_column_ids (impl);
8952
9016
/* Creates the search_model and puts it in the tree view */
8954
9018
search_setup_model (GtkFileChooserDefault *impl)
9128
9193
/* FMQ: hide the filter combo? */
9131
/* Stops running operations like populating the browse model, searches, and the recent-files model */
9133
stop_operation (GtkFileChooserDefault *impl, OperationMode mode)
9137
case OPERATION_MODE_BROWSE:
9138
stop_loading_and_clear_list_model (impl, TRUE);
9141
case OPERATION_MODE_SEARCH:
9142
search_stop_searching (impl, FALSE);
9143
search_clear_model (impl, TRUE);
9145
gtk_widget_destroy (impl->search_hbox);
9146
impl->search_hbox = NULL;
9147
impl->search_entry = NULL;
9150
case OPERATION_MODE_RECENT:
9151
recent_stop_loading (impl);
9152
recent_clear_model (impl, TRUE);
9157
/* Sometimes we need to frob the selection in the shortcuts list manually */
9159
shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos)
9161
GtkTreeSelection *selection;
9164
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
9166
g_signal_handlers_block_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
9168
path = gtk_tree_path_new_from_indices (pos, -1);
9169
gtk_tree_selection_select_path (selection, path);
9170
gtk_tree_path_free (path);
9172
g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
9175
/* Main entry point to the searching functions; this gets called when the user
9176
* activates the Search shortcut.
9179
search_activate (GtkFileChooserDefault *impl)
9181
OperationMode previous_mode;
9183
if (impl->operation_mode == OPERATION_MODE_SEARCH)
9185
focus_search_entry_in_idle (impl);
9189
previous_mode = impl->operation_mode;
9190
impl->operation_mode = OPERATION_MODE_SEARCH;
9192
shortcuts_select_item_without_activating (impl, shortcuts_get_index (impl, SHORTCUTS_SEARCH));
9194
stop_operation (impl, previous_mode);
9196
g_assert (impl->search_hbox == NULL);
9197
g_assert (impl->search_entry == NULL);
9198
g_assert (impl->search_model == NULL);
9200
search_setup_widgets (impl);
9201
file_list_set_sort_column_ids (impl);
9205
9197
* Recent files support
9236
/* Stops any pending load, clears the file list, and switches
9237
* back to OPERATION_MODE_BROWSE
9240
recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
9242
g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9244
recent_stop_loading (impl);
9245
recent_clear_model (impl, TRUE);
9247
impl->operation_mode = OPERATION_MODE_BROWSE;
9248
path_bar_update (impl);
9250
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9251
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9253
gtk_widget_show (impl->location_button);
9255
if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9256
gtk_widget_show (impl->location_entry_box);
9259
gtk_tree_view_column_set_visible (impl->list_size_column, impl->show_size_column);
9261
file_list_set_sort_column_ids (impl);
9265
9229
recent_setup_model (GtkFileChooserDefault *impl)
9395
9350
if (!impl->recent_manager)
9398
/* first iteration: load all the items */
9353
load_data->items = gtk_recent_manager_get_items (impl->recent_manager);
9399
9354
if (!load_data->items)
9401
load_data->items = gtk_recent_manager_get_items (impl->recent_manager);
9402
if (!load_data->items)
9405
load_data->needs_sorting = TRUE;
9410
/* second iteration: MRU sorting and clamping, and populating the model */
9411
if (load_data->needs_sorting)
9413
load_data->items = g_list_sort (load_data->items, recent_sort_mru);
9415
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
9416
populate_model_with_recent_items (impl, load_data->items);
9418
populate_model_with_folders (impl, load_data->items);
9420
g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9421
g_list_free (load_data->items);
9422
load_data->items = NULL;
9357
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
9358
populate_model_with_recent_items (impl, load_data->items);
9360
populate_model_with_folders (impl, load_data->items);
9362
g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL);
9363
g_list_free (load_data->items);
9364
load_data->items = NULL;
9494
9434
return (gtk_tree_selection_count_selected_rows (selection) != 0);
9497
/* Hide the location widgets temporarily */
9499
recent_hide_entry (GtkFileChooserDefault *impl)
9501
path_bar_update (impl);
9503
/* Hide the location widgets temporarily */
9504
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9505
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9507
gtk_widget_hide (impl->location_button);
9508
gtk_widget_hide (impl->location_entry_box);
9512
/* Main entry point to the recent files functions; this gets called when
9513
* the user activates the Recently Used shortcut.
9516
recent_activate (GtkFileChooserDefault *impl)
9518
OperationMode previous_mode;
9520
if (impl->operation_mode == OPERATION_MODE_RECENT)
9523
previous_mode = impl->operation_mode;
9524
impl->operation_mode = OPERATION_MODE_RECENT;
9526
shortcuts_select_item_without_activating (impl, shortcuts_get_index (impl, SHORTCUTS_RECENT));
9528
stop_operation (impl, previous_mode);
9530
recent_hide_entry (impl);
9532
file_list_set_sort_column_ids (impl);
9533
recent_start_loading (impl);
9537
9438
set_current_filter (GtkFileChooserDefault *impl,
9538
9439
GtkFileFilter *filter)
10150
10048
if (impl->operation_mode != OPERATION_MODE_BROWSE)
10152
10050
GtkWidget *widget_to_focus;
10052
operation_mode_set (impl, OPERATION_MODE_BROWSE);
10154
/* This will give us the location widgets back */
10155
switch (impl->operation_mode)
10157
case OPERATION_MODE_SEARCH:
10158
search_switch_to_browse_mode (impl);
10160
case OPERATION_MODE_RECENT:
10161
recent_switch_to_browse_mode (impl);
10163
case OPERATION_MODE_BROWSE:
10164
g_assert_not_reached ();
10168
10054
if (impl->current_folder)
10169
10055
change_folder_and_display_error (impl, impl->current_folder, FALSE);
10180
10066
if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
10181
10067
impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
10183
LocationMode new_mode;
10187
/* since the user typed something, we unconditionally want to turn on the entry */
10188
new_mode = LOCATION_MODE_FILENAME_ENTRY;
10190
else if (impl->location_mode == LOCATION_MODE_PATH_BAR)
10191
new_mode = LOCATION_MODE_FILENAME_ENTRY;
10192
else if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
10193
new_mode = LOCATION_MODE_PATH_BAR;
10196
g_assert_not_reached ();
10200
location_mode_set (impl, new_mode, TRUE);
10201
if (new_mode == LOCATION_MODE_FILENAME_ENTRY)
10204
location_set_user_text (impl, path);
10207
location_entry_set_initial_text (impl);
10208
gtk_editable_select_region (GTK_EDITABLE (impl->location_entry), 0, -1);
10072
location_mode_set (impl, LOCATION_MODE_FILENAME_ENTRY, TRUE);
10073
location_set_user_text (impl, path);
10212
10075
else if (impl->action == GTK_FILE_CHOOSER_ACTION_SAVE ||
10213
10076
impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)