static void instantsave_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { if (enable_instantsave && doc->file_name == NULL) { gchar *new_filename; gint fd; GeanyFiletype *ft = doc->file_type; fd = g_file_open_tmp("gis_XXXXXX", &new_filename, NULL); if (fd != -1) close(fd); /* close the returned file descriptor as we only need the filename */ if (ft == NULL || ft->id == GEANY_FILETYPES_NONE) /* ft is NULL when a new file without template was opened, so use the * configured default file type */ ft = filetypes_lookup_by_name(instantsave_default_ft); if (ft != NULL) /* add the filetype's default extension to the new filename */ SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL)); doc->file_name = new_filename; if (doc->file_type->id == GEANY_FILETYPES_NONE) document_set_filetype(doc, filetypes_lookup_by_name(instantsave_default_ft)); /* force saving the file to enable all the related actions(tab name, filetype, etc.) */ document_save_file(doc, TRUE); } }
static int Document_set_property(Document *self, PyObject *value, const gchar *prop_name) { g_return_val_if_fail(self != NULL, -1); g_return_val_if_fail(value != NULL, -1); g_return_val_if_fail(prop_name != NULL, -1); if (!self->doc) { PyErr_SetString(PyExc_RuntimeError, "Document instance not initialized properly"); return -1; } if (g_str_equal(prop_name, "encoding")) { gchar *encoding = PyString_AsString(value); if (encoding) { document_set_encoding(self->doc, encoding); return 0; } } else if (g_str_equal(prop_name, "filetype")) { Filetype *filetype = (Filetype *) value; if (filetype->ft) { document_set_filetype(self->doc, filetype->ft); return 0; } } else if (g_str_equal(prop_name, "text_changed")) { long v = PyInt_AsLong(value); if (v == -1 && PyErr_Occurred()) { PyErr_Print(); return -1; } document_set_text_changed(self->doc, (gboolean) v); return 0; } PyErr_SetString(PyExc_AttributeError, "can't set property"); return -1; }
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); }