Commit c798f967 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

removed the last artefact of context signal handling from 1.2:

2004-01-29  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpcontext.[ch]: removed the last artefact of context
	signal handling from 1.2:

	GimpContext used to connect to e.g. the current brush's
	"invalidate_preview" and "name_changed" signals and emitted
	"brush_changed" when the callback was invoked. This was needed to
	make 1.2 work, but is conceptually broken with the real model <->
	view approach implemented in the current code.
	This change also optimizes things quite a bit because lots of
	signal emissions are saved.

	Added utility function which finds a container's current object
	after a freeze/thaw.

	* app/widgets/gimpcontainerview.[ch]: added new virtual function
	GimpContainerView::rename_item(). Connect to "name_changed" of the
	corrent container's children and invoke rename_item() accordingly.

	* app/widgets/gimpcontainertreeview.[ch]: removed name_changed
	handler and implement GimpContainerView::rename_item().

	* app/widgets/gimpcontainergridview.c: ditto. the grid view was
	still relying on the removed GimpContext behaviour for updating
	the label showing the sleected item's name.
parent 44cac5ae
2004-01-29 Michael Natterer <mitch@gimp.org>
* app/core/gimpcontext.[ch]: removed the last artefact of context
signal handling from 1.2:
GimpContext used to connect to e.g. the current brush's
"invalidate_preview" and "name_changed" signals and emitted
"brush_changed" when the callback was invoked. This was needed to
make 1.2 work, but is conceptually broken with the real model <->
view approach implemented in the current code.
This change also optimizes things quite a bit because lots of
signal emissions are saved.
Added utility function which finds a container's current object
after a freeze/thaw.
* app/widgets/gimpcontainerview.[ch]: added new virtual function
GimpContainerView::rename_item(). Connect to "name_changed" of the
corrent container's children and invoke rename_item() accordingly.
* app/widgets/gimpcontainertreeview.[ch]: removed name_changed
handler and implement GimpContainerView::rename_item().
* app/widgets/gimpcontainergridview.c: ditto. the grid view was
still relying on the removed GimpContext behaviour for updating
the label showing the sleected item's name.
2004-01-29 Michael Natterer <mitch@gimp.org>
 
