Ejemplo n.º 1
0
static void create_selection(ScintillaObject *sci, int anchor, int anchor_space,
	gboolean rectangle)
{
	int cursor = sci_get_current_position(sci);
	int cursor_space = sci_get_cursor_space(sci);

	if (rectangle)
	{
		sci_set_selection_mode(sci, SC_SEL_RECTANGLE);
		sci_set_anchor(sci, anchor);
		/* sci_set_current_position() sets anchor = cursor, bypass */
		scintilla_send_message(sci, SCI_SETCURRENTPOS, cursor, 0);
	}
	else
	{
		sci_set_selection_mode(sci, SC_SEL_STREAM);
		scintilla_send_message(sci, SCI_SETSEL, anchor, cursor);
	}

	sci_set_anchor_space(sci, anchor_space);
	sci_set_cursor_space(sci, cursor_space);

	/* SCI bug: CANCEL may reduce a rectangle selection to a single line */
	if (rectangle)
		sci_set_selection_mode(sci, SC_SEL_RECTANGLE);
	else
		sci_send_command(sci, SCI_CANCEL);
}
Ejemplo n.º 2
0
void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
	GeanyDocument *doc = document_get_current();
	ScintillaObject *sci;
	gchar *text;
	gboolean keep_sel = TRUE;

	g_return_if_fail(doc != NULL);

	sci = doc->editor->sci;
	if (! sci_has_selection(sci))
	{
		keybindings_send_command(GEANY_KEY_GROUP_SELECT, GEANY_KEYS_SELECT_WORD);
		keep_sel = FALSE;
	}

	/* either we already had a selection or we created one for current word */
	if (sci_has_selection(sci))
	{
		gchar *result = NULL;
		gint cmd = SCI_LOWERCASE;
		gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0);

		text = sci_get_selection_contents(sci);

		if (utils_str_has_upper(text))
		{
			if (rectsel)
				cmd = SCI_LOWERCASE;
			else
				result = g_utf8_strdown(text, -1);
		}
		else
		{
			if (rectsel)
				cmd = SCI_UPPERCASE;
			else
				result = g_utf8_strup(text, -1);
		}

		if (result != NULL)
		{
			sci_replace_sel(sci, result);
			g_free(result);
			if (keep_sel)
				sci_set_selection_start(sci, sci_get_current_position(sci) - strlen(text));
		}
		else
			sci_send_command(sci, cmd);

		g_free(text);

	}
}
Ejemplo n.º 3
0
static PyObject *
Scintilla_send_command(Scintilla *self, PyObject *args, PyObject *kwargs)
{
	gint cmd;
	static gchar *kwlist[] = { "cmd", NULL };

	SCI_RET_IF_FAIL(self);

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &cmd))
		sci_send_command(self->sci, cmd);

	Py_RETURN_NONE;
}
Ejemplo n.º 4
0
static void column_mode_command(ScintillaObject *sci, int command)
{
	/* In the current SCI versions, using the command_keys->command for
	   rectangular selection creates various problems. So we select a
	   stream instead, and convert it to rectangle. It's slower, but all
	   command-s move the cursor at least a word. */
	int anchor = sci_get_anchor(sci);
	int anchor_space = sci_get_anchor_space(sci);

	sci_set_selection_mode(sci, SC_SEL_STREAM);
	sci_send_command(sci, command);
	create_selection(sci, anchor, anchor_space, TRUE);
}