mirror of https://github.com/GNOME/gimp.git
app: add GimpContainerTreeStore which is a GtkTreeStore subclass
and pulls the store handling logic out of GimpContainerTreeView so it can be reused.
This commit is contained in:
parent
00f0350413
commit
82a5c62e54
|
@ -81,6 +81,8 @@ libappwidgets_a_sources = \
|
|||
gimpcontainergridview.h \
|
||||
gimpcontainerpopup.c \
|
||||
gimpcontainerpopup.h \
|
||||
gimpcontainertreestore.c \
|
||||
gimpcontainertreestore.h \
|
||||
gimpcontainertreeview.c \
|
||||
gimpcontainertreeview.h \
|
||||
gimpcontainertreeview-dnd.c \
|
||||
|
|
|
@ -0,0 +1,466 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpcontainertreestore.c
|
||||
* Copyright (C) 2010 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 <string.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "core/gimpcontainer.h"
|
||||
#include "core/gimpviewable.h"
|
||||
|
||||
#include "gimpcontainertreestore.h"
|
||||
#include "gimpcontainerview.h"
|
||||
#include "gimpviewrenderer.h"
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CONTAINER_VIEW
|
||||
};
|
||||
|
||||
|
||||
typedef struct _GimpContainerTreeStorePrivate GimpContainerTreeStorePrivate;
|
||||
|
||||
struct _GimpContainerTreeStorePrivate
|
||||
{
|
||||
GimpContainerView *container_view;
|
||||
};
|
||||
|
||||
#define GET_PRIVATE(store) \
|
||||
G_TYPE_INSTANCE_GET_PRIVATE (store, \
|
||||
GIMP_TYPE_CONTAINER_TREE_STORE, \
|
||||
GimpContainerTreeStorePrivate)
|
||||
|
||||
|
||||
static GObject * gimp_container_tree_store_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params);
|
||||
static void gimp_container_tree_store_finalize (GObject *object);
|
||||
static void gimp_container_tree_store_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gimp_container_tree_store_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gimp_container_tree_store_set (GimpContainerTreeStore *store,
|
||||
GtkTreeIter *iter,
|
||||
GimpViewable *viewable);
|
||||
static void gimp_container_tree_store_renderer_update (GimpViewRenderer *renderer,
|
||||
GimpContainerTreeStore *store);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpContainerTreeStore, gimp_container_tree_store,
|
||||
GTK_TYPE_TREE_STORE)
|
||||
|
||||
#define parent_class gimp_container_tree_store_parent_class
|
||||
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_class_init (GimpContainerTreeStoreClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->constructor = gimp_container_tree_store_constructor;
|
||||
object_class->finalize = gimp_container_tree_store_finalize;
|
||||
object_class->set_property = gimp_container_tree_store_set_property;
|
||||
object_class->get_property = gimp_container_tree_store_get_property;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CONTAINER_VIEW,
|
||||
g_param_spec_object ("container-view",
|
||||
NULL, NULL,
|
||||
GIMP_TYPE_CONTAINER_VIEW,
|
||||
GIMP_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GimpContainerTreeStorePrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_init (GimpContainerTreeStore *store)
|
||||
{
|
||||
}
|
||||
|
||||
static GObject *
|
||||
gimp_container_tree_store_constructor (GType type,
|
||||
guint n_params,
|
||||
GObjectConstructParam *params)
|
||||
{
|
||||
GimpContainerTreeStore *store;
|
||||
GObject *object;
|
||||
|
||||
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
||||
|
||||
store = GIMP_CONTAINER_TREE_STORE (object);
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_finalize (GObject *object)
|
||||
{
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTAINER_VIEW:
|
||||
private->container_view = g_value_get_object (value); /* don't ref */
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private = GET_PRIVATE (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTAINER_VIEW:
|
||||
g_value_set_object (value, private->container_view);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
GtkTreeModel *
|
||||
gimp_container_tree_store_new (GimpContainerView *container_view,
|
||||
gint n_columns,
|
||||
GType *types)
|
||||
{
|
||||
GimpContainerTreeStore *store;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONTAINER_VIEW (container_view), NULL);
|
||||
g_return_val_if_fail (n_columns >= GIMP_CONTAINER_TREE_STORE_N_COLUMNS, NULL);
|
||||
g_return_val_if_fail (types != NULL, NULL);
|
||||
|
||||
store = g_object_new (GIMP_TYPE_CONTAINER_TREE_STORE,
|
||||
"container-view", container_view,
|
||||
NULL);
|
||||
|
||||
gtk_tree_store_set_column_types (GTK_TREE_STORE (store), n_columns, types);
|
||||
|
||||
return GTK_TREE_MODEL (store);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_container_tree_store_set_context_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GimpContext *context = data;
|
||||
GimpViewRenderer *renderer;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
||||
-1);
|
||||
|
||||
gimp_view_renderer_set_context (renderer, context);
|
||||
|
||||
g_object_unref (renderer);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_tree_store_set_context (GimpContainerTreeStore *store,
|
||||
GimpContext *context)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store));
|
||||
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (store),
|
||||
gimp_container_tree_store_set_context_foreach,
|
||||
context);
|
||||
}
|
||||
|
||||
GtkTreeIter *
|
||||
gimp_container_tree_store_insert_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *parent,
|
||||
gint index)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store), NULL);
|
||||
|
||||
if (index == -1)
|
||||
gtk_tree_store_append (GTK_TREE_STORE (store), &iter, parent);
|
||||
else
|
||||
gtk_tree_store_insert (GTK_TREE_STORE (store), &iter, parent, index);
|
||||
|
||||
gimp_container_tree_store_set (store, &iter, viewable);
|
||||
|
||||
return gtk_tree_iter_copy (&iter);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_tree_store_remove_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
if (iter)
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (store), iter);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_tree_store_reorder_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
gint new_index,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private = GET_PRIVATE (store);
|
||||
GimpViewable *parent;
|
||||
GimpContainer *container;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store));
|
||||
|
||||
private = GET_PRIVATE (store);
|
||||
|
||||
if (! iter)
|
||||
return;
|
||||
|
||||
parent = gimp_viewable_get_parent (viewable);
|
||||
|
||||
if (parent)
|
||||
container = gimp_viewable_get_children (parent);
|
||||
else
|
||||
container = gimp_container_view_get_container (private->container_view);
|
||||
|
||||
if (new_index == -1 ||
|
||||
new_index == gimp_container_get_n_children (container) - 1)
|
||||
{
|
||||
gtk_tree_store_move_before (GTK_TREE_STORE (store), iter, NULL);
|
||||
}
|
||||
else if (new_index == 0)
|
||||
{
|
||||
gtk_tree_store_move_after (GTK_TREE_STORE (store), iter, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter place_iter;
|
||||
gint depth;
|
||||
gint *indices;
|
||||
gint old_index;
|
||||
|
||||
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
|
||||
indices = gtk_tree_path_get_indices (path);
|
||||
|
||||
depth = gtk_tree_path_get_depth (path);
|
||||
|
||||
old_index = indices[depth - 1];
|
||||
|
||||
if (new_index != old_index)
|
||||
{
|
||||
indices[depth - 1] = new_index;
|
||||
|
||||
gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &place_iter, path);
|
||||
|
||||
if (new_index > old_index)
|
||||
gtk_tree_store_move_after (GTK_TREE_STORE (store),
|
||||
iter, &place_iter);
|
||||
else
|
||||
gtk_tree_store_move_before (GTK_TREE_STORE (store),
|
||||
iter, &place_iter);
|
||||
}
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_container_tree_store_rename_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
gboolean new_name_shorter = FALSE;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store), FALSE);
|
||||
|
||||
if (iter)
|
||||
{
|
||||
gchar *name = gimp_viewable_get_description (viewable, NULL);
|
||||
gchar *old_name;
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME, &old_name,
|
||||
-1);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (store), iter,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME, name,
|
||||
-1);
|
||||
|
||||
if (name && old_name && strlen (name) < strlen (old_name))
|
||||
new_name_shorter = TRUE;
|
||||
|
||||
g_free (name);
|
||||
g_free (old_name);
|
||||
}
|
||||
|
||||
return new_name_shorter;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_tree_store_clear_items (GimpContainerTreeStore *store)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store));
|
||||
|
||||
gtk_tree_store_clear (GTK_TREE_STORE (store));
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint view_size;
|
||||
gint border_width;
|
||||
} SetSizeForeachData;
|
||||
|
||||
static gboolean
|
||||
gimp_container_tree_store_set_view_size_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
SetSizeForeachData *size_data = data;
|
||||
GimpViewRenderer *renderer;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
||||
-1);
|
||||
|
||||
gimp_view_renderer_set_size (renderer,
|
||||
size_data->view_size,
|
||||
size_data->border_width);
|
||||
|
||||
g_object_unref (renderer);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_container_tree_store_set_view_size (GimpContainerTreeStore *store)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private;
|
||||
SetSizeForeachData size_data;
|
||||
|
||||
g_return_if_fail (GIMP_IS_CONTAINER_TREE_STORE (store));
|
||||
|
||||
private = GET_PRIVATE (store);
|
||||
|
||||
size_data.view_size =
|
||||
gimp_container_view_get_view_size (private->container_view,
|
||||
&size_data.border_width);
|
||||
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL (store),
|
||||
gimp_container_tree_store_set_view_size_foreach,
|
||||
&size_data);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_set (GimpContainerTreeStore *store,
|
||||
GtkTreeIter *iter,
|
||||
GimpViewable *viewable)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private = GET_PRIVATE (store);
|
||||
GimpContext *context;
|
||||
GimpViewRenderer *renderer;
|
||||
gchar *name;
|
||||
gint view_size;
|
||||
gint border_width;
|
||||
|
||||
context = gimp_container_view_get_context (private->container_view);
|
||||
|
||||
view_size = gimp_container_view_get_view_size (private->container_view,
|
||||
&border_width);
|
||||
|
||||
renderer = gimp_view_renderer_new (context,
|
||||
G_TYPE_FROM_INSTANCE (viewable),
|
||||
view_size, border_width,
|
||||
FALSE);
|
||||
gimp_view_renderer_set_viewable (renderer, viewable);
|
||||
gimp_view_renderer_remove_idle (renderer);
|
||||
|
||||
g_signal_connect (renderer, "update",
|
||||
G_CALLBACK (gimp_container_tree_store_renderer_update),
|
||||
store);
|
||||
|
||||
name = gimp_viewable_get_description (viewable, NULL);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (store), iter,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, renderer,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME, name,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME_SENSITIVE, TRUE,
|
||||
-1);
|
||||
|
||||
g_free (name);
|
||||
g_object_unref (renderer);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_store_renderer_update (GimpViewRenderer *renderer,
|
||||
GimpContainerTreeStore *store)
|
||||
{
|
||||
GimpContainerTreeStorePrivate *private = GET_PRIVATE (store);
|
||||
GtkTreeIter *iter;
|
||||
|
||||
iter = gimp_container_view_lookup (private->container_view,
|
||||
renderer->viewable);
|
||||
|
||||
if (iter)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
|
||||
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
|
||||
gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, iter);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpcontainertreestore.h
|
||||
* Copyright (C) 2010 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_CONTAINER_TREE_STORE_H__
|
||||
#define __GIMP_CONTAINER_TREE_STORE_H__
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME_ATTRIBUTES,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME_SENSITIVE,
|
||||
GIMP_CONTAINER_TREE_STORE_COLUMN_USER_DATA,
|
||||
GIMP_CONTAINER_TREE_STORE_N_COLUMNS
|
||||
};
|
||||
|
||||
|
||||
#define GIMP_TYPE_CONTAINER_TREE_STORE (gimp_container_tree_store_get_type ())
|
||||
#define GIMP_CONTAINER_TREE_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTAINER_TREE_STORE, GimpContainerTreeStore))
|
||||
#define GIMP_CONTAINER_TREE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CONTAINER_TREE_STORE, GimpContainerTreeStoreClass))
|
||||
#define GIMP_IS_CONTAINER_TREE_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTAINER_TREE_STORE))
|
||||
#define GIMP_IS_CONTAINER_TREE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTAINER_TREE_STORE))
|
||||
#define GIMP_CONTAINER_TREE_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CONTAINER_TREE_STORE, GimpContainerTreeStoreClass))
|
||||
|
||||
|
||||
typedef struct _GimpContainerTreeStoreClass GimpContainerTreeStoreClass;
|
||||
|
||||
struct _GimpContainerTreeStore
|
||||
{
|
||||
GtkTreeStore parent_instance;
|
||||
};
|
||||
|
||||
struct _GimpContainerTreeStoreClass
|
||||
{
|
||||
GtkTreeStoreClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GType gimp_container_tree_store_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkTreeModel * gimp_container_tree_store_new (GimpContainerView *container_view,
|
||||
gint n_columns,
|
||||
GType *types);
|
||||
|
||||
void gimp_container_tree_store_set_context (GimpContainerTreeStore *store,
|
||||
GimpContext *context);
|
||||
GtkTreeIter * gimp_container_tree_store_insert_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *parent,
|
||||
gint index);
|
||||
void gimp_container_tree_store_remove_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *iter);
|
||||
void gimp_container_tree_store_reorder_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
gint new_index,
|
||||
GtkTreeIter *iter);
|
||||
gboolean gimp_container_tree_store_rename_item (GimpContainerTreeStore *store,
|
||||
GimpViewable *viewable,
|
||||
GtkTreeIter *iter);
|
||||
void gimp_container_tree_store_clear_items (GimpContainerTreeStore *store);
|
||||
void gimp_container_tree_store_set_view_size (GimpContainerTreeStore *store);
|
||||
|
||||
|
||||
#endif /* __GIMP_CONTAINER_TREE_STORE_H__ */
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/gimpviewable.h"
|
||||
|
||||
#include "gimpcellrendererviewable.h"
|
||||
#include "gimpcontainertreestore.h"
|
||||
#include "gimpcontainertreeview.h"
|
||||
#include "gimpcontainertreeview-dnd.h"
|
||||
#include "gimpcontainertreeview.h"
|
||||
|
@ -94,8 +95,6 @@ static gboolean gimp_container_tree_view_tooltip (GtkWidget
|
|||
gboolean keyboard_tip,
|
||||
GtkTooltip *tooltip,
|
||||
GimpContainerTreeView *tree_view);
|
||||
static void gimp_container_tree_view_renderer_update (GimpViewRenderer *renderer,
|
||||
GimpContainerTreeView *tree_view);
|
||||
static GimpViewable *gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
||||
GimpContext **context,
|
||||
gpointer data);
|
||||
|
@ -195,7 +194,6 @@ gimp_container_tree_view_constructor (GType type,
|
|||
GimpContainerTreeView *tree_view;
|
||||
GimpContainerView *view;
|
||||
GimpContainerBox *box;
|
||||
GtkTreeStore *tree;
|
||||
GObject *object;
|
||||
|
||||
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
||||
|
@ -204,19 +202,19 @@ gimp_container_tree_view_constructor (GType type,
|
|||
view = GIMP_CONTAINER_VIEW (object);
|
||||
box = GIMP_CONTAINER_BOX (object);
|
||||
|
||||
tree = gtk_tree_store_newv (tree_view->n_model_columns,
|
||||
tree_view->model_columns);
|
||||
tree_view->model = GTK_TREE_MODEL (tree);
|
||||
tree_view->model = gimp_container_tree_store_new (view,
|
||||
tree_view->n_model_columns,
|
||||
tree_view->model_columns);
|
||||
|
||||
tree_view->view = g_object_new (GTK_TYPE_TREE_VIEW,
|
||||
"model", tree,
|
||||
"model", tree_view->model,
|
||||
"search-column", GIMP_CONTAINER_TREE_VIEW_COLUMN_NAME,
|
||||
"enable-search", FALSE,
|
||||
"headers-visible", FALSE,
|
||||
"has-tooltip", TRUE,
|
||||
"show-expanders", GIMP_CONTAINER_VIEW_GET_INTERFACE (view)->model_is_tree,
|
||||
NULL);
|
||||
g_object_unref (tree);
|
||||
g_object_unref (tree_view->model);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (box->scrolled_win),
|
||||
GTK_WIDGET (tree_view->view));
|
||||
|
@ -479,41 +477,6 @@ gimp_container_tree_view_connect_name_edited (GimpContainerTreeView *tree_view,
|
|||
data);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_view_set (GimpContainerTreeView *tree_view,
|
||||
GtkTreeIter *iter,
|
||||
GimpViewable *viewable)
|
||||
{
|
||||
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
|
||||
GimpViewRenderer *renderer;
|
||||
gchar *name;
|
||||
gint view_size;
|
||||
gint border_width;
|
||||
|
||||
view_size = gimp_container_view_get_view_size (view, &border_width);
|
||||
|
||||
renderer = gimp_view_renderer_new (gimp_container_view_get_context (view),
|
||||
G_TYPE_FROM_INSTANCE (viewable),
|
||||
view_size, border_width,
|
||||
FALSE);
|
||||
gimp_view_renderer_set_viewable (renderer, viewable);
|
||||
gimp_view_renderer_remove_idle (renderer);
|
||||
|
||||
g_signal_connect (renderer, "update",
|
||||
G_CALLBACK (gimp_container_tree_view_renderer_update),
|
||||
tree_view);
|
||||
|
||||
name = gimp_viewable_get_description (viewable, NULL);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (tree_view->model), iter,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, renderer,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_NAME, name,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_NAME_SENSITIVE, TRUE,
|
||||
-1);
|
||||
|
||||
g_free (name);
|
||||
g_object_unref (renderer);
|
||||
}
|
||||
|
||||
/* GimpContainerView methods */
|
||||
|
||||
|
@ -575,26 +538,6 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
|
|||
gtk_tree_view_columns_autosize (tree_view->view);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_container_tree_view_set_context_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GimpContext *context = data;
|
||||
GimpViewRenderer *renderer;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, &renderer,
|
||||
-1);
|
||||
|
||||
gimp_view_renderer_set_context (renderer, context);
|
||||
|
||||
g_object_unref (renderer);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_view_set_context (GimpContainerView *view,
|
||||
GimpContext *context)
|
||||
|
@ -604,11 +547,8 @@ gimp_container_tree_view_set_context (GimpContainerView *view,
|
|||
parent_view_iface->set_context (view, context);
|
||||
|
||||
if (tree_view->model)
|
||||
{
|
||||
gtk_tree_model_foreach (tree_view->model,
|
||||
gimp_container_tree_view_set_context_foreach,
|
||||
context);
|
||||
}
|
||||
gimp_container_tree_store_set_context (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
||||
context);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -631,27 +571,23 @@ gimp_container_tree_view_insert_item (GimpContainerView *view,
|
|||
gint index)
|
||||
{
|
||||
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
||||
GtkTreeIter iter;
|
||||
GtkTreeIter *iter;
|
||||
|
||||
if (index == -1)
|
||||
gtk_tree_store_append (GTK_TREE_STORE (tree_view->model), &iter,
|
||||
parent_insert_data);
|
||||
else
|
||||
gtk_tree_store_insert (GTK_TREE_STORE (tree_view->model), &iter,
|
||||
parent_insert_data, index);
|
||||
|
||||
gimp_container_tree_view_set (tree_view, &iter, viewable);
|
||||
iter = gimp_container_tree_store_insert_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
||||
viewable,
|
||||
parent_insert_data,
|
||||
index);
|
||||
|
||||
if (parent_insert_data)
|
||||
{
|
||||
GtkTreePath *path = gtk_tree_model_get_path (tree_view->model, &iter);
|
||||
GtkTreePath *path = gtk_tree_model_get_path (tree_view->model, iter);
|
||||
|
||||
gtk_tree_view_expand_to_path (tree_view->view, path);
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
|
||||
return gtk_tree_iter_copy (&iter);
|
||||
return iter;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -662,10 +598,12 @@ gimp_container_tree_view_remove_item (GimpContainerView *view,
|
|||
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
||||
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
||||
|
||||
gimp_container_tree_store_remove_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
||||
viewable,
|
||||
iter);
|
||||
|
||||
if (iter)
|
||||
{
|
||||
gtk_tree_store_remove (GTK_TREE_STORE (tree_view->model), iter);
|
||||
|
||||
gtk_tree_view_columns_autosize (tree_view->view);
|
||||
|
||||
/* If the store is empty after this remove, clear out renderers
|
||||
|
@ -690,20 +628,11 @@ gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
|||
{
|
||||
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
||||
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
||||
gboolean selected = FALSE;
|
||||
|
||||
if (iter)
|
||||
{
|
||||
GimpViewable *parent;
|
||||
GimpContainer *container;
|
||||
GtkTreeIter selected_iter;
|
||||
gboolean selected;
|
||||
|
||||
parent = gimp_viewable_get_parent (viewable);
|
||||
|
||||
if (parent)
|
||||
container = gimp_viewable_get_children (parent);
|
||||
else
|
||||
container = gimp_container_view_get_container (view);
|
||||
GtkTreeIter selected_iter;
|
||||
|
||||
selected = gimp_container_tree_view_get_selected_single (tree_view,
|
||||
&selected_iter);
|
||||
|
@ -721,53 +650,15 @@ gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
|||
|
||||
g_object_unref (renderer);
|
||||
}
|
||||
|
||||
if (new_index == -1 ||
|
||||
new_index == gimp_container_get_n_children (container) - 1)
|
||||
{
|
||||
gtk_tree_store_move_before (GTK_TREE_STORE (tree_view->model),
|
||||
iter, NULL);
|
||||
}
|
||||
else if (new_index == 0)
|
||||
{
|
||||
gtk_tree_store_move_after (GTK_TREE_STORE (tree_view->model),
|
||||
iter, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter place_iter;
|
||||
gint depth;
|
||||
gint *indices;
|
||||
gint old_index;
|
||||
|
||||
path = gtk_tree_model_get_path (tree_view->model, iter);
|
||||
indices = gtk_tree_path_get_indices (path);
|
||||
|
||||
depth = gtk_tree_path_get_depth (path);
|
||||
|
||||
old_index = indices[depth - 1];
|
||||
|
||||
if (new_index != old_index)
|
||||
{
|
||||
indices[depth - 1] = new_index;
|
||||
|
||||
gtk_tree_model_get_iter (tree_view->model, &place_iter, path);
|
||||
|
||||
if (new_index > old_index)
|
||||
gtk_tree_store_move_after (GTK_TREE_STORE (tree_view->model),
|
||||
iter, &place_iter);
|
||||
else
|
||||
gtk_tree_store_move_before (GTK_TREE_STORE (tree_view->model),
|
||||
iter, &place_iter);
|
||||
}
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
|
||||
if (selected)
|
||||
gimp_container_view_select_item (view, viewable);
|
||||
}
|
||||
|
||||
gimp_container_tree_store_reorder_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
||||
viewable,
|
||||
new_index,
|
||||
iter);
|
||||
|
||||
if (selected)
|
||||
gimp_container_view_select_item (view, viewable);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -778,24 +669,11 @@ gimp_container_tree_view_rename_item (GimpContainerView *view,
|
|||
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
||||
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
||||
|
||||
if (iter)
|
||||
if (gimp_container_tree_store_rename_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
||||
viewable,
|
||||
iter))
|
||||
{
|
||||
gchar *name = gimp_viewable_get_description (viewable, NULL);
|
||||
gchar *old_name;
|
||||
|
||||
gtk_tree_model_get (tree_view->model, iter,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_NAME, &old_name,
|
||||
-1);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (tree_view->model), iter,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_NAME, name,
|
||||
-1);
|
||||
|
||||
if (name && old_name && strlen (name) < strlen (old_name))
|
||||
gtk_tree_view_columns_autosize (tree_view->view);
|
||||
|
||||
g_free (name);
|
||||
g_free (old_name);
|
||||
gtk_tree_view_columns_autosize (tree_view->view);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -851,7 +729,7 @@ gimp_container_tree_view_clear_items (GimpContainerView *view)
|
|||
{
|
||||
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
||||
|
||||
gtk_tree_store_clear (GTK_TREE_STORE (tree_view->model));
|
||||
gimp_container_tree_store_clear_items (GIMP_CONTAINER_TREE_STORE (tree_view->model));
|
||||
|
||||
/* Clear out renderers from all cells so they don't keep refing the
|
||||
* viewables (see bug #149906).
|
||||
|
@ -867,34 +745,6 @@ gimp_container_tree_view_clear_items (GimpContainerView *view)
|
|||
parent_view_iface->clear_items (view);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gint view_size;
|
||||
gint border_width;
|
||||
} SetSizeForeachData;
|
||||
|
||||
static gboolean
|
||||
gimp_container_tree_view_set_view_size_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
SetSizeForeachData *size_data = data;
|
||||
GimpViewRenderer *renderer;
|
||||
|
||||
gtk_tree_model_get (model, iter,
|
||||
GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, &renderer,
|
||||
-1);
|
||||
|
||||
gimp_view_renderer_set_size (renderer,
|
||||
size_data->view_size,
|
||||
size_data->border_width);
|
||||
|
||||
g_object_unref (renderer);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_view_set_view_size (GimpContainerView *view)
|
||||
{
|
||||
|
@ -907,13 +757,7 @@ gimp_container_tree_view_set_view_size (GimpContainerView *view)
|
|||
view_size = gimp_container_view_get_view_size (view, &border_width);
|
||||
|
||||
if (tree_view->model)
|
||||
{
|
||||
SetSizeForeachData size_data = { view_size, border_width };
|
||||
|
||||
gtk_tree_model_foreach (tree_view->model,
|
||||
gimp_container_tree_view_set_view_size_foreach,
|
||||
&size_data);
|
||||
}
|
||||
gimp_container_tree_store_set_view_size (GIMP_CONTAINER_TREE_STORE (tree_view->model));
|
||||
|
||||
tree_widget = GTK_WIDGET (tree_view->view);
|
||||
|
||||
|
@ -1324,25 +1168,6 @@ gimp_container_tree_view_tooltip (GtkWidget *widget,
|
|||
return show_tip;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_container_tree_view_renderer_update (GimpViewRenderer *renderer,
|
||||
GimpContainerTreeView *tree_view)
|
||||
{
|
||||
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
|
||||
GtkTreeIter *iter;
|
||||
|
||||
iter = gimp_container_view_lookup (view, renderer->viewable);
|
||||
|
||||
if (iter)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
|
||||
path = gtk_tree_model_get_path (tree_view->model, iter);
|
||||
gtk_tree_model_row_changed (tree_view->model, path, iter);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
||||
|
||||
static GimpViewable *
|
||||
gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
||||
GimpContext **context,
|
||||
|
|
|
@ -83,6 +83,7 @@ typedef struct _GimpContainerBox GimpContainerBox;
|
|||
typedef struct _GimpContainerComboBox GimpContainerComboBox;
|
||||
typedef struct _GimpContainerEntry GimpContainerEntry;
|
||||
typedef struct _GimpContainerGridView GimpContainerGridView;
|
||||
typedef struct _GimpContainerTreeStore GimpContainerTreeStore;
|
||||
typedef struct _GimpContainerTreeView GimpContainerTreeView;
|
||||
typedef struct _GimpItemTreeView GimpItemTreeView;
|
||||
typedef struct _GimpDrawableTreeView GimpDrawableTreeView;
|
||||
|
|
Loading…
Reference in New Issue