SF.net SVN: geany-plugins:[918] trunk/geany-plugins/pretty-printer/src

ctabin at users.sourceforge.net ctabin at xxxxx
Sat Sep 5 14:46:23 UTC 2009


Revision: 918
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=918&view=rev
Author:   ctabin
Date:     2009-09-05 14:46:23 +0000 (Sat, 05 Sep 2009)

Log Message:
-----------
Pretty-print : Doctype supporte added, bugfix on cdata processing

Modified Paths:
--------------
    trunk/geany-plugins/pretty-printer/src/Makefile.am
    trunk/geany-plugins/pretty-printer/src/PluginEntry.c
    trunk/geany-plugins/pretty-printer/src/PluginEntry.h
    trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c

Added Paths:
-----------
    trunk/geany-plugins/pretty-printer/src/ConfigUI.c
    trunk/geany-plugins/pretty-printer/src/ConfigUI.h

Added: trunk/geany-plugins/pretty-printer/src/ConfigUI.c
===================================================================
--- trunk/geany-plugins/pretty-printer/src/ConfigUI.c	                        (rev 0)
+++ trunk/geany-plugins/pretty-printer/src/ConfigUI.c	2009-09-05 14:46:23 UTC (rev 918)
@@ -0,0 +1,77 @@
+/**
+ *   Copyright (C) 2009  Cedric Tabin
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License along
+ *   with this program; if not, write to the Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "ConfigUI.h"
+
+GtkWidget* createPrettyPrinterConfigUI(GtkDialog* dialog)
+{
+	//default printing options
+	if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); }
+	
+	//TODO create configuration widget
+}
+
+void saveSettings()
+{
+	//TODO save settings into a file
+}
+
+
+/*
+GtkWidget* plugin_configure(GtkDialog * dialog)   	
+{
+	//default printing options
+	if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); }
+	
+	GtkWidget* globalBox = gtk_hbox_new(TRUE, 4);
+	GtkWidget* rightBox = gtk_vbox_new(FALSE, 6);
+	GtkWidget* centerBox = gtk_vbox_new(FALSE, 6);
+	GtkWidget* leftBox = gtk_vbox_new(FALSE, 6);
+	
+	GtkWidget* textLabel = gtk_label_new("Text nodes");
+	GtkWidget* textOneLine =   gtk_check_button_new_with_label("One line");
+	GtkWidget* textInline =   gtk_check_button_new_with_label("Inline");
+	
+	GtkWidget* cdataLabel = gtk_label_new("CDATA nodes");
+	GtkWidget* cdataOneLine =   gtk_check_button_new_with_label("One line");
+	GtkWidget* cdataInline =   gtk_check_button_new_with_label("Inline");
+	
+	GtkWidget* commentLabel = gtk_label_new("Comments");
+	GtkWidget* commentOneLine =   gtk_check_button_new_with_label("One line");
+	GtkWidget* commentInline =   gtk_check_button_new_with_label("Inline");
+	
+	gtk_box_pack_start(GTK_BOX(globalBox), leftBox, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(globalBox), centerBox, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(globalBox), rightBox, FALSE, FALSE, 3);
+
+	gtk_box_pack_start(GTK_BOX(leftBox), textLabel, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(centerBox), textOneLine, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(rightBox), textInline, FALSE, FALSE, 3);
+
+	gtk_box_pack_start(GTK_BOX(leftBox), cdataLabel, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(centerBox), cdataOneLine, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(rightBox), cdataInline, FALSE, FALSE, 3);
+	
+	gtk_box_pack_start(GTK_BOX(leftBox), commentLabel, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(centerBox), commentOneLine, FALSE, FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(rightBox), commentInline, FALSE, FALSE, 3);
+
+	gtk_widget_show_all(globalBox);
+	return globalBox;
+}
+*/

