[gimp/metadata-browser] app: move the "exclusive visible" logic to the core



commit 3538293933038cbc3854c89acd312bdf2a8b469d
Author: Michael Natterer <mitch gimp org>
Date:   Wed Oct 12 11:13:41 2011 +0200

    app: move the "exclusive visible" logic to the core
    
    but don't fix it for item trees yet (refactoring only). Kill the
    "exclusive liked" function which only existed because it was so easy
    to have, but was always utterly useless. Prove me wrong and I will
    revive it.

 app/core/Makefile.am           |    2 +
 app/core/gimpitem-exclusive.c  |  160 ++++++++++++++++++++++++++++++++++++++++
 app/core/gimpitem-exclusive.h  |   29 +++++++
 app/widgets/gimpitemtreeview.c |  117 +++--------------------------
 po/POTFILES.in                 |    1 +
 5 files changed, 204 insertions(+), 105 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index b1d620b..5e29df8 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -270,6 +270,8 @@ libappcore_a_sources = \
 	gimpimagemapconfig.h			\
 	gimpitem.c				\
 	gimpitem.h				\
+	gimpitem-exclusive.c			\
+	gimpitem-exclusive.h			\
 	gimpitem-linked.c			\
 	gimpitem-linked.h			\
 	gimpitem-preview.c			\
diff --git a/app/core/gimpitem-exclusive.c b/app/core/gimpitem-exclusive.c
new file mode 100644
index 0000000..2ed9686
--- /dev/null
+++ b/app/core/gimpitem-exclusive.c
@@ -0,0 +1,160 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpitem-exclusive.c
+ * Copyright (C) 2011 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include "core-types.h"
+
+#include "gimpcontext.h"
+#include "gimpimage-undo.h"
+#include "gimpimage-undo-push.h"
+#include "gimpitem.h"
+#include "gimpitem-exclusive.h"
+#include "gimpitemstack.h"
+#include "gimpitemtree.h"
+#include "gimpundostack.h"
+
+#include "gimp-intl.h"
+
+
+static void   gimp_item_exclusive_get_lists (GimpItem     *item,
+                                             const gchar  *property,
+                                             GList       **on,
+                                             GList       **off);
+
+
+/*  public functions  */
+
+void
+gimp_item_toggle_exclusive_visible (GimpItem    *item,
+                                    GimpContext *context)
+{
+  GList *on;
+  GList *off;
+  GList *list;
+
+  g_return_if_fail (GIMP_IS_ITEM (item));
+  g_return_if_fail (gimp_item_is_attached (item));
+  g_return_if_fail (GIMP_IS_CONTEXT (context));
+
+  gimp_item_exclusive_get_lists (item, "visible", &on, &off);
+
+  if (on || off || ! gimp_item_get_visible (item))
+    {
+      GimpImage *image = gimp_item_get_image (item);
+      GimpUndo  *undo;
+
+      gboolean  push_undo = TRUE;
+
+      undo = gimp_image_undo_can_compress (image, GIMP_TYPE_UNDO_STACK,
+                                           GIMP_UNDO_GROUP_ITEM_VISIBILITY);
+
+      if (undo && (g_object_get_data (G_OBJECT (undo), "exclusive-item") ==
+                   (gpointer) item))
+        push_undo = FALSE;
+
+      if (push_undo)
+        {
+          if (gimp_image_undo_group_start (image,
+                                           GIMP_UNDO_GROUP_ITEM_VISIBILITY,
+                                           _("Set Item Exclusive Visible")))
+            {
+              undo = gimp_image_undo_can_compress (image, GIMP_TYPE_UNDO_STACK,
+                                                   GIMP_UNDO_GROUP_ITEM_VISIBILITY);
+
+              if (undo)
+                g_object_set_data (G_OBJECT (undo), "exclusive-item",
+                                   (gpointer) item);
+            }
+
+          gimp_image_undo_push_item_visibility (image, NULL, item);
+
+          for (list = on; list; list = g_list_next (list))
+            gimp_image_undo_push_item_visibility (image, NULL, list->data);
+
+          for (list = off; list; list = g_list_next (list))
+            gimp_image_undo_push_item_visibility (image, NULL, list->data);
+
+          gimp_image_undo_group_end (image);
+        }
+      else
+        {
+          gimp_undo_refresh_preview (undo, context);
+        }
+
+      gimp_item_set_visible (item, TRUE, FALSE);
+
+      if (on)
+        {
+          for (list = on; list; list = g_list_next (list))
+            gimp_item_set_visible (list->data, FALSE, FALSE);
+        }
+      else if (off)
+        {
+          for (list = off; list; list = g_list_next (list))
+            gimp_item_set_visible (list->data, TRUE, FALSE);
+        }
+
+      g_list_free (on);
+      g_list_free (off);
+    }
+}
+
+
+/*  private functions  */
+
+static void
+gimp_item_exclusive_get_lists (GimpItem     *item,
+                               const gchar  *property,
+                               GList       **on,
+                               GList       **off)
+{
+  GimpItemTree *tree;
+  GList        *items;
+  GList        *list;
+
+  *on  = NULL;
+  *off = NULL;
+
+  tree = gimp_item_get_tree (item);
+
+  items = gimp_item_stack_get_item_list (GIMP_ITEM_STACK (tree->container));
+
+  for (list = items; list; list = g_list_next (list))
+    {
+      GimpItem *other = list->data;
+
+      if (other != item)
+        {
+          gboolean value;
+
+          g_object_get (other, property, &value, NULL);
+
+          if (value)
+            *on = g_list_prepend (*on, other);
+          else
+            *off = g_list_prepend (*off, other);
+        }
+    }
+
+  g_list_free (items);
+}
diff --git a/app/core/gimpitem-exclusive.h b/app/core/gimpitem-exclusive.h
new file mode 100644
index 0000000..932c89e
--- /dev/null
+++ b/app/core/gimpitem-exclusive.h
@@ -0,0 +1,29 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpitem-exclusive.h
+ * Copyright (C) 2011 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_ITEM_EXCLUSIVE_H__
+#define __GIMP_ITEM_EXCLUSIVE_H__
+
+
+void   gimp_item_toggle_exclusive_visible (GimpItem    *item,
+                                           GimpContext *context);
+
+
+#endif /* __GIMP_ITEM_EXCLUSIVE_H__ */
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index 9a63710..3c30dfb 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -2,7 +2,7 @@
  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  *
  * gimpitemtreeview.c
