Commit 6a2694df authored by Johannes Schmid's avatar Johannes Schmid Committed by Johannes Schmid

Added methods to add pages from gtkbuilder instead of glade

2009-04-07  Johannes Schmid  <jhs@gnome.org>

	* libanjuta/anjuta-preferences.c
	(anjuta_preferences_register_all_properties_from_builder_xml),
	(anjuta_preferences_add_from_builder):
	* libanjuta/anjuta-preferences.h:
	Added methods to add pages from gtkbuilder instead of glade
	
	* plugins/sourceview/Makefile.am:
	* plugins/sourceview/anjuta-editor-sourceview.glade:
	* plugins/sourceview/anjuta-editor-sourceview.ui:
	* plugins/sourceview/plugin.c (on_font_check_toggled),
	(ipreferences_merge), (ipreferences_unmerge):
	* plugins/sourceview/sourceview.c (sourceview_new):
	Replace libglade with gtkbuilder

	* scripts/build-schemas.mk:
	* scripts/builder2schema.pl:
	* scripts/Makefile.am
	Add a new script to generate schemas from gtkbuilder instead of glade
	files and adjusted Makefile.

svn path=/trunk/; revision=4929
parent 3be465b9
2009-04-07 Johannes Schmid <jhs@gnome.org>
* libanjuta/anjuta-preferences.c
(anjuta_preferences_register_all_properties_from_builder_xml),
(anjuta_preferences_add_from_builder):
* libanjuta/anjuta-preferences.h:
Added methods to add pages from gtkbuilder instead of glade
* plugins/sourceview/Makefile.am:
* plugins/sourceview/anjuta-editor-sourceview.glade:
* plugins/sourceview/anjuta-editor-sourceview.ui:
* plugins/sourceview/plugin.c (on_font_check_toggled),
(ipreferences_merge), (ipreferences_unmerge):
* plugins/sourceview/sourceview.c (sourceview_new):
Replace libglade with gtkbuilder
* scripts/build-schemas.mk:
* scripts/builder2schema.pl:
* scripts/Makefile.am
Add a new script to generate schemas from gtkbuilder instead of glade
files and adjusted Makefile.
2009-04-06 Johannes Schmid <jhs@gnome.org>
Based on patch from : Maxim Ermilov <zaspire@rambler.ru>
......@@ -1512,6 +1512,64 @@ anjuta_preferences_register_all_properties_from_glade_xml (AnjutaPreferences *pr
}
}
/**
* anjuta_preferences_register_all_properties_from_builder_xml:
* @pr: a #AnjutaPreferences Object
* @builder: GtkBuilder object containing the properties widgets.
* @parent: Parent widget in the builder object
*
* This will register all the properties names of the format described above
* without considering the UI. Useful if you have the widgets shown elsewhere
* but you want them to be part of preferences system.
*/
void
anjuta_preferences_register_all_properties_from_builder_xml (AnjutaPreferences *pr,
GtkBuilder *builder,
GtkWidget *parent)
{
GSList *widgets;
GSList *node;
g_return_if_fail (ANJUTA_IS_PREFERENCES (pr));
g_return_if_fail (builder != NULL);
widgets = gtk_builder_get_objects (builder);
for (node = widgets; node != NULL; node = g_slist_next (node))
{
const gchar *name;
const gchar *property;
GtkWidget *widget, *p;
gboolean cont_flag = FALSE;
if (!GTK_IS_WIDGET (node->data))
continue;
widget = node->data;
name = gtk_widget_get_name (widget);
if (!g_str_has_prefix (name, PREFERENCE_PROPERTY_PREFIX))
continue;
p = gtk_widget_get_parent (widget);
/* Added only if it's a desendend child of the parent */
while (p != parent)
{
if (p == NULL)
{
cont_flag = TRUE;
break;
}
p = gtk_widget_get_parent (p);
}
if (cont_flag)
continue;
property = &name[strlen (PREFERENCE_PROPERTY_PREFIX)];
anjuta_preferences_register_property_from_string (pr, widget,
property);
}
}
/**
* anjuta_preferences_reset_defaults:
* @pr: a #AnjutaPreferences object.
......@@ -1649,6 +1707,86 @@ anjuta_preferences_add_page (AnjutaPreferences* pr, GladeXML *gxml,
g_object_unref (pixbuf);
}
/**
* anjuta_preferences_add_page:
* @pr: a #AnjutaPreferences object
* @builder: #GtkBuilder object containing the preferences page
* @gwidget_name: Page widget name (as give with glade interface editor).
* The widget will be searched with the given name and detached
* (that is, removed from the container, if present) from it's parent.
* @icon_filename: File name (of the form filename.png) of the icon representing
* the preference page.
*
* Add a page to the preferences sytem.
* builder is the GtkBuilder object of the dialog containing the page widget.
* The dialog will contain the layout of the preferences widgets.
* The widgets which are preference widgets (e.g. toggle button) should have
* widget names of the form:
*
* <programlisting>
* preferences_OBJECTTYPE:DATATYPE:DEFAULT:FLAGS:PROPERTYKEY
* where,
* OBJECTTYPE is 'toggle', 'spin', 'entry', 'text', 'color', 'font' or 'file' .
* DATATYPE is 'bool', 'int', 'float', 'text', 'color' or 'font'.
* DEFAULT is the default value (in the appropriate format). The format
* for color is '#XXXXXX' representing RGB value and for
* font, it is the pango font description.
* FLAGS is any flag associated with the property. Currently it
* has only two values -- 0 and 1. For normal preference
* property which is saved/retrieved globally, the flag = 0.
* For preference property which is also saved/retrieved
* along with the project, the flag = 1.
* PROPERTYKEY is the property key. e.g - 'tab.size'.
* </programlisting>
*
* All widgets having the above names in the gxml tree will be registered
* and will become part of auto saving/loading. For example, refer to
* anjuta preferences dialogs and study the widget names.
*/
void
anjuta_preferences_add_from_builder (AnjutaPreferences* pr,
GtkBuilder* builder,
const gchar* widget_name,
const gchar* title,
const gchar *icon_filename)
{
GtkWidget *parent;
GtkWidget *page;
GdkPixbuf *pixbuf;
gchar *image_path;
g_return_if_fail (ANJUTA_IS_PREFERENCES (pr));
g_return_if_fail (widget_name != NULL);
g_return_if_fail (icon_filename != NULL);
page = GTK_WIDGET(gtk_builder_get_object (builder, widget_name));
g_object_ref (page);
g_return_if_fail (GTK_IS_WIDGET (page));
parent = gtk_widget_get_parent (page);
if (parent && GTK_IS_CONTAINER (parent))
{
if (GTK_IS_NOTEBOOK (parent))
{
gint page_num;
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (parent), page);
gtk_notebook_remove_page (GTK_NOTEBOOK (parent), page_num);
}
else
{
gtk_container_remove (GTK_CONTAINER (parent), page);
}
}
image_path = anjuta_res_get_pixmap_file (icon_filename);
pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);
anjuta_preferences_dialog_add_page (ANJUTA_PREFERENCES_DIALOG (pr->priv->prefs_dialog),
widget_name, title, pixbuf, page);
anjuta_preferences_register_all_properties_from_builder_xml (pr, builder, page);
g_object_unref (page);
g_free (image_path);
g_object_unref (pixbuf);
}
void
anjuta_preferences_remove_page (AnjutaPreferences *pr,
const gchar *page_name)
......
......@@ -94,6 +94,11 @@ void anjuta_preferences_add_page (AnjutaPreferences* pr, GladeXML *gxml,
const gchar* glade_widget_name,
const gchar* title,
const gchar *icon_filename);
void anjuta_preferences_add_from_builder (AnjutaPreferences* pr,GtkBuilder *builder,
const gchar* glade_widget_name,
const gchar* title,
const gchar *icon_filename);
void anjuta_preferences_remove_page (AnjutaPreferences *pr,
const gchar *page_name);
......@@ -104,6 +109,13 @@ void anjuta_preferences_remove_page (AnjutaPreferences *pr,
void anjuta_preferences_register_all_properties_from_glade_xml (AnjutaPreferences* pr,
GladeXML *gxml,
GtkWidget *parent);
/*
* Registers all properties defined for widgets below the 'parent' widget
* in the given gtkbuilder UI tree
*/
void anjuta_preferences_register_all_properties_from_builder_xml (AnjutaPreferences* pr,
GtkBuilder* builder,
GtkWidget *parent);
gboolean
anjuta_preferences_register_property_from_string (AnjutaPreferences *pr,
GtkWidget *object,
......
if HAVE_PLUGIN_SOURCEVIEW
# Plugin glade file
sourceview_gladedir = $(anjuta_glade_dir)
sourceview_glade_DATA = anjuta-editor-sourceview.glade
sourceview_xmldir = $(anjuta_glade_dir)
sourceview_xml_DATA = anjuta-editor-sourceview.ui
# Plugin Icon file
sourceview_pixmapsdir = $(anjuta_image_dir)
......@@ -80,7 +80,7 @@ libanjuta_sourceview_la_LIBADD = \
$(GLADE_LIBS) \
$(LIBANJUTA_LIBS)
prefs_glade_files = anjuta-editor-sourceview.glade
prefs_ui_files = anjuta-editor-sourceview.ui
include $(top_srcdir)/scripts/build-schemas.mk
endif
......@@ -90,6 +90,6 @@ EXTRA_DIST = \
$(plugin_in_files) \
$(sourceview_plugin_DATA) \
$(sourceview_pixmaps_DATA) \
$(sourceview_glade_DATA)
$(sourceview_xml_DATA)
......@@ -38,7 +38,7 @@
#include "sourceview.h"
#include "sourceview-private.h"
#define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-editor-sourceview.glade"
#define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-editor-sourceview.ui"
#define ICON_FILE "anjuta-editor-sourceview-plugin-48.png"
#define COMBO_STYLES "combo_styles"
......@@ -49,13 +49,13 @@
static gpointer parent_class;
static GladeXML* gxml = NULL;
static GtkBuilder* builder = NULL;
static void
on_font_check_toggled(GtkToggleButton* button, GladeXML* gxml)
on_font_check_toggled(GtkToggleButton* button, GtkBuilder* builder)
{
GtkWidget* font_button;
font_button = glade_xml_get_widget(gxml, FONT_BUTTON);
font_button = GTK_WIDGET (gtk_builder_get_object (builder, FONT_BUTTON));
gtk_widget_set_sensitive(font_button, !gtk_toggle_button_get_active(button));
}
......@@ -218,16 +218,28 @@ ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError**
GtkCellRenderer* renderer_name = gtk_cell_renderer_text_new ();
GtkCellRenderer* renderer_desc = gtk_cell_renderer_text_new ();
GtkTreeIter* iter = NULL;
gxml = glade_xml_new (PREFS_GLADE, "preferences_dialog", NULL);
anjuta_preferences_add_page (prefs,
gxml, "Editor", _("GtkSourceView Editor"), ICON_FILE);
GError* error = NULL;
builder = gtk_builder_new ();
if (!gtk_builder_add_from_file(builder, PREFS_GLADE, &error))
{
DEBUG_PRINT ("Could load sourceview preferences: %s", error->msg);
g_error_free (error);
return;
}
anjuta_preferences_add_from_builder (prefs,
builder,
"Editor",
_("GtkSourceView Editor"),
ICON_FILE);
plugin->check_font = glade_xml_get_widget(gxml, FONT_USE_THEME_BUTTON);
g_signal_connect(G_OBJECT(plugin->check_font), "toggled", G_CALLBACK(on_font_check_toggled), gxml);
on_font_check_toggled (GTK_TOGGLE_BUTTON (plugin->check_font), gxml);
plugin->check_font = GTK_WIDGET (gtk_builder_get_object (builder,
FONT_USE_THEME_BUTTON));
g_signal_connect(G_OBJECT(plugin->check_font), "toggled",
G_CALLBACK(on_font_check_toggled), builder);
on_font_check_toggled (GTK_TOGGLE_BUTTON (plugin->check_font), builder);
/* Init styles combo */
plugin->combo_styles = glade_xml_get_widget (gxml, COMBO_STYLES);
plugin->combo_styles = GTK_WIDGET (gtk_builder_get_object (builder, COMBO_STYLES));
gtk_combo_box_set_model (GTK_COMBO_BOX (plugin->combo_styles),
create_style_model(prefs, &iter));
g_signal_connect (plugin->combo_styles, "changed", G_CALLBACK (on_style_changed), plugin);
......@@ -254,13 +266,13 @@ ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError
{
SourceviewPlugin* plugin = ANJUTA_PLUGIN_SOURCEVIEW (ipref);
g_signal_handlers_disconnect_by_func(G_OBJECT(plugin->check_font),
G_CALLBACK(on_font_check_toggled), gxml);
G_CALLBACK(on_font_check_toggled), builder);
g_signal_handlers_disconnect_by_func(G_OBJECT(plugin->combo_styles),
G_CALLBACK(on_style_changed), gxml);
G_CALLBACK(on_style_changed), builder);
anjuta_preferences_remove_page(prefs, _("GtkSourceView Editor"));
g_object_unref(gxml);
gxml = NULL;
g_object_unref(builder);
builder = NULL;
}
static void
......
......@@ -705,14 +705,12 @@ the file will be loaded in the buffer */
Sourceview *
sourceview_new(GFile* file, const gchar* filename, AnjutaPlugin* plugin)
{
AnjutaShell* shell;
GtkAdjustment* v_adj;
Sourceview *sv = ANJUTA_SOURCEVIEW(g_object_new(ANJUTA_TYPE_SOURCEVIEW, NULL));
/* Apply Preferences */
g_object_get(G_OBJECT(plugin), "shell", &shell, NULL);
sv->priv->prefs = anjuta_shell_get_preferences(shell, NULL);
sv->priv->prefs = anjuta_preferences_default();
sourceview_prefs_init(sv);
sv->priv->plugin = plugin;
......
2009-04-07 Johannes Schmid <jhs@gnome.org>
* POTFILES.in: Updated
2009-04-06 Johannes Schmid <jhs@Obelix>
Patch from Yuriy Penkin <yuriy.penkin@gmail.com>
......
......@@ -168,6 +168,7 @@ plugins/profiler/profiler-flat-profile.glade
plugins/profiler/profiler-function-call-tree.glade
plugins/profiler/profiler.glade
plugins/profiler/string-utils.c
plugins/project-import/plugin.c
plugins/project-import/project-import.glade
plugins/project-import/project-import-dialog.c
plugins/project-manager/create_dialogs.glade
......@@ -199,7 +200,7 @@ plugins/search/search-replace_backend.c
plugins/sourceview/sourceview.c
plugins/sourceview/sourceview-io.c
plugins/sourceview/sourceview-print.c
plugins/sourceview/anjuta-editor-sourceview.glade
plugins/sourceview/anjuta-editor-sourceview.ui
plugins/starter/plugin.c
plugins/starter/starter.c
plugins/subversion/anjuta-subversion.glade
......
......@@ -8,3 +8,5 @@ EXTRA_DIST = $(anjuta_data_DATA)
dist-hook:
cp $(srcdir)/glade2schema.pl $(distdir)
chmod +x $(distdir)/glade2schema.pl
cp $(srcdir)/builder2schema.pl $(distdir)
chmod +x $(distdir)/builder2schema.pl
\ No newline at end of file
......@@ -7,17 +7,30 @@ prefs_glade_schemas_DATA = $(prefs_glade_schemas)
%.schemas: %.glade
$(top_srcdir)/scripts/glade2schema.pl $(srcdir)/$(?) > $(@)
prefs_ui_schemasdir = @GCONF_SCHEMA_FILE_DIR@
prefs_ui_schemas = $(prefs_ui_files:.ui=.schemas)
prefs_ui_schemas_DATA = $(prefs_ui_schemas)
%.schemas: %.ui
$(top_srcdir)/scripts/builder2schema.pl $(srcdir)/$(?) > $(@)
if GCONF_SCHEMAS_INSTALL
install-data-local: $(prefs_glade_schemas)
install-data-local: $(prefs_glade_schemas) $(prefs_ui_schemas)
for p in $(prefs_glade_schemas) ; do \
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $$p ; \
done
for p in $(prefs_ui_schemas) ; do \
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $$p ; \
done
@killall -1 gconfd-2 || true
uninstall-local: $(prefs_glade_schemas)
uninstall-local: $(prefs_glade_schemas) $(prefs_ui_schemas)
for p in $(prefs_glade_schemas) ; do \
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-uninstall-rule $$p ; \
done
for p in $(prefs_ui_schemas) ; do \
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-uninstall-rule $$p ; \
done
@killall -1 gconfd-2 || true
else
......
#!/usr/bin/perl
use XML::Parser;
%datatypes = (
"bool" => "bool",
"int" => "int",
"string" => "string",
"text" => "string",
"float" => "float",
"color" => "string",
"font" => "string",
"folder" => "string",
"file" => "string"
);
%boolean = (
0 => "FALSE",
1 => "TRUE"
);
$schema_path = "/schemas/apps/anjuta/preferences/";
$key_path ="/apps/anjuta/preferences/";
my $parser = new XML::Parser(Style => "Stream");
print "<gconfschemafile>\n";
print "\t<schemalist>\n";
$parser->parsefile($ARGV[0]);
print "\t</schemalist>\n";
print "</gconfschemafile>\n";
sub StartTag {
my $parser = shift;
my $key = shift;
if ($key =~ /object/) {
my $k = $_{"id"};
if ($k =~ /(preferences_color|entry|font|spin|text|toggle|menu|folder|file):(.*):(.*):(\d):(.*)/) {
my $type = $2;
my $default = $3;
my $flags = $4;
my $propkey = $5;
if ($type =~ /bool/) {
$default = $boolean{$default};
}
print "\t\t<schema>\n";
print "\t\t\t<key>$schema_path$propkey</key>\n";
print "\t\t\t<applyto>$key_path$propkey</applyto>\n";
print "\t\t\t<owner>anjuta</owner>\n";
print "\t\t\t<type>$datatypes{$type}</type>\n";
print "\t\t\t<default>$default</default>\n";
# Hack to keep gconftool happy
print "\t\t\t<locale name=\"C\" />\n";
print "\t\t</schema>\n\n";
}
}
}
sub EndTag {}
sub Text {}
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