Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Centralize changing the operation mode in operation_mode_set()

This will be the central function to switch operation modes:  stop searches or the recent-files
process; switch widgets, etc.

We factor out the common code from recent_switch_to_browse_mode() and search_switch_to_browse_mode(),
and remove those functions.  All the code that switched modes by hand now calls
the central operation_mode_set().

Signed-off-by: Federico Mena Quintero <federico@gnome.org>
  • Loading branch information...
commit cccf35f862289dbc9acc27a0e3ad060ea6d3fe23 1 parent 7726276
Federico Mena Quintero authored July 26, 2011

Showing 1 changed file with 40 additions and 88 deletions. Show diff stats Hide diff stats

  1. 128  gtk/gtkfilechooserdefault.c
128  gtk/gtkfilechooserdefault.c
@@ -411,7 +411,6 @@ static void     search_stop_searching        (GtkFileChooserDefault *impl,
411 411
 static void     search_clear_model           (GtkFileChooserDefault *impl, 
412 412
 					      gboolean               remove_from_treeview);
413 413
 static gboolean search_should_respond        (GtkFileChooserDefault *impl);
414  
-static void     search_switch_to_browse_mode (GtkFileChooserDefault *impl);
415 414
 static GSList  *search_get_selected_files    (GtkFileChooserDefault *impl);
416 415
 static void     search_entry_activate_cb     (GtkEntry              *entry, 
417 416
 					      gpointer               data);
@@ -421,7 +420,6 @@ static void     recent_stop_loading          (GtkFileChooserDefault *impl);
421 420
 static void     recent_clear_model           (GtkFileChooserDefault *impl,
422 421
                                               gboolean               remove_from_treeview);
423 422
 static gboolean recent_should_respond        (GtkFileChooserDefault *impl);
424  
-static void     recent_switch_to_browse_mode (GtkFileChooserDefault *impl);
425 423
 static GSList * recent_get_selected_files    (GtkFileChooserDefault *impl);
426 424
 static void     set_file_system_backend      (GtkFileChooserDefault *impl);
427 425
 static void     unset_file_system_backend    (GtkFileChooserDefault *impl);
@@ -5256,6 +5254,42 @@ operation_mode_stop (GtkFileChooserDefault *impl, OperationMode mode)
5256 5254
     }
5257 5255
 }
5258 5256
 
  5257
+static void
  5258
+operation_mode_set_browse (GtkFileChooserDefault *impl)
  5259
+{
  5260
+  path_bar_update (impl);
  5261
+
  5262
+  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
  5263
+      impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
  5264
+    {
  5265
+      gtk_widget_show (impl->location_button);
  5266
+
  5267
+      if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
  5268
+	gtk_widget_show (impl->location_entry_box);
  5269
+    }
  5270
+
  5271
+  file_list_set_sort_column_ids (impl);
  5272
+}
  5273
+
  5274
+static void
  5275
+operation_mode_set (GtkFileChooserDefault *impl, OperationMode mode)
  5276
+{
  5277
+  operation_mode_stop (impl, impl->operation_mode);
  5278
+
  5279
+  impl->operation_mode = mode;
  5280
+
  5281
+  switch (impl->operation_mode)
  5282
+    {
  5283
+    case OPERATION_MODE_BROWSE:
  5284
+      operation_mode_set_browse (impl);
  5285
+      break;
  5286
+
  5287
+    default:
  5288
+      g_assert_not_reached ();
  5289
+    }
  5290
+
  5291
+}
  5292
+
5259 5293
 /* This function is basically a do_all function.
5260 5294
  *
5261 5295
  * It sets the visibility on all the widgets based on the current state, and
@@ -7153,17 +7187,7 @@ gtk_file_chooser_default_update_current_folder (GtkFileChooser    *chooser,
7153 7187
 
7154 7188
   g_object_ref (file);
7155 7189
 
7156  
-  switch (impl->operation_mode)
7157  
-    {
7158  
-    case OPERATION_MODE_SEARCH:
7159  
-      search_switch_to_browse_mode (impl);
7160  
-      break;
7161  
-    case OPERATION_MODE_RECENT:
7162  
-      recent_switch_to_browse_mode (impl);
7163  
-      break;
7164  
-    case OPERATION_MODE_BROWSE:
7165  
-      break;
7166  
-    }
  7190
+  operation_mode_set (impl, OPERATION_MODE_BROWSE);
7167 7191
 
7168 7192
   if (impl->local_only && !g_file_is_native (file))
7169 7193
     {
@@ -8995,29 +9019,6 @@ search_stop_searching (GtkFileChooserDefault *impl,
8995 9019
     }
8996 9020
 }
8997 9021
 
8998  
-/* Stops any pending searches, clears the file list, and switches back to OPERATION_MODE_BROWSE */
8999  
-static void
9000  
-search_switch_to_browse_mode (GtkFileChooserDefault *impl)
9001  
-{
9002  
-  g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9003  
-
9004  
-  operation_mode_stop (impl, impl->operation_mode);
9005  
-
9006  
-  impl->operation_mode = OPERATION_MODE_BROWSE;
9007  
-  path_bar_update (impl);
9008  
-
9009  
-  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9010  
-      impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9011  
-    {
9012  
-      gtk_widget_show (impl->location_button);
9013  
-
9014  
-      if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9015  
-	gtk_widget_show (impl->location_entry_box);
9016  
-    }
9017  
-
9018  
-  file_list_set_sort_column_ids (impl);
9019  
-}
9020  
-
9021 9022
 /* Creates the search_model and puts it in the tree view */
