[gnome-photos] main-toolbar: Use switches for enums instead of if-else
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] main-toolbar: Use switches for enums instead of if-else
- Date: Wed, 17 Jan 2018 12:39:01 +0000 (UTC)
commit 9f9441e1686408b5987954341e082d4876632980
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 | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 9db15c2c..3d7fc32f 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -115,28 +115,38 @@ 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_MODE_NONE:
+ default:
+ break;
}
if (selection_mode)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]