Commit c4dc31af authored by Tristan Van Berkom's avatar Tristan Van Berkom
Browse files

* plugins/gtk+/glade-model-data.c, plugins/gtk+/glade-attributes.c: Use GladeCellRendererIcon

	  instead of GladeCellRendererButton which was more convoluted (included only an icon when editing).

	* plugins/gtk+/Makefile.am: Removed glade-cell-renderer-button.[ch]
parent 65cc1458
......@@ -5,6 +5,11 @@
* gladeui/glade-signal-editor.c: Use new activatable pixbuf renderer to render a devhelp icon
and fire signal contextual devhelp searches.
* plugins/gtk+/glade-model-data.c, plugins/gtk+/glade-attributes.c: Use GladeCellRendererIcon
instead of GladeCellRendererButton which was more convoluted (included only an icon when editing).
* plugins/gtk+/Makefile.am: Removed glade-cell-renderer-button.[ch]
2010-03-28 Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
* gladeui/glade-base-editor.c: Avoid GtkEntry feedback loop with g_signal_handlers_block_by_func(),
......
......@@ -789,6 +789,8 @@ glade_signal_editor_construct_signals_list (GladeSignalEditor *editor)
g_object_set (G_OBJECT (renderer),
"width", 20,
NULL);
g_object_set_data (G_OBJECT (renderer), "signal-after-cell",
GINT_TO_POINTER (TRUE));
g_signal_connect (renderer, "toggled",
G_CALLBACK (glade_signal_editor_after_swapped_toggled), editor);
......@@ -824,8 +826,6 @@ glade_signal_editor_construct_signals_list (GladeSignalEditor *editor)
}
gtk_tree_view_append_column (view, column);
g_object_set_data (G_OBJECT (renderer), "signal-after-cell",
GINT_TO_POINTER (TRUE));
editor->signals_list = view_widget;
......
......@@ -46,5 +46,6 @@
#include <gladeui/glade-name-context.h>
#include <gladeui/glade-editable.h>
#include <gladeui/glade-displayable-values.h>
#include <gladeui/glade-cell-renderer-icon.h>
#endif /* __GLADE_H__ */
......@@ -24,7 +24,7 @@ libgladegtk_la_CFLAGS = \
$(AM_CFLAGS)
libgladegtk_la_SOURCES = glade-gtk.c glade-accels.c glade-attributes.c glade-convert.c fixed-bg.xpm \
glade-column-types.c glade-model-data.c glade-text-button.c glade-cell-renderer-button.c \
glade-column-types.c glade-model-data.c glade-text-button.c \
glade-icon-sources.c glade-button-editor.c glade-tool-button-editor.c glade-image-editor.c \
glade-image-item-editor.c glade-icon-factory-editor.c glade-store-editor.c glade-label-editor.c \
glade-cell-renderer-editor.c glade-treeview-editor.c glade-entry-editor.c glade-activatable-editor.c
......@@ -34,7 +34,7 @@ libgladegtk_la_LIBADD = $(libgladeui) $(GTK_LIBS)
libgladegtkincludedir= $(includedir)/libgladeui-1.0/gladeui
libgladegtkinclude_HEADERS = glade-gtk.h glade-accels.h glade-attributes.h glade-column-types.h glade-model-data.h \
glade-text-button.h glade-cell-renderer-button.h glade-icon-sources.h glade-button-editor.h \
glade-text-button.h glade-icon-sources.h glade-button-editor.h \
glade-tool-button-editor.h glade-image-editor.h glade-image-item-editor.h glade-icon-factory-editor.h \
glade-store-editor.h glade-label-editor.h glade-cell-renderer-editor.h glade-treeview-editor.h \
glade-entry-editor.h glade-activatable-editor.h
......
......@@ -32,7 +32,6 @@
#include <glib/gi18n-lib.h>
#include "glade-attributes.h"
#include "glade-cell-renderer-button.h"
#define GLADE_RESPONSE_CLEAR 42
......@@ -695,9 +694,9 @@ get_row_by_type (GtkTreeModel *model,
static void
value_button_clicked (GtkCellRendererToggle *cell_renderer,
gchar *path,
GladeEPropAttrs *eprop_attrs)
value_icon_activate (GtkCellRendererToggle *cell_renderer,
gchar *path,
GladeEPropAttrs *eprop_attrs)
{
GtkWidget *dialog;
GtkWidget *colorsel;
......@@ -881,9 +880,9 @@ glade_eprop_attrs_view (GladeEditorProperty *eprop)
G_CALLBACK (value_toggled), eprop);
/* Button renderer */
renderer = glade_cell_renderer_button_new ();
g_object_set (G_OBJECT (renderer), "entry-editable", FALSE, NULL);
/* Text renderer */
renderer = gtk_cell_renderer_text_new ();
g_object_set (G_OBJECT (renderer), "editable", FALSE, NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
"editable", COLUMN_BUTTON_ACTIVE,
......@@ -892,8 +891,20 @@ glade_eprop_attrs_view (GladeEditorProperty *eprop)
"style", COLUMN_TEXT_STYLE,
"foreground", COLUMN_TEXT_FG,
NULL);
g_signal_connect (G_OBJECT (renderer), "clicked",
G_CALLBACK (value_button_clicked), eprop);
/* Icon renderer */
renderer = glade_cell_renderer_icon_new ();
g_object_set (G_OBJECT (renderer),
"icon-name", GTK_STOCK_EDIT,
NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
"activatable", COLUMN_BUTTON_ACTIVE,
"visible", COLUMN_BUTTON_ACTIVE,
NULL);
g_signal_connect (G_OBJECT (renderer), "activate",
G_CALLBACK (value_icon_activate), eprop);
/* Combo renderer */
renderer = gtk_cell_renderer_combo_new ();
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Tristan Van Berkom <tvb@gnome.org>
*/
#include <config.h>
#include <gladeui/glade.h>
#include <glib/gi18n-lib.h>
#include <gdk/gdkkeysyms.h>
#include "glade-cell-renderer-button.h"
#include "glade-text-button.h"
#define GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GLADE_TYPE_CELL_RENDERER_BUTTON, GladeCellRendererButtonPrivate))
typedef struct
{
GladeTextButton *button;
gboolean entry_editable;
} GladeCellRendererButtonPrivate;
static void glade_cell_renderer_button_finalize (GObject *object);
static void glade_cell_renderer_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *spec);
static void glade_cell_renderer_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *spec);
static GtkCellEditable * glade_cell_renderer_button_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags);
enum {
PROP_0,
PROP_ENTRY_EDITABLE
};
enum {
CLICKED,
LAST_SIGNAL
};
static guint glade_cell_renderer_signals [LAST_SIGNAL];
G_DEFINE_TYPE (GladeCellRendererButton, glade_cell_renderer_button, GTK_TYPE_CELL_RENDERER_TEXT)
#define GLADE_CELL_RENDERER_BUTTON_PATH "glade-cell-renderer-button-path"
static void
glade_cell_renderer_button_class_init (GladeCellRendererButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
object_class->finalize = glade_cell_renderer_button_finalize;
object_class->get_property = glade_cell_renderer_button_get_property;
object_class->set_property = glade_cell_renderer_button_set_property;
cell_class->start_editing = glade_cell_renderer_button_start_editing;
g_object_class_install_property (object_class,
PROP_ENTRY_EDITABLE,
g_param_spec_boolean ("entry-editable",
_("Entry Editable"),
_("Whether the entry is editable"),
TRUE,
G_PARAM_READWRITE));
glade_cell_renderer_signals[CLICKED] =
g_signal_new ("clicked",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GladeCellRendererButtonClass, clicked),
NULL, NULL,
g_cclosure_marshal_VOID__STRING,
G_TYPE_NONE, 1, G_TYPE_STRING);
g_type_class_add_private (object_class, sizeof (GladeCellRendererButtonPrivate));
}
static void
glade_cell_renderer_button_init (GladeCellRendererButton *self)
{
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (self);
priv->entry_editable = TRUE;
}
static void
glade_cell_renderer_button_finalize (GObject *object)
{
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (object);
G_OBJECT_CLASS (glade_cell_renderer_button_parent_class)->finalize (object);
}
static void
glade_cell_renderer_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GladeCellRendererButton *renderer;
GladeCellRendererButtonPrivate *priv;
renderer = GLADE_CELL_RENDERER_BUTTON (object);
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (renderer);
switch (prop_id)
{
case PROP_ENTRY_EDITABLE:
g_value_set_boolean (value, priv->entry_editable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_cell_renderer_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GladeCellRendererButton *renderer;
GladeCellRendererButtonPrivate *priv;
renderer = GLADE_CELL_RENDERER_BUTTON (object);
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (renderer);
switch (prop_id)
{
case PROP_ENTRY_EDITABLE:
priv->entry_editable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
glade_cell_renderer_button_clicked (GtkButton *button,
GladeCellRendererButton *self)
{
gchar *path = g_object_get_data (G_OBJECT (button), GLADE_CELL_RENDERER_BUTTON_PATH);
g_signal_emit (self, glade_cell_renderer_signals[CLICKED], 0, path);
}
static gboolean
glade_cell_renderer_button_focus_out_event (GtkWidget *entry,
GdkEvent *event,
GtkCellRendererText *cell_text)
{
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (cell_text);
g_object_set (entry,
"editing-canceled", TRUE,
NULL);
gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
/* entry needs focus-out-event */
return FALSE;
}
static gboolean
glade_cell_renderer_button_key_press_event (GtkWidget *entry,
GdkEventKey *event,
GtkCellRendererText *cell_text)
{
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (cell_text);
if (event->keyval == GDK_Tab)
{
g_signal_handlers_block_by_func (entry, glade_cell_renderer_button_focus_out_event, cell_text);
gtk_widget_grab_focus (priv->button->button);
g_signal_handlers_unblock_by_func (entry, glade_cell_renderer_button_focus_out_event, cell_text);
return TRUE;
}
return FALSE;
}
static void
glade_cell_renderer_button_activate (GtkCellEditable *entry,
GtkCellRendererText *cell_text)
{
gboolean canceled;
const gchar *path;
const gchar *new_text;
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (cell_text);
g_signal_handlers_disconnect_by_func (entry, glade_cell_renderer_button_focus_out_event, cell_text);
g_object_get (entry,
"editing-canceled", &canceled,
NULL);
gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (cell_text), canceled);
if (canceled)
return;
path = g_object_get_data (G_OBJECT (entry), GLADE_CELL_RENDERER_BUTTON_PATH);
new_text = gtk_entry_get_text (GTK_ENTRY (entry));
g_signal_emit_by_name (cell_text, "edited", path, new_text);
}
static void
glade_cell_renderer_button_editing_done (GtkCellEditable *entry,
GtkCellRendererText *cell_text)
{
gboolean canceled;
const gchar *path;
const gchar *new_text;
GladeCellRendererButtonPrivate *priv;
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (cell_text);
g_signal_handlers_disconnect_by_func (entry, glade_cell_renderer_button_focus_out_event, cell_text);
g_object_get (entry,
"editing-canceled", &canceled,
NULL);
gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (cell_text), canceled);
if (canceled)
return;
path = g_object_get_data (G_OBJECT (entry), GLADE_CELL_RENDERER_BUTTON_PATH);
new_text = gtk_entry_get_text (GTK_ENTRY (entry));
g_signal_emit_by_name (cell_text, "edited", path, new_text);
}
static GtkCellEditable *
glade_cell_renderer_button_start_editing (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GladeCellRendererButtonPrivate *priv;
GtkCellRendererText *cell_text;
GladeTextButton *text_button;
gboolean editable;
gchar *text;
gfloat xalign;
cell_text = GTK_CELL_RENDERER_TEXT (cell);
priv = GLADE_CELL_RENDERER_BUTTON_GET_PRIVATE (cell);
g_object_get (cell_text,
"editable", &editable,
"text", &text,
NULL);
if (editable == FALSE)
return NULL;
priv->button = text_button = (GladeTextButton *)glade_text_button_new ();
gtk_entry_set_text (GTK_ENTRY (text_button->entry), text ? text : "");
g_free (text);
gtk_editable_set_editable (GTK_EDITABLE (text_button->entry), priv->entry_editable);
g_object_get (cell,
"xalign", &xalign,
NULL);
g_object_set (text_button->entry,
"has-frame", FALSE,
"xalign", xalign,
NULL);
g_object_set_data_full (G_OBJECT (text_button->entry), GLADE_CELL_RENDERER_BUTTON_PATH,
g_strdup (path), g_free);
g_object_set_data_full (G_OBJECT (text_button->button), GLADE_CELL_RENDERER_BUTTON_PATH,
g_strdup (path), g_free);
g_signal_connect (G_OBJECT (text_button->button), "clicked",
G_CALLBACK (glade_cell_renderer_button_clicked),
cell);
g_signal_connect (G_OBJECT (text_button->entry), "activate",
G_CALLBACK (glade_cell_renderer_button_activate),
cell);
g_signal_connect (text_button->entry,
"editing-done",
G_CALLBACK (glade_cell_renderer_button_editing_done),
cell);
g_signal_connect (text_button->entry, "key-press-event",
G_CALLBACK (glade_cell_renderer_button_key_press_event),
cell);
g_signal_connect_after (text_button->entry, "focus-out-event",
G_CALLBACK (glade_cell_renderer_button_focus_out_event),
cell);
gtk_widget_show_all (GTK_WIDGET (text_button));
return GTK_CELL_EDITABLE (text_button);
}
/**
* glade_cell_renderer_button_new:
*
* Creates a new #GladeCellRendererButton.
*
* Returns: a new #GladeCellRendererButton
*
*/
GtkCellRenderer *
glade_cell_renderer_button_new (void)
{
return g_object_new (GLADE_TYPE_CELL_RENDERER_BUTTON, NULL);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Tristan Van Berkom <tvb@gnome.org>
*/
#ifndef _GLADE_CELL_RENDERER_BUTTON_H_
#define _GLADE_CELL_RENDERER_BUTTON_H_
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GLADE_TYPE_CELL_RENDERER_BUTTON (glade_cell_renderer_button_get_type ())
#define GLADE_CELL_RENDERER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CELL_RENDERER_BUTTON, GladeCellRendererButton))
#define GLADE_CELL_RENDERER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \
((klass), GLADE_TYPE_CELL_RENDERER_BUTTON, GladeCellRendererButtonClass))
#define GLADE_IS_CELL_RENDERER_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CELL_RENDERER_BUTTON))
#define GLADE_IS_CELL_RENDERER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CELL_RENDERER_BUTTON))
#define GLADE_CELL_RENDERER_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CELL_RENDERER_BUTTON, GladeCellRendererTextClass))
typedef struct _GladeCellRendererButton GladeCellRendererButton;
typedef struct _GladeCellRendererButtonClass GladeCellRendererButtonClass;
struct _GladeCellRendererButton
{
GtkCellRendererText parent;
};
struct _GladeCellRendererButtonClass
{
GtkCellRendererTextClass parent;
void (*clicked) (GladeCellRendererButton *, const gchar *);
};
GType glade_cell_renderer_button_get_type (void);
GtkCellRenderer *glade_cell_renderer_button_new (void);
G_END_DECLS
#endif /* _GLADE_CELL_RENDERER_BUTTON_H_ */
......@@ -30,7 +30,6 @@
#include "glade-model-data.h"
#include "glade-column-types.h"
#include "glade-cell-renderer-button.h"
GladeModelData *
glade_model_data_new (GType type, const gchar *column_name)
......@@ -666,9 +665,9 @@ value_toggled (GtkCellRendererToggle *cell,
}
static void
value_i18n_clicked (GladeCellRendererButton *cell,
const gchar *path,
GladeEditorProperty *eprop)
value_i18n_activate (GladeCellRendererIcon *cell,
const gchar *path,
GladeEditorProperty *eprop)
{
GladeEPropModelData *eprop_data = GLADE_EPROP_MODEL_DATA (eprop);
GtkTreeIter iter;
......@@ -863,10 +862,7 @@ eprop_model_generate_column (GladeEditorProperty *eprop,
type == GDK_TYPE_PIXBUF)
{
/* Text renderer */
if (type == G_TYPE_STRING)
renderer = glade_cell_renderer_button_new ();
else
renderer = gtk_cell_renderer_text_new ();
renderer = gtk_cell_renderer_text_new ();
g_object_set (G_OBJECT (renderer),
"editable", TRUE,
......@@ -874,7 +870,6 @@ eprop_model_generate_column (GladeEditorProperty *eprop,
"width", 90,
NULL);
gtk_tree_view_column_pack_start (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
"text", NUM_COLUMNS + colnum,
......@@ -892,8 +887,18 @@ eprop_model_generate_column (GladeEditorProperty *eprop,
/* Trigger i18n dialog from here */
if (type == G_TYPE_STRING)
{
g_signal_connect (G_OBJECT (renderer), "clicked",
G_CALLBACK (value_i18n_clicked), eprop);
GtkCellRenderer *icon_renderer = glade_cell_renderer_icon_new ();
g_object_set (G_OBJECT (icon_renderer),
"activatable", TRUE,
"icon-name", GTK_STOCK_EDIT,
NULL);
gtk_tree_view_column_pack_start (column, icon_renderer, FALSE);
g_object_set_data (G_OBJECT (icon_renderer), "column-number", GINT_TO_POINTER (colnum));
g_signal_connect (G_OBJECT (icon_renderer), "activate",
G_CALLBACK (value_i18n_activate), eprop);
}
}
......@@ -1261,7 +1266,7 @@ glade_eprop_model_data_create_input (GladeEditorProperty *eprop)
G_CALLBACK (eprop_treeview_key_press),
eprop);
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (eprop_data->view), GTK_TREE_VIEW_GRID_LINES_BOTH);
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (eprop_data->view), TRUE);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (eprop_data->view), TRUE);
gtk_container_add (GTK_CONTAINER (swin), GTK_WIDGET (eprop_data->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