[gimp] Bug 155164 - Merge Palettes is unimplemented



commit 3dc5d3da9fa24f43816f3455cddd4062ec41e877
Author: Michael Natterer <mitch gimp org>
Date:   Mon Oct 17 01:03:59 2016 +0200

    Bug 155164 - Merge Palettes is unimplemented
    
    We have multiple selection in lists, so finally fix merge palette.

 app/actions/palettes-actions.c  |   15 +++--
 app/actions/palettes-commands.c |  103 ++++++++++++++++++++-------------------
 2 files changed, 62 insertions(+), 56 deletions(-)
---
diff --git a/app/actions/palettes-actions.c b/app/actions/palettes-actions.c
index 6983d5a..2747329 100644
--- a/app/actions/palettes-actions.c
+++ b/app/actions/palettes-actions.c
@@ -120,16 +120,19 @@ void
 palettes_actions_update (GimpActionGroup *group,
                          gpointer         user_data)
 {
-  GimpContext *context = action_data_get_context (user_data);
-  GimpPalette *palette = NULL;
-  GimpData    *data    = NULL;
-  GFile       *file    = NULL;
+  GimpContext *context   = action_data_get_context (user_data);
+  GimpPalette *palette   = NULL;
+  GimpData    *data      = NULL;
+  GFile       *file      = NULL;
+  gint         sel_count = 0;
 
   if (context)
     {
       palette = gimp_context_get_palette (context);
 
-      if (action_data_sel_count (user_data) > 1)
+      sel_count = action_data_sel_count (user_data);
+
+      if (sel_count > 1)
         {
           palette = NULL;
         }
@@ -147,7 +150,7 @@ palettes_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("palettes-edit",                 palette);
   SET_SENSITIVE ("palettes-duplicate",            palette && GIMP_DATA_GET_CLASS (data)->duplicate);
-  SET_SENSITIVE ("palettes-merge",                FALSE); /* FIXME palette && GIMP_IS_CONTAINER_LIST_VIEW 
(editor->view)); */
+  SET_SENSITIVE ("palettes-merge",                sel_count > 1);
   SET_SENSITIVE ("palettes-copy-location",        file);
   SET_SENSITIVE ("palettes-show-in-file-manager", file);
   SET_SENSITIVE ("palettes-delete",               palette && gimp_data_is_deletable (data));
diff --git a/app/actions/palettes-commands.c b/app/actions/palettes-commands.c
index eaa1b39..d601c1a 100644
--- a/app/actions/palettes-commands.c
+++ b/app/actions/palettes-commands.c
@@ -24,11 +24,11 @@
 
 #include "actions-types.h"
 
-#include "core/gimppalette.h"
-#include "core/gimpcontainer.h"
+#include "core/gimp.h"
 #include "core/gimpcontext.h"
+#include "core/gimpdatafactory.h"
+#include "core/gimppalette.h"
 
-#include "widgets/gimpcontainertreeview.h"
 #include "widgets/gimpcontainerview.h"
 #include "widgets/gimpdatafactoryview.h"
 #include "widgets/gimpdialogfactory.h"
@@ -36,6 +36,8 @@
 #include "widgets/gimpview.h"
 #include "widgets/gimpwidgets-utils.h"
 
+#include "dialogs/dialogs.h"
+
 #include "actions.h"
 #include "palettes-commands.h"
 
@@ -72,16 +74,25 @@ palettes_merge_cmd_callback (GtkAction *action,
   GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (data);
   GtkWidget           *dialog;
 
-  dialog = gimp_query_string_box (_("Merge Palette"),
-                                  GTK_WIDGET (editor),
-                                  gimp_standard_help_func,
-                                  GIMP_HELP_PALETTE_MERGE,
-                                  _("Enter a name for the merged palette"),
-                                  NULL,
-                                  G_OBJECT (editor), "destroy",
-                                  palettes_merge_callback,
-                                  editor);
-  gtk_widget_show (dialog);
+#define MERGE_DIALOG_KEY "gimp-palettes-merge-dialog"
+
+  dialog = dialogs_get_dialog (G_OBJECT (editor), MERGE_DIALOG_KEY);
+
+  if (! dialog)
+    {
+      dialog = gimp_query_string_box (_("Merge Palettes"),
+                                      GTK_WIDGET (editor),
+                                      gimp_standard_help_func,
+                                      GIMP_HELP_PALETTE_MERGE,
+                                      _("Enter a name for the merged palette"),
+                                      NULL,
+                                      G_OBJECT (editor), "destroy",
+                                      palettes_merge_callback, editor);
+
+      dialogs_attach_dialog (G_OBJECT (editor), MERGE_DIALOG_KEY, dialog);
+    }
+
+  gtk_window_present (GTK_WINDOW (dialog));
 }
 
 
@@ -92,56 +103,48 @@ palettes_merge_callback (GtkWidget   *widget,
                          const gchar *palette_name,
                          gpointer     data)
 {
-  /* FIXME: reimplement palettes_merge_callback() */
-#if 0
-  GimpContainerEditor *editor;
-  GimpPalette         *palette;
+  GimpContainerEditor *editor = data;
+  GimpDataFactoryView *view   = data;
+  GimpDataFactory     *factory;
+  GimpContext         *context;
   GimpPalette         *new_palette;
-  GList               *sel_list;
+  GList               *selected = NULL;
+  GList               *list;
 
-  editor = (GimpContainerEditor *) data;
+  context = gimp_container_view_get_context (editor->view);
+  factory = gimp_data_factory_view_get_data_factory (view);
 
-  sel_list = GTK_LIST (GIMP_CONTAINER_LIST_VIEW (editor->view)->gtk_list)->selection;
+  gimp_container_view_get_selected (editor->view, &selected);
 
-  if (! sel_list)
+  if (g_list_length (selected) < 2)
     {
-      gimp_message_literal (gimp,
-                            G_OBJECT (widget), GIMP_MESSAGE_WARNING,
-                            "Can't merge palettes because "
-                            "there are no palettes selected.");
+      gimp_message_literal (context->gimp,
+                            G_OBJECT (editor), GIMP_MESSAGE_WARNING,
+                            _("There must be at least two palettes selected "
+                              "to merge."));
+      g_list_free (selected);
       return;
     }
 
-  new_palette = GIMP_PALETTE (gimp_palette_new (palette_name, FALSE));
+  new_palette = GIMP_PALETTE (gimp_data_factory_data_new (factory, context,
+                                                          palette_name));
 
-  while (sel_list)
+  for (list = selected; list; list = g_list_next (list))
     {
-      GimpListItem *list_item;
-
-      list_item = GIMP_LIST_ITEM (sel_list->data);
+      GimpPalette *palette = list->data;
+      GList       *cols;
 
-      palette = (GimpPalette *) GIMP_VIEW (list_item->preview)->viewable;
-
-      if (palette)
+      for (cols = gimp_palette_get_colors (palette);
+           cols;
+           cols = g_list_next (cols))
         {
-          GList *cols;
-
-          for (cols = gimp_palette_get_colors (palette);
-               cols;
-               cols = g_list_next (cols))
-            {
-              GimpPaletteEntry *entry = cols->data;
-
-              gimp_palette_add_entry (new_palette,
-                                      entry->name,
-                                      &entry->color);
-            }
-        }
+          GimpPaletteEntry *entry = cols->data;
 
-      sel_list = sel_list->next;
+          gimp_palette_add_entry (new_palette, -1,
+                                  entry->name,
+                                  &entry->color);
+        }
     }
 
-  gimp_container_add (editor->view->container,
-                      GIMP_OBJECT (new_palette));
-#endif
+  g_list_free (selected);
 }


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