SF.net SVN: geany: [2103] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Dec 16 11:27:59 UTC 2007


Revision: 2103
          http://geany.svn.sourceforge.net/geany/?rev=2103&view=rev
Author:   eht16
Date:     2007-12-16 03:27:59 -0800 (Sun, 16 Dec 2007)

Log Message:
-----------
Use pluginmacros.h (for classbuilder and htmlchars plugins).
Add highlighting_get_style().
Add highlighting_get_style() to the plugin API.
Rename DocumentFuncs field in GeanyData struct to avoid name clashes.	      

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/classbuilder.c
    trunk/plugins/htmlchars.c
    trunk/plugins/pluginmacros.h
    trunk/src/highlighting.c
    trunk/src/highlighting.h
    trunk/src/plugindata.h
    trunk/src/plugins.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/ChangeLog	2007-12-16 11:27:59 UTC (rev 2103)
@@ -3,6 +3,13 @@
  * geany.desktop.in.in:
    Apply patch from Ubuntu package to match FD.o standards
    (thanks to Siegfried-Angel Gevatter Pujals).
+ * plugins/classbuilder.c, plugins/htmlchars.c:
+   Use pluginmacros.h.
+ * src/highlighting.c, src/highlighting.h:
+   Add highlighting_get_style().
+ * plugins/pluginmacros.h, src/plugindata.h, src/plugins.c:
+   Add highlighting_get_style() to the plugin API.
+   Rename DocumentFuncs field in GeanyData struct to avoid name clashes.
 
 
 2007-12-14  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/plugins/classbuilder.c
===================================================================
--- trunk/plugins/classbuilder.c	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/plugins/classbuilder.c	2007-12-16 11:27:59 UTC (rev 2103)
@@ -30,20 +30,13 @@
 #include "support.h"
 #include "filetypes.h"
 #include "document.h"
+#include "pluginmacros.h"
 
 
 PluginFields	*plugin_fields;
 GeanyData		*geany_data;
 
-#define doc_array	geany_data->doc_array
-// can't use document as a macro because it's currently a typename
-#define documents	geany_data->document
-#define scintilla	geany_data->sci
-#define templates	geany_data->templates
-#define utils		geany_data->utils
-#define ui			geany_data->ui
 
