static PyObject * ZenEditor_get_file_path(ZenEditor *self, PyObject *args) { PyObject *result; GeanyDocument *doc; print_called(); py_return_none_if_null(doc = ZenEditor_get_context(self)); py_return_none_if_null(doc->file_name); result = Py_BuildValue("s", doc->file_name); return result; }
static PyObject * ZenEditor_get_selection_range(ZenEditor *self, PyObject *args) { PyObject *result; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); result = Py_BuildValue("(ii)", sci_get_selection_start(sci), sci_get_selection_end(sci)); py_return_none_if_null(result); return result; }
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 * ZenEditor_get_content(ZenEditor *self, PyObject *args) { PyObject *result; gchar *text; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); text = sci_get_contents(sci, sci_get_length(sci) + 1); py_return_none_if_null(text); result = PyString_FromString(text); g_free(text); py_return_none_if_null(result); return result; }
static PyObject * ZenEditor_prompt(ZenEditor *self, PyObject *args) { PyObject *result; GtkWidget *dialog, *input, *content_area, *vbox; gchar *abbr = NULL; const gchar *title = NULL; print_called(); if (!PyArg_ParseTuple(args, "s", &title) || title == NULL) title = "Enter Abbreviation"; dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(geany_data->main_widgets->window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_has_separator(GTK_DIALOG(dialog), TRUE); gtk_window_set_default_size(GTK_WINDOW(dialog), 300, -1); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); input = gtk_entry_new(); gtk_entry_set_activates_default(GTK_ENTRY(input), TRUE); vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), input, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 12); gtk_container_add(GTK_CONTAINER(content_area), vbox); gtk_widget_show_all(vbox); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) abbr = g_strdup(gtk_entry_get_text(GTK_ENTRY(input))); gtk_widget_destroy(dialog); py_return_none_if_null(abbr); if (strlen(abbr) == 0) { g_free(abbr); Py_RETURN_NONE; } result = PyString_FromString(abbr); g_free(abbr); return result; }
static PyObject * ZenEditor_set_caret_pos(ZenEditor *self, PyObject *args) { gint pos; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "i", &pos)) sci_set_current_position(sci, pos, TRUE); Py_RETURN_NONE; }
static PyObject * ZenEditor_get_caret_pos(ZenEditor *self, PyObject *args) { PyObject *result; gint pos; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); pos = sci_get_current_position(sci); result = Py_BuildValue("i", pos); return result; }
static PyObject * ZenEditor_get_selection(ZenEditor *self, PyObject *args) { PyObject *result; gchar *text; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); text = sci_get_selection_contents(sci); result = Py_BuildValue("s", text); g_free(text); return result; }
static PyObject * ZenEditor_get_current_line(ZenEditor *self, PyObject *args) { PyObject *result; gchar *line; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); line = sci_get_line(sci, sci_get_current_line(sci)); result = Py_BuildValue("s", line); g_free(line); return result; }
static PyObject * ZenEditor_get_current_line_range(ZenEditor *self, PyObject *args) { PyObject *result; gint line, line_start, line_end; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); line = sci_get_current_line(sci); line_start = sci_get_position_from_line(sci, line); line_end = sci_get_line_end_position(sci, line); result = Py_BuildValue("ii", line_start, line_end); return result; }
static PyObject * ZenEditor_set_context(ZenEditor *self, PyObject *args) { PyObject *context = NULL, *tmp; print_called(); if (PyArg_ParseTuple(args, "O", &context)) { py_return_none_if_null(context); if (DOC_VALID((GeanyDocument *) PyLong_AsVoidPtr(context))) { tmp = self->context; Py_INCREF(context); self->context = context; Py_XDECREF(tmp); } } Py_RETURN_NONE; }
static PyObject * ZenEditor_create_selection(ZenEditor *self, PyObject *args) { gint sel_start = -1, sel_end = -1; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); if (PyArg_ParseTuple(args, "i|i", &sel_start, &sel_end)) { if (sel_end == -1) sci_set_current_position(sci, sel_start, TRUE); else { sci_set_selection_start(sci, sel_start); sci_set_selection_end(sci, sel_end); } } Py_RETURN_NONE; }
/* Reads all of the .conf files in the passed in directory, parses them into * Zen Coding profiles and then sets each of them up in using * zencoding.utils.setup_profile(). */ static PyObject * ZenEditor_init_profiles(ZenEditor *self, PyObject *args) { gint result = -1; gchar *profiles_dir = NULL, *runcode = NULL; static gboolean has_run = 0; static const gchar *runfmt = "import os\n" "from ConfigParser import SafeConfigParser\n" "import zencoding.utils\n" "for cfg_file in os.listdir('%s'):\n" " if cfg_file.endswith('.conf'):\n" " cfg_file = os.path.join('%s', cfg_file)\n" " p = SafeConfigParser()\n" " p.read(cfg_file)\n" " if p.has_section('profile') and p.has_option('profile', 'name'):\n" " d = {}\n" " name = p.get('profile', 'name')\n" " if not name: continue\n" " if p.has_option('profile', 'tag_case'):\n" " d['case'] = p.get('profile', 'tag_case').lower()\n" " if p.has_option('profile', 'attr_case'):\n" " d['attr_case'] = p.get('profile', 'attr_case').lower()\n" " if p.has_option('profile', 'attr_quotes'):\n" " d['attr_quotes'] = p.get('profile', 'attr_quotes').lower()\n" " if p.has_option('profile', 'tag_nl'):\n" " if p.get('profile', 'tag_nl').lower() == 'decide':\n" " d['tag_nl'] = 'decide'\n" " else:\n" " d['tag_nl'] = p.getboolean('profile', 'tag_nl')\n" " if p.has_option('profile', 'place_cursor'):\n" " d['place_cursor'] = p.getboolean('profile', 'place_cursor')\n" " if p.has_option('profile', 'indent'):\n" " d['indent'] = p.getboolean('profile', 'indent')\n" " if p.has_option('profile', 'self_closing_tag'):\n" " if p.get('profile', 'self_closing_tag').lower() == 'xhtml':\n" " d['self_closing_tag'] = 'xhtml'\n" " else:\n" " d['self_closing_tag'] = p.getboolean('profile', \n" " 'self_closing_tag')\n" " d['filters'] = None\n" " zencoding.utils.setup_profile(name, d)\n"; print_called(); if (has_run) Py_RETURN_TRUE; if (PyArg_ParseTuple(args, "s", &profiles_dir)) { py_return_none_if_null(profiles_dir); runcode = g_strdup_printf(runfmt, profiles_dir, profiles_dir); result = PyRun_SimpleString(runcode); g_free(runcode); } if (result == 0) { has_run = TRUE; Py_RETURN_TRUE; } Py_RETURN_FALSE; }