+ mode = PATH_BAR_RECENTLY_USED;
+
+ break;
+
+ case OPERATION_MODE_SEARCH:
+ mode = PATH_BAR_SEARCH;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ return;
+ }
+
+ path_bar_set_mode (impl, mode);
+}
+
+static void
+operation_mode_discard_search_widgets (GtkFileChooserDefault *impl)
+{
+ if (impl->search_hbox)
+ {
+ gtk_widget_destroy (impl->search_hbox);
+
+ impl->search_hbox = NULL;
+ impl->search_entry = NULL;
+ }
+}
+
+/* Stops running operations like populating the browse model, searches, and the recent-files model */
+static void
+operation_mode_stop (GtkFileChooserDefault *impl, OperationMode mode)
+{
+ switch (mode)
+ {
+ case OPERATION_MODE_BROWSE:
+ stop_loading_and_clear_list_model (impl, TRUE);
+ break;
+
+ case OPERATION_MODE_SEARCH:
+ search_stop_searching (impl, FALSE);
+ search_clear_model (impl, TRUE);
+
+ operation_mode_discard_search_widgets (impl);
+ break;
+
+ case OPERATION_MODE_RECENT:
+ recent_stop_loading (impl);
+ recent_clear_model (impl, TRUE);
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+operation_mode_set_browse (GtkFileChooserDefault *impl)
+{
+ path_bar_update (impl);
+
+ if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
+ impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ {
+ gtk_widget_show (impl->location_button);
+ location_mode_set (impl, impl->location_mode, TRUE);
+
+ if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
+ gtk_widget_show (impl->location_entry_box);
+ }
+}
+
+static void
+operation_mode_set_search (GtkFileChooserDefault *impl)
+{
+ g_assert (impl->search_hbox == NULL);
+ g_assert (impl->search_entry == NULL);
+ g_assert (impl->search_model == NULL);
+
+ search_setup_widgets (impl);
+}
+
+static void
+operation_mode_set_recent (GtkFileChooserDefault *impl)
+{
+ path_bar_update (impl);
+
+ /* Hide the location widgets temporarily */
+ if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
+ impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ {
+ gtk_widget_hide (impl->location_button);
+ gtk_widget_hide (impl->location_entry_box);
+ }
+
+ recent_start_loading (impl);
+}
+
+/* Sometimes we need to frob the selection in the shortcuts list manually */
+static void
+shortcuts_select_item_without_activating (GtkFileChooserDefault *impl, int pos)
+{
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->browse_shortcuts_tree_view));
+
+ g_signal_handlers_block_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
+
+ path = gtk_tree_path_new_from_indices (pos, -1);
+ gtk_tree_selection_select_path (selection, path);
+ gtk_tree_path_free (path);
+
+ g_signal_handlers_unblock_by_func (selection, G_CALLBACK (shortcuts_selection_changed_cb), impl);
+}
+
+static void
+operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode)
+{
+ ShortcutsIndex shortcut_to_select;
+
+ operation_mode_stop (impl, impl->operation_mode);
+
+ impl->operation_mode = mode;
+
+ switch (impl->operation_mode)
+ {
+ case OPERATION_MODE_BROWSE:
+ operation_mode_set_browse (impl);
+ shortcut_to_select = SHORTCUTS_CURRENT_FOLDER;
+ break;
+
+ case OPERATION_MODE_SEARCH:
+ operation_mode_set_search (impl);
+ shortcut_to_select = SHORTCUTS_SEARCH;
+ break;
+
+ case OPERATION_MODE_RECENT:
+ operation_mode_set_recent (impl);
+ shortcut_to_select = SHORTCUTS_RECENT;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ return;