gimp r24627 - in branches/weskaggs: . app/actions app/core app/widgets



Author: weskaggs
Date: Wed Jan 16 19:11:41 2008
New Revision: 24627
URL: http://svn.gnome.org/viewvc/gimp?rev=24627&view=rev

Log:
Bill Skaggs  <weskaggs primate ucdavis edu>

	Preliminary experimental implementation of data chooser
	functionality.

	* app/widgets/gimpdatachooserdialog.c
	* app/widgets/gimpdatachooserdialog.h: new files

	* app/core/gimpdatafactory.c
	* app/core/gimpdatafactory.h
	* app/actions/data-commands.c
	* app/actions/data-commands.h
	* app/actions/gradients-actions.c
	* app/actions/palettes-actions.c
	* app/actions/brushes-actions.c
	* app/actions/patterns-actions.c
	* app/widgets/Makefile.am
	* app/widgets/gimpdatafactoryview.c
	* app/widgets/gimpdatafactoryview.h
	* app/widgets/gimphelp-ids.h


Added:
   branches/weskaggs/app/widgets/gimpdatachooserdialog.c
   branches/weskaggs/app/widgets/gimpdatachooserdialog.h
Modified:
   branches/weskaggs/ChangeLog
   branches/weskaggs/app/actions/brushes-actions.c
   branches/weskaggs/app/actions/data-commands.c
   branches/weskaggs/app/actions/data-commands.h
   branches/weskaggs/app/actions/gradients-actions.c
   branches/weskaggs/app/actions/palettes-actions.c
   branches/weskaggs/app/actions/patterns-actions.c
   branches/weskaggs/app/core/gimpdatafactory.c
   branches/weskaggs/app/core/gimpdatafactory.h
   branches/weskaggs/app/widgets/Makefile.am
   branches/weskaggs/app/widgets/gimpdatafactoryview.c
   branches/weskaggs/app/widgets/gimpdatafactoryview.h
   branches/weskaggs/app/widgets/gimphelp-ids.h

Modified: branches/weskaggs/app/actions/brushes-actions.c
==============================================================================
--- branches/weskaggs/app/actions/brushes-actions.c	(original)
+++ branches/weskaggs/app/actions/brushes-actions.c	Wed Jan 16 19:11:41 2008
@@ -49,6 +49,18 @@
     G_CALLBACK (data_open_as_image_cmd_callback),
     GIMP_HELP_BRUSH_OPEN_AS_IMAGE },
 
+  { "brushes-load", GTK_STOCK_NEW,
+    N_("_Load Brush"), "",
+    N_("Load brush"),
+    G_CALLBACK (data_load_cmd_callback),
+    GIMP_HELP_BRUSH_LOAD },
+
+  { "brushes-save", GTK_STOCK_NEW,
+    N_("_Save Brush"), "",
+    N_("Save brush"),
+    G_CALLBACK (data_save_cmd_callback),
+    GIMP_HELP_BRUSH_SAVE },
+
   { "brushes-new", GTK_STOCK_NEW,
     N_("_New Brush"), "",
     N_("New brush"),

Modified: branches/weskaggs/app/actions/data-commands.c
==============================================================================
--- branches/weskaggs/app/actions/data-commands.c	(original)
+++ branches/weskaggs/app/actions/data-commands.c	Wed Jan 16 19:11:41 2008
@@ -20,6 +20,8 @@
 
 #include <gtk/gtk.h>
 
+#include "libgimpbase/gimpbase.h"
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
 #include "actions-types.h"
@@ -36,6 +38,7 @@
 
 #include "widgets/gimpclipboard.h"
 #include "widgets/gimpcontainerview.h"
+#include "widgets/gimpdatachooserdialog.h"
 #include "widgets/gimpdataeditor.h"
 #include "widgets/gimpdatafactoryview.h"
 #include "widgets/gimpdialogfactory.h"
@@ -117,6 +120,23 @@
 }
 
 void