Added: trunk/geany-plugins/pretty-printer/src/ConfigUI.h
===================================================================
--- trunk/geany-plugins/pretty-printer/src/ConfigUI.h	                        (rev 0)
+++ trunk/geany-plugins/pretty-printer/src/ConfigUI.h	2009-09-05 14:46:23 UTC (rev 918)
@@ -0,0 +1,36 @@
+/**
+ *   Copyright (C) 2009  Cedric Tabin
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License along
+ *   with this program; if not, write to the Free Software Foundation, Inc.,
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PP_CONFIG_UI_H
+#define PP_CONFIG_UI_H
+
+//========================================== INCLUDES =========================================================
+
+#include <gtk/gtk.h>
+#include "PrettyPrinter.h"
+
+//========================================== VARIABLES ========================================================
+
+PrettyPrintingOptions* prettyPrintingOptions;
+
+//========================================== FUNCTIONS ========================================================
+
+GtkWidget* createPrettyPrinterConfigUI(GtkDialog* dialog);
+void saveSettings();
+
+#endif

Modified: trunk/geany-plugins/pretty-printer/src/Makefile.am
===================================================================
--- trunk/geany-plugins/pretty-printer/src/Makefile.am	2009-09-03 21:08:56 UTC (rev 917)
+++ trunk/geany-plugins/pretty-printer/src/Makefile.am	2009-09-05 14:46:23 UTC (rev 918)
@@ -6,7 +6,9 @@
 	PluginEntry.h \
 	PluginEntry.c \
 	PrettyPrinter.c \
-	PrettyPrinter.h
+	PrettyPrinter.h \
+	ConfigUI.h \
+	ConfigUI.c
 
-pretty_print_la_CFLAGS = $(AM_CFLAGS) $(LIBXML_CFLAGS)
+pretty_print_la_CFLAGS = $(AM_CFLAGS) $(LIBXML_CFLAGS) -Wall
 pretty_print_la_LIBADD = $(COMMONLIBS) $(LIBXML_LIBS)

Modified: trunk/geany-plugins/pretty-printer/src/PluginEntry.c
===================================================================
--- trunk/geany-plugins/pretty-printer/src/PluginEntry.c	2009-09-03 21:08:56 UTC (rev 917)
+++ trunk/geany-plugins/pretty-printer/src/PluginEntry.c	2009-09-05 14:46:23 UTC (rev 918)
@@ -26,20 +26,20 @@
 //========================================== PLUGIN INFORMATION ==========================================================
 
 PLUGIN_VERSION_CHECK(130)
-PLUGIN_SET_INFO("XML PrettyPrinter", "Formats an XML and make it readable for human.",
-                "1.0", "Cédric Tabin - http://www.astorm.ch");
+PLUGIN_SET_INFO("XML PrettyPrinter", "Formats an XML and makes it readable for human.",
+                "1.1", "Cédric Tabin - http://www.astorm.ch");
 
 //========================================== DECLARATIONS ================================================================
 
 GeanyPlugin*           geany_plugin;
 GeanyData*             geany_data;
 GeanyFunctions*        geany_functions;
-PrettyPrintingOptions* prettyPrintingOptions;
 
-static GtkWidget *main_menu_item = NULL; //the main menu of the plugin
+static GtkWidget* main_menu_item = NULL; //the main menu of the plugin
 
 //declaration of the functions
-static void item_activate_cb(GtkMenuItem *menuitem, gpointer gdata);
+static void xml_format(GtkMenuItem *menuitem, gpointer gdata);
+static void config_closed(GtkWidget* configWidget, gint response, gpointer data);
 void plugin_init(GeanyData *data);
 void plugin_cleanup(void);
 
@@ -56,7 +56,7 @@
     gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), main_menu_item);
 
     //add activation callback
-    g_signal_connect(main_menu_item, "activate", G_CALLBACK(item_activate_cb), NULL);
+    g_signal_connect(main_menu_item, "activate", G_CALLBACK(xml_format), NULL);
 }
 
 void plugin_cleanup(void)
@@ -65,10 +65,28 @@
     gtk_widget_destroy(main_menu_item);
 }
 
+//TODO uncomment when configuration widget ready
+/*GtkWidget* plugin_configure(GtkDialog * dialog)   	
+{
+	//creates the configuration widget
+	GtkWidget* widget = createPrettyPrinterConfigUI(dialog);
+	g_signal_connect(dialog, "response", G_CALLBACK(config_closed), NULL);
+	return widget;
+}*/
+
 //========================================== LISTENERS ===================================================================
 
-void item_activate_cb(GtkMenuItem *menuitem, gpointer gdata)
+void config_closed(GtkWidget* configWidget, gint response, gpointer gdata)
 {
+	//if the user clicked OK or APPLY, then save the settings
+	if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY)
+	{
+		saveSettings();
+	}
+}
+
+void xml_format(GtkMenuItem* menuitem, gpointer gdata)
+{
 	//default printing options
 	if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); }
 	
