app: Convert GimpToolView into a non-dockable GimpToolEditor

Convert the GimpToolView dockable to a non-dockable GimpToolEditor,
but wait with renaming the file so that we get better diffs. Part of
fix for bug #500930.
This commit is contained in:
Stephen Griffiths 2009-07-03 14:55:07 +10:00 committed by Martin Nordholts
parent c53113d0cc
commit 450db18abb
3 changed files with 301 additions and 183 deletions

View File

@ -1,7 +1,7 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptoolview.c
* gimptooleditor.c
* Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
@ -31,7 +31,6 @@
#include "core/gimpcontext.h"
#include "core/gimptoolinfo.h"
#include "gimpcontainertreeview.h"
#include "gimpcontainerview.h"
#include "gimpviewrenderer.h"
#include "gimptoolview.h"
@ -42,207 +41,333 @@
#include "gimp-intl.h"
static void gimp_tool_view_destroy (GtkObject *object);
typedef struct _GimpToolEditorPrivate GimpToolEditorPrivate;
static void gimp_tool_view_select_item (GimpContainerEditor *editor,
GimpViewable *viewable);
static void gimp_tool_view_activate_item (GimpContainerEditor *editor,
GimpViewable *viewable);
struct _GimpToolEditorPrivate
{
GtkTreeModel *model;
GimpContext *context;
GimpContainer *container;
GtkWidget *scrolled;
static void gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
GParamSpec *pspec,
GimpContainerTreeView *tree_view);
static void gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data);
static void gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
gchar *path_str,
GdkModifierType state,
GimpContainerTreeView *tree_view);
GtkWidget *raise_button;
GtkWidget *lower_button;
GtkWidget *reset_button;
GQuark visible_handler_id;
GList *default_tool_order;
};
G_DEFINE_TYPE (GimpToolView, gimp_tool_view, GIMP_TYPE_CONTAINER_EDITOR)
static void gimp_tool_editor_destroy (GtkObject *object);
#define parent_class gimp_tool_view_parent_class
static void gimp_tool_editor_visible_notify
(GimpToolInfo *tool_info,
GParamSpec *pspec,
GimpToolEditor *tool_editor);
static void gimp_tool_editor_eye_data_func
(GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data);
static void gimp_tool_editor_eye_clicked (GtkCellRendererToggle *toggle,
gchar *path_str,
GdkModifierType state,
GimpToolEditor *tool_editor);
static void gimp_tool_editor_button_clicked
(GtkButton *button,
GimpToolEditor *tool_editor);
static void gimp_tool_editor_button_extend_clicked
(GtkButton *button,
GdkModifierType mask,
GimpToolEditor *tool_editor);
G_DEFINE_TYPE (GimpToolEditor, gimp_tool_editor, GIMP_TYPE_CONTAINER_TREE_VIEW)
#define parent_class gimp_tool_editor_parent_class
#define GIMP_TOOL_EDITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
GIMP_TYPE_TOOL_EDITOR, \
GimpToolEditorPrivate))
static void
gimp_tool_view_class_init (GimpToolViewClass *klass)
gimp_tool_editor_class_init (GimpToolEditorClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
object_class->destroy = gimp_tool_view_destroy;
g_type_class_add_private (klass, sizeof (GimpToolEditorPrivate));
editor_class->select_item = gimp_tool_view_select_item;
editor_class->activate_item = gimp_tool_view_activate_item;
object_class->destroy = gimp_tool_editor_destroy;
}
static void
gimp_tool_view_init (GimpToolView *view)
gimp_tool_editor_init (GimpToolEditor *tool_editor)
{
view->visible_handler_id = 0;
view->raise_button = NULL;
view->lower_button = NULL;
view->reset_button = NULL;
GimpToolEditorPrivate *priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
priv->model = NULL;
priv->context = NULL;
priv->container = NULL;
priv->scrolled = NULL;
priv->visible_handler_id = 0;
priv->default_tool_order = NULL;
priv->raise_button = NULL;
priv->lower_button = NULL;
priv->reset_button = NULL;
}
static void
gimp_tool_view_destroy (GtkObject *object)
gimp_tool_editor_destroy (GtkObject *object)
{
GimpToolView *tool_view = GIMP_TOOL_VIEW (object);
GimpToolEditorPrivate *priv = GIMP_TOOL_EDITOR_GET_PRIVATE (object);
if (tool_view->visible_handler_id)
if (priv->visible_handler_id)
{
GimpContainerEditor *editor = GIMP_CONTAINER_EDITOR (tool_view);
GimpContainerView *view = GIMP_CONTAINER_VIEW (editor->view);
gimp_container_remove_handler (gimp_container_view_get_container (view),
tool_view->visible_handler_id);
tool_view->visible_handler_id = 0;
gimp_container_remove_handler (priv->container,
priv->visible_handler_id);
priv->visible_handler_id = 0;
}
priv->context = NULL;
priv->container = NULL;
priv->raise_button = NULL;
priv->lower_button = NULL;
priv->reset_button = NULL;
priv->scrolled = NULL;
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
GtkWidget *
gimp_tool_view_new (GimpViewType view_type,
GimpContainer *container,
GimpContext *context,
gint view_size,
gint view_border_width,
GimpMenuFactory *menu_factory)
gimp_tool_editor_new (GimpContainer *container,
GimpContext *context,
GList *default_tool_order,
gint view_size,
gint view_border_width)
{
GimpToolView *tool_view;
GimpContainerEditor *editor;
GimpToolEditor *tool_editor;
GimpContainerTreeView *tree_view;
GimpContainerView *container_view;
GObject *object;
GimpToolEditorPrivate *priv;
tool_view = g_object_new (GIMP_TYPE_TOOL_VIEW, NULL);
g_return_val_if_fail (container != NULL, NULL);
g_return_val_if_fail (context != NULL, NULL);
if (! gimp_container_editor_construct (GIMP_CONTAINER_EDITOR (tool_view),
view_type,
container, context,
view_size, view_border_width,
menu_factory, "<Tools>",
"/tools-popup"))
object = g_object_new (GIMP_TYPE_TOOL_EDITOR, NULL);
tool_editor = GIMP_TOOL_EDITOR (object);
tree_view = GIMP_CONTAINER_TREE_VIEW (object);
container_view = GIMP_CONTAINER_VIEW (object);
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
priv->container = container;
priv->context = context;
priv->model = tree_view->model;
priv->default_tool_order = default_tool_order;
gimp_container_view_set_view_size (container_view,
view_size, view_border_width);
gimp_container_view_set_container (container_view, priv->container);
gimp_container_view_set_context (container_view, context);
gimp_container_view_set_reorderable (container_view, TRUE);
gimp_editor_set_show_name (GIMP_EDITOR (tree_view), FALSE);
/* Construct tree view */
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (tool_editor);
GtkWidget *tree_widget = GTK_WIDGET (tree_view);
GtkStyle *tree_style = gtk_widget_get_style (tree_widget);
GtkTreeViewColumn *column;
GtkCellRenderer *eye_cell;
GtkIconSize icon_size;
column = gtk_tree_view_column_new ();
gtk_tree_view_insert_column (tree_view->view, column, 0);
eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
icon_size = gimp_get_icon_size (GTK_WIDGET (tool_editor),
GIMP_STOCK_VISIBLE,
GTK_ICON_SIZE_BUTTON,
view_size -
2 * tree_style->xthickness,
view_size -
2 * tree_style->ythickness);
g_object_set (eye_cell, "stock-size", icon_size, NULL);
gtk_tree_view_column_pack_start (column, eye_cell, FALSE);
gtk_tree_view_column_set_cell_data_func (column, eye_cell,
gimp_tool_editor_eye_data_func,
tree_view, NULL);
gimp_container_tree_view_prepend_toggle_cell_renderer (tree_view,
eye_cell);
g_signal_connect (eye_cell, "clicked",
G_CALLBACK (gimp_tool_editor_eye_clicked),
tool_editor);
priv->visible_handler_id =
gimp_container_add_handler (container, "notify::visible",
G_CALLBACK (gimp_tool_editor_visible_notify),
tool_editor);
}
/* buttons */
priv->raise_button =
gimp_editor_add_button (GIMP_EDITOR (tree_view), GTK_STOCK_GO_UP,
_("Raise this tool Raise this tool to the top"),
NULL,
G_CALLBACK (gimp_tool_editor_button_clicked),
G_CALLBACK (gimp_tool_editor_button_extend_clicked),
tool_editor);
priv->lower_button =
gimp_editor_add_button (GIMP_EDITOR (tree_view), GTK_STOCK_GO_DOWN,
_("Lower this tool Lower this tool to the bottom"),
NULL,
G_CALLBACK (gimp_tool_editor_button_clicked),
G_CALLBACK (gimp_tool_editor_button_extend_clicked),
tool_editor);
priv->reset_button =
gimp_editor_add_button (GIMP_EDITOR (tree_view), GIMP_STOCK_RESET,
_("Reset tool order and visibility"), NULL,
G_CALLBACK (gimp_tool_editor_button_clicked), NULL,
tool_editor);
return GTK_WIDGET (tool_editor);
}
static void
gimp_tool_editor_button_clicked (GtkButton *button,
GimpToolEditor *tool_editor)
{
GimpToolInfo *tool_info;
GimpToolEditorPrivate *priv;
gint index;
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
tool_info = gimp_context_get_tool (priv->context);
if (tool_info && button == GTK_BUTTON (priv->raise_button))
{
g_object_unref (tool_view);
return NULL;
index = gimp_container_get_child_index (priv->container,
GIMP_OBJECT (tool_info));
if (index > 0)
{
gimp_container_reorder (priv->container,
GIMP_OBJECT (tool_info), index - 1);
}
}
editor = GIMP_CONTAINER_EDITOR (tool_view);
tool_view->raise_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
"tools-raise",
"tools-raise-to-top", GDK_SHIFT_MASK,
NULL);
tool_view->lower_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
"tools-lower",
"tools-lower-to-bottom", GDK_SHIFT_MASK,
NULL);
tool_view->reset_button =
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "tools",
"tools-reset", NULL);
if (view_type == GIMP_VIEW_TYPE_LIST)
else if (tool_info && button == GTK_BUTTON (priv->lower_button))
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (editor->view);
GtkWidget *tree_widget = GTK_WIDGET (tree_view);
GtkStyle *tree_style = gtk_widget_get_style (tree_widget);
GtkTreeViewColumn *column;
GtkCellRenderer *eye_cell;
GtkIconSize icon_size;
index = gimp_container_get_child_index (priv->container,
GIMP_OBJECT (tool_info));
column = gtk_tree_view_column_new ();
gtk_tree_view_insert_column (tree_view->view, column, 0);
eye_cell = gimp_cell_renderer_toggle_new (GIMP_STOCK_VISIBLE);
icon_size = gimp_get_icon_size (GTK_WIDGET (tree_view),
GIMP_STOCK_VISIBLE,
GTK_ICON_SIZE_BUTTON,
view_size -
2 * tree_style->xthickness,
view_size -
2 * tree_style->ythickness);
g_object_set (eye_cell, "stock-size", icon_size, NULL);
gtk_tree_view_column_pack_start (column, eye_cell, FALSE);
gtk_tree_view_column_set_cell_data_func (column, eye_cell,
gimp_tool_view_eye_data_func,
tree_view,
NULL);
gimp_container_tree_view_prepend_toggle_cell_renderer (tree_view,
eye_cell);
g_signal_connect (eye_cell, "clicked",
G_CALLBACK (gimp_tool_view_eye_clicked),
tree_view);
tool_view->visible_handler_id =
gimp_container_add_handler (container, "notify::visible",
G_CALLBACK (gimp_tool_view_visible_notify),
tree_view);
if (index + 1 < gimp_container_get_n_children (priv->container))
{
gimp_container_reorder (priv->container,
GIMP_OBJECT (tool_info), index + 1);
}
}
else if (tool_info && button == GTK_BUTTON (priv->reset_button))
{
GList *list;
gint i = 0;
gimp_ui_manager_update (GIMP_EDITOR (editor->view)->ui_manager, editor);
for (list = priv->default_tool_order;
list;
list = g_list_next (list))
{
GimpObject *object =
gimp_container_get_child_by_name (priv->container, list->data);
return GTK_WIDGET (tool_view);
if (object)
{
gboolean visible;
gpointer data;
gimp_container_reorder (priv->container, object, i);
data = g_object_get_data (G_OBJECT (object),
"gimp-tool-default-visible");
visible = GPOINTER_TO_INT (data);
g_object_set (object, "visible", visible, NULL);
i++;
}
}
}
}
static void
gimp_tool_view_select_item (GimpContainerEditor *editor,
GimpViewable *viewable)
gimp_tool_editor_button_extend_clicked (GtkButton *button,
GdkModifierType mask,
GimpToolEditor *tool_editor)
{
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item)
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->select_item (editor, viewable);
GimpToolInfo *tool_info;
GimpToolEditorPrivate *priv;
gint index;
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
tool_info = gimp_context_get_tool (priv->context);
if (! mask == GDK_SHIFT_MASK)
{
/* do nothing */
}
if (button == GTK_BUTTON (priv->raise_button))
{
index = gimp_container_get_child_index (priv->container,
GIMP_OBJECT (tool_info));
if (index > 0)
gimp_container_reorder (priv->container,
GIMP_OBJECT (tool_info), 0);
}
else if (button == GTK_BUTTON (priv->lower_button))
{
index = gimp_container_get_n_children (priv->container) - 1;
index = index >= 0 ? index : 0;
gimp_container_reorder (priv->container,
GIMP_OBJECT (tool_info), index);
}
}
static void
gimp_tool_view_activate_item (GimpContainerEditor *editor,
GimpViewable *viewable)
gimp_tool_editor_visible_notify (GimpToolInfo *tool_info,
GParamSpec *pspec,
GimpToolEditor *tool_editor)
{
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
}
GimpToolEditorPrivate *priv;
GtkTreeIter *iter;
/* "visible" callbaks */
static void
gimp_tool_view_visible_notify (GimpToolInfo *tool_info,
GParamSpec *pspec,
GimpContainerTreeView *tree_view)
{
GtkTreeIter *iter;
iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tree_view),
(GimpViewable *) tool_info);
priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
iter = gimp_container_view_lookup (GIMP_CONTAINER_VIEW (tool_editor),
GIMP_VIEWABLE (tool_info));
if (iter)
{
GtkTreePath *path;
path = gtk_tree_model_get_path (tree_view->model, iter);
path = gtk_tree_model_get_path (priv->model, iter);
gtk_tree_model_row_changed (tree_view->model, path, iter);
gtk_tree_model_row_changed (priv->model, path, iter);
gtk_tree_path_free (path);
}
}
static void
gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
gimp_tool_editor_eye_data_func (GtkTreeViewColumn *tree_column,
GtkCellRenderer *cell,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
{
GimpViewRenderer *renderer;
gboolean visible;
@ -259,17 +384,18 @@ gimp_tool_view_eye_data_func (GtkTreeViewColumn *tree_column,
}
static void
gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
gchar *path_str,
GdkModifierType state,
GimpContainerTreeView *tree_view)
gimp_tool_editor_eye_clicked (GtkCellRendererToggle *toggle,
gchar *path_str,
GdkModifierType state,
GimpToolEditor *tool_editor)
{
GtkTreePath *path;
GtkTreeIter iter;
GtkTreeIter iter;
GtkTreePath *path;
GimpToolEditorPrivate *priv = GIMP_TOOL_EDITOR_GET_PRIVATE (tool_editor);
path = gtk_tree_path_new_from_string (path_str);
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
if (gtk_tree_model_get_iter (priv->model, &iter, path))
{
GimpViewRenderer *renderer;
gboolean active;
@ -277,8 +403,7 @@ gimp_tool_view_eye_clicked (GtkCellRendererToggle *toggle,
g_object_get (toggle,
"active", &active,
NULL);
gtk_tree_model_get (tree_view->model, &iter,
gtk_tree_model_get (priv->model, &iter,
GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, &renderer,
-1);

View File

@ -1,7 +1,7 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimptoolview.h
* gimptooleditor.h
* Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
@ -18,48 +18,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_TOOL_VIEW_H__
#define __GIMP_TOOL_VIEW_H__
#ifndef __GIMP_TOOL_EDITOR_H__
#define __GIMP_TOOL_EDITOR_H__
#include "gimpcontainereditor.h"
#include "gimpcontainertreeview.h"
#define GIMP_TYPE_TOOL_VIEW (gimp_tool_view_get_type ())
#define GIMP_TOOL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_VIEW, GimpToolView))
#define GIMP_TOOL_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_VIEW, GimpToolViewClass))
#define GIMP_IS_TOOL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_VIEW))
#define GIMP_IS_TOOL_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_VIEW))
#define GIMP_TOOL_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_VIEW, GimpToolViewClass))
#define GIMP_TYPE_TOOL_EDITOR (gimp_tool_editor_get_type ())
#define GIMP_TOOL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TOOL_EDITOR, GimpToolEditor))
#define GIMP_TOOL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TOOL_EDITOR, GimpToolEditorClass))
#define GIMP_IS_TOOL_EDITOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TOOL_EDITOR))
#define GIMP_IS_TOOL_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TOOL_EDITOR))
#define GIMP_TOOL_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TOOL_EDITOR, GimpToolEditorClass))
typedef struct _GimpToolViewClass GimpToolViewClass;
typedef struct _GimpToolEditorClass GimpToolEditorClass;
struct _GimpToolView
struct _GimpToolEditor
{
GimpContainerEditor parent_instance;
GQuark visible_handler_id;
GtkWidget *raise_button;
GtkWidget *lower_button;
GtkWidget *reset_button;
GimpContainerTreeView parent_instance;
};
struct _GimpToolViewClass
struct _GimpToolEditorClass
{
GimpContainerEditorClass parent_class;
GimpContainerTreeViewClass parent_class;
};
GType gimp_tool_view_get_type (void) G_GNUC_CONST;
GType gimp_tool_editor_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_tool_view_new (GimpViewType view_type,
GimpContainer *container,
GimpContext *context,
gint view_size,
gint view_border_width,
GimpMenuFactory *menu_factory);
GtkWidget * gimp_tool_editor_new (GimpContainer *container,
GimpContext *context,
GList *defualt_tool_order,
gint view_size,
gint view_border_width);
#endif /* __GIMP_TOOL_VIEW_H__ */
#endif /* __GIMP_TOOL_EDITOR_H__ */

View File

@ -100,7 +100,7 @@ typedef struct _GimpDocumentView GimpDocumentView;
typedef struct _GimpFontView GimpFontView;
typedef struct _GimpImageView GimpImageView;
typedef struct _GimpTemplateView GimpTemplateView;
typedef struct _GimpToolView GimpToolView;
typedef struct _GimpToolEditor GimpToolEditor;
/* GimpDataFactoryView widgets */