+data_load_cmd_callback (GtkAction *action,
+                        gpointer   user_data)
+{
+  GimpDataFactoryView *view        = GIMP_DATA_FACTORY_VIEW (user_data);
+  GimpDataFactory     *factory     = view->factory;
+  GimpDataLoadContext  load_context;
+
+  gimp_data_chooser_dialog_new (factory, GIMP_VIEW_TYPE_LIST);
+}
+
+void
+data_save_cmd_callback (GtkAction *action,
+                        gpointer   user_data)
+{
+}
+
+void
 data_new_cmd_callback (GtkAction *action,
                        gpointer   user_data)
 {

Modified: branches/weskaggs/app/actions/data-commands.h
==============================================================================
--- branches/weskaggs/app/actions/data-commands.h	(original)
+++ branches/weskaggs/app/actions/data-commands.h	Wed Jan 16 19:11:41 2008
@@ -22,6 +22,10 @@
 
 void   data_open_as_image_cmd_callback (GtkAction   *action,
                                         gpointer     data);
+void   data_load_cmd_callback          (GtkAction   *action,
+                                        gpointer     data);
+void   data_save_cmd_callback          (GtkAction   *action,
+                                        gpointer     data);
 void   data_new_cmd_callback           (GtkAction   *action,
                                         gpointer     data);
 void   data_duplicate_cmd_callback     (GtkAction   *action,

Modified: branches/weskaggs/app/actions/gradients-actions.c
==============================================================================
--- branches/weskaggs/app/actions/gradients-actions.c	(original)
+++ branches/weskaggs/app/actions/gradients-actions.c	Wed Jan 16 19:11:41 2008
@@ -44,6 +44,18 @@
     N_("Gradients Menu"), NULL, NULL, NULL,
     GIMP_HELP_GRADIENT_DIALOG },
 
+  { "gradients-load", GTK_STOCK_NEW,
+    N_("_Load Gradient"), "",
+    N_("Load gradient"),
+    G_CALLBACK (data_load_cmd_callback),
+    GIMP_HELP_GRADIENT_LOAD },
+
+  { "gradients-save", GTK_STOCK_NEW,
+    N_("_Save Gradient"), "",
+    N_("Save gradient"),
+    G_CALLBACK (data_save_cmd_callback),
+    GIMP_HELP_GRADIENT_SAVE },
+
   { "gradients-new", GTK_STOCK_NEW,
     N_("_New Gradient"), "",
     N_("New gradient"),

Modified: branches/weskaggs/app/actions/palettes-actions.c
==============================================================================
--- branches/weskaggs/app/actions/palettes-actions.c	(original)
+++ branches/weskaggs/app/actions/palettes-actions.c	Wed Jan 16 19:11:41 2008
@@ -44,6 +44,18 @@
     N_("Palettes Menu"), NULL, NULL, NULL,
     GIMP_HELP_PALETTE_DIALOG },
 
+  { "palettes-load", GTK_STOCK_NEW,
+    N_("_Load Palette"), "",
+    N_("Load palette"),
+    G_CALLBACK (data_load_cmd_callback),
+    GIMP_HELP_PALETTE_LOAD },
+
+  { "palettes-save", GTK_STOCK_NEW,
+    N_("_Save Palette"), "",
+    N_("Save palette"),
+    G_CALLBACK (data_save_cmd_callback),
+    GIMP_HELP_PALETTE_NEW },
+
   { "palettes-new", GTK_STOCK_NEW,
     N_("_New Palette"), "",
     N_("New palette"),

Modified: branches/weskaggs/app/actions/patterns-actions.c
==============================================================================
--- branches/weskaggs/app/actions/patterns-actions.c	(original)
+++ branches/weskaggs/app/actions/patterns-actions.c	Wed Jan 16 19:11:41 2008
@@ -49,6 +49,18 @@
     G_CALLBACK (data_open_as_image_cmd_callback),
     GIMP_HELP_PATTERN_OPEN_AS_IMAGE },
 
+  { "patterns-load", GTK_STOCK_NEW,
+    N_("_Load Pattern"), "",
+    N_("Load pattern"),
+    G_CALLBACK (data_load_cmd_callback),
+    GIMP_HELP_PATTERN_LOAD },
+
+  { "patterns-save", GTK_STOCK_NEW,
+    N_("_Save Pattern"), "",
+    N_("Save pattern"),
+    G_CALLBACK (data_save_cmd_callback),
+    GIMP_HELP_PATTERN_SAVE },
+
   { "patterns-new", GTK_STOCK_NEW,
     N_("_New Pattern"), "",
     N_("New pattern"),

Modified: branches/weskaggs/app/core/gimpdatafactory.c
==============================================================================
--- branches/weskaggs/app/core/gimpdatafactory.c	(original)
+++ branches/weskaggs/app/core/gimpdatafactory.c	Wed Jan 16 19:11:41 2008
@@ -54,9 +54,6 @@
 
 static gchar * gimp_data_factory_get_save_dir (GimpDataFactory      *factory);
 
-static void    gimp_data_factory_load_data  (const GimpDatafileData *file_data,
-                                             gpointer                data);
-
 
 G_DEFINE_TYPE (GimpDataFactory, gimp_data_factory, GIMP_TYPE_OBJECT)
 
@@ -191,12 +188,6 @@
   gimp_container_thaw (factory->container);
 }
 
-typedef struct
-{
-  GimpDataFactory *factory;
-  GHashTable      *cache;
-} GimpDataLoadContext;
-
 static gboolean
 gimp_data_factory_refresh_cache_remove (gpointer key,
                                         gpointer value,
@@ -322,6 +313,28 @@
   g_free (writable_path);
 }
 
+void
+gimp_data_factory_data_load_path (GimpDataFactory *factory,
+                                  gchar           *path)
+{
+  if (path && strlen (path))
+    {
+      gchar               *tmp;
+      GimpDataLoadContext  context;
+
+      context.factory = factory;
+      context.cache   = NULL;
+
+      tmp = gimp_config_path_expand (path, TRUE, NULL);
+      g_free (path);
+      path = tmp;
+
+      gimp_datafiles_read_directories (path, G_FILE_TEST_EXISTS,
+                                       gimp_data_factory_load_data,
+                                       &context);
+    }
+}
+
 static void
 gimp_data_factory_data_reload (GimpDataFactory *factory)
 {
@@ -645,15 +658,18 @@
   return writable_dir;
 }
 
-static void
+void
 gimp_data_factory_load_data (const GimpDatafileData *file_data,
-                             gpointer                data)
+                             gpointer                user_data)
 {
-  GimpDataLoadContext *context = data;
+  GimpDataLoadContext *context = user_data;
   GimpDataFactory     *factory = context->factory;
   GHashTable          *cache   = context->cache;
   gint                 i;
 
+  if (factory->gimp->be_verbose)
+    g_print ("gimp_data_factory_load_data: loading %s\n", file_data->filename);
+
   for (i = 0; i < factory->n_loader_entries; i++)
     {
       if (! factory->loader_entries[i].extension ||
@@ -668,11 +684,12 @@
   {
     GList    *cached_data;
     gboolean  load_from_disk = TRUE;
+    GimpData *data           = NULL;
 
     if (cache &&
         (cached_data = g_hash_table_lookup (cache, file_data->filename)))
       {
-        GimpData *data = cached_data->data;
+        data = cached_data->data;
 
         load_from_disk = (data->mtime == 0 || data->mtime != file_data->mtime);
 
@@ -682,7 +699,10 @@
 
             for (list = cached_data; list; list = g_list_next (list))
               gimp_container_add (factory->container, GIMP_OBJECT (list->data));
+
+            return;
           }
+
       }
 
     if (load_from_disk)
@@ -711,7 +731,7 @@
 
             for (list = data_list; list; list = g_list_next (list))
               {
-                GimpData *data = list->data;
+                data = list->data;
 
                 gimp_data_set_filename (data, file_data->filename,
                                         writable, deletable);
@@ -723,6 +743,8 @@
               }
 
             g_list_free (data_list);
+
+            return;
           }
 
         if (G_UNLIKELY (error))
@@ -730,7 +752,11 @@
             gimp_message (factory->gimp, NULL, GIMP_MESSAGE_ERROR,
                           _("Failed to load data:\n\n%s"), error->message);
             g_clear_error (&error);
+
+            return;
           }
       }
   }
