Commit 65cc1458 authored by Tristan Van Berkom's avatar Tristan Van Berkom

2010-03-28 Tristan Van Berkom <tvb@gnome.org>

	* gladeui/Makefile.am, gladeui/glade-cell-renderer-icon.[ch]: Added activatable pixbuf renderer

	* gladeui/glade-signal-editor.c: Use new activatable pixbuf renderer to render a devhelp icon
	  and fire signal contextual devhelp searches.
parent 69012cea
2010-03-28 Tristan Van Berkom <tvb@gnome.org>
* gladeui/Makefile.am, gladeui/glade-cell-renderer-icon.[ch]: Added activatable pixbuf renderer
* gladeui/glade-signal-editor.c: Use new activatable pixbuf renderer to render a devhelp icon
and fire signal contextual devhelp searches.
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(),
......
......@@ -59,7 +59,8 @@ libgladeui_1_la_SOURCES = \
glade-name-context.c \
glade-displayable-values.c \
glade-editable.c \
glade-editor-table.c
glade-editor-table.c \
glade-cell-renderer-icon.c
libgladeui_1_la_CPPFLAGS = \
$(common_defines) \
......@@ -113,7 +114,9 @@ libgladeuiinclude_HEADERS = \
glade-name-context.h \
glade-displayable-values.h \
glade-editable.h \
glade-editor-table.h
glade-editor-table.h \
glade-cell-renderer-icon.c
if PLATFORM_WIN32
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* This library is free software; you can redistribute it and/or it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 "glade-cell-renderer-icon.h"
#include "glade-marshallers.h"
static void glade_cell_renderer_icon_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void glade_cell_renderer_icon_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static gboolean glade_cell_renderer_icon_activate (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags);
enum {
ACTIVATE,
LAST_SIGNAL
};
enum {
PROP_0,
PROP_ACTIVATABLE,
PROP_ACTIVE,
};
static guint icon_cell_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GladeCellRendererIcon, glade_cell_renderer_icon, GTK_TYPE_CELL_RENDERER_PIXBUF)
static void
glade_cell_renderer_icon_init (GladeCellRendererIcon *cellicon)
{
cellicon->activatable = TRUE;
cellicon->active = FALSE;
GTK_CELL_RENDERER (cellicon)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
}
static void
glade_cell_renderer_icon_class_init (GladeCellRendererIconClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
object_class->get_property = glade_cell_renderer_icon_get_property;
object_class->set_property = glade_cell_renderer_icon_set_property;
cell_class->activate = glade_cell_renderer_icon_activate;
g_object_class_install_property (object_class,
PROP_ACTIVE,
g_param_spec_boolean ("active", "Icon state",
"The icon state of the button",
FALSE,
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_ACTIVATABLE,
g_param_spec_boolean ("activatable", "Activatable",
"The icon button can be activated",
TRUE,
G_PARAM_READABLE | G_PARAM_WRITABLE));
icon_cell_signals[ACTIVATE] =
g_signal_new ("activate",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GladeCellRendererIconClass, activate),
NULL, NULL,
glade_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
}
static void
glade_cell_renderer_icon_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GladeCellRendererIcon *cellicon = GLADE_CELL_RENDERER_ICON (object);
switch (param_id)
{
case PROP_ACTIVE:
g_value_set_boolean (value, cellicon->active);
break;
case PROP_ACTIVATABLE:
g_value_set_boolean (value, cellicon->activatable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
glade_cell_renderer_icon_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GladeCellRendererIcon *cellicon = GLADE_CELL_RENDERER_ICON (object);
switch (param_id)
{
case PROP_ACTIVE:
cellicon->active = g_value_get_boolean (value);
break;
case PROP_ACTIVATABLE:
cellicon->activatable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
GtkCellRenderer *
glade_cell_renderer_icon_new (void)
{
return g_object_new (GLADE_TYPE_CELL_RENDERER_ICON, NULL);
}
static gint
glade_cell_renderer_icon_activate (GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
GladeCellRendererIcon *cellicon;
cellicon = GLADE_CELL_RENDERER_ICON (cell);
if (cellicon->activatable)
{
g_signal_emit (cell, icon_cell_signals[ACTIVATE], 0, path);
return TRUE;
}
return FALSE;
}
gboolean
glade_cell_renderer_icon_get_active (GladeCellRendererIcon *icon)
{
g_return_val_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon), FALSE);
return icon->active;
}
void
glade_cell_renderer_icon_set_active (GladeCellRendererIcon *icon,
gboolean setting)
{
g_return_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon));
g_object_set (icon, "active", setting ? TRUE : FALSE, NULL);
}
gboolean
glade_cell_renderer_icon_get_activatable (GladeCellRendererIcon *icon)
{
g_return_val_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon), FALSE);
return icon->activatable;
}
void
glade_cell_renderer_icon_set_activatable (GladeCellRendererIcon *icon,
gboolean setting)
{
g_return_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon));
if (icon->activatable != setting)
{
icon->activatable = setting ? TRUE : FALSE;
g_object_notify (G_OBJECT (icon), "activatable");
}
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2010 Tristan Van Berkom.
*
* This library is free software; you can redistribute it and/or it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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_ICON_H__
#define __GLADE_CELL_RENDERER_ICON_H__
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GLADE_TYPE_CELL_RENDERER_ICON (glade_cell_renderer_icon_get_type ())
#define GLADE_CELL_RENDERER_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CELL_RENDERER_ICON, GladeCellRendererIcon))
#define GLADE_CELL_RENDERER_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_CELL_RENDERER_ICON, GladeCellRendererIconClass))
#define GLADE_IS_CELL_RENDERER_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CELL_RENDERER_ICON))
#define GLADE_IS_CELL_RENDERER_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CELL_RENDERER_ICON))
#define GLADE_CELL_RENDERER_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CELL_RENDERER_ICON, GladeCellRendererIconClass))
typedef struct _GladeCellRendererIcon GladeCellRendererIcon;
typedef struct _GladeCellRendererIconClass GladeCellRendererIconClass;
struct _GladeCellRendererIcon
{
GtkCellRendererPixbuf parent;
guint active : 1;
guint activatable : 1;
};
struct _GladeCellRendererIconClass
{
GtkCellRendererPixbufClass parent_class;
void (* activate) (GladeCellRendererIcon *cell_renderer_icon,
const gchar *path);
};
GType glade_cell_renderer_icon_get_type (void) G_GNUC_CONST;
GtkCellRenderer *glade_cell_renderer_icon_new (void);
gboolean glade_cell_renderer_icon_get_active (GladeCellRendererIcon *icon);
void glade_cell_renderer_icon_set_active (GladeCellRendererIcon *icon,
gboolean setting);
gboolean glade_cell_renderer_icon_get_activatable (GladeCellRendererIcon *icon);
void glade_cell_renderer_icon_set_activatable (GladeCellRendererIcon *icon,
gboolean setting);
G_END_DECLS
#endif /* __GLADE_CELL_RENDERER_ICON_H__ */
......@@ -2,6 +2,7 @@ VOID:POINTER,POINTER
VOID:POINTER
VOID:STRING,ULONG,UINT,STRING
VOID:OBJECT
VOID:STRING
VOID:OBJECT,OBJECT
VOID:OBJECT,BOOLEAN
VOID:STRING,STRING,STRING
......
......@@ -42,6 +42,7 @@
#include "glade-widget-adaptor.h"
#include "glade-signal.h"
#include "glade-signal-editor.h"
#include "glade-cell-renderer-icon.h"
#include "glade-editor.h"
#include "glade-command.h"
#include "glade-marshallers.h"
......@@ -177,6 +178,7 @@ append_slot (GtkTreeModel *model, GtkTreeIter *iter_signal)
GSE_COLUMN_AFTER_VISIBLE, FALSE,
GSE_COLUMN_SLOT, TRUE,
GSE_COLUMN_USERDATA_SLOT, TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
gtk_tree_model_iter_parent (model, &iter_class, iter_signal);
......@@ -198,9 +200,9 @@ move_row (GtkTreeModel *model, GtkTreeIter *from, GtkTreeIter *to)
gboolean userdata_editable;
gboolean swapped;
gboolean swapped_visible;
gboolean bold;
gboolean bold, content;
gtk_tree_model_get (model, from,
gtk_tree_model_get (model, from,
GSE_COLUMN_HANDLER, &handler,
GSE_COLUMN_USERDATA, &userdata,
GSE_COLUMN_AFTER, &after,
......@@ -212,9 +214,10 @@ move_row (GtkTreeModel *model, GtkTreeIter *from, GtkTreeIter *to)
GSE_COLUMN_SWAPPED, &swapped,
GSE_COLUMN_SWAPPED_VISIBLE, &swapped_visible,
GSE_COLUMN_BOLD, &bold,
GSE_COLUMN_CONTENT, &content,
-1);
gtk_tree_store_set (GTK_TREE_STORE (model), to,
gtk_tree_store_set (GTK_TREE_STORE (model), to,
GSE_COLUMN_HANDLER, handler,
GSE_COLUMN_USERDATA, userdata,
GSE_COLUMN_AFTER, after,
......@@ -225,7 +228,8 @@ move_row (GtkTreeModel *model, GtkTreeIter *from, GtkTreeIter *to)
GSE_COLUMN_USERDATA_SLOT, userdata_slot,
GSE_COLUMN_SWAPPED, swapped,
GSE_COLUMN_SWAPPED_VISIBLE, swapped_visible,
GSE_COLUMN_BOLD, &bold,
GSE_COLUMN_BOLD, bold,
GSE_COLUMN_CONTENT, content,
-1);
g_free (handler);
g_free (userdata);
......@@ -341,6 +345,7 @@ glade_signal_editor_handler_editing_done_impl (GladeSignalEditor *self,
GSE_COLUMN_AFTER_VISIBLE, FALSE,
GSE_COLUMN_SLOT, TRUE,
GSE_COLUMN_USERDATA_SLOT, TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
remove_slot (model, is_top_handler ? NULL : iter, &iter_signal);
......@@ -621,6 +626,38 @@ glade_signal_editor_userdata_cell_data_func (GtkTreeViewColumn *tree_column,
"foreground", NULL, NULL);
}
static void
glade_signal_editor_devhelp_cb (GtkCellRenderer *cell,
const gchar *path_str,
GladeSignalEditor *editor)
{
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
GtkTreeModel *model = GTK_TREE_MODEL (editor->model);
GtkTreeIter iter;
GladeSignalClass *signal_class;
gchar *signal, *search, *book = NULL;
g_return_if_fail (gtk_tree_model_get_iter (model, &iter, path));
gtk_tree_path_free (path);
signal = glade_signal_editor_get_signal_name (model, &iter);
search = g_strdup_printf ("The %s signal", signal);
signal_class = glade_widget_adaptor_get_signal_class (editor->widget->adaptor,
signal);
g_assert (signal_class);
g_object_get (signal_class->adaptor, "book", &book, NULL);
glade_editor_search_doc_search (glade_app_get_editor (),
book, signal_class->adaptor->name, search);
g_free (search);
g_free (book);
g_free (signal);
}
void
glade_signal_editor_construct_signals_list (GladeSignalEditor *editor)
{
......@@ -643,7 +680,8 @@ glade_signal_editor_construct_signals_list (GladeSignalEditor *editor)
G_TYPE_BOOLEAN, /* Handler editable */
G_TYPE_BOOLEAN, /* Userdata editable */
G_TYPE_BOOLEAN, /* New slot */
G_TYPE_BOOLEAN); /* Mark with bold */
G_TYPE_BOOLEAN, /* Mark with bold */
G_TYPE_BOOLEAN); /* Not a class title slot */
model = GTK_TREE_MODEL (editor->model);
......@@ -738,20 +776,54 @@ glade_signal_editor_construct_signals_list (GladeSignalEditor *editor)
column = gtk_tree_view_column_new_with_attributes
(_("Swapped"), renderer,
"active", GSE_COLUMN_SWAPPED,
"visible", GSE_COLUMN_SWAPPED_VISIBLE, NULL);
"sensitive", GSE_COLUMN_SWAPPED_VISIBLE,
"activatable", GSE_COLUMN_SWAPPED_VISIBLE,
"visible", GSE_COLUMN_CONTENT,
NULL);
gtk_tree_view_append_column (view, column);
/************************ after column ************************/
renderer = gtk_cell_renderer_toggle_new ();
g_object_set (G_OBJECT (renderer),
"width", 20,
NULL);
g_signal_connect (renderer, "toggled",
G_CALLBACK (glade_signal_editor_after_swapped_toggled), editor);
column = gtk_tree_view_column_new_with_attributes
(_("After"), renderer,
"active", GSE_COLUMN_AFTER,
"visible", GSE_COLUMN_AFTER_VISIBLE, NULL);
gtk_tree_view_append_column (view, column);
"sensitive", GSE_COLUMN_AFTER_VISIBLE,
"activatable", GSE_COLUMN_AFTER_VISIBLE,
"visible", GSE_COLUMN_CONTENT,
NULL);
/* Append the devhelp icon if we have it */
if (glade_util_have_devhelp ())
{
renderer = glade_cell_renderer_icon_new ();
g_object_set (G_OBJECT (renderer),
"activatable", TRUE,
NULL);
if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), GLADE_DEVHELP_ICON_NAME))
g_object_set (G_OBJECT (renderer), "icon-name", GLADE_DEVHELP_ICON_NAME, NULL);
else
g_object_set (G_OBJECT (renderer), "icon-name", GTK_STOCK_INFO, NULL);
g_signal_connect (G_OBJECT (renderer), "activate",
G_CALLBACK (glade_signal_editor_devhelp_cb), editor);
gtk_tree_view_column_pack_end (column, renderer, FALSE);
gtk_tree_view_column_set_attributes (column, renderer,
"visible", GSE_COLUMN_CONTENT, NULL);
}
gtk_tree_view_append_column (view, column);
g_object_set_data (G_OBJECT (renderer), "signal-after-cell",
GINT_TO_POINTER (TRUE));
......@@ -875,7 +947,9 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
GSE_COLUMN_HANDLER_EDITABLE, FALSE,
GSE_COLUMN_USERDATA_EDITABLE,FALSE,
GSE_COLUMN_SLOT, FALSE,
GSE_COLUMN_BOLD, FALSE, -1);
GSE_COLUMN_BOLD, FALSE,
GSE_COLUMN_CONTENT, FALSE,
-1);
last_type = signal->type;
}
......@@ -897,6 +971,7 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
GSE_COLUMN_AFTER_VISIBLE, FALSE,
GSE_COLUMN_SLOT, TRUE,
GSE_COLUMN_USERDATA_SLOT, TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
}
else
......@@ -933,7 +1008,9 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
GSE_COLUMN_SLOT, FALSE,
GSE_COLUMN_USERDATA_SLOT,
widget_signal->userdata ? FALSE : TRUE,
GSE_COLUMN_BOLD, TRUE, -1);
GSE_COLUMN_BOLD, TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
for (i = 1; i < signals->len; i++)
{
......@@ -956,6 +1033,7 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
GSE_COLUMN_SLOT, FALSE,
GSE_COLUMN_USERDATA_SLOT,
widget_signal->userdata ? FALSE : TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
}
......@@ -972,7 +1050,9 @@ glade_signal_editor_load_widget (GladeSignalEditor *editor,
GSE_COLUMN_USERDATA_EDITABLE,FALSE,
GSE_COLUMN_AFTER_VISIBLE, FALSE,
GSE_COLUMN_SLOT, TRUE,
GSE_COLUMN_USERDATA_SLOT, TRUE, -1);
GSE_COLUMN_USERDATA_SLOT, TRUE,
GSE_COLUMN_CONTENT, TRUE,
-1);
}
}
......
......@@ -33,6 +33,7 @@ enum
GSE_COLUMN_USERDATA_EDITABLE,
GSE_COLUMN_SLOT, /* if this row contains a "<Type...>" label */
GSE_COLUMN_BOLD,
GSE_COLUMN_CONTENT,
GSE_NUM_COLUMNS
};
......
......@@ -58,8 +58,6 @@
#define GLADE_UTIL_SELECTION_NODE_SIZE 7
#define GLADE_UTIL_COPY_BUFFSIZE 1024
#define GLADE_DEVHELP_ICON_NAME "devhelp"
#define GLADE_DEVHELP_FALLBACK_ICON_FILE "devhelp.png"
/* List of widgets that have selection
*/
......
......@@ -6,6 +6,9 @@
G_BEGIN_DECLS
#define GLADE_DEVHELP_ICON_NAME "devhelp"
#define GLADE_DEVHELP_FALLBACK_ICON_FILE "devhelp.png"
typedef enum _GladeUtilFileDialogType
{
GLADE_FILE_DIALOG_ACTION_OPEN,
......
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