9022 9023
 static void
9023 9024
 search_setup_model (GtkFileChooserDefault *impl)
@@ -9276,33 +9277,6 @@ recent_stop_loading (GtkFileChooserDefault *impl)
9276 9277
     }
9277 9278
 }
9278 9279
 
9279  
-/* Stops any pending load, clears the file list, and switches
9280  
- * back to OPERATION_MODE_BROWSE
9281  
- */
9282  
-static void
9283  
-recent_switch_to_browse_mode (GtkFileChooserDefault *impl)
9284  
-{
9285  
-  g_assert (impl->operation_mode != OPERATION_MODE_BROWSE);
9286  
-
9287  
-  operation_mode_stop (impl, impl->operation_mode);
9288  
-
9289  
-  impl->operation_mode = OPERATION_MODE_BROWSE;
9290  
-  path_bar_update (impl);
9291  
-
9292  
-  if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN ||
9293  
-      impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
9294  
-    {
9295  
-      gtk_widget_show (impl->location_button);
9296  
-
9297  
-      if (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY)
9298  
-	gtk_widget_show (impl->location_entry_box);
9299  
-    }
9300  
-
9301  
-  gtk_tree_view_column_set_visible (impl->list_size_column, impl->show_size_column);
9302  
-
9303  
-  file_list_set_sort_column_ids (impl);
9304  
-}
9305  
-
9306 9280
 static void
9307 9281
 recent_setup_model (GtkFileChooserDefault *impl)
9308 9282
 {
@@ -9748,17 +9722,7 @@ shortcuts_activate_volume (GtkFileChooserDefault *impl,
9748 9722
 {
9749 9723
   GFile *file;
9750 9724
 
9751  
-  switch (impl->operation_mode)
9752  
-    {
9753  
-    case OPERATION_MODE_BROWSE:
9754  
-      break;
9755  
-    case OPERATION_MODE_SEARCH:
9756  
-      search_switch_to_browse_mode (impl);
9757  
-      break;
9758  
-    case OPERATION_MODE_RECENT:
9759  
-      recent_switch_to_browse_mode (impl);
9760  
-      break;
9761  
-    }
  9725
+  operation_mode_set (impl, OPERATION_MODE_BROWSE);
9762 9726
 
9763 9727
   /* We ref the file chooser since volume_mount() may run a main loop, and the
9764 9728
    * user could close the file chooser window in the meantime.
@@ -10195,21 +10159,9 @@ location_popup_handler (GtkFileChooserDefault *impl,
10195 10159
   if (impl->operation_mode != OPERATION_MODE_BROWSE)
10196 10160
     {
10197 10161
       GtkWidget *widget_to_focus;
10198  
-      
10199  
-      /* This will give us the location widgets back */
10200  
-      switch (impl->operation_mode)
10201  
-        {
10202  
-        case OPERATION_MODE_SEARCH:
10203  
-          search_switch_to_browse_mode (impl);
10204  
-          break;
10205  
-        case OPERATION_MODE_RECENT:
10206  
-          recent_switch_to_browse_mode (impl);
10207  
-          break;
10208  
-        case OPERATION_MODE_BROWSE:
10209  
-          g_assert_not_reached ();
10210  
-          break;
10211  
-        }
10212 10162
 
  10163
+      operation_mode_set (impl, OPERATION_MODE_BROWSE);
  10164
+      
10213 10165
       if (impl->current_folder)
10214 10166
         change_folder_and_display_error (impl, impl->current_folder, FALSE);
10215 10167
 

0 notes on commit cccf35f

Please sign in to comment.
Something went wrong with that request. Please try again.