[gnome-photos] application, item-manager: Clarify state changes due to search provider



commit 73a26459417bc71e4b65f7a32496c957d897e8a0
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Jan 21 18:05:15 2018 +0100

    application, item-manager: Clarify state changes due to search provider
    
    The guiding principle is to ignore ActivateResult and LaunchSearch if
    the application is in EDIT or PREVIEW. Being in one of those two modes
    implies that the user is focused on a specific BaseItem, and shouldn't
    be interfered with from a different context. The mode can only change
    if the user explicitly requests it from the application.
    
    The presence of a separate mode for viewing the contents of a
    collection removes the need to unset the active collection before a
    collection BaseItem can be added to the ItemManager.

 src/photos-application.c  | 106 +++++++++++++++++++++++++++++++++++++++++++++-
 src/photos-item-manager.c |  16 ++-----
 2 files changed, 108 insertions(+), 14 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 38b9de0d..8e7e4363 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -705,9 +705,64 @@ photos_application_create_window (PhotosApplication *self)
 static void
 photos_application_activate_item (PhotosApplication *self, GObject *item)
 {
+  PhotosWindowMode mode;
+  gboolean can_activate;
+
+  mode = photos_mode_controller_get_window_mode (self->state->mode_cntrlr);
+
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      can_activate = TRUE;
+      break;
+
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+      can_activate = FALSE;
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  if (!can_activate)
+    {
+      g_return_if_fail (PHOTOS_IS_MAIN_WINDOW (self->main_window));
+      return;
+    }
+
   if (!photos_application_create_window (self))
     return;
 
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_NONE:
+      photos_mode_controller_set_window_mode (self->state->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
+      break;
+
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+      photos_mode_controller_go_back (self->state->mode_cntrlr);
+      break;
+
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      break;
+
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
   photos_base_manager_set_active_object (self->state->item_mngr, item);
   g_application_activate (G_APPLICATION (self));
 
@@ -925,14 +980,63 @@ static void
 photos_application_launch_search (PhotosApplication *self, const gchar* const *terms, guint timestamp)
 {
   GVariant *state;
+  PhotosWindowMode mode;
+  gboolean can_launch;
   g_autofree gchar *str = NULL;
 
   photos_debug (PHOTOS_DEBUG_APPLICATION, "PhotosApplication::launch_search");
 
+  mode = photos_mode_controller_get_window_mode (self->state->mode_cntrlr);
+
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_NONE:
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      can_launch = TRUE;
+      break;
+
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+      can_launch = FALSE;
+      break;
+
+    default:
+      g_assert_not_reached ();
+      break;
+    }
+
+  if (!can_launch)
+    {
+      g_return_if_fail (PHOTOS_IS_MAIN_WINDOW (self->main_window));
+      return;
+    }
+
   if (!photos_application_create_window (self))
     return;
 
-  photos_mode_controller_set_window_mode (self->state->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
+  switch (mode)
+    {
+    case PHOTOS_WINDOW_MODE_NONE:
+      photos_mode_controller_set_window_mode (self->state->mode_cntrlr, PHOTOS_WINDOW_MODE_OVERVIEW);
+      break;
+
+    case PHOTOS_WINDOW_MODE_COLLECTION_VIEW:
+    case PHOTOS_WINDOW_MODE_COLLECTIONS:
+    case PHOTOS_WINDOW_MODE_FAVORITES:
+    case PHOTOS_WINDOW_MODE_OVERVIEW:
+    case PHOTOS_WINDOW_MODE_SEARCH:
+      break;
+
+    case PHOTOS_WINDOW_MODE_EDIT:
+    case PHOTOS_WINDOW_MODE_PREVIEW:
+    default:
+      g_assert_not_reached ();
+      break;
+    }
 
   str = g_strjoinv (" ", (gchar **) terms);
   photos_search_controller_set_string (self->state->srch_cntrlr, str);
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 616552eb..573ed209 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -668,6 +668,7 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
 
   g_return_val_if_fail (object != NULL, FALSE);
   g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (object), FALSE);
+  g_return_val_if_fail (self->mode != PHOTOS_WINDOW_MODE_EDIT, FALSE);
 
   is_collection = photos_base_item_is_collection (PHOTOS_BASE_ITEM (object));
   if (is_collection)
@@ -961,11 +962,7 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
 
   if (photos_item_manager_cursor_is_collection (cursor))
     {
-      if (self->active_collection != NULL && force)
-        photos_mode_controller_go_back (self);
-
-      if (self->active_collection == NULL)
-        photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_COLLECTIONS, force);
+      photos_item_manager_add_cursor_for_mode (self, cursor, PHOTOS_WINDOW_MODE_COLLECTIONS, force);
     }
   else
     {
@@ -1295,14 +1292,6 @@ photos_mode_controller_go_back (PhotosModeController *self)
   g_return_if_fail (!g_queue_is_empty (self->history));
 
   old_mode = (PhotosWindowMode) GPOINTER_TO_INT (g_queue_peek_head (self->history));
-
-  /* Always go back to the overview when activated from the search
-   * provider. It is easier to special case it here instead of all
-   * over the code.
-   */
-  if (self->mode == PHOTOS_WINDOW_MODE_PREVIEW && old_mode == PHOTOS_WINDOW_MODE_NONE)
-    old_mode = PHOTOS_WINDOW_MODE_OVERVIEW;
-
   g_return_if_fail (old_mode != PHOTOS_WINDOW_MODE_NONE);
 
   switch (self->mode)
@@ -1439,6 +1428,7 @@ photos_mode_controller_set_window_mode (PhotosModeController *self, PhotosWindow
     }
   else
     {
+      g_return_if_fail (self->mode != PHOTOS_WINDOW_MODE_EDIT);
       g_return_if_fail (self->mode != PHOTOS_WINDOW_MODE_PREVIEW);
     }
 


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