gedit r6886 - in trunk: . plugins/snippets/data



Author: icq
Date: Sun Feb  8 21:23:14 2009
New Revision: 6886
URL: http://svn.gnome.org/viewvc/gedit?rev=6886&view=rev

Log:
2009-02-08  Ignacio Casal Quinteiro  <nacho resa gmail com>

        * plugins/snippets/data/chdr.xml:
        * plugins/snippets/data/c.xml:
        Add ginterface snippets.



Modified:
   trunk/ChangeLog
   trunk/plugins/snippets/data/c.xml
   trunk/plugins/snippets/data/chdr.xml

Modified: trunk/plugins/snippets/data/c.xml
==============================================================================
--- trunk/plugins/snippets/data/c.xml	(original)
+++ trunk/plugins/snippets/data/c.xml	Sun Feb  8 21:23:14 2009
@@ -206,4 +206,78 @@
     <tag>gobject</tag>
     <description>GObject template</description>
   </snippet>
+  <snippet id="ginterface">
+    <text><![CDATA[#include "$1.h"
+$<
+global camel_str,low_str,up_str
+components = $1.split('-')
+low_str = '_'.join(components).lower()
+up_str = '_'.join(components).upper()
+camel_str = ''
+
+for t in components:
+  camel_str += t.capitalize()
+>
+/*
+ * This is an method example for an interface
+ */
+const gchar *
+$<[1]: return low_str>_example_method ($<[1]: return camel_str > *self)
+{
+	g_return_val_if_fail ($<[1]: return up_str> (self), NULL);
+	return $<[1]: return up_str>_GET_INTERFACE (self)->example_method (self);
+}
+
+/* Default implementation */
+static const gchar *
+$<[1]: return low_str>_example_method_default ($<[1]: return camel_str > *self)
+{
+	g_return_val_if_reached (NULL);
+}
+
+static void 
+$<[1]: return low_str>_init ($<[1]: return camel_str >Iface *iface)
+{
+	static gboolean initialized = FALSE;
+	
+	iface->example_method = $<[1]: return low_str>_example_method_default;
+	
+	if (!initialized)
+	{
+		initialized = TRUE;
+	}
+}
+
+GType 
+$<[1]: return low_str>_get_type ()
+{
+	static GType $<[1]: return low_str>_type_id = 0;
+	
+	if (!$<[1]: return low_str>_type_id)
+	{
+		static const GTypeInfo g_define_type_info =
+		{
+			sizeof ($<[1]: return camel_str >Iface),
+			(GBaseInitFunc) $<[1]: return low_str>_init, 
+			NULL,
+			NULL,
+			NULL,
+			NULL,
+			0,
+			0,
+			NULL
+		};
+		
+		$<[1]: return low_str>_type_id = 
+			g_type_register_static (G_TYPE_INTERFACE,
+						"$<[1]: return camel_str>",
+						&g_define_type_info,
+						0);
+	}
+	
+	return $<[1]: return low_str>_type_id;
+}]]></text>
+    <tag>ginterface</tag>
+    <description>GObject interface</description>
+  </snippet>
 </snippets>

Modified: trunk/plugins/snippets/data/chdr.xml
==============================================================================
--- trunk/plugins/snippets/data/chdr.xml	(original)
+++ trunk/plugins/snippets/data/chdr.xml	Sun Feb  8 21:23:14 2009
@@ -186,4 +186,56 @@
     <tag>gobject</tag>
     <description>GObject template</description>
   </snippet>
+  <snippet id="ginterface">
+    <text><![CDATA[#ifndef __${1:NAME}_H__
+#define __$1_H__
+
+#include <${2:glib-object.h}>
+
+G_BEGIN_DECLS
+
+$<
+global camel_str
+components = $1.split('_')
+type_str = '_'.join([components[0], 'TYPE'] + components[1:])
+is_str = '_'.join([components[0], 'IS'] + components[1:])
+camel_str = ''
+
+for t in components:
+  camel_str += t.capitalize()
+
+items = [ \
+['#define ' + type_str, '(' + $1.lower() + '_get_type ())'], \
+['#define ' + $1 + '(obj)', '(G_TYPE_CHECK_INSTANCE_CAST ((obj), ' + type_str + ', ' + camel_str + '))'], \
+['#define ' + is_str + '(obj)', '(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ' + type_str + '))'], \
+['#define ' + $1 + '_GET_INTERFACE(obj)', '(G_TYPE_INSTANCE_GET_INTERFACE ((obj), ' + type_str + ', ' + camel_str + 'Iface))']
+]
+
+return align(items) >
+
+$<[1]:
+items = [ \
+['typedef struct _' + camel_str, camel_str + ';'], \
+['typedef struct _' + camel_str + 'Iface', camel_str + 'Iface;'], \
+]
+
+return align(items) >
+
+struct _$<[1]: return camel_str >Iface
+{
+	${7:GTypeInterface} parent;
+	
+	const gchar * (*example_method) ($<[1]: return camel_str > *self);
+};
+
+GType $< return $1.lower() + '_get_type' > (void) G_GNUC_CONST;
+
+const gchar *$< return $1.lower()>_example_method ($<[1]: return camel_str > *self);
+$0
+G_END_DECLS
+
+#endif /* __$1_H__ */]]></text>
+    <tag>ginterface</tag>
+    <description>GObject interface</description>
+  </snippet>
 </snippets>



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