+
+  return;
 }

Modified: branches/weskaggs/app/core/gimpdatafactory.h
==============================================================================
--- branches/weskaggs/app/core/gimpdatafactory.h	(original)
+++ branches/weskaggs/app/core/gimpdatafactory.h	Wed Jan 16 19:11:41 2008
@@ -50,6 +50,12 @@
 #define GIMP_DATA_FACTORY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DATA_FACTORY, GimpDataFactoryClass))
 
 
+typedef struct
+{
+  GimpDataFactory *factory;
+  GHashTable      *cache;
+} GimpDataLoadContext;
+
 typedef struct _GimpDataFactoryClass  GimpDataFactoryClass;
 
 struct _GimpDataFactory
@@ -104,6 +110,10 @@
 gboolean   gimp_data_factory_data_save_single  (GimpDataFactory  *factory,
                                                 GimpData         *data,
                                                 GError          **error);
+void       gimp_data_factory_data_load_path    (GimpDataFactory  *factory,
+                                                gchar            *path);
 
+void       gimp_data_factory_load_data   (const GimpDatafileData *file_data,
+                                          gpointer                data);
 
 #endif  /*  __GIMP_DATA_FACTORY_H__  */

Modified: branches/weskaggs/app/widgets/Makefile.am
==============================================================================
--- branches/weskaggs/app/widgets/Makefile.am	(original)
+++ branches/weskaggs/app/widgets/Makefile.am	Wed Jan 16 19:11:41 2008
@@ -102,6 +102,8 @@
 	gimpcurveview.h			\
 	gimpdasheditor.c		\
 	gimpdasheditor.h		\