@@ -104,8 +122,11 @@
 
 	//updates the document
 	sci_set_text(sco, buffer);
-	sci_set_current_position(sco, 0, TRUE);
 	
+	//set the line
+	int xOffset = scintilla_send_message(sco, SCI_GETXOFFSET, NULL, NULL);
+	scintilla_send_message(sco, SCI_LINESCROLL, -xOffset, 0); //TODO update with the right function-call for geany-0.19
+	
 	//sets the type
 	GeanyFiletype* fileType = filetypes_index(GEANY_FILETYPES_XML); 
 	document_set_filetype(doc, fileType);
@@ -113,48 +134,3 @@
 	//free all
 	xmlFreeDoc(xmlDoc);
 }
-
-//TODO create configuration widget
-/*
-GtkWidget* plugin_configure(GtkDialog * dialog)   	
-{
-	//default printing options
-	if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); }
-	
-	GtkWidget* globalBox = gtk_hbox_new(TRUE, 4);
-	GtkWidget* rightBox = gtk_vbox_new(FALSE, 6);
-	GtkWidget* centerBox = gtk_vbox_new(FALSE, 6);
-	GtkWidget* leftBox = gtk_vbox_new(FALSE, 6);
-	
-	GtkWidget* textLabel = gtk_label_new("Text nodes");
-	GtkWidget* textOneLine =   gtk_check_button_new_with_label("One line");
-	GtkWidget* textInline =   gtk_check_button_new_with_label("Inline");
-	
-	GtkWidget* cdataLabel = gtk_label_new("CDATA nodes");
-	GtkWidget* cdataOneLine =   gtk_check_button_new_with_label("One line");
-	GtkWidget* cdataInline =   gtk_check_button_new_with_label("Inline");
-	
-	GtkWidget* commentLabel = gtk_label_new("Comments");
-	GtkWidget* commentOneLine =   gtk_check_button_new_with_label("One line");
-	GtkWidget* commentInline =   gtk_check_button_new_with_label("Inline");
-	
-	gtk_box_pack_start(GTK_BOX(globalBox), leftBox, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(globalBox), centerBox, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(globalBox), rightBox, FALSE, FALSE, 3);
-
-	gtk_box_pack_start(GTK_BOX(leftBox), textLabel, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(centerBox), textOneLine, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(rightBox), textInline, FALSE, FALSE, 3);
-
-	gtk_box_pack_start(GTK_BOX(leftBox), cdataLabel, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(centerBox), cdataOneLine, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(rightBox), cdataInline, FALSE, FALSE, 3);
-	
-	gtk_box_pack_start(GTK_BOX(leftBox), commentLabel, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(centerBox), commentOneLine, FALSE, FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(rightBox), commentInline, FALSE, FALSE, 3);
-
-	gtk_widget_show_all(globalBox);
-	return globalBox;
-}
-*/

Modified: trunk/geany-plugins/pretty-printer/src/PluginEntry.h
===================================================================
--- trunk/geany-plugins/pretty-printer/src/PluginEntry.h	2009-09-03 21:08:56 UTC (rev 917)
+++ trunk/geany-plugins/pretty-printer/src/PluginEntry.h	2009-09-05 14:46:23 UTC (rev 918)
@@ -24,25 +24,14 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <geany.h>
-#include <ui_utils.h>
-#include <plugindata.h>
-#include <editor.h>
-#include <document.h>
-#include <filetypes.h>
-#include <geanyfunctions.h>
-#include <Scintilla.h>
+#include <geanyplugin.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
-#include <glib/gmacros.h>
 #include "PrettyPrinter.h"
+#include "ConfigUI.h"
 
 //========================================== PROPERTIES ========================================================
 
-
-
 //========================================== FUNCTIONS =========================================================
 
-// ???
-
 #endif

Modified: trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c
===================================================================
--- trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c	2009-09-03 21:08:56 UTC (rev 917)
+++ trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c	2009-09-05 14:46:23 UTC (rev 918)
@@ -30,6 +30,7 @@
 static char getPreviousInsertedChar();                                                                  //returns the last inserted char into the new buffer
 static gboolean isWhite(char c);                                                                        //check if the specified char is a white
 static gboolean isLineBreak(char c);                                                                    //check if the specified char is a new line
