[gnome-photos/wip/rishi/collection: 24/25] main-toolbar: Use switches for enums instead of if-else



commit d822532c58820d295a7be9ffc54ee6260a5f93c7
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jan 16 22:52:27 2018 +0100

    main-toolbar: Use switches for enums instead of if-else
    
    Using a switch statement lets the compiler warn us through
    -Wswitch-enum whenever we extend the enumeration range. An if-else
    block does not do that.

 src/photos-main-toolbar.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index a32d1505..ec57d78f 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -116,28 +116,39 @@ photos_main_toolbar_set_toolbar_title (PhotosMainToolbar *self)
 
   active_collection = photos_item_manager_get_active_collection (PHOTOS_ITEM_MANAGER (self->item_mngr));
 
-  if (window_mode == PHOTOS_WINDOW_MODE_COLLECTION_VIEW)
+  switch (window_mode)
     {
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
       if (selection_mode)
         primary = photos_main_toolbar_create_selection_mode_label (self, active_collection);
       else
         primary = g_strdup (photos_base_item_get_name (active_collection));
-    }
-  else if (window_mode == PHOTOS_WINDOW_MODE_OVERVIEW
-           || window_mode == PHOTOS_WINDOW_MODE_COLLECTIONS
-           || window_mode == PHOTOS_WINDOW_MODE_FAVORITES
-           || window_mode == PHOTOS_WINDOW_MODE_SEARCH)
-    {
+      break;
+
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
       if (selection_mode)
         primary = photos_main_toolbar_create_selection_mode_label (self, NULL);
-    }
-  else if (window_mode == PHOTOS_WINDOW_MODE_EDIT || window_mode == PHOTOS_WINDOW_MODE_PREVIEW)
-    {
-      GObject *item;
+      break;
+
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+      {
+        GObject *item;
+
+        item = photos_base_manager_get_active_object (self->item_mngr);
+        if (item != NULL)
+          primary = g_strdup (photos_base_item_get_name_with_fallback (PHOTOS_BASE_ITEM (item)));
+
+        break;
+      }
 
-      item = photos_base_manager_get_active_object (self->item_mngr);
-      if (item != NULL)
-        primary = g_strdup (photos_base_item_get_name_with_fallback (PHOTOS_BASE_ITEM (item)));
+    case PHOTOS_WINDOW_NONE:
+    default:
+      g_assert_not_reached ();
+      break;
     }
 
   if (selection_mode)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]