+	gimpdatachooserdialog.c		\
+	gimpdatachooserdialog.h		\
 	gimpdataeditor.c		\
 	gimpdataeditor.h		\
 	gimpdatafactoryview.c		\

Added: branches/weskaggs/app/widgets/gimpdatachooserdialog.c
==============================================================================
--- (empty file)
+++ branches/weskaggs/app/widgets/gimpdatachooserdialog.c	Wed Jan 16 19:11:41 2008
@@ -0,0 +1,407 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpdatachooserdialog.c
+ * Copyright (C) 2008 Bill Skaggs <weskaggs primate ucdavis edu>
+ *
+ * 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <sys/stat.h>
+#include <string.h>
+
+#include <glib/gstdio.h>
+
+#include <gtk/gtk.h>
+
+#include <libgimpbase/gimpbase.h>
+#include <libgimpwidgets/gimpwidgets.h>
+#include <libgimpconfig/gimpconfig.h>
+
+#include "widgets-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpcontainer.h"
+#include "core/gimpcontext.h"
+#include "core/gimpdata.h"
+#include "core/gimpdatafactory.h"
+
+#include "config/gimpguiconfig.h"
+
+#include "file/file-utils.h"
+
+#include "dialogs/dialogs.h"
+
+#include "gimpcontainereditor.h"
+#include "gimpdatafactoryview.h"
+#include "gimpdatachooserdialog.h"
+#include "gimpdialogfactory.h"
+#include "gimpdocked.h"
+#include "gimpeditor.h"
+#include "gimphelp-ids.h"
+
+#include "gimp-intl.h"
+
+static void        gimp_data_chooser_dialog_init          (GimpDataChooserDialog *dialog);
+
+static gchar *     gimp_data_chooser_dialog_get_filename  (GimpDataChooserDialog *dialog);
+
+static GtkWidget * gimp_data_chooser_dialog_path_view     (GimpDataChooserDialog *dialog,
+                                                           GList                 *dirlist);
+
+static void        path_view_selection_changed            (GtkTreeSelection      *selection,
+                                                           gpointer               data);
+
+static gboolean    gimp_data_chooser_dialog_activate_item (GtkWidget             *widget,
+                                                           GimpData              *data,
+                                                           gpointer               insert_data,
+                                                           GimpDataChooserDialog *dialog);
+
+static gboolean    gimp_data_chooser_dialog_select_item   (GtkWidget             *widget,
+                                                           GimpData              *data,
+                                                           gpointer               insert_data,
+                                                           GimpDataChooserDialog *dialog);
+
+
+G_DEFINE_TYPE (GimpDataChooserDialog, gimp_data_chooser_dialog, GIMP_TYPE_DIALOG)
+
+#define parent_class gimp_data_chooser_dialog_parent_class
+
+
+static void
+gimp_data_chooser_dialog_class_init (GimpDataChooserDialogClass *klass)
+{
+}
+
+static void
+gimp_data_chooser_dialog_init (GimpDataChooserDialog *dialog)
+{
+  dialog->filename        = NULL;
+  dialog->factory_view    = NULL;
+  dialog->working_factory = NULL;
+}
+
+/*  public functions  */
+
+gchar *
+gimp_data_chooser_dialog_new (GimpDataFactory *working_factory,
+                              GimpViewType      view_type)
+{
+  GtkWidget       *dialog;
+  GtkWidget       *factory_view;
+  GimpDataFactory *factory;
+  gchar           *filename = NULL;
+  GType            data_type;
+  gint             view_size = 32;
+  gchar           *path      = NULL;
+  gchar           *tmp;
+  GimpContext     *context;
+  gchar           *dirname;
+  GList           *dirlist;
+  GtkWidget       *path_view;
+  GtkWidget       *hbox;
+  GimpDocked      *docked;
+
+  GimpContainerEditor *container_editor;
+
+  g_object_get (working_factory->gimp->config,
+                working_factory->path_property_name,     &path,
+                NULL);
+  tmp = gimp_config_path_expand (path, TRUE, NULL);
+  g_free (path);
+  path = tmp;
+
+  dirlist = gimp_path_parse (path, 256, FALSE, NULL);
+  dirname = g_strdup (dirlist->data);
+
+  data_type = working_factory->container->children_type;
+
+  /* create a context */
+  context = gimp_context_new (working_factory->gimp, "tmp", NULL);
+
+  /* create the data factory */
+  factory = gimp_data_factory_new (working_factory->gimp,
+                                   data_type,
+                                   working_factory->path_property_name,
+                                   working_factory->writable_property_name,
+                                   working_factory->loader_entries,
+                                   working_factory->n_loader_entries,
+                                   NULL,
+                                   NULL);
+
+  /* load the data */
+  gimp_data_factory_data_load_path (factory, dirname);
+
+  /* create the data factory view */
+  factory_view = gimp_data_factory_view_new (view_type, factory, context,
+                                             view_size, 1,
+                                             global_dock_factory->menu_factory,
+                                             "<Brushes>",
+                                             "/brushes-popup",
+                                             "brushes");
+
+  /* suppress the button bar */
+  container_editor = GIMP_CONTAINER_EDITOR (factory_view);
+  docked = GIMP_DOCKED (container_editor->view);
+  gimp_docked_set_show_button_bar (docked, FALSE);
+
+  /* kludge to prevent activation from opening an editor */
+  gtk_widget_set_sensitive (GIMP_DATA_FACTORY_VIEW (factory_view)->edit_button,
+                            FALSE);
+
+  /* create the dialog */
+  dialog = g_object_new (GIMP_TYPE_DATA_CHOOSER_DIALOG,
+                         "title",                     _("Load Data"),
+                         "role",                      "gimp-data-load",
+                         NULL);
+
+  GIMP_DATA_CHOOSER_DIALOG (dialog)->working_factory = working_factory;
+
+  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                          GTK_STOCK_OPEN,   GTK_RESPONSE_OK,
+                          NULL);
+
+  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+                                           GTK_RESPONSE_OK,
+                                           GTK_RESPONSE_CANCEL,
+                                           -1);
+
+  gimp_help_connect (GTK_WIDGET (dialog),
+                     gimp_standard_help_func, GIMP_HELP_HELP, dialog);
+
+  /* put an hbox in the main vbox */
+  hbox = gtk_hbox_new (FALSE, 10);
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0);
+  gtk_widget_show (hbox);
+
+  path_view = gimp_data_chooser_dialog_path_view (GIMP_DATA_CHOOSER_DIALOG (dialog),
+                                                  dirlist);
+  gtk_box_pack_start (GTK_BOX (hbox), path_view, FALSE, FALSE, 0);
+  gtk_widget_show (path_view);
+
+  gtk_box_pack_start (GTK_BOX (hbox), factory_view, FALSE, FALSE, 0);
+  GIMP_DATA_CHOOSER_DIALOG (dialog)->factory_view = GIMP_DATA_FACTORY_VIEW (factory_view);
+  gtk_widget_set_size_request (factory_view, 300, 400);
+  gtk_widget_show (factory_view);
+
+  gtk_widget_show (dialog);
+
+  g_signal_connect_object (container_editor->view, "activate-item",
+                           G_CALLBACK (gimp_data_chooser_dialog_activate_item),
+                           dialog, 0);
+  g_signal_connect_object (container_editor->view, "select-item",
+                           G_CALLBACK (gimp_data_chooser_dialog_select_item),
+                           dialog, 0);
+
+  if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+    filename = gimp_data_chooser_dialog_get_filename (GIMP_DATA_CHOOSER_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
+  g_object_unref (context);
+  return filename;
+}
+
+static gchar *
+gimp_data_chooser_dialog_get_filename (GimpDataChooserDialog *dialog)
+{
+  return dialog->filename;
+}
+
+static GtkWidget *
+gimp_data_chooser_dialog_path_view (GimpDataChooserDialog *dialog,
+                                    GList                 *dirlist)
+{
+  GtkListStore      *list_store;
+  GtkTreeIter        iter;
+  GtkWidget         *view;
+  GtkCellRenderer   *renderer;
+  GtkTreeViewColumn *column;
+  GtkTreeSelection  *select;
+  GList             *list;
+
+  list_store = gtk_list_store_new (1, G_TYPE_STRING);
+
+  for (list = dirlist; list; list = g_list_next (list))
+    {
+      gtk_list_store_append (list_store, &iter);
+      gtk_list_store_set (list_store, &iter, 0, list->data, -1);
+    }
+
+  view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
+
+  renderer = gtk_cell_renderer_text_new ();
+  column = gtk_tree_view_column_new_with_attributes ("Folder", renderer,
+                                                     "text", 0,
+                                                     NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (view), column);
+
+  select = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+  gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
+  g_signal_connect (G_OBJECT (select), "changed",
+                    G_CALLBACK (path_view_selection_changed),
+                    dialog);
+  return view;
+}
+
+static void
+path_view_selection_changed (GtkTreeSelection *selection,
+                             gpointer          data)
+{
+  GimpDataChooserDialog *dialog = GIMP_DATA_CHOOSER_DIALOG (data);
+  GimpDataFactoryView   *factory_view;
+  GtkTreeIter            iter;
+  GtkTreeModel          *model;
+  gchar                 *dirname;
+
+  factory_view = dialog->factory_view;
+
+  if (gtk_tree_selection_get_selected (selection, &model, &iter))
+    {
+      GimpContainerEditor *container_editor;
+
+      container_editor = GIMP_CONTAINER_EDITOR (factory_view);
+
+      gtk_tree_model_get (model, &iter, 0, &dirname, -1);
+
+      gimp_data_factory_data_free (factory_view->factory);
+
+      gimp_data_factory_data_load_path (factory_view->factory,
+                                        dirname);
+    }
+}
+
+static gboolean
+gimp_data_chooser_dialog_select_item (GtkWidget             *widget,
+                                      GimpData              *data,
+                                      gpointer               insert_data,
+                                      GimpDataChooserDialog *dialog)
+{
+  GimpDataFactoryView *factory_view;
+
+  factory_view = dialog->factory_view;
+
+  /* kludge to prevent activation from opening an editor */
+  gtk_widget_set_sensitive (factory_view->edit_button,
+                            FALSE);
+
+  return FALSE;
+}
+
+static gboolean
+gimp_data_chooser_dialog_activate_item (GtkWidget             *widget,
+                                        GimpData              *data,
+                                        gpointer               insert_data,
+                                        GimpDataChooserDialog *dialog)
+{
+  GimpDataFactory     *factory;
+  GimpDataFactory     *working_factory;
+  GimpDataFactoryView *factory_view;
+  gchar               *filename;
+  gchar               *contents;
+  gsize                length;
+  GError              *error       = NULL;
+  gchar               *writable_path;
+  gchar               *tmp;
+  gchar               *basename;
+  gchar               *new_filename;
+  struct stat          filestat;
+  GimpDatafileData     file_data;
+  GimpDataLoadContext  load_context;
+  GimpContainerEditor *container_editor;
+
+  g_return_val_if_fail (GIMP_IS_DATA_CHOOSER_DIALOG (dialog), FALSE);
+
+  factory_view = dialog->factory_view;
+  factory = factory_view->factory;
+  working_factory = dialog->working_factory;
+
+  container_editor = GIMP_CONTAINER_EDITOR (factory_view);
+
+  if (! GIMP_IS_DATA (data))
+    return FALSE;
+
+  filename = data->filename;
+
+  if (! filename)
+    return FALSE;
+
+  g_file_get_contents (filename, &contents, &length, &error);
+  if (error)
+    {
+      g_print ("error getting contents of %s\n", filename);
+      /* handle error */
+      return FALSE;
+    }
+
+  g_object_get (factory->gimp->config,
+                factory->writable_property_name, &writable_path,
+                NULL);
+  tmp = gimp_config_path_expand (writable_path, TRUE, NULL);
+  g_free (writable_path);
+  writable_path = tmp;
+
+  basename = g_path_get_basename (filename);
+
+  new_filename = g_build_filename (writable_path, basename, NULL);
+
+  if (g_file_test (new_filename, G_FILE_TEST_EXISTS))
+    {
+      g_print ("error setting contents of %s: file already exists\n", new_filename);
+      g_free (contents);
+      return FALSE;
+      /* come up with a new name */
+    }
+
+  g_file_set_contents (new_filename, contents, length, &error);
+
+  g_free (contents);
+
+  if (error)
+    {
+      /* handle error */
+      return FALSE;
+    }
+
+  g_stat (new_filename, &filestat);
+
+  file_data.filename = new_filename;
+  file_data.dirname  = writable_path;
+  file_data.basename = basename;
+  file_data.atime    = filestat.st_atime;
+  file_data.mtime    = filestat.st_mtime;
+  file_data.ctime    = filestat.st_ctime;
+
+  load_context.factory = working_factory;
+  load_context.cache   = NULL;
+
+  gimp_data_factory_load_data (&file_data, &load_context);
+
+  g_free (new_filename);
+  g_free (writable_path);
+  g_free (basename);
+
+/*   if (data) */
+/*     { */
+/*       gimp_context_set_by_type (context, */
+/*                                 factory->container->children_type, */
+/*                                 GIMP_OBJECT (data)); */
+/*     } */
+
+  return FALSE;
+}

