[gnome-photos] preview-menu, preview-nav-buttons: Support deleting from the preview
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] preview-menu, preview-nav-buttons: Support deleting from the preview
- Date: Mon, 26 Oct 2015 14:21:50 +0000 (UTC)
commit b45bc1a4c94eac4e4d7ccf26782ed0e4a0725c6a
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Oct 25 20:11:01 2015 +0100
preview-menu, preview-nav-buttons: Support deleting from the preview
https://bugzilla.gnome.org/show_bug.cgi?id=733660
src/photos-preview-menu.ui | 4 ++
src/photos-preview-nav-buttons.c | 77 +++++++++++++++++++++++++++++++++++++-
src/photos-preview-view.c | 5 ++-
3 files changed, 84 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-preview-menu.ui b/src/photos-preview-menu.ui
index 3d29507..df41adf 100644
--- a/src/photos-preview-menu.ui
+++ b/src/photos-preview-menu.ui
@@ -11,6 +11,10 @@
<attribute name="accel"><Primary>p</attribute>
</item>
<item>
+ <attribute name="action">app.delete</attribute>
+ <attribute name="label" translatable="yes">Delete</attribute>
+ </item>
+ <item>
<attribute name="action">app.remote-display-current</attribute>
<attribute name="label" translatable="yes">Display on…</attribute>
</item>
diff --git a/src/photos-preview-nav-buttons.c b/src/photos-preview-nav-buttons.c
index e72d95f..8ada3d6 100644
--- a/src/photos-preview-nav-buttons.c
+++ b/src/photos-preview-nav-buttons.c
@@ -29,7 +29,9 @@
#include <glib/gi18n.h>
#include "photos-base-manager.h"
+#include "photos-delete-notification.h"
#include "photos-icons.h"
+#include "photos-item-manager.h"
#include "photos-preview-model.h"
#include "photos-preview-nav-buttons.h"
#include "photos-search-context.h"
@@ -48,12 +50,15 @@ struct _PhotosPreviewNavButtonsPrivate
GtkWidget *prev_widget;
GtkWidget *preview_view;
PhotosBaseManager *item_mngr;
+ PhotosModeController *mode_cntrlr;
gboolean enable_next;
gboolean enable_prev;
gboolean visible;
gboolean visible_internal;
guint auto_hide_id;
guint motion_id;
+ gulong row_deleted_id;
+ gulong row_inserted_id;
};
enum
@@ -68,6 +73,36 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosPreviewNavButtons, photos_preview_nav_buttons,
static void
+photos_preview_nav_buttons_delete (PhotosPreviewNavButtons *self)
+{
+ PhotosPreviewNavButtonsPrivate *priv = self->priv;
+ GList *items = NULL;
+ PhotosBaseItem *item;
+ PhotosWindowMode mode;
+
+ mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
+ if (mode != PHOTOS_WINDOW_MODE_PREVIEW)
+ return;
+
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (priv->item_mngr));
+ if (item == NULL)
+ return;
+
+ if (priv->enable_next)
+ g_action_activate (priv->load_next, NULL);
+ else if (priv->enable_prev)
+ g_action_activate (priv->load_previous, NULL);
+ else
+ photos_mode_controller_go_back (priv->mode_cntrlr);
+
+ items = g_list_prepend (items, g_object_ref (item));
+ photos_base_manager_remove_object (priv->item_mngr, G_OBJECT (item));
+ photos_delete_notification_new (items);
+ g_list_free_full (items, g_object_unref);
+}
+
+
+static void
photos_preview_nav_buttons_fade_in_button (PhotosPreviewNavButtons *self, GtkWidget *widget)
{
PhotosPreviewNavButtonsPrivate *priv = self->priv;
@@ -260,6 +295,13 @@ photos_preview_nav_buttons_multi_press_stopped (PhotosPreviewNavButtons *self)
static void
+photos_preview_nav_buttons_row_changed (PhotosPreviewNavButtons *self)
+{
+ photos_preview_nav_buttons_update_visibility (self);
+}
+
+
+static void
photos_preview_nav_buttons_set_active_path (PhotosPreviewNavButtons *self, GtkTreePath *current_path)
{
PhotosPreviewNavButtonsPrivate *priv = self->priv;
@@ -331,6 +373,7 @@ photos_preview_nav_buttons_dispose (GObject *object)
g_clear_object (&priv->overlay);
g_clear_object (&priv->preview_view);
g_clear_object (&priv->item_mngr);
+ g_clear_object (&priv->mode_cntrlr);
G_OBJECT_CLASS (photos_preview_nav_buttons_parent_class)->dispose (object);
}
@@ -456,6 +499,7 @@ static void
photos_preview_nav_buttons_init (PhotosPreviewNavButtons *self)
{
PhotosPreviewNavButtonsPrivate *priv;
+ GAction *action;
GApplication *app;
PhotosSearchContextState *state;
@@ -480,6 +524,14 @@ photos_preview_nav_buttons_init (PhotosPreviewNavButtons *self)
G_CONNECT_SWAPPED);
priv->item_mngr = g_object_ref (state->item_mngr);
+ priv->mode_cntrlr = g_object_ref (state->mode_cntrlr);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (app), "delete");
+ g_signal_connect_object (action,
+ "activate",
+ G_CALLBACK (photos_preview_nav_buttons_delete),
+ self,
+ G_CONNECT_SWAPPED);
}
@@ -536,9 +588,32 @@ photos_preview_nav_buttons_set_model (PhotosPreviewNavButtons *self,
{
PhotosPreviewNavButtonsPrivate *priv = self->priv;
+ if (priv->row_deleted_id != 0)
+ {
+ g_signal_handler_disconnect (priv->model, priv->row_deleted_id);
+ priv->row_deleted_id = 0;
+ }
+
+ if (priv->row_inserted_id != 0)
+ {
+ g_signal_handler_disconnect (priv->model, priv->row_inserted_id);
+ priv->row_inserted_id = 0;
+ }
+
g_clear_object (&priv->model);
+
if (child_model != NULL)
- priv->model = photos_preview_model_new (child_model);
+ {
+ priv->model = photos_preview_model_new (child_model);
+ priv->row_deleted_id = g_signal_connect_swapped (priv->model,
+ "row-deleted",
+ G_CALLBACK (photos_preview_nav_buttons_row_changed),
+ self);
+ priv->row_inserted_id = g_signal_connect_swapped (priv->model,
+ "row-inserted",
+ G_CALLBACK (photos_preview_nav_buttons_row_changed),
+ self);
+ }
g_clear_pointer (&priv->current_row, (GDestroyNotify) gtk_tree_row_reference_free);
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 8431a3f..a5bc5f4 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -160,13 +160,16 @@ photos_preview_view_create_view (PhotosPreviewView *self)
static void
photos_preview_view_window_mode_changed (PhotosPreviewView *self, PhotosWindowMode mode, PhotosWindowMode
old_mode)
{
+ PhotosPreviewViewPrivate *priv = self->priv;
+
switch (mode)
{
case PHOTOS_WINDOW_MODE_COLLECTIONS:
case PHOTOS_WINDOW_MODE_FAVORITES:
case PHOTOS_WINDOW_MODE_OVERVIEW:
case PHOTOS_WINDOW_MODE_SEARCH:
- photos_preview_nav_buttons_hide (self->priv->nav_buttons);
+ photos_preview_nav_buttons_hide (priv->nav_buttons);
+ photos_preview_nav_buttons_set_model (priv->nav_buttons, NULL, NULL);
break;
case PHOTOS_WINDOW_MODE_PREVIEW:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]