[anjuta] project-wizard: bgo #641331 - Add a (non-alphabetical) sorting order to wizard files



commit fa41a4976648fbff41a044f0689da47370100249
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sat Mar 5 22:47:05 2011 +0100

    project-wizard: bgo #641331 - Add a (non-alphabetical) sorting order to wizard files

 plugins/project-wizard/header.c                    |   31 +++++++++++++++++++-
 plugins/project-wizard/header.h                    |    3 ++
 plugins/project-wizard/parser.c                    |    6 ++++
 plugins/project-wizard/templates/gtk.wiz.in        |    1 +
 .../project-wizard/templates/gtkapplication.wiz.in |    1 +
 5 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/plugins/project-wizard/header.c b/plugins/project-wizard/header.c
index 59c32ad..a3849cf 100644
--- a/plugins/project-wizard/header.c
+++ b/plugins/project-wizard/header.c
@@ -26,6 +26,7 @@
 #include <config.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 #include "header.h"
 
@@ -43,6 +44,7 @@ struct _NPWHeader {
 	gint description_lang;
 	gchar* iconfile;
 	gchar* category;
+	guint  order;
 	gchar* filename;
 	GList* required_programs;
 	GList* required_packages;
@@ -150,6 +152,18 @@ npw_header_get_iconfile (const NPWHeader* self)
 }
 
 void
+npw_header_set_order (NPWHeader* self, const gchar* order)
+{
+	self->order = strtoul (order, NULL, 10);
+}
+
+const guint
+npw_header_get_order (const NPWHeader* self)
+{
+	return self->order;
+}
+
+void
 npw_header_add_required_program (NPWHeader* self, const gchar* program)
 {
 	self->required_programs =
@@ -230,7 +244,22 @@ npw_header_list_free (GList* list)
 static gint
 compare_header_name (NPWHeader *a, NPWHeader *b)
 {
-	return g_utf8_collate (npw_header_get_name (a), npw_header_get_name (b));
+	if (npw_header_get_order (a) == npw_header_get_order (b))
+	{
+		return g_utf8_collate (npw_header_get_name (a), npw_header_get_name (b));
+	}
+	else if (npw_header_get_order (a) == 0)
+	{
+		return 1;
+	}
+	else if (npw_header_get_order (b) == 0)
+	{
+		return -1;
+	}
+	else
+	{
+		return npw_header_get_order (a) - npw_header_get_order (b);
+	}
 }
 
 GList *
diff --git a/plugins/project-wizard/header.h b/plugins/project-wizard/header.h
index 7d4ccf5..4e0ab7e 100644
--- a/plugins/project-wizard/header.h
+++ b/plugins/project-wizard/header.h
@@ -44,6 +44,9 @@ const gchar* npw_header_get_description (const NPWHeader* self);
 void npw_header_set_iconfile (NPWHeader* this, const gchar* confile);
 const gchar* npw_header_get_iconfile (const NPWHeader* self);
 
+void npw_header_set_order (NPWHeader* this, const gchar *order);
+const guint npw_header_get_order (const NPWHeader* self);
+
 void npw_header_add_required_program (NPWHeader* self, const gchar* program);
 
 /* Returns list of missing programs, or NULL if none is missing
diff --git a/plugins/project-wizard/parser.c b/plugins/project-wizard/parser.c
index ffd51e2..9c54982 100644
--- a/plugins/project-wizard/parser.c
+++ b/plugins/project-wizard/parser.c
@@ -53,6 +53,7 @@ typedef enum {
 	NPW_REQUIRED_PROGRAM_TAG,
 	NPW_REQUIRED_PACKAGE_TAG,
 	NPW_ICON_TAG,
+	NPW_ORDER_TAG,
 	NPW_PAGE_TAG,
 	NPW_PROPERTY_TAG,
 	NPW_ITEM_TAG,
@@ -74,6 +75,7 @@ static NPWStringMapping npw_tag_mapping [] = {
 		{"_description", NPW_DESCRIPTION_TAG},
 		{"description", NPW_DESCRIPTION_TAG},
 		{"icon", NPW_ICON_TAG},
+		{"order", NPW_ORDER_TAG},
 		{"category", NPW_CATEGORY_TAG},
 		{"required-program", NPW_REQUIRED_PROGRAM_TAG},
 		{"required-package", NPW_REQUIRED_PACKAGE_TAG},
@@ -388,6 +390,7 @@ parse_header_start (GMarkupParseContext* context,
 			case NPW_NAME_TAG:
 			case NPW_DESCRIPTION_TAG:
 			case NPW_ICON_TAG:
+			case NPW_ORDER_TAG:
 			case NPW_CATEGORY_TAG:
 			case NPW_REQUIRED_PROGRAM_TAG:
 			case NPW_REQUIRED_PACKAGE_TAG:
@@ -492,6 +495,9 @@ parse_header_text (GMarkupParseContext* context,
 			g_free (path);
 			g_free (filename);
 			break;
+		case NPW_ORDER_TAG:
+			npw_header_set_order (parser->header, text);
+			break;
 		case NPW_CATEGORY_TAG:
 			npw_header_set_category (parser->header, text);
 			break;
diff --git a/plugins/project-wizard/templates/gtk.wiz.in b/plugins/project-wizard/templates/gtk.wiz.in
index 132c065..8aaaa7d 100644
--- a/plugins/project-wizard/templates/gtk.wiz.in
+++ b/plugins/project-wizard/templates/gtk.wiz.in
@@ -4,6 +4,7 @@
 		<_description>Simple GTK+ project</_description>
 		<icon>gtk-logo.png</icon>
 		<category>C</category>
+		<order>2000</order>
 		<required-program>automake</required-program>
 		<required-program>autoconf</required-program>
 		<required-program>make</required-program>
diff --git a/plugins/project-wizard/templates/gtkapplication.wiz.in b/plugins/project-wizard/templates/gtkapplication.wiz.in
index b92de0d..1528b8d 100644
--- a/plugins/project-wizard/templates/gtkapplication.wiz.in
+++ b/plugins/project-wizard/templates/gtkapplication.wiz.in
@@ -4,6 +4,7 @@
 		<_description>Full features Gtk+ Application with file handling</_description>
 		<icon>gtk-logo.png</icon>
 		<category>C</category>
+		<order>1000</order>
 		<required-program>automake</required-program>
 		<required-program>autoconf</required-program>
 		<required-program>make</required-program>



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