Added: branches/weskaggs/app/widgets/gimpdatachooserdialog.h
==============================================================================
--- (empty file)
+++ branches/weskaggs/app/widgets/gimpdatachooserdialog.h	Wed Jan 16 19:11:41 2008
@@ -0,0 +1,59 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpfiledialog.h
+ * Copyright (C) 2004 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 2 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GIMP_DATA_CHOOSER_DIALOG_H__
+#define __GIMP_DATA_CHOOSER_DIALOG_H__
+
+G_BEGIN_DECLS
+
+#define GIMP_TYPE_DATA_CHOOSER_DIALOG            (gimp_data_chooser_dialog_get_type ())
+#define GIMP_DATA_CHOOSER_DIALOG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_DATA_CHOOSER_DIALOG, GimpDataChooserDialog))
+#define GIMP_DATA_CHOOSER_DIALOG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_DATA_CHOOSER_DIALOG, GimpDataChooserDialogClass))
+#define GIMP_IS_DATA_CHOOSER_DIALOG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_DATA_CHOOSER_DIALOG))
+#define GIMP_IS_DATA_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_DATA_CHOOSER_DIALOG))
+#define GIMP_DATA_CHOOSER_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DATA_CHOOSER_DIALOG, GimpDataChooserDialogClass))
+
+
+typedef struct _GimpDataChooserDialogClass  GimpDataChooserDialogClass;
+
+struct _GimpDataChooserDialog
+{
+  GimpDialog            parent_instance;
+
+  GimpDataFactory      *working_factory;
+  GimpDataFactoryView  *factory_view;
+  gchar                *filename;
+};
+
+struct _GimpDataChooserDialogClass
+{
+  GimpDialogClass  parent_class;
+};
+
+
+GType   gimp_data_chooser_dialog_get_type (void) G_GNUC_CONST;
+
+gchar * gimp_data_chooser_dialog_new      (GimpDataFactory *factory,
+                                           GimpViewType     view_type);
+
+G_END_DECLS
+
+#endif /* __GIMP_DATA_CHOOSER_DIALOG_H__ */