-
 VERSION_CHECK(7)
 
 PLUGIN_INFO(_("Class Builder"), _("Creates source files for new class types."), VERSION,
@@ -360,7 +353,7 @@
 	cc_dlg->class_type = type;
 
 	cc_dlg->dialog = gtk_dialog_new_with_buttons(_("Create Class"),
-			GTK_WINDOW(geany_data->app->window),
+			GTK_WINDOW(app->window),
 			GTK_DIALOG_MODAL,
 			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 			GTK_STOCK_OK, GTK_RESPONSE_OK,

Modified: trunk/plugins/htmlchars.c
===================================================================
--- trunk/plugins/htmlchars.c	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/plugins/htmlchars.c	2007-12-16 11:27:59 UTC (rev 2103)
@@ -28,18 +28,13 @@
 #include "support.h"
 #include "plugindata.h"
 #include "document.h"
+#include "pluginmacros.h"
 
 
 PluginFields	*plugin_fields;
 GeanyData		*geany_data;
 
-#define doc_array	geany_data->doc_array
-// can't use document as a macro because it's currently a typename
-#define documents	geany_data->document
-#define scintilla	geany_data->sci
-#define ui			geany_data->ui
 
-
 VERSION_CHECK(7)
 
 PLUGIN_INFO(_("HTML Characters"), _("Inserts HTML character entities like '&'."), VERSION,
@@ -76,7 +71,7 @@
 		GtkWidget *swin, *vbox, *label;
 
 		sc_dialog = gtk_dialog_new_with_buttons(
-					_("Special Characters"), GTK_WINDOW(geany_data->app->window),
+					_("Special Characters"), GTK_WINDOW(app->window),
 					GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 					_("_Insert"), GTK_RESPONSE_OK, NULL);
 		vbox = ui->dialog_vbox_new(GTK_DIALOG(sc_dialog));

Modified: trunk/plugins/pluginmacros.h
===================================================================
--- trunk/plugins/pluginmacros.h	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/plugins/pluginmacros.h	2007-12-16 11:27:59 UTC (rev 2103)
@@ -27,22 +27,23 @@
 #ifndef PLUGINMACROS_H
 #define PLUGINMACROS_H
 
-#define app			geany_data->app
-#define doc_array	geany_data->doc_array
-#define prefs		geany_data->prefs
-#define project		app->project
+#define app				geany_data->app
+#define doc_array		geany_data->doc_array
+#define prefs			geany_data->prefs
+#define project			app->project
 
-#define dialogs		geany_data->dialogs
-#define documents	geany_data->document	// avoids conflict with document typedef
-#define encodings	geany_data->encoding	// avoids conflict with document::encoding
-#define keybindings	geany_data->keybindings
-#define msgwindow	geany_data->msgwindow
-#define scintilla	geany_data->sci
-#define search		geany_data->search
-#define support		geany_data->support
-#define templates	geany_data->templates
-#define tagmanager	geany_data->tm			// avoids conflict with "struct tm *t"
-#define ui			geany_data->ui
-#define utils		geany_data->utils
+#define dialogs			geany_data->dialogs
+#define documents		geany_data->documents	// avoids conflict with document typedef
+#define encodings		geany_data->encoding	// avoids conflict with document::encoding
+#define highlighting	geany_data->highlighting
+#define keybindings		geany_data->keybindings
+#define msgwindow		geany_data->msgwindow
+#define scintilla		geany_data->sci
+#define search			geany_data->search
+#define support			geany_data->support
+#define templates		geany_data->templates
+#define tagmanager		geany_data->tm			// avoids conflict with "struct tm *t"
+#define ui				geany_data->ui
+#define utils			geany_data->utils
 
 #endif

Modified: trunk/src/highlighting.c
===================================================================
--- trunk/src/highlighting.c	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/src/highlighting.c	2007-12-16 11:27:59 UTC (rev 2103)
@@ -46,17 +46,9 @@
 
 typedef struct
 {
-	gint	foreground;
-	gint	background;
-	gboolean bold:1;
-	gboolean italic:1;
-} Style;
-
-typedef struct
-{
-	Style	 *styling;		// array of styles, NULL if not used or uninitialised
-	gchar	**keywords;
-	gchar	 *wordchars;	// NULL used for style sets with no styles
+	HighlightingStyle	 *styling;		// array of styles, NULL if not used or uninitialised
+	gchar				**keywords;
+	gchar				 *wordchars;	// NULL used for style sets with no styles
 } StyleSet;
 
 // each filetype has a styleset except GEANY_FILETYPE_ALL
@@ -88,35 +80,27 @@
 
 static struct
 {
-	Style			styling[GCS_MAX];
-	FoldingStyle	folding_style;
-	gboolean		invert_all;
-	gchar			*wordchars;
+	HighlightingStyle	 styling[GCS_MAX];
+	FoldingStyle		 folding_style;
+	gboolean			 invert_all;
+	gchar				*wordchars;
 } common_style_set;
 
 
 // used for default styles
 typedef struct
 {
-	gchar *name;
-	Style *style;
+	gchar				*name;
+	HighlightingStyle	*style;
 } StyleEntry;
 
 
 static void new_style_array(gint file_type_id, gint styling_count)
 {
-	style_sets[file_type_id].styling = g_new0(Style, styling_count);
+	style_sets[file_type_id].styling = g_new0(HighlightingStyle, styling_count);
 }
 
 
-#if 0
-static Style *get_styling(gint file_type_id, gint styling_index)
-{
-	return &style_sets[file_type_id].styling[styling_index];
-}
-#endif
-
-
 static void get_keyfile_keywords(GKeyFile *config, GKeyFile *configh, const gchar *section,
 				const gchar *key, gint index, gint pos, const gchar *default_value)
 {
@@ -174,7 +158,7 @@
 
 
 static void get_keyfile_style(GKeyFile *config, GKeyFile *configh,
-		const gchar *key_name, const Style *default_style, Style *style)
+		const gchar *key_name, const HighlightingStyle *default_style, HighlightingStyle *style)
 {
 	gchar **list;
 	gsize len;
@@ -208,7 +192,7 @@
 static void get_keyfile_hex(GKeyFile *config, GKeyFile *configh,
 				const gchar *section, const gchar *key,
 				const gchar *foreground, const gchar *background, const gchar *bold,
-				Style *style)
+				HighlightingStyle *style)
 {
 	gchar **list;
 	gsize len;
@@ -240,7 +224,7 @@
 
 static void get_keyfile_int(GKeyFile *config, GKeyFile *configh, const gchar *section,
 							const gchar *key, gint fdefault_val, gint sdefault_val,
-							Style *style)
+							HighlightingStyle *style)
 {
 	gchar **list;
 	gchar *end1, *end2;
@@ -281,7 +265,7 @@
 
 static void set_sci_style(ScintillaObject *sci, gint style, gint ft, gint styling_index)
 {
-	Style *style_ptr;
+	HighlightingStyle *style_ptr;
 
 	if (ft == GEANY_FILETYPES_ALL)
 		style_ptr = &common_style_set.styling[styling_index];
@@ -379,7 +363,7 @@
 		"0xc0c0c0", "0xffffff", "true", &common_style_set.styling[GCS_WHITE_SPACE]);
 	{
 		// hack because get_keyfile_int uses a Style struct
-		Style tmp_style;
+		HighlightingStyle tmp_style;
 		get_keyfile_int(config, config_home, "styling", "folding_style",
 			1, 1, &tmp_style);
 		common_style_set.folding_style.marker = tmp_style.foreground;
@@ -582,26 +566,26 @@
  * Ideally these would be used as common styling for all compilable programming
  * languages (and perhaps partially used for scripting languages too).
  * Currently only used as default styling for C-like languages. */
-Style gsd_default =		{0x000000, 0xffffff, FALSE, FALSE};
-Style gsd_comment =		{0xd00000, 0xffffff, FALSE, FALSE};
-Style gsd_comment_doc =	{0x3f5fbf, 0xffffff, TRUE, FALSE};
-Style gsd_number =		{0x007f00, 0xffffff, FALSE, FALSE};
-Style gsd_reserved_word =	{0x00007f, 0xffffff, TRUE, FALSE};
-Style gsd_system_word =	{0x991111, 0xffffff, TRUE, FALSE};
-Style gsd_user_word =	{0x0000d0, 0xffffff, TRUE, FALSE};
-Style gsd_string =		{0xff901e, 0xffffff, FALSE, FALSE};
-Style gsd_pragma =		{0x007f7f, 0xffffff, FALSE, FALSE};
-Style gsd_string_eol =	{0x000000, 0xe0c0e0, FALSE, FALSE};
+HighlightingStyle gsd_default =		{0x000000, 0xffffff, FALSE, FALSE};
+HighlightingStyle gsd_comment =		{0xd00000, 0xffffff, FALSE, FALSE};
+HighlightingStyle gsd_comment_doc =	{0x3f5fbf, 0xffffff, TRUE, FALSE};
+HighlightingStyle gsd_number =		{0x007f00, 0xffffff, FALSE, FALSE};
+HighlightingStyle gsd_reserved_word =	{0x00007f, 0xffffff, TRUE, FALSE};
+HighlightingStyle gsd_system_word =	{0x991111, 0xffffff, TRUE, FALSE};
+HighlightingStyle gsd_user_word =	{0x0000d0, 0xffffff, TRUE, FALSE};
+HighlightingStyle gsd_string =		{0xff901e, 0xffffff, FALSE, FALSE};
+HighlightingStyle gsd_pragma =		{0x007f7f, 0xffffff, FALSE, FALSE};
+HighlightingStyle gsd_string_eol =	{0x000000, 0xe0c0e0, FALSE, FALSE};
 
 
 // call new_style_array(filetype_idx, >= 20) before using this.
 static void
 styleset_c_like_init(GKeyFile *config, GKeyFile *config_home, gint filetype_idx)
 {
-	Style uuid = {0x404080, 0xffffff, FALSE, FALSE};
-	Style operator = {0x301010, 0xffffff, FALSE, FALSE};
-	Style verbatim = {0x301010, 0xffffff, FALSE, FALSE};
-	Style regex = {0x105090, 0xffffff, FALSE, FALSE};
+	HighlightingStyle uuid = {0x404080, 0xffffff, FALSE, FALSE};
+	HighlightingStyle operator = {0x301010, 0xffffff, FALSE, FALSE};
+	HighlightingStyle verbatim = {0x301010, 0xffffff, FALSE, FALSE};
+	HighlightingStyle regex = {0x105090, 0xffffff, FALSE, FALSE};
 
 	StyleEntry entries[] =
 	{
@@ -3001,3 +2985,21 @@
 		styleset_case(GEANY_FILETYPES_ALL,		none);
 	}
 }
+
+
+/* Retrieve a style style_id for the filetype ft_id. If the style was not already initialised
+ * (e.g. by by opening a file of this type), it will be initialised. The returned pointer is
+ * owned by Geany and must not be freed.
+ * style_id is a Scintilla lexer style, see scintilla/SciLexer.h */
+const HighlightingStyle *highlighting_get_style(gint ft_id, gint style_id)
+{
+	if (ft_id < 0 || ft_id > GEANY_MAX_FILE_TYPES)
+		return NULL;
+
+	if (style_sets[ft_id].styling == NULL)
+		filetypes_load_config(ft_id);
+
+	/// TODO style_id might not be the real array index (Scintilla styles are not always synced
+	///	with array indices)
+	return (const HighlightingStyle*) &style_sets[ft_id].styling[style_id];
+}

Modified: trunk/src/highlighting.h
===================================================================
--- trunk/src/highlighting.h	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/src/highlighting.h	2007-12-16 11:27:59 UTC (rev 2103)
@@ -29,10 +29,21 @@
 #include "ScintillaWidget.h"
 
 
+typedef struct HighlightingStyle
+{
+	gint	foreground;
+	gint	background;
+	gboolean bold:1;
+	gboolean italic:1;
+} HighlightingStyle;
+
+
 void highlighting_init_styles(gint filetype_idx, GKeyFile *config, GKeyFile *configh);
 
 void highlighting_set_styles(ScintillaObject *sci, gint filetype_idx);
 
+const HighlightingStyle *highlighting_get_style(gint ft_id, gint style_id);
+
 void highlighting_free_styles(void);
 
 #endif

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/src/plugindata.h	2007-12-16 11:27:59 UTC (rev 2103)
@@ -93,7 +93,7 @@
 
 /* The API version should be incremented whenever any plugin data types below are
  * modified or appended to. */
-static const gint api_version = 34;
+static const gint api_version = 35;
 
 /* The ABI version should be incremented whenever existing fields in the plugin
  * data types below have to be changed or reordered. It should stay the same if fields
@@ -184,18 +184,19 @@
 	struct EditorPrefs	*editor_prefs;
 	struct BuildInfo	*build_info;
 
-	struct DocumentFuncs	*document;
-	struct ScintillaFuncs	*sci;
-	struct TemplateFuncs	*templates;
-	struct UtilsFuncs		*utils;
-	struct UIUtilsFuncs		*ui;
-	struct SupportFuncs		*support;
-	struct DialogFuncs		*dialogs;
-	struct MsgWinFuncs		*msgwindow;
-	struct EncodingFuncs	*encoding;
-	struct KeybindingFuncs	*keybindings;
-	struct TagManagerFuncs	*tm;
-	struct SearchFuncs		*search;
+	struct DocumentFuncs		*documents;
+	struct ScintillaFuncs		*sci;
+	struct TemplateFuncs		*templates;
+	struct UtilsFuncs			*utils;
+	struct UIUtilsFuncs			*ui;
+	struct SupportFuncs			*support;
+	struct DialogFuncs			*dialogs;
+	struct MsgWinFuncs			*msgwindow;
+	struct EncodingFuncs		*encoding;
+	struct KeybindingFuncs		*keybindings;
+	struct TagManagerFuncs		*tm;
+	struct SearchFuncs			*search;
+	struct HighlightingFuncs	*highlighting;
 }
 GeanyData;
 
@@ -205,7 +206,6 @@
 /* For more info about these functions, see the main source code.
  * E.g. for GeanyData::document->new_file(), see document_new_file() in document.[hc]. */
 
-struct filetype;
 
 typedef struct DocumentFuncs
 {
@@ -338,6 +338,13 @@
 KeybindingFuncs;
 
 
+typedef struct HighlightingFuncs
+{
+	const struct HighlightingStyle* (*get_style) (gint ft_id, gint style_id);
+}
+HighlightingFuncs;
+
+
 typedef struct SearchFuncs
 {
 	void		(*show_find_in_files_dialog) (const gchar *dir);

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2007-12-16 11:07:20 UTC (rev 2102)
+++ trunk/src/plugins.c	2007-12-16 11:27:59 UTC (rev 2103)
@@ -51,6 +51,7 @@
 #include "build.h"
 #include "encodings.h"
 #include "search.h"
+#include "highlighting.h"
 
 void keybindings_cmd(gint cmd_id);	// don't require keybindings.h enum in plugindata.h
 
@@ -188,7 +189,11 @@
 	&search_show_find_in_files_dialog
 };
 
+static HighlightingFuncs highlighting_funcs = {
+	&highlighting_get_style
+};
 
+
 static GeanyData geany_data = {
 	NULL,
 	NULL,
@@ -210,6 +215,7 @@
 	&keybindings_funcs,
 	&tagmanager_funcs,
 	&search_funcs,
+	&highlighting_funcs
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list