- * Copyright (C) 2001-2009 Michael Natterer <mitch gimp org>
+ * Copyright (C) 2001-2011 Michael Natterer <mitch gimp org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -37,6 +37,7 @@
 #include "core/gimpimage.h"
 #include "core/gimpimage-undo.h"
 #include "core/gimpimage-undo-push.h"
+#include "core/gimpitem-exclusive.h"
 #include "core/gimpitemundo.h"
 #include "core/gimpmarshal.h"
 #include "core/gimptreehandler.h"
@@ -1299,6 +1300,7 @@ gimp_item_tree_view_eye_clicked (GtkCellRendererToggle *toggle,
                                       GIMP_UNDO_ITEM_VISIBILITY);
 }
 
+
 /*  "Linked" callbacks  */
 
 static void
@@ -1473,33 +1475,23 @@ gimp_item_tree_view_toggle_clicked (GtkCellRendererToggle *toggle,
   GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
   GtkTreePath           *path;
   GtkTreeIter            iter;
-  GimpUndoType           group_type;
-  const gchar           *undo_desc;
 
-  gboolean   (* getter) (const GimpItem *item);
-  void       (* setter) (GimpItem       *item,
-                         gboolean        value,
-                         gboolean        push_undo);
-  GimpUndo * (* pusher) (GimpImage      *image,
-                         const gchar    *undo_desc,
-                         GimpItem       *item);
+  void (* setter)    (GimpItem    *item,
+                      gboolean     value,
+                      gboolean     push_undo);
+  void (* exclusive) (GimpItem    *item,
+                      GimpContext *context);
 
   switch (undo_type)
     {
     case GIMP_UNDO_ITEM_VISIBILITY:
-      getter     = gimp_item_get_visible;
       setter     = gimp_item_set_visible;
-      pusher     = gimp_image_undo_push_item_visibility;
-      group_type = GIMP_UNDO_GROUP_ITEM_VISIBILITY;
-      undo_desc  = _("Set Item Exclusive Visible");
+      exclusive  = gimp_item_toggle_exclusive_visible;
       break;
 
     case GIMP_UNDO_ITEM_LINKED:
-      getter     = gimp_item_get_linked;
       setter     = gimp_item_set_linked;
-      pusher     = gimp_image_undo_push_item_linked;
-      group_type = GIMP_UNDO_GROUP_ITEM_LINKED;
-      undo_desc  = _("Set Item Exclusive Linked");
+      exclusive  = NULL;
       break;
 
     default:
@@ -1530,94 +1522,9 @@ gimp_item_tree_view_toggle_clicked (GtkCellRendererToggle *toggle,
 
       image = gimp_item_get_image (item);
 
-      if (state & GDK_SHIFT_MASK)
+      if ((state & GDK_SHIFT_MASK) && exclusive)
         {
-          GList    *on  = NULL;
-          GList    *off = NULL;
-          GList    *list;
-          gboolean  iter_valid;
-
-          for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model,
-                                                           &iter);
-               iter_valid;
-               iter_valid = gtk_tree_model_iter_next (tree_view->model,
-                                                      &iter))
-            {
-              gtk_tree_model_get (tree_view->model, &iter,
-                                  GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
-                                  -1);
-
-              if ((GimpItem *) renderer->viewable != item)
-                {
-                  if (getter (GIMP_ITEM (renderer->viewable)))
-                    on = g_list_prepend (on, renderer->viewable);
-                  else
-                    off = g_list_prepend (off, renderer->viewable);
-                }
-
-              g_object_unref (renderer);
-            }
-
-          if (on || off || ! getter (item))
-            {
-              GimpItemTreeViewClass *view_class;
-              GimpUndo              *undo;
-              gboolean               push_undo = TRUE;
-
-              view_class = GIMP_ITEM_TREE_VIEW_GET_CLASS (view);
-
-              undo = gimp_image_undo_can_compress (image, GIMP_TYPE_UNDO_STACK,
-                                                   group_type);
-
-              if (undo && (g_object_get_data (G_OBJECT (undo), "item-type") ==
-                           (gpointer) view_class->item_type))
-                push_undo = FALSE;
-
-              if (push_undo)
-                {
-                  if (gimp_image_undo_group_start (image, group_type,
-                                                   undo_desc))
-                    {
-                      undo = gimp_image_undo_can_compress (image,
-                                                           GIMP_TYPE_UNDO_STACK,
-                                                           group_type);
-
-                      if (undo)
-                        g_object_set_data (G_OBJECT (undo), "item-type",
-                                           (gpointer) view_class->item_type);
-                    }
-
-                  pusher (image, NULL, item);
-
-                  for (list = on; list; list = g_list_next (list))
-                    pusher (image, NULL, list->data);
-
-                  for (list = off; list; list = g_list_next (list))
-                    pusher (image, NULL, list->data);
-
-                  gimp_image_undo_group_end (image);
-                }
-              else
-                {
-                  gimp_undo_refresh_preview (undo, context);
-                }
-            }
-
-          setter (item, TRUE, FALSE);
-
-          if (on)
-            {
-              for (list = on; list; list = g_list_next (list))
-                setter (GIMP_ITEM (list->data), FALSE, FALSE);
-            }
-          else if (off)
-            {
-              for (list = off; list; list = g_list_next (list))
-                setter (GIMP_ITEM (list->data), TRUE, FALSE);
-            }
-
-          g_list_free (on);
-          g_list_free (off);
+          exclusive (item, context);
         }
       else
         {
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5f8fa13..840e2b9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -156,6 +156,7 @@ app/core/gimpimage-undo-push.c
 app/core/gimpimage.c
 app/core/gimpimagefile.c
 app/core/gimpitem.c
+app/core/gimpitem-exclusive.c
 app/core/gimplayer-floating-sel.c
 app/core/gimplayer.c
 app/core/gimplayermask.c



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