Modified: branches/weskaggs/app/widgets/gimpdatafactoryview.c
==============================================================================
--- branches/weskaggs/app/widgets/gimpdatafactoryview.c	(original)
+++ branches/weskaggs/app/widgets/gimpdatafactoryview.c	Wed Jan 16 19:11:41 2008
@@ -75,6 +75,8 @@
 static void
 gimp_data_factory_view_init (GimpDataFactoryView *view)
 {
+  view->load_button      = NULL;
+  view->save_button      = NULL;
   view->edit_button      = NULL;
   view->new_button       = NULL;
   view->duplicate_button = NULL;
@@ -169,6 +171,18 @@
                         factory_view);
     }
 
+  str = g_strdup_printf ("%s-load", action_group);
+  factory_view->load_button =
+    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
+                                   str, NULL);
+  g_free (str);
+
+  str = g_strdup_printf ("%s-save", action_group);
+  factory_view->save_button =
+    gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,
+                                   str, NULL);
+  g_free (str);
+
   str = g_strdup_printf ("%s-edit", action_group);
   factory_view->edit_button =
     gimp_editor_add_action_button (GIMP_EDITOR (editor->view), action_group,

Modified: branches/weskaggs/app/widgets/gimpdatafactoryview.h
==============================================================================
--- branches/weskaggs/app/widgets/gimpdatafactoryview.h	(original)
+++ branches/weskaggs/app/widgets/gimpdatafactoryview.h	Wed Jan 16 19:11:41 2008
@@ -42,6 +42,8 @@
 
   GimpDataFactory     *factory;
 
+  GtkWidget           *load_button;
+  GtkWidget           *save_button;
   GtkWidget           *edit_button;
   GtkWidget           *new_button;
   GtkWidget           *duplicate_button;

Modified: branches/weskaggs/app/widgets/gimphelp-ids.h
==============================================================================
--- branches/weskaggs/app/widgets/gimphelp-ids.h	(original)
+++ branches/weskaggs/app/widgets/gimphelp-ids.h	Wed Jan 16 19:11:41 2008
@@ -295,6 +295,8 @@
 #define GIMP_HELP_BRUSH_DIALOG                    "gimp-brush-dialog"
 #define GIMP_HELP_BRUSH_EDIT                      "gimp-brush-edit"
 #define GIMP_HELP_BRUSH_OPEN_AS_IMAGE             "gimp-brush-open-as-image"
+#define GIMP_HELP_BRUSH_LOAD                      "gimp-brush-load"
+#define GIMP_HELP_BRUSH_SAVE                      "gimp-brush-save"
 #define GIMP_HELP_BRUSH_NEW                       "gimp-brush-new"
 #define GIMP_HELP_BRUSH_DUPLICATE                 "gimp-brush-duplicate"
 #define GIMP_HELP_BRUSH_COPY_LOCATION             "gimp-brush-copy-location"
@@ -307,6 +309,8 @@
 #define GIMP_HELP_PATTERN_DIALOG                  "gimp-pattern-dialog"
 #define GIMP_HELP_PATTERN_EDIT                    "gimp-pattern-edit"
 #define GIMP_HELP_PATTERN_OPEN_AS_IMAGE           "gimp-pattern-open-as-image"
+#define GIMP_HELP_PATTERN_LOAD                    "gimp-pattern-load"
+#define GIMP_HELP_PATTERN_SAVE                    "gimp-pattern-save"
 #define GIMP_HELP_PATTERN_NEW                     "gimp-pattern-new"
 #define GIMP_HELP_PATTERN_DUPLICATE               "gimp-pattern-duplicate"
 #define GIMP_HELP_PATTERN_COPY_LOCATION           "gimp-pattern-copy-location"
@@ -315,6 +319,8 @@
 
 #define GIMP_HELP_GRADIENT_DIALOG                 "gimp-gradient-dialog"
 #define GIMP_HELP_GRADIENT_EDIT                   "gimp-gradient-edit"
+#define GIMP_HELP_GRADIENT_LOAD                   "gimp-gradient-load"
+#define GIMP_HELP_GRADIENT_SAVE                   "gimp-gradient-save"
 #define GIMP_HELP_GRADIENT_NEW                    "gimp-gradient-new"
 #define GIMP_HELP_GRADIENT_DUPLICATE              "gimp-gradient-duplicate"
 #define GIMP_HELP_GRADIENT_COPY_LOCATION          "gimp-gradient-copy-location"
@@ -347,6 +353,8 @@
 
 #define GIMP_HELP_PALETTE_DIALOG                  "gimp-palette-dialog"
 #define GIMP_HELP_PALETTE_EDIT                    "gimp-palette-edit"
+#define GIMP_HELP_PALETTE_LOAD                    "gimp-palette-load"
+#define GIMP_HELP_PALETTE_SAVE                    "gimp-palette-save"
 #define GIMP_HELP_PALETTE_NEW                     "gimp-palette-new"
 #define GIMP_HELP_PALETTE_DUPLICATE               "gimp-palette-duplicate"
 #define GIMP_HELP_PALETTE_COPY_LOCATION           "gimp-palette-copy-location"



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