gchar * getDefaultPrefs (GError** error) { gchar *contents = NULL; gsize size = 0; PrettyPrintingOptions* ppo; ppo = createDefaultPrettyPrintingOptions(); g_return_val_if_fail (ppo != NULL, NULL); contents = prefsToData (ppo, &size, error); return contents; }
/* Will never be used, just here for example */ GtkWidget* createPrettyPrinterConfigUI(GtkDialog * dialog) { PrettyPrintingOptions* ppo; GtkWidget* container; GtkWidget* leftBox; GtkWidget* rightBox; GtkWidget* commentOptions; GtkWidget* textOptions; GtkWidget* cdataOptions; GtkWidget* emptyOptions; GtkWidget* indentationOptions; GtkWidget* lineReturnOptions; /* default printing options */ if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); } ppo = prettyPrintingOptions; container = gtk_hbox_new(FALSE, 10); leftBox = gtk_vbox_new(FALSE, 6); commentOptions = createThreeOptionsBox(_("Comments"), _("Put on one line"), _("Inline if possible"), _("Alignment"), ppo->oneLineComment, ppo->inlineComment, ppo->alignComment, &commentOneLine, &commentInline, &commentAlign); textOptions = createThreeOptionsBox(_("Text nodes"), _("Put on one line"), _("Inline if possible"), _("Alignment"), ppo->oneLineText, ppo->inlineText, ppo->alignText, &textOneLine, &textInline, &textAlign); cdataOptions = createThreeOptionsBox(_("CDATA"), _("Put on one line"), _("Inline if possible"), _("Alignment"), ppo->oneLineCdata, ppo->inlineCdata, ppo->alignCdata, &cdataOneLine, &cdataInline, &cdataAlign); emptyOptions = createEmptyTextOptions(ppo->emptyNodeStripping, ppo->emptyNodeStrippingSpace, ppo->forceEmptyNodeSplit); indentationOptions = createIndentationOptions(ppo->indentChar, ppo->indentLength); 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); 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; }
gboolean prefsLoad (const gchar* filename, GError** error) { PrettyPrintingOptions* ppo; gchar *contents = NULL; gsize size = 0; g_return_val_if_fail (filename != NULL, FALSE); /* default printing options */ if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); } ppo = prettyPrintingOptions; if (!g_file_get_contents (filename, &contents, &size, error)) return FALSE; if (!prefsFromData (ppo, contents, size, error)) { g_free (contents); return FALSE; } g_free (contents); return TRUE; }
void xml_format(GtkMenuItem* menuitem, gpointer gdata) { /* retrieves the current document */ GeanyDocument* doc = document_get_current(); GeanyEditor* editor; ScintillaObject* sco; int length; char* buffer; xmlDoc* parsedDocument; int result; int xOffset; GeanyFiletype* fileType; g_return_if_fail(doc != NULL); editor = doc->editor; sco = editor->sci; /* default printing options */ if (prettyPrintingOptions == NULL) { prettyPrintingOptions = createDefaultPrettyPrintingOptions(); } /* prepare the buffer that will contain the text * from the scintilla object */ length = sci_get_length(sco)+1; buffer = (char*)malloc(length*sizeof(char)); if (buffer == NULL) { exit(-1); } /* malloc error */ /* retrieves the text */ sci_get_text(sco, length, buffer); /* checks if the data is an XML format */ parsedDocument = xmlParseDoc((unsigned char*)buffer); /* this is not a valid xml => exit with an error message */ if(parsedDocument == NULL) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Unable to parse the content as XML.")); return; } /* free all */ xmlFreeDoc(parsedDocument); /* process pretty-printing */ result = processXMLPrettyPrinting(&buffer, &length, prettyPrintingOptions); if (result != PRETTY_PRINTING_SUCCESS) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Unable to process PrettyPrinting on the specified XML because some features are not supported.\n\nSee Help > Debug messages for more details...")); return; } /* updates the document */ sci_set_text(sco, buffer); /* set the line */ xOffset = scintilla_send_message(sco, SCI_GETXOFFSET, 0, 0); scintilla_send_message(sco, SCI_LINESCROLL, -xOffset, 0); /* TODO update with the right function-call for geany-0.19 */ /* sets the type */ fileType = filetypes_index(GEANY_FILETYPES_XML); document_set_filetype(doc, fileType); }