lists.geany.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
List overview
Plugins-Commits
July 2011
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
plugins-commits@lists.geany.org
3 participants
12 discussions
Start a n
N
ew thread
SF.net SVN: geany-plugins:[2104] trunk/geany-plugins/pretty-printer/src
by ctabin@users.sourceforge.net
22 Jul '11
22 Jul '11
Revision: 2104
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2104&view=rev
Author: ctabin Date: 2011-07-22 12:33:30 +0000 (Fri, 22 Jul 2011) Log Message: ----------- XML Pretty-Printer: a lot of warning fixed Modified Paths: -------------- trunk/geany-plugins/pretty-printer/src/ConfigUI.c trunk/geany-plugins/pretty-printer/src/PluginEntry.c trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h Modified: trunk/geany-plugins/pretty-printer/src/ConfigUI.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/ConfigUI.c 2011-07-22 09:57:55 UTC (rev 2103) +++ trunk/geany-plugins/pretty-printer/src/ConfigUI.c 2011-07-22 12:33:30 UTC (rev 2104) @@ -167,11 +167,11 @@ GtkWidget* leftBox = gtk_vbox_new(FALSE, 6); GtkWidget* lbl = gtk_label_new("Indentation"); - GtkWidget* comboChar = gtk_combo_box_text_new(); + GtkWidget* comboChar = gtk_combo_box_new_text(); GtkWidget* spinIndent = gtk_spin_button_new_with_range(0, 100, 1); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "Tab"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "Space"); + gtk_combo_box_append_text(GTK_COMBO_BOX(comboChar), "Tab"); + gtk_combo_box_append_text(GTK_COMBO_BOX(comboChar), "Space"); gtk_combo_box_set_active(GTK_COMBO_BOX(comboChar), (indentation == ' ') ? 1 : 0); gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinIndent), count); @@ -196,11 +196,11 @@ GtkWidget* leftBox = gtk_vbox_new(FALSE, 6); GtkWidget* lbl = gtk_label_new("Line break"); - GtkWidget* comboChar = gtk_combo_box_text_new(); + GtkWidget* comboChar = gtk_combo_box_new_text(); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\r"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\n"); - gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\r\\n"); + gtk_combo_box_append_text(GTK_COMBO_BOX(comboChar), "\\r"); + gtk_combo_box_append_text(GTK_COMBO_BOX(comboChar), "\\n"); + gtk_combo_box_append_text(GTK_COMBO_BOX(comboChar), "\\r\\n"); int active = 0; if (strlen(lineReturn) == 2) active = 2; Modified: trunk/geany-plugins/pretty-printer/src/PluginEntry.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/PluginEntry.c 2011-07-22 09:57:55 UTC (rev 2103) +++ trunk/geany-plugins/pretty-printer/src/PluginEntry.c 2011-07-22 12:33:30 UTC (rev 2104) @@ -25,10 +25,10 @@ //========================================== PLUGIN INFORMATION ========================================================== -PLUGIN_VERSION_CHECK(130); +PLUGIN_VERSION_CHECK(130) PLUGIN_SET_INFO("XML PrettyPrinter", "Formats an XML and makes it human-readable.", - "1.11", "Cédric Tabin -
http://www.astorm.ch
"); -PLUGIN_KEY_GROUP(prettyprinter, 1); + "1.2", "Cédric Tabin -
http://www.astorm.ch
") +PLUGIN_KEY_GROUP(prettyprinter, 1) //========================================== DECLARATIONS ================================================================ @@ -96,12 +96,12 @@ } } -static void kb_run_xml_pretty_print(G_GNUC_UNUSED guint key_id) +void kb_run_xml_pretty_print(G_GNUC_UNUSED guint key_id) { xml_format(NULL, NULL); } -static void xml_format(GtkMenuItem* menuitem, gpointer gdata) +void xml_format(GtkMenuItem* menuitem, gpointer gdata) { //retrieves the current document GeanyDocument* doc = document_get_current(); Modified: trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c 2011-07-22 09:57:55 UTC (rev 2103) +++ trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c 2011-07-22 12:33:30 UTC (rev 2104) @@ -22,7 +22,7 @@ //xml pretty printing functions static void putCharInBuffer(char charToAdd); //put a char into the new char buffer -static void putCharsInBuffer(char* charsToAdd); //put the chars into the new char buffer +static void putCharsInBuffer(const char* charsToAdd); //put the chars into the new char buffer static void putNextCharsInBuffer(int nbChars); //put the next nbChars of the input buffer into the new buffer static int readWhites(gboolean considerLineBreakAsWhite); //read the next whites into the input buffer static char readNextChar(); //read the next char into the input buffer; @@ -49,7 +49,7 @@ static void processDoctypeElement(); //process a DOCTYPE ELEMENT node //debug function -static void printError(char *msg, ...); //just print a message like the printf method +static void printError(const char *msg, ...); //just print a message like the printf method static void printDebugStatus(); //just print some variables into the console for debugging //============================================ PRIVATE PROPERTIES ====================================== @@ -139,30 +139,30 @@ PrettyPrintingOptions* createDefaultPrettyPrintingOptions() { - PrettyPrintingOptions* options = (PrettyPrintingOptions*)malloc(sizeof(PrettyPrintingOptions)); - if (options == NULL) + PrettyPrintingOptions* defaultOptions = (PrettyPrintingOptions*)malloc(sizeof(PrettyPrintingOptions)); + if (defaultOptions == NULL) { g_error("Unable to allocate memory for PrettyPrintingOptions"); return NULL; } - options->newLineChars = "\r\n"; - options->indentChar = ' '; - options->indentLength = 2; - options->oneLineText = FALSE; - options->inlineText = TRUE; - options->oneLineComment = FALSE; - options->inlineComment = TRUE; - options->oneLineCdata = FALSE; - options->inlineCdata = TRUE; - options->emptyNodeStripping = TRUE; - options->emptyNodeStrippingSpace = TRUE; - options->forceEmptyNodeSplit = FALSE; - options->trimLeadingWhites = TRUE; - options->trimTrailingWhites = TRUE; - options->commentAlign = TRUE; + defaultOptions->newLineChars = "\r\n"; + defaultOptions->indentChar = ' '; + defaultOptions->indentLength = 2; + defaultOptions->oneLineText = FALSE; + defaultOptions->inlineText = TRUE; + defaultOptions->oneLineComment = FALSE; + defaultOptions->inlineComment = TRUE; + defaultOptions->oneLineCdata = FALSE; + defaultOptions->inlineCdata = TRUE; + defaultOptions->emptyNodeStripping = TRUE; + defaultOptions->emptyNodeStrippingSpace = TRUE; + defaultOptions->forceEmptyNodeSplit = FALSE; + defaultOptions->trimLeadingWhites = TRUE; + defaultOptions->trimTrailingWhites = TRUE; + defaultOptions->commentAlign = TRUE; - return options; + return defaultOptions; } void putNextCharsInBuffer(int nbChars) @@ -191,13 +191,13 @@ ++xmlPrettyPrintedIndex; } -void putCharsInBuffer(char* charsToAdd) +void putCharsInBuffer(const char* charsToAdd) { - int index = 0; - while (charsToAdd[index] != '\0') + int currentIndex = 0; + while (charsToAdd[currentIndex] != '\0') { - putCharInBuffer(charsToAdd[index]); - ++index; + putCharInBuffer(charsToAdd[currentIndex]); + ++currentIndex; } } @@ -278,7 +278,7 @@ int secondChar = inputBuffer[inputBufferIndex+1]; //should be '!' int thirdChar = inputBuffer[inputBufferIndex+2]; //should be '-' or '[' - int index = inputBufferIndex+1; + int currentIndex = inputBufferIndex+1; if (firstChar == '<') { //another node is being open ==> no inline ! @@ -292,33 +292,33 @@ //read until closing char oldChar = ' '; - index += 3; //that by pass meanless chars + currentIndex += 3; //that by pass meanless chars gboolean loop = TRUE; while (loop) { - char current = inputBuffer[index]; + char current = inputBuffer[currentIndex]; if (current == closingComment && oldChar == closingComment) { loop = FALSE; } //end of comment oldChar = current; - ++index; + ++currentIndex; } //okay now avoid blanks // inputBuffer[index] is now '>' - ++index; - while (isWhite(inputBuffer[index])) { ++index; } + ++currentIndex; + while (isWhite(inputBuffer[currentIndex])) { ++currentIndex; } } else { //this is a text node. Simply loop to the next '<' - while (inputBuffer[index] != '<') { ++index; } + while (inputBuffer[currentIndex] != '<') { ++currentIndex; } } //check what do we have now - char currentChar = inputBuffer[index]; + char currentChar = inputBuffer[currentIndex]; if (currentChar == '<') { //check if that is a closing node - currentChar = inputBuffer[index+1]; + currentChar = inputBuffer[currentIndex+1]; if (currentChar == '/') { //as we are in a correct XML (so far...), if the node is @@ -334,13 +334,13 @@ gboolean isOnSingleLine(int skip, char stop1, char stop2) { int currentIndex = inputBufferIndex+skip; //skip the n first chars (in comment <!--) - gboolean isOnSingleLine = TRUE; + gboolean onSingleLine = TRUE; char oldChar = inputBuffer[currentIndex]; char currentChar = inputBuffer[currentIndex+1]; - while(isOnSingleLine && oldChar != stop1 && currentChar != stop2) + while(onSingleLine && oldChar != stop1 && currentChar != stop2) { - isOnSingleLine = !isLineBreak(oldChar); + onSingleLine = !isLineBreak(oldChar); ++currentIndex; oldChar = currentChar; @@ -352,7 +352,7 @@ * are only spaces and it may be wanted to be considered as a single * line). //TODO externalize an option for that ? */ - if (!isOnSingleLine) + if (!onSingleLine) { while(oldChar != stop1 && currentChar != stop2) { @@ -370,7 +370,7 @@ } } - return isOnSingleLine; + return onSingleLine; } void resetBackwardIndentation(gboolean resetLineBreak) @@ -575,8 +575,8 @@ int i; for (i=0 ; i<nodeNameLength ; ++i) { - int index = xmlPrettyPrintedIndex-nodeNameLength+i; - nodeName[i] = xmlPrettyPrinted[index]; + int tempIndex = xmlPrettyPrintedIndex-nodeNameLength+i; + nodeName[i] = xmlPrettyPrinted[tempIndex]; } currentNodeName = nodeName; //set the name for using in other methods @@ -711,14 +711,14 @@ if (!loop && options->commentAlign) //end of comment { //ensures the chars preceding the first '-' are all spaces - gboolean rewind = xmlPrettyPrinted[xmlPrettyPrintedIndex-3] == ' ' && - xmlPrettyPrinted[xmlPrettyPrintedIndex-4] == ' ' && - xmlPrettyPrinted[xmlPrettyPrintedIndex-5] == ' ' && - xmlPrettyPrinted[xmlPrettyPrintedIndex-6] == ' ' && - xmlPrettyPrinted[xmlPrettyPrintedIndex-7] == ' '; + gboolean onlySpaces = xmlPrettyPrinted[xmlPrettyPrintedIndex-3] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-4] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-5] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-6] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-7] == ' '; //if all the preceding chars are white, then go for replacement - if (rewind) + if (onlySpaces) { xmlPrettyPrintedIndex -= 7; //remove indentation spaces putCharsInBuffer("--"); //reset the first chars of '-->' @@ -975,7 +975,7 @@ result = PRETTY_PRINTING_NOT_SUPPORTED_YET; } -void printError(char *msg, ...) +void printError(const char *msg, ...) { va_list va; va_start(va, msg); Modified: trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h =================================================================== --- trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h 2011-07-22 09:57:55 UTC (rev 2103) +++ trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h 2011-07-22 12:33:30 UTC (rev 2104) @@ -43,7 +43,7 @@ */ typedef struct { - char* newLineChars; //char used to generate a new line (generally \r\n) + const char* newLineChars; //char used to generate a new line (generally \r\n) char indentChar; //char used for indentation int indentLength; //number of char to use for indentation (by default 2 spaces) gboolean oneLineText; //text is put on one line This was sent by the
SourceForge.net
collaborative development platform, the world's largest Open Source development site.
1
0
0
0
SF.net SVN: geany-plugins:[2103] trunk/geany-plugins/pretty-printer/src
by ctabin@users.sourceforge.net
22 Jul '11
22 Jul '11
Revision: 2103
http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2103&view=rev
Author: ctabin Date: 2011-07-22 09:57:55 +0000 (Fri, 22 Jul 2011) Log Message: ----------- XML Pretty-Printer: Configuration panel added and new features for comments and text node formatting Modified Paths: -------------- trunk/geany-plugins/pretty-printer/src/ConfigUI.c trunk/geany-plugins/pretty-printer/src/PluginEntry.c trunk/geany-plugins/pretty-printer/src/PluginEntry.h trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h Modified: trunk/geany-plugins/pretty-printer/src/ConfigUI.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/ConfigUI.c 2011-06-26 22:03:46 UTC (rev 2102) +++ trunk/geany-plugins/pretty-printer/src/ConfigUI.c 2011-07-22 09:57:55 UTC (rev 2103) @@ -18,65 +18,203 @@ #include "ConfigUI.h" -//redefine the variable declared as extern +//======================= FUNCTIONS ==================================================================== + +static GtkWidget* createTwoOptionsBox(const char* label, const char* checkBox1, const char* checkBox2, gboolean cb1Active, gboolean cb2Active, GtkWidget** option1, GtkWidget** option2); +static GtkWidget* createEmptyTextOptions(gboolean emptyNodeStripping, gboolean emptyNodeStrippingSpace, gboolean forceEmptyNodeSplit); +static GtkWidget* createIndentationOptions(char indentation, int count); +static GtkWidget* createLineReturnOptions(const char* lineReturn); + +//============================================ PRIVATE PROPERTIES ====================================== + +static GtkWidget* commentOneLine; +static GtkWidget* commentInline; +static GtkWidget* textOneLine; +static GtkWidget* textInline; +static GtkWidget* cdataOneLine; +static GtkWidget* cdataInline; +static GtkWidget* emptyNodeStripping; +static GtkWidget* emptyNodeStrippingSpace; +static GtkWidget* emptyNodeSplit; +static GtkWidget* indentationChar; +static GtkWidget* indentationCount; +static GtkWidget* lineBreak; + +//============================================= PUBLIC FUNCTIONS ======================================== + +//redeclaration of extern variable PrettyPrintingOptions* prettyPrintingOptions; -GtkWidget* createPrettyPrinterConfigUI(GtkDialog* dialog) +//Will never be used, just here for example +GtkWidget* createPrettyPrinterConfigUI(GtkDialog * dialog) { //default printing options if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); } + PrettyPrintingOptions* ppo = prettyPrintingOptions; + + GtkWidget* container = gtk_hbox_new(FALSE, 10); - //TODO create configuration widget + GtkWidget* leftBox = gtk_vbox_new(TRUE, 6); + GtkWidget* commentOptions = createTwoOptionsBox("Comments", "Put on one line", "Inline if possible", ppo->oneLineComment, ppo->inlineComment, &commentOneLine, &commentInline); + GtkWidget* textOptions = createTwoOptionsBox("Text nodes", "Put on one line", "Inline if possible", ppo->oneLineText, ppo->inlineText, &textOneLine, &textInline); + GtkWidget* cdataOptions = createTwoOptionsBox("CDATA", "Put on one line", "Inline if possible", ppo->oneLineCdata, ppo->inlineCdata, &cdataOneLine, &cdataInline); + GtkWidget* emptyOptions = createEmptyTextOptions(ppo->emptyNodeStripping, ppo->emptyNodeStrippingSpace, ppo->forceEmptyNodeSplit); + GtkWidget* indentationOptions = createIndentationOptions(ppo->indentChar, ppo->indentLength); + GtkWidget* lineReturnOptions = createLineReturnOptions(ppo->newLineChars); + + gtk_box_pack_start(GTK_BOX(leftBox), commentOptions, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(leftBox), textOptions, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(leftBox), cdataOptions, FALSE, FALSE, 3); - return NULL; + GtkWidget* rightBox = gtk_vbox_new(FALSE, 6); + gtk_box_pack_start(GTK_BOX(rightBox), emptyOptions, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), indentationOptions, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), lineReturnOptions, FALSE, FALSE, 3); + + gtk_box_pack_start(GTK_BOX(container), leftBox, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(container), rightBox, FALSE, FALSE, 3); + + gtk_widget_show_all(container); + return container; } void saveSettings() { - //TODO save settings into a file + PrettyPrintingOptions* ppo = prettyPrintingOptions; + + ppo->oneLineComment = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(commentOneLine)); + ppo->inlineComment = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(commentInline)); + ppo->oneLineText = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(textOneLine)); + ppo->inlineText = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(textInline)); + ppo->oneLineCdata = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cdataOneLine)); + ppo->inlineCdata = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cdataInline)); + + ppo->emptyNodeStripping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(emptyNodeStripping)); + ppo->emptyNodeStrippingSpace = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(emptyNodeStrippingSpace)); + ppo->forceEmptyNodeSplit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(emptyNodeSplit)); + + ppo->indentLength = gtk_spin_button_get_value(GTK_SPIN_BUTTON(indentationCount)); + ppo->indentChar = gtk_combo_box_get_active(GTK_COMBO_BOX(indentationChar))==0 ? '\t' : ' '; + + int breakStyle = gtk_combo_box_get_active(GTK_COMBO_BOX(lineBreak)); + if (breakStyle == 0) ppo->newLineChars = "\r"; + else if (breakStyle == 1) ppo->newLineChars = "\n"; + else ppo->newLineChars = "\r\n"; } +//============================================= PRIVATE FUNCTIONS ======================================= -//Will never be used, just here for example -/*GtkWidget* plugin_configure(GtkDialog * dialog) +GtkWidget* createTwoOptionsBox(const char* label, const char* checkBox1, const char* checkBox2, gboolean cb1Active, gboolean cb2Active, GtkWidget** option1, GtkWidget** option2) { - //default printing options - if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); } + GtkWidget* container = gtk_hbox_new(TRUE, 2); + GtkWidget* rightBox = gtk_vbox_new(FALSE, 6); + GtkWidget* leftBox = gtk_vbox_new(FALSE, 6); - GtkWidget* globalBox = gtk_hbox_new(TRUE, 4); + GtkWidget* lbl = gtk_label_new(label); + GtkWidget* chb1 = gtk_check_button_new_with_label(checkBox1); + GtkWidget* chb2 = gtk_check_button_new_with_label(checkBox2); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chb1), cb1Active); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chb2), cb2Active); + + gtk_box_pack_start(GTK_BOX(container), leftBox, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(container), rightBox, FALSE, FALSE, 3); + + gtk_box_pack_start(GTK_BOX(leftBox), lbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), chb1, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), chb2, FALSE, FALSE, 3); + + *option1 = chb1; + *option2 = chb2; + + return container; +} + +GtkWidget* createEmptyTextOptions(gboolean optEmptyNodeStripping, gboolean optEmptyNodeStrippingSpace, gboolean optForceEmptyNodeSplit) +{ + GtkWidget* container = gtk_hbox_new(FALSE, 2); 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* lbl = gtk_label_new("Empty nodes"); + GtkWidget* chb1 = gtk_check_button_new_with_label("Concatenation (<x></x> to <x/>)"); + GtkWidget* chb2 = gtk_check_button_new_with_label("Spacing (<x/> to <x />)"); + GtkWidget* chb3 = gtk_check_button_new_with_label("Expansion (<x/> to <x></x>)"); - 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"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chb1), optEmptyNodeStripping); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chb2), optEmptyNodeStrippingSpace); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chb3), optForceEmptyNodeSplit); - 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(container), leftBox, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(container), rightBox, FALSE, FALSE, 3); - 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), lbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), chb1, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), chb2, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), chb3, FALSE, FALSE, 3); + + emptyNodeStripping = chb1; + emptyNodeStrippingSpace = chb2; + emptyNodeSplit = chb3; + + return container; +} - 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); +GtkWidget* createIndentationOptions(char indentation, int count) +{ + GtkWidget* container = gtk_hbox_new(FALSE, 20); + GtkWidget* rightBox = gtk_hbox_new(FALSE, 6); + GtkWidget* leftBox = gtk_vbox_new(FALSE, 6); + + GtkWidget* lbl = gtk_label_new("Indentation"); + GtkWidget* comboChar = gtk_combo_box_text_new(); + GtkWidget* spinIndent = gtk_spin_button_new_with_range(0, 100, 1); + + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "Tab"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "Space"); + gtk_combo_box_set_active(GTK_COMBO_BOX(comboChar), (indentation == ' ') ? 1 : 0); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinIndent), count); + + gtk_box_pack_start(GTK_BOX(leftBox), lbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), comboChar, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), spinIndent, FALSE, FALSE, 3); + + gtk_box_pack_start(GTK_BOX(container), leftBox, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(container), rightBox, FALSE, FALSE, 3); + + indentationChar = comboChar; + indentationCount = spinIndent; + + return container; +} - 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); +static GtkWidget* createLineReturnOptions(const char* lineReturn) +{ + GtkWidget* container = gtk_hbox_new(FALSE, 25); + GtkWidget* rightBox = gtk_hbox_new(FALSE, 6); + GtkWidget* leftBox = gtk_vbox_new(FALSE, 6); - 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; + GtkWidget* lbl = gtk_label_new("Line break"); + GtkWidget* comboChar = gtk_combo_box_text_new(); + + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\r"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\n"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(comboChar), "\\r\\n"); + + int active = 0; + if (strlen(lineReturn) == 2) active = 2; + else if (lineReturn[0] == '\n') active = 1; + + gtk_combo_box_set_active(GTK_COMBO_BOX(comboChar), active); + + gtk_box_pack_start(GTK_BOX(leftBox), lbl, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(rightBox), comboChar, FALSE, FALSE, 3); + + gtk_box_pack_start(GTK_BOX(container), leftBox, FALSE, FALSE, 3); + gtk_box_pack_start(GTK_BOX(container), rightBox, FALSE, FALSE, 3); + + lineBreak = comboChar; + + return container; } -*/ Modified: trunk/geany-plugins/pretty-printer/src/PluginEntry.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/PluginEntry.c 2011-06-26 22:03:46 UTC (rev 2102) +++ trunk/geany-plugins/pretty-printer/src/PluginEntry.c 2011-07-22 09:57:55 UTC (rev 2103) @@ -41,8 +41,11 @@ //declaration of the functions static void xml_format(GtkMenuItem *menuitem, gpointer gdata); static void kb_run_xml_pretty_print(G_GNUC_UNUSED guint key_id); +static void config_closed(GtkWidget* configWidget, gint response, gpointer data); + void plugin_init(GeanyData *data); void plugin_cleanup(void); +GtkWidget* plugin_configure(GtkDialog * dialog); //========================================== FUNCTIONS =================================================================== @@ -73,29 +76,25 @@ gtk_widget_destroy(main_menu_item); } -#ifdef PLUGIN_XMLPP_GUI - static void config_closed(GtkWidget* configWidget, gint response, gpointer data); +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; +} - 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 config_closed(GtkWidget* configWidget, gint response, 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) { - //if the user clicked OK or APPLY, then save the settings - if (response == GTK_RESPONSE_OK || - response == GTK_RESPONSE_APPLY) - { - saveSettings(); - } + saveSettings(); } -#endif +} static void kb_run_xml_pretty_print(G_GNUC_UNUSED guint key_id) { @@ -124,15 +123,18 @@ sci_get_text(sco, length, buffer); //checks if the data is an XML format - xmlDoc* xmlDoc = xmlParseDoc((unsigned char*)buffer); + xmlDoc* parsedDocument = xmlParseDoc((unsigned char*)buffer); //this is not a valid xml => exit with an error message - if(xmlDoc == NULL) + if(parsedDocument == NULL) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, "Unable to parse the content as XML."); return; } + //free all + xmlFreeDoc(parsedDocument); + //process pretty-printing int result = processXMLPrettyPrinting(&buffer, &length, prettyPrintingOptions); if (result != PRETTY_PRINTING_SUCCESS) @@ -151,7 +153,4 @@ //sets the type GeanyFiletype* fileType = filetypes_index(GEANY_FILETYPES_XML); document_set_filetype(doc, fileType); - - //free all - xmlFreeDoc(xmlDoc); } Modified: trunk/geany-plugins/pretty-printer/src/PluginEntry.h =================================================================== --- trunk/geany-plugins/pretty-printer/src/PluginEntry.h 2011-06-26 22:03:46 UTC (rev 2102) +++ trunk/geany-plugins/pretty-printer/src/PluginEntry.h 2011-07-22 09:57:55 UTC (rev 2103) @@ -19,9 +19,6 @@ #ifndef PLUGIN_ENTRY_H #define PLUGIN_ENTRY_H -// This constants will be enabled once the preferences GUI will be finished :) -//#define PLUGIN_XMLPP_GUI - //========================================== INCLUDES ========================================================== #include <stdlib.h> Modified: trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c =================================================================== --- trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c 2011-06-26 22:03:46 UTC (rev 2102) +++ trunk/geany-plugins/pretty-printer/src/PrettyPrinter.c 2011-07-22 09:57:55 UTC (rev 2103) @@ -24,7 +24,7 @@ static void putCharInBuffer(char charToAdd); //put a char into the new char buffer static void putCharsInBuffer(char* charsToAdd); //put the chars into the new char buffer static void putNextCharsInBuffer(int nbChars); //put the next nbChars of the input buffer into the new buffer -static int readWhites(); //read the next whites into the input buffer +static int readWhites(gboolean considerLineBreakAsWhite); //read the next whites into the input buffer static char readNextChar(); //read the next char into the input buffer; static char getNextChar(); //returns the next char but do not increase the input buffer index (use readNextChar for that) static char getPreviousInsertedChar(); //returns the last inserted char into the new buffer @@ -33,6 +33,7 @@ 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 gboolean isOnSingleLine(int skip, char stop1, char stop2);//check if the current node data is on one line (for inlining) static void resetBackwardIndentation(gboolean resetLineBreak); //reset the indentation for the current depth (just reset the index in fact) //specific parsing functions @@ -98,7 +99,7 @@ if (xmlPrettyPrinted == NULL) { g_error("Allocation error"); } //go to the first char - readWhites(); + readWhites(TRUE); //process the pretty-printing processElements(); @@ -148,17 +149,18 @@ options->newLineChars = "\r\n"; options->indentChar = ' '; options->indentLength = 2; - options->oneLineText = TRUE; + options->oneLineText = FALSE; options->inlineText = TRUE; - options->oneLineComment = TRUE; + options->oneLineComment = FALSE; options->inlineComment = TRUE; - options->oneLineCdata = TRUE; + options->oneLineCdata = FALSE; options->inlineCdata = TRUE; options->emptyNodeStripping = TRUE; options->emptyNodeStrippingSpace = TRUE; options->forceEmptyNodeSplit = FALSE; options->trimLeadingWhites = TRUE; options->trimTrailingWhites = TRUE; + options->commentAlign = TRUE; return options; } @@ -227,10 +229,12 @@ return inputBuffer[inputBufferIndex++]; } -int readWhites() +int readWhites(gboolean considerLineBreakAsWhite) { int counter = 0; - while(isWhite(inputBuffer[inputBufferIndex])) + while(isWhite(inputBuffer[inputBufferIndex]) && + (!isLineBreak(inputBuffer[inputBufferIndex]) || + considerLineBreakAsWhite)) { ++counter; ++inputBufferIndex; @@ -327,6 +331,48 @@ return FALSE; } +gboolean isOnSingleLine(int skip, char stop1, char stop2) +{ + int currentIndex = inputBufferIndex+skip; //skip the n first chars (in comment <!--) + gboolean isOnSingleLine = TRUE; + + char oldChar = inputBuffer[currentIndex]; + char currentChar = inputBuffer[currentIndex+1]; + while(isOnSingleLine && oldChar != stop1 && currentChar != stop2) + { + isOnSingleLine = !isLineBreak(oldChar); + + ++currentIndex; + oldChar = currentChar; + currentChar = inputBuffer[currentIndex+1]; + + /** + * A line break inside the node has been reached. But we should check + * if there is something before the end of the node (otherwise, there + * are only spaces and it may be wanted to be considered as a single + * line). //TODO externalize an option for that ? + */ + if (!isOnSingleLine) + { + while(oldChar != stop1 && currentChar != stop2) + { + //okay there is something else => this is not on one line + if (!isWhite(oldChar)) return FALSE; + + ++currentIndex; + oldChar = currentChar; + currentChar = inputBuffer[currentIndex+1]; + } + + //the end of the node has been reached with only whites. Then + //the node can be considered being one single line + return TRUE; + } + } + + return isOnSingleLine; +} + void resetBackwardIndentation(gboolean resetLineBreak) { xmlPrettyPrintedIndex -= (currentDepth*options->indentLength); @@ -355,7 +401,7 @@ while (loop && result == PRETTY_PRINTING_SUCCESS) { //strip unused whites - readWhites(); + readWhites(TRUE); char nextChar = getNextChar(); if (nextChar == '\0') { return 0; } //no more data to read @@ -459,7 +505,7 @@ gboolean loop = TRUE; while (loop) { - readWhites(); //strip the whites + readWhites(TRUE); //strip the whites char next = getNextChar(); //don't read the last char (processed afterwards) if (next == '/') { loop = FALSE; } /* end of node */ @@ -492,7 +538,7 @@ while(!isWhite(getNextChar())) { putNextCharsInBuffer(1); } - readWhites(); + readWhites(TRUE); processElementAttributes(); //puts the '?' and '>' chars into the new buffer @@ -537,7 +583,7 @@ lastNodeOpen = TRUE; //process the attributes - readWhites(); + readWhites(TRUE); processElementAttributes(); //process the end of the tag @@ -642,6 +688,7 @@ { gboolean inlineAllowed = FALSE; if (options->inlineComment) { inlineAllowed = isInlineNodeAllowed(); } + if (inlineAllowed && !options->oneLineComment) { inlineAllowed = isOnSingleLine(4, '-', '-'); } if (inlineAllowed) { resetBackwardIndentation(TRUE); } putNextCharsInBuffer(4); //add the chars '<!--' @@ -660,18 +707,45 @@ { putCharInBuffer(nextChar); oldChar = nextChar; + + if (!loop && options->commentAlign) //end of comment + { + //ensures the chars preceding the first '-' are all spaces + gboolean rewind = xmlPrettyPrinted[xmlPrettyPrintedIndex-3] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-4] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-5] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-6] == ' ' && + xmlPrettyPrinted[xmlPrettyPrintedIndex-7] == ' '; + + //if all the preceding chars are white, then go for replacement + if (rewind) + { + xmlPrettyPrintedIndex -= 7; //remove indentation spaces + putCharsInBuffer("--"); //reset the first chars of '-->' + } + } } - else if (!options->oneLineComment) //oh ! there is a line break + else if (!options->oneLineComment && !inlineAllowed) //oh ! there is a line break { - readWhites(); //strip the whites and new line - putNewLine(); //put a new indentation line + int read = readWhites(FALSE); //strip the whites and new line + if (nextChar == '\r' && read == 0 && getNextChar() == '\n') //handles the \r\n return line + { + readNextChar(); + readWhites(FALSE); + } + + //if the comments need to be aligned, just add 5 spaces + if (options->commentAlign) + { + putNewLine(); //put a new indentation line + putCharsInBuffer(" "); + } + oldChar = ' '; //and update the last char - - //TODO manage relative spacing } else //the comments must be inlined { - readWhites(); //strip the whites and add a space if needed + readWhites(TRUE); //strip the whites and add a space if needed if (getPreviousInsertedChar() != ' ') { putCharInBuffer(' '); @@ -699,6 +773,7 @@ //checks if inline is allowed gboolean inlineTextAllowed = FALSE; if (options->inlineText) { inlineTextAllowed = isInlineNodeAllowed(); } + if (inlineTextAllowed && !options->oneLineText) { inlineTextAllowed = isOnSingleLine(0, '<', '/'); } if (inlineTextAllowed) { resetBackwardIndentation(TRUE); } //remove previous indentation //the leading whites are automatically stripped. So we re-add it @@ -730,9 +805,10 @@ char nextChar = readNextChar(); if (isLineBreak(nextChar)) { - readWhites(); if (options->oneLineText) { + readWhites(TRUE); + //as we can put text on one line, remove the line break //and replace it by a space but only if the previous //char wasn't a space @@ -743,6 +819,13 @@ } else { + int read = readWhites(FALSE); + if (nextChar == '\r' && read == 0 && getNextChar() == '\n') //handles the '\r\n' + { + nextChar = readNextChar(); + readWhites(FALSE); + } + //put a new line only if the closing tag is not reached if (getNextChar() != '<') { @@ -796,7 +879,7 @@ } else if (!options->oneLineCdata) { - readWhites(); //strip the whites and new line + readWhites(TRUE); //strip the whites and new line putNewLine(); //put a new indentation line oldChar = ' '; //and update the last char @@ -804,7 +887,7 @@ } else //cdata are inlined { - readWhites(); //strip the whites and add a space if necessary + readWhites(TRUE); //strip the whites and add a space if necessary if(getPreviousInsertedChar() != ' ') { putCharInBuffer(' '); } } } @@ -832,7 +915,7 @@ gboolean loop = TRUE; while(loop) { - readWhites(); + readWhites(TRUE); putCharInBuffer(' '); //only one space for the attributes int nextChar = readNextChar(); @@ -892,7 +975,7 @@ result = PRETTY_PRINTING_NOT_SUPPORTED_YET; } -void printError(char *msg, ...) +void printError(char *msg, ...) { va_list va; va_start(va, msg); @@ -902,7 +985,7 @@ //TODO also do a fprintf on stderr ? printDebugStatus(); -} +} void printDebugStatus() { Modified: trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h =================================================================== --- trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h 2011-06-26 22:03:46 UTC (rev 2102) +++ trunk/geany-plugins/pretty-printer/src/PrettyPrinter.h 2011-07-22 09:57:55 UTC (rev 2103) @@ -57,7 +57,8 @@ gboolean forceEmptyNodeSplit; //force an empty node to be splitted : <node /> becomes <node></node> (only if emptyNodeStripping = false) gboolean trimLeadingWhites; //trim the leading whites in a text node gboolean trimTrailingWhites; //trim the trailing whites in a text node -} + gboolean commentAlign; //align the comments: add 5 spaces in indentation (only if oneLineComment = false) +} PrettyPrintingOptions; //========================================== FUNCTIONS ========================================================= This was sent by the
SourceForge.net
collaborative development platform, the world's largest Open Source development site.
1
0
0
0
← Newer
1
2
Older →
Jump to page:
1
2
Results per page:
10
25
50
100
200