+static gboolean isQuote(char c);                                                                        //check if the specified char is a quote (simple or double)
 static int putNewLine();                                                                                //put a new line into the new char buffer with the correct number of whites (indentation)
 static gboolean isInlineNodeAllowed();                                                                  //check if it is possible to have an inline node
 static void resetBackwardIndentation(gboolean resetLineBreak);                                          //reset the indentation for the current depth (just reset the index in fact)
@@ -140,7 +141,7 @@
 	PrettyPrintingOptions* options = (PrettyPrintingOptions*)malloc(sizeof(PrettyPrintingOptions));
 	if (options == NULL) 
 	{ 
-		printError("createDefaultPrettyPrintingOptions : Unable to allocate memory"); 
+		g_error("Unable to allocate memory for PrettyPrintingOptions");
 		return NULL; 
 	}
 	
@@ -238,6 +239,14 @@
 	return counter;
 }
 
+gboolean isQuote(char c)
+{
+	if (c == '\'') return TRUE;
+	if (c == '"') return TRUE;
+	
+	return FALSE;
+}
+
 gboolean isWhite(char c)
 {
 	if (c == ' ') return TRUE;
@@ -321,7 +330,11 @@
 void resetBackwardIndentation(gboolean resetLineBreak)
 {
 	xmlPrettyPrintedIndex -= (currentDepth*options->indentLength);
-	if (resetLineBreak) { --xmlPrettyPrintedIndex; }
+	if (resetLineBreak) 
+	{ 
+		int len = strlen(options->newLineChars);
+		xmlPrettyPrintedIndex -= len; 
+	}
 }
 
 //#########################################################################################################################################
@@ -773,7 +786,8 @@
 	while(loop)
 	{
 		char nextChar = readNextChar();
-		if (oldChar == ']' && nextChar == ']') { loop = FALSE; } //end of cdata
+		char nextChar2 = getNextChar();
+		if (oldChar == ']' && nextChar == ']' && nextChar2 == '>') { loop = FALSE; } //end of cdata
 		
 		if (!isLineBreak(nextChar)) //the cdata simply continues
 		{
@@ -813,8 +827,63 @@
 
 void processDoctype()	
 {
-	printError("DOCTYPE is currently not supported by PrettyPrinter\n");
-	result = PRETTY_PRINTING_NOT_SUPPORTED_YET;
+	putNextCharsInBuffer(9); //put the '<!DOCTYPE' into the buffer
+	
+	gboolean loop = TRUE;
+	while(loop)
+	{
+		readWhites();
+		putCharInBuffer(' '); //only one space for the attributes
+		
+		int nextChar = readNextChar();
+		while(!isWhite(nextChar) && 
+		      !isQuote(nextChar) &&  //begins a quoted text
+		      nextChar != '=' && //begins an attribute
+		      nextChar != '>' &&  //end of doctype
+		      nextChar != '[') //inner <!ELEMENT> types
+		{
+			putCharInBuffer(nextChar);
+			nextChar = readNextChar();
+		}
+		
+		if (isWhite(nextChar)) {} //do nothing, just let the next loop do the job
+		else if (isQuote(nextChar) || nextChar == '=')
+		{
+			if (nextChar == '=')
+			{
+				putCharInBuffer(nextChar);
+				nextChar = readNextChar(); //now we should have a quote
+				
+				if (!isQuote(nextChar)) 
+				{ 
+					printError("processDoctype : the next char should be a quote (not '%c')", nextChar); 
+					result = PRETTY_PRINTING_INVALID_CHAR_ERROR; 
+					return; 
+				}
+			}
+			
+			//simply process the content
+			char quote = nextChar;
+			do
+			{
+				putCharInBuffer(nextChar);
+				nextChar = readNextChar();
+			}
+			while (nextChar != quote);
+			putCharInBuffer(nextChar); //now the last char is the last quote
+		}
+		else if (nextChar == '>') //end of doctype
+		{
+			putCharInBuffer(nextChar);
+			loop = FALSE;
+		}
+		else //the char is a '[' => not supported yet
+		{
+			printError("DOCTYPE inner ELEMENT is currently not supported by PrettyPrinter\n");
+			result = PRETTY_PRINTING_NOT_SUPPORTED_YET;
+			loop = FALSE;
+		}
+	}
 }
 
 void processDoctypeElement()


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



More information about the Plugins-Commits mailing list