/* Get or Set the entire text of the currently active Geany document */ static gint glspi_text(lua_State* L) { GeanyDocument *doc = document_get_current(); if (!doc) { return 0; } if (0 == lua_gettop(L)) { /* Called with no args, GET the current text */ gint len = sci_get_length(doc->editor->sci); gchar *txt = NULL; if (len>0) { txt = g_malloc0((guint)len+2); sci_get_text(doc->editor->sci, len+1, txt); lua_pushstring(L, (const gchar *) txt); g_free(txt); } else { lua_pushstring(L, ""); } return 1; } else { /* Called with one arg, SET the current text */ const gchar*txt; if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); } txt = lua_tostring(L, 1); sci_set_text(doc->editor->sci, txt); return 0; } }
/* name should be in UTF-8, and can have a path. */ static void show_output(const gchar * std_output, const gchar * name, const gchar * force_encoding, gint filetype_new_file) { gint page; GtkNotebook *book; GeanyDocument *doc, *cur_doc; if (std_output) { cur_doc = document_get_current(); doc = document_find_by_filename(name); if (doc == NULL) { doc = document_new_file(name, filetypes[filetype_new_file], std_output); } else { sci_set_text(doc->editor->sci, std_output); book = GTK_NOTEBOOK(geany->main_widgets->notebook); page = gtk_notebook_page_num(book, GTK_WIDGET(doc->editor->sci)); gtk_notebook_set_current_page(book, page); } document_set_text_changed(doc, FALSE); document_set_encoding(doc, (force_encoding ? force_encoding : "UTF-8")); navqueue_goto_line(cur_doc, document_get_current(), 1); } else { ui_set_statusbar(FALSE, _("Could not parse the output of command")); } }
static PyObject * ZenEditor_replace_content(ZenEditor *self, PyObject *args) { PyObject *result; gint sel_start = -1, sel_end = -1, ph_pos; gchar *text, *ph, *tmp, *tmp2; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "s|ii", &text, &sel_start, &sel_end)) { tmp = ZenEditor_replace_caret_placeholder(self->caret_placeholder, text, &ph_pos); tmp2 = ZenEditor_replace_range(tmp); g_free(tmp); if (sel_start == -1 && sel_end == -1) { /* replace whole editor content */ sci_set_text(sci, tmp2); } else if (sel_start != -1 && sel_end == -1) { /* insert text at sel_start */ sci_insert_text(sci, sel_start, tmp2); } else if (sel_start != -1 && sel_end != -1) { /* replace from sel_start to sel_end */ sci_set_selection_start(sci, sel_start); sci_set_selection_end(sci, sel_end); sci_replace_sel(sci, tmp2); } else { dbgf("Invalid arguments were supplied."); g_free(tmp2); Py_RETURN_NONE; } g_free(tmp2); /* Move cursor to first placeholder position, if found */ if (ph_pos > -1) sci_set_current_position(sci, sel_start + ph_pos, TRUE); } else { if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } } Py_RETURN_NONE; }
static PyObject * Scintilla_set_text(Scintilla *self, PyObject *args, PyObject *kwargs) { gchar *text; static gchar *kwlist[] = { "text", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &text)) sci_set_text(self->sci, text); Py_RETURN_NONE; }
/* Get or Set the entire text of the currently active Geany document */ static gint glspi_text(lua_State* L) { GeanyDocument *doc = document_get_current(); if (!doc) { return 0; } if (0 == lua_gettop(L)) { /* Called with no args, GET the current text */ gchar *txt = sci_get_contents(doc->editor->sci, -1); lua_pushstring(L, txt ? txt : ""); g_free(txt); return 1; } else { /* Called with one arg, SET the current text */ const gchar*txt; if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); } txt = lua_tostring(L, 1); sci_set_text(doc->editor->sci, txt); return 0; } }
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); }