Esempio n. 1
0
static PyObject *
ZenEditor_replace_content(ZenEditor *self, PyObject *args)
{
	gint sel_start = -1, sel_end = -1, ph_pos;
	gchar *text, *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);

			/* Move cursor to first placeholder position, if found */
			if (ph_pos > -1)
				sci_set_current_position(sci, sel_start + ph_pos, TRUE);
		}
		else if (sel_start != -1)
		{
			/* replace from sel_start to sel_end */
			if (sel_end == -1)
			{
				/* insert text at sel_start */
				sel_end = sel_start;
			}

			sci_set_selection_start(sci, sel_start);
			sci_set_selection_end(sci, sel_end);
			sci_replace_sel(sci, "");
			editor_insert_text_block(ZenEditor_get_context(self)->editor, tmp2, sel_start, ph_pos, -1, FALSE);
		}
		else
		{
			dbgf("Invalid arguments were supplied.");
			g_free(tmp2);
			Py_RETURN_NONE;
		}

		g_free(tmp2);
	}
	else
	{
		if (PyErr_Occurred())
		{
			PyErr_Print();
			PyErr_Clear();
		}
	}

	Py_RETURN_NONE;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
static ScintillaObject *
ZenEditor_get_scintilla(ZenEditor *self)
{
	GeanyDocument *doc;

	print_called();

	doc = ZenEditor_get_context(self);
	if (doc == NULL || doc->editor == NULL || doc->editor->sci == NULL)
		return NULL;

	return doc->editor->sci;
}