[Glade-devel] [patch, glade3] decouple glade-palette from glade-project-window
- From: pborelli katamail com (paolo borelli)
- Subject: [Glade-devel] [patch, glade3] decouple glade-palette from glade-project-window
- Date: 16 May 2003 18:31:32 +0200
--=-dkps2lvsJVY995nt4XNc
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hi!
The attached patch decouples completely glade-palette from
glade-project-window, to the point that glade-project.c does not need to
include glade-project-window.h anymore. This way an external app can
create/use a GladePalette without having a gpw.
The patch consist of the following:
- when a button on the palette is clicked, instead of directly change
the current project (gpw->project), the palette emit a signal
"widget_class_chosen" (I know the name sucks ;), suggestions?)
- when the palette is created in glade-project-window.c it's connected
to a signal handler for "widget_class_chosen" which updates the project.
ciao
paolo
--=-dkps2lvsJVY995nt4XNc
Content-Disposition: attachment; filename=palette-gpw.patch
Content-Type: text/x-patch; name=palette-gpw.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit
diff -upr gnome2/glade3/ChangeLog glade3/ChangeLog
--- gnome2/glade3/ChangeLog 2003-05-15 09:32:17.000000000 +0200
+++ glade3/ChangeLog 2003-05-16 16:51:56.000000000 +0200
@@ -1,3 +1,10 @@
+2003-05-16 Paolo Borelli <pborelli katamail com>
+
+ * src/palette.[ch]: make the palette emit a signal when the user
+ choose a widget class instead of directly messing with the current
+ project.
+ * src/glade-project-window.c: connect a handler to the above signal.
+
2003-05-14 Joaquin Cuenca Abela <e98cuenc yahoo com>
* src/glade-project-window.[ch]: Make the undo/redo toolbar items
diff -upr gnome2/glade3/src/glade-palette.c glade3/src/glade-palette.c
--- gnome2/glade3/src/glade-palette.c 2003-05-05 14:11:36.000000000 +0200
+++ glade3/src/glade-palette.c 2003-05-16 16:41:31.000000000 +0200
@@ -36,16 +36,19 @@
#include "glade-project.h"
#include "glade-widget.h"
#include "glade-widget-class.h"
-#include "glade-project-window.h"
+
static void glade_palette_class_init (GladePaletteClass *class);
static void glade_palette_init (GladePalette *glade_palette);
enum
{
+ WIDGET_CLASS_CHOSEN,
LAST_SIGNAL
};
+static guint glade_palette_signals[LAST_SIGNAL] = {0};
+
static GtkWindowClass *parent_class = NULL;
GType
@@ -80,6 +83,17 @@ glade_palette_class_init (GladePaletteCl
object_class = G_OBJECT_CLASS (class);
parent_class = g_type_class_peek_parent (class);
+
+ glade_palette_signals[WIDGET_CLASS_CHOSEN] =
+ g_signal_new ("widget_class_chosen",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GladePaletteClass, widget_class_chosen),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
}
static GtkWidget *
@@ -136,33 +150,19 @@ glade_palette_widget_create_icon_from_cl
static void
glade_palette_button_clicked (GtkWidget *button, GladePalette *palette)
{
- GladeProjectWindow *gpw;
GladeWidgetClass *class;
- GladeProject *project;
- static gboolean dont_recurse = FALSE;
- if (dont_recurse)
+ if (!GTK_TOGGLE_BUTTON (button)->active)
return;
- if (!GTK_TOGGLE_BUTTON (button)->active)
+ if (button == palette->dummy_button)
return;
class = g_object_get_data (G_OBJECT (button), "user");
g_return_if_fail (class != NULL);
- gpw = glade_project_window_get ();
-
- if (GLADE_WIDGET_CLASS_TOPLEVEL (class)) {
- project = gpw->project;
- g_return_if_fail (project != NULL);
- glade_widget_new_toplevel (project, class);
- dont_recurse = TRUE;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (palette->dummy_button), TRUE);
- dont_recurse = FALSE;
- glade_project_window_set_add_class (gpw, NULL);
- } else {
- glade_project_window_set_add_class (gpw, class);
- }
+ g_signal_emit (G_OBJECT (palette),
+ glade_palette_signals[WIDGET_CLASS_CHOSEN], 0, class);
}
static gboolean
diff -upr gnome2/glade3/src/glade-palette.h glade3/src/glade-palette.h
--- gnome2/glade3/src/glade-palette.h 2003-05-05 14:11:36.000000000 +0200
+++ glade3/src/glade-palette.h 2003-05-16 16:47:03.000000000 +0200
@@ -73,6 +73,7 @@ struct _GladePaletteClass
{
GtkVBoxClass parent_class;
+ void (*widget_class_chosen) (GladePalette *palette, GladeWidgetClass *class);
};
GladePalette *glade_palette_new (GList *catalogs);
diff -upr gnome2/glade3/src/glade-project-window.c glade3/src/glade-project-window.c
--- gnome2/glade3/src/glade-project-window.c 2003-05-15 09:32:23.000000000 +0200
+++ glade3/src/glade-project-window.c 2003-05-16 16:32:46.000000000 +0200
@@ -385,6 +385,24 @@ gpw_hide_palette_on_delete (GtkWidget *p
}
static void
+gpw_palette_button_clicked (GladePalette *palette, GladeWidgetClass *class)
+{
+ GladeProjectWindow *gpw;
+ GladeProject *project;
+
+ gpw = glade_project_window_get ();
+
+ if (GLADE_WIDGET_CLASS_TOPLEVEL (class)) {
+ project = gpw->project;
+ g_return_if_fail (project != NULL);
+ glade_widget_new_toplevel (project, class);
+ glade_project_window_set_add_class (gpw, NULL);
+ } else {
+ glade_project_window_set_add_class (gpw, class);
+ }
+}
+
+static void
gpw_create_palette (GladeProjectWindow *gpw)
{
GtkWidget *palette_item;
@@ -404,6 +422,9 @@ gpw_create_palette (GladeProjectWindow *
g_signal_connect (G_OBJECT (gpw->palette_window), "delete_event",
G_CALLBACK (gpw_hide_palette_on_delete), gpw->item_factory);
+ g_signal_connect (G_OBJECT (gpw->palette), "widget_class_chosen",
+ G_CALLBACK (gpw_palette_button_clicked), NULL);
+
palette_item = gtk_item_factory_get_item (gpw->item_factory,
"<main>/View/Palette");
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (palette_item), TRUE);
--=-dkps2lvsJVY995nt4XNc--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]