SF.net SVN: geany:[2977] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Fri Sep 19 17:19:35 UTC 2008


Revision: 2977
          http://geany.svn.sourceforge.net/geany/?rev=2977&view=rev
Author:   ntrel
Date:     2008-09-19 17:19:34 +0000 (Fri, 19 Sep 2008)

Log Message:
-----------
Add GeanyFiletypePrivate instead of using inheritance for non-public
fields (this was unnecessary and meant using ugly casts).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/filetypes.c
    trunk/src/filetypes.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-09-19 16:45:07 UTC (rev 2976)
+++ trunk/ChangeLog	2008-09-19 17:19:34 UTC (rev 2977)
@@ -5,6 +5,9 @@
    distracting as added/removed lines don't get them.
  * src/plugindata.h:
    Remove 2 unnecessary deprecated macros.
+ * src/filetypes.c, src/filetypes.h:
+   Add GeanyFiletypePrivate instead of using inheritance for non-public
+   fields (this was unnecessary and meant using ugly casts).
 
 
 2008-09-18  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/filetypes.c
===================================================================
--- trunk/src/filetypes.c	2008-09-19 16:45:07 UTC (rev 2976)
+++ trunk/src/filetypes.c	2008-09-19 17:19:34 UTC (rev 2977)
@@ -42,15 +42,13 @@
 #include "ui_utils.h"
 
 
-/* This type 'inherits' from filetype so FullFileType* can be cast to filetype*. */
-typedef struct FullFileType
+/* Private GeanyFiletype fields */
+typedef struct GeanyFiletypePrivate
 {
-	GeanyFiletype	public;
-	/* Private fields */
 	GtkWidget		*menu_item;			/* holds a pointer to the menu item for this filetype */
 	gboolean		keyfile_loaded;
 }
-FullFileType;
+GeanyFiletypePrivate;
 
 
 GPtrArray *filetypes_array = NULL;	/* Dynamic array of filetype pointers */
@@ -476,12 +474,13 @@
 /* initialize fields. */
 static GeanyFiletype *filetype_new(void)
 {
-	FullFileType *fft = g_new0(FullFileType, 1);
-	GeanyFiletype *ft = (GeanyFiletype*) fft;
+	GeanyFiletype *ft = g_new0(GeanyFiletype, 1);
 
 	ft->lang = -2;	/* assume no tagmanager parser */
 	ft->programs = g_new0(struct build_programs, 1);
 	ft->actions = g_new0(struct build_actions, 1);
+
+	ft->priv = g_new0(GeanyFiletypePrivate, 1);
 	return ft;
 }
 
@@ -788,16 +787,13 @@
 
 void filetypes_select_radio_item(const GeanyFiletype *ft)
 {
-	FullFileType *fft;
-
 	/* ignore_callback has to be set by the caller */
 	g_return_if_fail(ignore_callback);
 
 	if (ft == NULL)
 		ft = filetypes[GEANY_FILETYPES_NONE];
 
-	fft = (FullFileType*)ft;
-	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(fft->menu_item), TRUE);
+	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(ft->priv->menu_item), TRUE);
 }
 
 
@@ -817,11 +813,10 @@
 {
 	static GSList *group = NULL;
 	GtkWidget *tmp;
-	FullFileType *fft = (FullFileType*)ftype;
 
 	tmp = gtk_radio_menu_item_new_with_label(group, label);
 	group = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(tmp));
-	fft->menu_item = tmp;
+	ftype->priv->menu_item = tmp;
 	gtk_widget_show(tmp);
 	gtk_container_add(GTK_CONTAINER(menu), tmp);
 	g_signal_connect(tmp, "activate", G_CALLBACK(on_filetype_change), (gpointer) ftype);
@@ -984,18 +979,20 @@
 void filetypes_load_config(gint ft_id, gboolean reload)
 {
 	GKeyFile *config, *config_home;
-	FullFileType *fft = (FullFileType*)filetypes[ft_id];
+	GeanyFiletypePrivate *pft;
 
 	g_return_if_fail(ft_id >= 0 && ft_id < (gint) filetypes_array->len);
 
+	pft = filetypes[ft_id]->priv;
+
 	/* when reloading, proceed only if the settings were already loaded */
-	if (reload && ! fft->keyfile_loaded)
+	if (reload && ! pft->keyfile_loaded)
 		return;
 
 	/* when not reloading, load the settings only once */
-	if (! reload && fft->keyfile_loaded)
+	if (! reload && pft->keyfile_loaded)
 		return;
-	fft->keyfile_loaded = TRUE;
+	pft->keyfile_loaded = TRUE;
 
 	config = g_key_file_new();
 	config_home = g_key_file_new();

Modified: trunk/src/filetypes.h
===================================================================
--- trunk/src/filetypes.h	2008-09-19 16:45:07 UTC (rev 2976)
+++ trunk/src/filetypes.h	2008-09-19 17:19:34 UTC (rev 2977)
@@ -132,6 +132,8 @@
 	struct build_programs	*programs;
 	struct build_actions	*actions;
 	GeanyFiletypeGroupID	group;
+
+	struct GeanyFiletypePrivate	*priv;	/* must be last, append fields before this item */
 };
 
 extern GPtrArray *filetypes_array;


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