GimpData code review:
This diff is collapsed.
......@@ -74,8 +74,13 @@ struct _GimpContext
gchar *font_name;
GimpBuffer *buffer;
gchar *buffer_name;
GimpImagefile *imagefile;
gchar *imagefile_name;
GimpTemplate *template;
gchar *template_name;
};
struct _GimpContextClass
......
......@@ -72,6 +72,9 @@ static void gimp_container_grid_view_reorder_item (GimpContainerView *v
GimpViewable *viewable,
gint new_index,
gpointer insert_data);
static void gimp_container_grid_view_rename_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data);
static gboolean gimp_container_grid_view_select_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data);
......@@ -94,6 +97,7 @@ static void gimp_container_grid_view_viewport_resized (GtkWidget *w
static GimpContainerViewClass *parent_class = NULL;
static guint grid_view_signals[LAST_SIGNAL] = { 0 };
static GimpRGB white_color;
......@@ -147,6 +151,7 @@ gimp_container_grid_view_class_init (GimpContainerGridViewClass *klass)
container_view_class->insert_item = gimp_container_grid_view_insert_item;
container_view_class->remove_item = gimp_container_grid_view_remove_item;
container_view_class->reorder_item = gimp_container_grid_view_reorder_item;
container_view_class->rename_item = gimp_container_grid_view_rename_item;
container_view_class->select_item = gimp_container_grid_view_select_item;
container_view_class->clear_items = gimp_container_grid_view_clear_items;
container_view_class->set_preview_size = gimp_container_grid_view_set_preview_size;
......@@ -188,9 +193,7 @@ gimp_container_grid_view_class_init (GimpContainerGridViewClass *klass)
static void
gimp_container_grid_view_init (GimpContainerGridView *grid_view)
{
GimpContainerView *view;
view = GIMP_CONTAINER_VIEW (grid_view);
GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view);
grid_view->rows = 1;
grid_view->columns = 1;
......@@ -320,7 +323,7 @@ static gboolean
gimp_container_grid_view_focus (GtkWidget *widget,
GtkDirectionType direction)
{
GimpContainerGridView *view;
GimpContainerGridView *view = GIMP_CONTAINER_GRID_VIEW (widget);
if (GTK_WIDGET_CAN_FOCUS (widget) && !GTK_WIDGET_HAS_FOCUS (widget))
{
......@@ -328,8 +331,6 @@ gimp_container_grid_view_focus (GtkWidget *widget,
return TRUE;
}
view = GIMP_CONTAINER_GRID_VIEW (widget);
switch (direction)
{
case GTK_DIR_UP:
......@@ -374,11 +375,8 @@ gimp_container_grid_view_menu_position (GtkMenu *menu,
static gboolean
gimp_container_grid_view_popup_menu (GtkWidget *widget)
{
GimpContainerGridView *grid_view;
GimpEditor *editor;
grid_view = GIMP_CONTAINER_GRID_VIEW (widget);
editor = GIMP_EDITOR (widget);
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (widget);
GimpEditor *editor = GIMP_EDITOR (widget);
if (editor->item_factory && grid_view->selected_item)
{
......@@ -399,11 +397,9 @@ gimp_container_grid_view_insert_item (GimpContainerView *view,
GimpViewable *viewable,
gint index)
{
GimpContainerGridView *grid_view;
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWidget *preview;
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
preview = gimp_preview_new_full (viewable,
view->preview_size,
view->preview_size,
......@@ -440,19 +436,13 @@ gimp_container_grid_view_remove_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data)
{
GimpContainerGridView *grid_view;
GtkWidget *preview;
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWidget *preview = GTK_WIDGET (insert_data);
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
preview = GTK_WIDGET (insert_data);
if (preview == (GtkWidget *) grid_view->selected_item)
grid_view->selected_item = NULL;
if (preview)
{
if (preview == (GtkWidget *) grid_view->selected_item)
grid_view->selected_item = NULL;
gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box), preview);
}
gtk_container_remove (GTK_CONTAINER (grid_view->wrap_box), preview);
}
static void
......@@ -461,16 +451,31 @@ gimp_container_grid_view_reorder_item (GimpContainerView *view,
gint new_index,
gpointer insert_data)
{
GimpContainerGridView *grid_view;
GtkWidget *preview;
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
preview = GTK_WIDGET (insert_data);
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWidget *preview = GTK_WIDGET (insert_data);
gtk_wrap_box_reorder_child (GTK_WRAP_BOX (grid_view->wrap_box),
preview, new_index);
}
static void
gimp_container_grid_view_rename_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data)
{
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWidget *preview = GTK_WIDGET (insert_data);
if (preview == (GtkWidget *) grid_view->selected_item)
{
gchar *name = gimp_viewable_get_description (viewable, NULL);
gtk_label_set_text (GTK_LABEL (grid_view->name_label), name);
g_free (name);
}
}
static gboolean
gimp_container_grid_view_select_item (GimpContainerView *view,
GimpViewable *viewable,
......@@ -484,9 +489,7 @@ gimp_container_grid_view_select_item (GimpContainerView *view,
static void
gimp_container_grid_view_clear_items (GimpContainerView *view)
{
GimpContainerGridView *grid_view;
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
grid_view->selected_item = NULL;
......@@ -500,11 +503,9 @@ gimp_container_grid_view_clear_items (GimpContainerView *view)
static void
gimp_container_grid_view_set_preview_size (GimpContainerView *view)
{
GimpContainerGridView *grid_view;
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GtkWrapBoxChild *child;
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
for (child = GTK_WRAP_BOX (grid_view->wrap_box)->children;
child;
child = child->next)
......@@ -561,10 +562,8 @@ gimp_container_grid_view_highlight_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data)
{
GimpContainerGridView *grid_view;
GimpPreview *preview = NULL;
grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GimpContainerGridView *grid_view = GIMP_CONTAINER_GRID_VIEW (view);
GimpPreview *preview = NULL;
if (insert_data)
preview = GIMP_PREVIEW (insert_data);
......@@ -627,9 +626,7 @@ gimp_container_grid_view_viewport_resized (GtkWidget *widget,
GtkAllocation *allocation,
GimpContainerGridView *grid_view)
{
GimpContainerView *view;
view = GIMP_CONTAINER_VIEW (grid_view);
GimpContainerView *view = GIMP_CONTAINER_VIEW (grid_view);
if (view->container)
{
......@@ -674,9 +671,7 @@ gimp_container_grid_view_viewport_resized (GtkWidget *widget,
if (grid_view->selected_item)
{
GimpPreview *preview;
preview = grid_view->selected_item;
GimpPreview *preview = grid_view->selected_item;
gimp_container_grid_view_highlight_item (view,
preview->viewable,
......
......@@ -75,6 +75,9 @@ static void gimp_container_tree_view_reorder_item (GimpContainerView *v
GimpViewable *viewable,
gint new_index,
gpointer insert_data);
static void gimp_container_tree_view_rename_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data);
static gboolean gimp_container_tree_view_select_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data);
......@@ -88,8 +91,6 @@ static gboolean gimp_container_tree_view_button_press (GtkWidget *w
GimpContainerTreeView *tree_view);
static void gimp_container_tree_view_renderer_update (GimpPreviewRenderer *renderer,
GimpContainerTreeView *tree_view);
static void gimp_container_tree_view_name_changed (GimpObject *object,
GimpContainerTreeView *tree_view);
static GimpViewable * gimp_container_tree_view_drag_viewable (GtkWidget *widget,
gpointer data);
......@@ -149,6 +150,7 @@ gimp_container_tree_view_class_init (GimpContainerTreeViewClass *klass)
container_view_class->insert_item = gimp_container_tree_view_insert_item;
container_view_class->remove_item = gimp_container_tree_view_remove_item;
container_view_class->reorder_item = gimp_container_tree_view_reorder_item;
container_view_class->rename_item = gimp_container_tree_view_rename_item;
container_view_class->select_item = gimp_container_tree_view_select_item;
container_view_class->clear_items = gimp_container_tree_view_clear_items;
container_view_class->set_preview_size = gimp_container_tree_view_set_preview_size;
......@@ -437,9 +439,6 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
if (view->container)
{
gimp_container_remove_handler (view->container,
tree_view->name_changed_handler_id);
if (! container)
{
if (gimp_dnd_viewable_source_remove (GTK_WIDGET (tree_view->view),
......@@ -475,21 +474,6 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
}
GIMP_CONTAINER_VIEW_CLASS (parent_class)->set_container (view, container);
if (view->container)
{
GimpViewableClass *viewable_class;
viewable_class = g_type_class_ref (container->children_type);
tree_view->name_changed_handler_id =
gimp_container_add_handler (view->container,
viewable_class->name_changed_signal,
G_CALLBACK (gimp_container_tree_view_name_changed),
tree_view);
g_type_class_unref (viewable_class);
}
}
static gpointer
......@@ -599,6 +583,28 @@ gimp_container_tree_view_reorder_item (GimpContainerView *view,
}
}
static void
gimp_container_tree_view_rename_item (GimpContainerView *view,
GimpViewable *viewable,
gpointer insert_data)
{
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
GtkTreeIter *iter;
iter = (GtkTreeIter *) insert_data;
if (iter)
{
gchar *name = gimp_viewable_get_description (viewable, NULL);
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), iter,
COLUMN_NAME, name,
-1);
g_free (name);
}
}
static gboolean
gimp_container_tree_view_select_item (GimpContainerView *view,
GimpViewable *viewable,
......@@ -970,29 +976,6 @@ gimp_container_tree_view_renderer_update (GimpPreviewRenderer *renderer,
}
}
static void
gimp_container_tree_view_name_changed (GimpObject *object,
GimpContainerTreeView *tree_view)
{
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
GtkTreeIter *iter;
iter = g_hash_table_lookup (view->hash_table, object);
if (iter)
{
gchar *name;
name = gimp_viewable_get_description (GIMP_VIEWABLE (object), NULL);
gtk_list_store_set (GTK_LIST_STORE (tree_view->model), iter,
COLUMN_NAME, name,
-1);
g_free (name);
}
}
static GimpViewable *
gimp_container_tree_view_drag_viewable (GtkWidget *widget,
gpointer data)
......
......@@ -60,7 +60,6 @@ struct _GimpContainerTreeView
GList *editable_cells;
GQuark invalidate_preview_handler_id;
GQuark name_changed_handler_id;
GimpViewable *dnd_viewable;
......
......@@ -97,6 +97,8 @@ static void gimp_container_view_freeze (GimpContainerView *view,
GimpContainer *container);
static void gimp_container_view_thaw (GimpContainerView *view,
GimpContainer *container);
static void gimp_container_view_name_changed (GimpViewable *viewable,
GimpContainerView *view);
static GtkWidget * gimp_container_view_get_preview (GimpDocked *docked,
GimpContext *context,
......@@ -215,6 +217,7 @@ gimp_container_view_class_init (GimpContainerViewClass *klass)
klass->insert_item = NULL;
klass->remove_item = NULL;
klass->reorder_item = NULL;
klass->rename_item = NULL;
klass->clear_items = gimp_container_view_real_clear_items;
klass->set_preview_size = NULL;
......@@ -352,6 +355,9 @@ gimp_container_view_real_set_container (GimpContainerView *view,
gimp_container_view_select_item (view, NULL);
gimp_container_view_clear_items (view);
gimp_container_remove_handler (view->container,
view->name_changed_handler_id);
g_signal_handlers_disconnect_by_func (view->container,
gimp_container_view_add,
view);
......@@ -395,10 +401,22 @@ gimp_container_view_real_set_container (GimpContainerView *view,
if (view->container)
{
GimpViewableClass *viewable_class;
viewable_class = g_type_class_ref (container->children_type);
gimp_container_foreach (view->container,
(GFunc) gimp_container_view_add_foreach,
view);
view->name_changed_handler_id =
gimp_container_add_handler (view->container,
viewable_class->name_changed_signal,
G_CALLBACK (gimp_container_view_name_changed),
view);
g_type_class_unref (viewable_class);
g_signal_connect_object (view->container, "add",
G_CALLBACK (gimp_container_view_add),
view,
......@@ -850,6 +868,22 @@ gimp_container_view_thaw (GimpContainerView *view,
}
}
static void
gimp_container_view_name_changed (GimpViewable *viewable,
GimpContainerView *view)
{
gpointer insert_data;
insert_data = g_hash_table_lookup (view->hash_table, viewable);
if (insert_data)
{
GIMP_CONTAINER_VIEW_GET_CLASS (view)->rename_item (view,
viewable,
insert_data);
}
}
static void
gimp_container_view_set_docked_context (GimpDocked *docked,
GimpContext *context,
......
......@@ -53,6 +53,8 @@ struct _GimpContainerView
/* initialized by subclass */
GtkWidget *dnd_widget;
GQuark name_changed_handler_id;
};
struct _GimpContainerViewClass
......@@ -83,6 +85,9 @@ struct _GimpContainerViewClass
GimpViewable *object,
gint new_index,
gpointer insert_data);
void (* rename_item) (GimpContainerView *view,
GimpViewable *object,
gpointer insert_data);
void (* clear_items) (GimpContainerView *view);
void (* set_preview_size) (GimpContainerView *view);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment