experimental bonobo-conf patches



Hi all,

Here are some experimental patches that add support for bonobo-conf to
the scintilla widget in gdl and to gide.

It has 1 property: a boolean line-numbers property. gIDE queries the
scintilla widget for a Bonobo/PropertyControl and uses that interface to
create a preferences dialog. The PropertyControl is implemented in the
scintilla widget. The scintilla widget is responsible for the actual
GUI.

There are some shortcomings:
- Dialog uses instant-apply. Haven't seen a way to change that behavior.
- The dialog is currently created by bonobo-conf. We want to create our
own at some point (have more than just the Scintilla tab in there).
Bonobo-conf currently works with 1 PropertyControl -> 1 dialog.
- scintilla widget doesn't load the properties on startup, initially, it
always displays the line-numbers margin.

But for now, i'm pretty happy that it actually works :)

Jeroen
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gIDE/configure.in,v
retrieving revision 1.46
diff -u -r1.46 configure.in
--- configure.in	2001/07/22 18:09:24	1.46
+++ configure.in	2001/07/24 18:50:32
@@ -53,6 +53,7 @@
 GDL_CHECK_LIB(gnome-libs, gnome, 1.2.9)
 GDL_CHECK_LIB(bonobo, bonobo, 1.0.7)
 GDL_CHECK_LIB(bonobox, bonobox, 1.0.7)
+GDL_CHECK_LIB(bonobo-conf, bonobo_conf, 0.6)
 GDL_CHECK_LIB(oaf, oaf, 0.6.5)
 GDL_CHECK_LIB(libglade, libglade)
 GDL_CHECK_LIB(glade, gal, 0.8.0)
@@ -62,8 +63,8 @@
 GDL_CHECK_LIB(gnome-debug, gdf, 0.1.6)
 
 dnl Extra stuff
-EXTRA_GNOME_LIBS=`gnome-config --libs bonobox libglade print gdf gnome_build gal gdl vfs`
-EXTRA_GNOME_CFLAGS=`gnome-config --cflags bonobox libglade print gdf gnome_build gal gdl vfs`
+EXTRA_GNOME_LIBS=`gnome-config --libs bonobox bonobo_conf libglade print gdf gnome_build gal gdl vfs`
+EXTRA_GNOME_CFLAGS=`gnome-config --cflags bonobox bonobo_conf libglade print gdf gnome_build gal gdl vfs`
 
 IDL_CFLAGS=`gnome-config --cflags idl`
 AC_SUBST(IDL_CFLAGS)
Index: src/gI_window.c
===================================================================
RCS file: /cvs/gnome/gIDE/src/gI_window.c,v
retrieving revision 1.37
diff -u -r1.37 gI_window.c
--- src/gI_window.c	2001/07/20 04:23:21	1.37
+++ src/gI_window.c	2001/07/24 18:50:38
@@ -21,10 +21,12 @@
 #include <liboaf/liboaf.h>
 #include <bonobo/bonobo-ui-util.h>
 #include <bonobo/bonobo-listener.h>
+#include <bonobo-conf/bonobo-preferences.h>
 #include <gal/e-paned/e-paned.h>
 #include <gal/e-paned/e-vpaned.h>
 #include <gal/e-paned/e-hpaned.h>
 #include "gI_window.h"
+#include "shell.h"
 
 #include <libgide/libgide.h>
 
@@ -69,13 +71,54 @@
 		gdk_window_raise (GTK_WIDGET (about)->window);
 }
 
+static void
+settings_cmd (GtkWidget *w, GideWindow *window)
+{
+	GNOME_Development_Environment_Document doc;
+	char *moniker;
+	Bonobo_Control control;
+	CORBA_Environment ev;
+	Bonobo_PropertyControl pc;
+	GtkWidget *prefs;
+	GideShell *shell;
+	
+	CORBA_exception_init (&ev);
+
+	/* Get GideShell instance for this window */
+	shell = GIDE_SHELL (gtk_object_get_data (GTK_OBJECT (window), "GideShell"));
+	
+	/* Create moniker for current document */
+	moniker = g_strdup_printf ("gide:%s!CurrentDocument", shell->id);
+
+	/* Get Document instance */	
+	doc = bonobo_get_object (moniker, "IDL:GNOME/Development/Environment/Document:1.0", &ev);
+	g_assert (!BONOBO_EX (&ev));
+
+	g_free (moniker);
+
+	/* Get editor control */	
+	control = GNOME_Development_Environment_Document_getEditor (doc, &ev);	
+	g_assert (!BONOBO_EX (&ev));
+	
+	bonobo_object_release_unref (doc, &ev);
+	g_assert (!BONOBO_EX (&ev));
+	
+	/* Query PropertyControl interface */
+	pc = Bonobo_Unknown_queryInterface (control, "IDL:Bonobo/PropertyControl:1.0", &ev);
+	g_assert (!BONOBO_EX (&ev));
+	
+	/* Create preferences widget & show */
+	prefs = bonobo_preferences_new (pc);	
+	gtk_widget_show_all (prefs);
+}
+
 /* Menu verbs */
 static BonoboUIVerb verbs [] = {
 	BONOBO_UI_UNSAFE_VERB ("FileExit", tmp_exit),
 #if 0
 	BONOBO_UI_UNSAFE_VERB ("ToolsPlugins", dialog_plugin_manager),
-	BONOBO_UI_UNSAFE_VERB ("SettingsSettings", dialog_prefs_cb),
 #endif
+	BONOBO_UI_UNSAFE_VERB ("SettingsSettings", settings_cmd),
 	BONOBO_UI_UNSAFE_VERB ("HelpAbout", about_cmd),
 	
 	BONOBO_UI_VERB_END
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gdl/configure.in,v
retrieving revision 1.7
diff -u -r1.7 configure.in
--- configure.in	2001/07/09 10:21:38	1.7
+++ configure.in	2001/07/24 19:49:43
@@ -107,8 +107,9 @@
 dnl ***************
 
 CHECK_LIB(gnome-libs, gnome, 1.2.9)
-CHECK_LIB(Bonobo, bonobo, 1.0.7)
-CHECK_LIB(Bonobo X, bonobox, 1.0.7)
+CHECK_LIB(bonobo, bonobo, 1.0.7)
+CHECK_LIB(bonobox, bonobox, 1.0.7)
+CHECK_LIB(bonobo-conf, bonobo_conf, 0.6)
 CHECK_LIB(OAF, oaf, 0.6.5)
 CHECK_LIB(GNOME-VFS, vfs, 1.0)
 
@@ -118,6 +119,8 @@
 AC_SUBST(BONOBO_LIBS)
 AC_SUBST(BONOBOX_CFLAGS)
 AC_SUBST(BONOBOX_LIBS)
+AC_SUBST(BONOBO_CONF_CFLAGS)
+AC_SUBST(BONOBO_CONF_LIBS)
 AC_SUBST(OAF_CFLAGS)
 AC_SUBST(VFS_CFLAGS)
 AC_SUBST(VFS_LIBS)
Index: scintilla-control/Makefile.am
===================================================================
RCS file: /cvs/gnome/gdl/scintilla-control/Makefile.am,v
retrieving revision 1.5
diff -u -r1.5 Makefile.am
--- scintilla-control/Makefile.am	2001/07/20 04:35:16	1.5
+++ scintilla-control/Makefile.am	2001/07/24 19:49:44
@@ -7,6 +7,7 @@
 	$(GNOME_CFLAGS) \
 	$(BONOBO_CFLAGS) \
 	$(BONOBOX_CFLAGS) \
+	$(BONOBO_CONF_CFLAGS) \
 	$(VFS_CFLAGS) \
 	$(OAF_CFLAGS)
 
@@ -33,7 +34,9 @@
 	scintilla-editor-gutter.c \
 	scintilla-editor-gutter.h \
 	scintilla-find.c \
-	scintilla-find.h
+	scintilla-find.h \
+	scintilla-property-control.c \
+	scintilla-property-control.h
 
 LEXER_OBJS = \
 	scintilla/LexCPP.o     \
@@ -45,14 +48,15 @@
 	scintilla/LexOthers.o  \
 	scintilla/LexVB.o
 
-scintilla_control_LDADD = \
-	$(GNOME_LIBS)     \
-	$(GNOMEUI_LIBS)   \
-	$(BONOBO_LIBS)    \
-	$(BONOBOX_LIBS)   \
-	$(VFS_LIBS)       \
-	$(LEXER_OBJS)     \
-	../gdl/libgdl.la  \
+scintilla_control_LDADD =   \
+	$(GNOME_LIBS)       \
+	$(GNOMEUI_LIBS)     \
+	$(BONOBO_LIBS)      \
+	$(BONOBOX_LIBS)     \
+	$(BONOBO_CONF_LIBS) \
+	$(VFS_LIBS)         \
+	$(LEXER_OBJS)       \
+	../gdl/libgdl.la    \
         scintilla/libscintilla-widget.a 
 
 test_scintilla_LDADD =  \
Index: scintilla-control/scintilla-control.c
===================================================================
RCS file: /cvs/gnome/gdl/scintilla-control/scintilla-control.c,v
retrieving revision 1.13
diff -u -r1.13 scintilla-control.c
--- scintilla-control/scintilla-control.c	2001/07/20 04:35:16	1.13
+++ scintilla-control/scintilla-control.c	2001/07/24 19:49:46
@@ -26,6 +26,8 @@
 #include <gtk/gtk.h>
 #include <liboaf/liboaf.h>
 #include <limits.h>
+#include <bonobo-conf/bonobo-config-database.h>
+#include <bonobo-conf/bonobo-config-control.h>
 
 #include "scintilla/Scintilla.h"
 #include "scintilla/ScintillaWidget.h"
@@ -35,6 +37,7 @@
 #include "scintilla-editor-buffer.h"
 #include "scintilla-editor-gutter.h"
 #include "scintilla-find.h"
+#include "scintilla-property-control.h"
 
 #include <gdl/gdl-server-manager.h>
 
@@ -91,9 +94,10 @@
     BonoboPropertyBag *pb;
     BonoboPersistFile *file_impl;
     BonoboPersistStream *stream_impl;
+    BonoboPropertyControl *pc_impl;
     ScintillaEditorBuffer *buffer_impl;
     ScintillaEditorGutter *gutter_impl;
-    
+
     sci = scintilla_new ();
 
     gtk_widget_show_all (GTK_WIDGET (sci));
@@ -143,6 +147,10 @@
     bonobo_object_add_interface (BONOBO_OBJECT (control),
                                  BONOBO_OBJECT (gutter_impl));
     
+    pc_impl = scintilla_property_control_new (SCINTILLA (sci));
+    bonobo_object_add_interface (BONOBO_OBJECT (control),
+    				 BONOBO_OBJECT (pc_impl));
+    				 
     gtk_signal_connect (GTK_OBJECT (sci), "notify",
                         GTK_SIGNAL_FUNC (notify_cb), NULL);
 
/* This file is part of the GNOME Devtool Libraries.
 * 
 * Copyright (C) 2000 Dave Camp <dave helixcode com>
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.  
 */

#include <config.h>
#include <gtk/gtk.h>
#include <gnome.h>
#include <bonobo.h>
#include <bonobo-conf/bonobo-config-control.h>
#include <bonobo-conf/bonobo-property-editor.h>

#include "scintilla/Scintilla.h"
#include "scintilla/ScintillaWidget.h"
#include "scintilla-property-control.h"

static void 
get_title (BonoboPropertyBag *bag,
	   BonoboArg *arg,
	   guint arg_id,
           CORBA_Environment *ev,
	   gpointer user_data)
{
	if (arg_id == 0 && arg->_type == BONOBO_ARG_STRING)
 		BONOBO_ARG_SET_STRING (arg, (char *)user_data);
}

static void 
property_change_cb (BonoboListener    *listener,
		    char              *event_name, 
		    CORBA_any         *any,
		    CORBA_Environment *ev,
		    gpointer           user_data)
{	
	gchar *type;
	PropertyData *data;
	GtkWidget *sci;
	CORBA_Environment ev;
	Bonobo_PropertyBag bag;
	Bonobo_Property prop;
	BonoboArg *arg;
	
	CORBA_exception_init (&ev);
	
	type = bonobo_event_subtype (event_name);
	data = (PropertyData *) user_data;
	sci = data->sci;
	bag = data->bag;
	
	if (!strcmp (type, "line-numbers")) {
		prop = Bonobo_PropertyBag_getPropertyByName (bag, "line-numbers", &ev);
		g_assert (!BONOBO_EX (&ev));
		
		arg = Bonobo_Property_getValue (prop, &ev);
		g_assert (!BONOBO_EX (&ev));
		
		if ( BONOBO_ARG_GET_BOOLEAN (arg)) {
			printf ("line-numbers = true\n");
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINWIDTHN, 1, 30);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINTYPEN, 1, SC_MARGIN_NUMBER);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINMASKN, 1, 0);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINSENSITIVEN, 1, 0);			
    
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINWIDTHN, 2, 25);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINTYPEN, 2, SC_MARGIN_SYMBOL);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINMASKN, 2, SC_MASK_FOLDERS);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINSENSITIVEN, 2, 1);
		} else {
			printf ("line-numbers = false\n");
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINWIDTHN, 1, 25);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINTYPEN, 1, SC_MARGIN_SYMBOL);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINMASKN, 1, SC_MASK_FOLDERS);
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINSENSITIVEN, 1, 1);
			
			scintilla_send_message (SCINTILLA (sci), SCI_SETMARGINWIDTHN, 2, 0);
		}
	}
}

BonoboControl *
get_impl (BonoboPropertyControl *control,
	  int page_number,
	  void *closure)
{
	GtkWidget *w, *box;
	CORBA_Environment ev;
	Bonobo_PropertyBag bag;
	BonoboControl *ctrl;
	PropertyData *data;
	static const gchar *name = "Scintilla";
	
	CORBA_exception_init (&ev);

	/* Get a reference to the property bag */
	bag = bonobo_get_object ("config:/scintilla", "Bonobo/PropertyBag", &ev);
	g_assert (!BONOBO_EX (&ev));
	
	/* Create vertical box */
	box = gtk_vbox_new (FALSE, 5);
	gtk_container_set_border_width (GTK_CONTAINER (box), 5);
	
	/* Create boolean property editor */
	w = bonobo_property_editor_boolean_new (_("Show line numbers"));
	bonobo_property_editor_set_property (BONOBO_PROPERTY_EDITOR (w), 
					     bag, "line-numbers", TC_boolean, 
					     NULL);
	gtk_container_add (GTK_CONTAINER (box), w);
	
	gtk_widget_show_all (box);
	
	/* Add a listener */
	data = g_new (PropertyData, 1);
	data->sci = GTK_WIDGET (closure);
	data->bag = bag;
	
	bonobo_event_source_client_add_listener (bag, property_change_cb,
						 NULL, &ev, data);
					     
	/* Create new BonoboControl */
	ctrl =  bonobo_control_new (box);
	g_assert (ctrl != NULL);
	
	/* Set title property */
	bag = bonobo_property_bag_new (get_title, NULL, name);
	
	bonobo_property_bag_add (bag, "bonobo:title", 0, 
				 BONOBO_ARG_STRING, NULL, NULL, 
				 BONOBO_PROPERTY_READABLE);

	bonobo_object_add_interface (BONOBO_OBJECT (ctrl),
				     BONOBO_OBJECT (bag));	
	
	return ctrl;
}

BonoboPropertyControl *
scintilla_property_control_new (GtkWidget *sci)
{
	g_return_val_if_fail (IS_SCINTILLA (sci), NULL);
	printf ("creating property control\n");
	return bonobo_property_control_new (get_impl, 1, sci);
}
/* This file is part of the GNOME Devtool Libraries.
 * 
 * Copyright (C) 2000 Dave Camp <dave helixcode com>
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.  
 */

#ifndef __SCINTILLA_PROPERTY_CONFIG_FILE__
#define __SCINTILLA_PROPERTY_CONFIG_FILE__

BonoboPropertyControl *scintilla_property_control_new (GtkWidget *sci);

typedef struct 
{
	GtkWidget *sci;
	Bonobo_PropertyBag *bag;
} PropertyData;

#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]