示例#1
0
void glatex_insert_latex_fontsize(G_GNUC_UNUSED GtkMenuItem * menuitem,
						 G_GNUC_UNUSED gpointer gdata)
{
	gint size = GPOINTER_TO_INT(gdata);
	GeanyDocument *doc = NULL;
	doc = document_get_current();

	if (doc != NULL)
	{
		if (sci_has_selection(doc->editor->sci))
		{
			gchar *selection;
			gchar *replacement = NULL;

			selection = sci_get_selection_contents(doc->editor->sci);

			replacement = g_strconcat("{",glatex_fontsize_pattern[size],
				" ", selection, "}", NULL);

			sci_replace_sel(doc->editor->sci, replacement);
			g_free(selection);
			g_free(replacement);
		}
		else
		{
			sci_start_undo_action(doc->editor->sci);
			glatex_insert_string(glatex_fontsize_pattern[size], TRUE);
			glatex_insert_string(" ", TRUE);
			sci_end_undo_action(doc->editor->sci);
		}
	}
}
示例#2
0
/**
 * \brief the function creates from the current selection to the input file
 */
static void create_selection_2_input_file( ScintillaObject *sci )
{
    gchar *contents = sci_get_selection_contents(sci);

    GMS_PNULL(contents) ;

    g_file_set_contents(gms_get_in_filename(gms_hnd), contents, -1 , NULL );
    GMS_G_FREE(contents);
}
示例#3
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);

	}
}
示例#4
0
static PyObject *
Scintilla_get_selection_contents(Scintilla *self)
{
	gchar *text;
	PyObject *py_text;
	SCI_RET_IF_FAIL(self);
	text = sci_get_selection_contents(self->sci);
	if (text == NULL)
		Py_RETURN_NONE;
	py_text = PyString_FromString(text);
	g_free(text);
	return py_text;
}
示例#5
0
static gchar *
current_word(void)
{
	GeanyDocument *doc;

	gint pos;
	gint cstart, cend;
	gchar c;

	doc = document_get_current();
	g_return_val_if_fail(doc != NULL && doc->file_name != NULL, NULL);

	if (sci_has_selection(doc->editor->sci))
		return sci_get_selection_contents(doc->editor->sci);

	pos = sci_get_current_position(doc->editor->sci);
	if (pos > 0)
		pos--;

	cstart = pos;
	c = sci_get_char_at(doc->editor->sci, cstart);

	if (!word_check_left(c))
		return NULL;

	while (word_check_left(c))
	{
		cstart--;
		if (cstart >= 0)
			c = sci_get_char_at(doc->editor->sci, cstart);
		else
			break;
	}
	cstart++;

	cend = pos;
	c = sci_get_char_at(doc->editor->sci, cend);
	while (word_check_right(c) && cend < sci_get_length(doc->editor->sci))
	{
		cend++;
		c = sci_get_char_at(doc->editor->sci, cend);
	}

	if (cstart == cend)
		return NULL;

	return sci_get_contents_range(doc->editor->sci, cstart, cend);
}
示例#6
0
文件: vte.c 项目: brettm2013/geany
void vte_send_selection_to_vte(void)
{
	GeanyDocument *doc;
	gchar *text;
	gsize len;

	doc = document_get_current();
	g_return_if_fail(doc != NULL);

	if (sci_has_selection(doc->editor->sci))
	{
		text = sci_get_selection_contents(doc->editor->sci);
	}
	else
	{	/* Get the current line */
		gint line_num = sci_get_current_line(doc->editor->sci);
		text = sci_get_line(doc->editor->sci, line_num);
	}

	len = strlen(text);

	if (vc->send_selection_unsafe)
	{	/* Explicitly append a trailing newline character to get the command executed,
		   this is disabled by default as it could cause all sorts of damage. */
		if (text[len-1] != '\n' && text[len-1] != '\r')
		{
			SETPTR(text, g_strconcat(text, "\n", NULL));
			len++;
		}
	}
	else
	{	/* Make sure there is no newline character at the end to prevent unwanted execution */
		while (text[len-1] == '\n' || text[len-1] == '\r')
		{
			text[len-1] = '\0';
			len--;
		}
	}

	vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), text, len);

	/* show the VTE */
	gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE);
	gtk_widget_grab_focus(vc->vte);
	msgwin_show_hide(TRUE);

	g_free(text);
}
示例#7
0
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;
}
示例#8
0
static gchar *get_selection(void)
{
	gchar *ret = NULL;
	GeanyDocument *doc = document_get_current();
	GeanyEditor *editor;

	if (!doc)
		return NULL;

	editor = doc->editor;

	if (sci_has_selection(editor->sci))
		ret = sci_get_selection_contents(editor->sci);
	else
		ret = editor_get_word_at_pos(editor, -1, GEANY_WORDCHARS);

	return ret;
}
示例#9
0
gchar *get_selection(void)
{
	GeanyDocument *doc = document_get_current();
	const gchar *wc;

#ifdef G_OS_WIN32
	wc = GEANY_WORDCHARS "./-" "\\";
#else
	wc = GEANY_WORDCHARS "./-";
#endif

	if (!doc)
		return NULL;

	if (sci_has_selection(doc->editor->sci))
		return sci_get_selection_contents(doc->editor->sci);
	else
		return editor_get_word_at_pos(doc->editor, -1, wc);
}
示例#10
0
void glatex_insert_latex_format(G_GNUC_UNUSED GtkMenuItem * menuitem,
						 G_GNUC_UNUSED gpointer gdata)
{
	gint format = GPOINTER_TO_INT(gdata);
	GeanyDocument *doc = NULL;
	doc = document_get_current();

	if (doc != NULL)
	{
		if (sci_has_selection(doc->editor->sci))
		{
			gchar *selection;
			gchar *replacement = NULL;

			selection = sci_get_selection_contents(doc->editor->sci);

			if (format == LATEX_SMALLCAPS &&
				glatex_lowercase_on_smallcaps == TRUE)
			{
				gchar *new_selection = NULL;
				new_selection = g_utf8_strdown(selection, -1);
				g_free(selection);
				selection = g_strdup(new_selection);
				g_free(new_selection);
			}
			replacement = g_strconcat(glatex_format_pattern[format],"{",
				selection, "}", NULL);

			sci_replace_sel(doc->editor->sci, replacement);
			g_free(selection);
			g_free(replacement);
		}
		else
		{
			sci_start_undo_action(doc->editor->sci);
			glatex_insert_string(glatex_format_pattern[format], TRUE);
			glatex_insert_string("{", TRUE);
			glatex_insert_string("}", FALSE);
			sci_end_undo_action(doc->editor->sci);
		}
	}
}
示例#11
0
void glatex_structure_lvlup(void)
{
	gint i;
	GeanyDocument *doc = NULL;
	gchar *tmp = NULL;
	GString *haystack = NULL;

	doc = document_get_current();

	if (doc == NULL)
		return;

	if (! sci_has_selection(doc->editor->sci))
		return;

	sci_start_undo_action(doc->editor->sci);
	tmp = sci_get_selection_contents(doc->editor->sci);
	haystack = g_string_new(tmp);

	g_free(tmp);
	tmp = NULL;

	for (i = 0; i < GLATEX_STRUCTURE_N_LEVEL; i++)
	{
		if (utils_string_replace_all
			(haystack,
			glatex_structure_values[i],
			glatex_structure_values[glatex_structure_rotate(FALSE, i)]
			) > 0)
		{
			tmp = g_string_free(haystack, FALSE);
			haystack = NULL;
			sci_replace_sel(doc->editor->sci, tmp);
			g_free(tmp);
			sci_end_undo_action(doc->editor->sci);
			break;
		}
	}

	if (haystack != NULL)
		g_string_free(haystack, TRUE);
}
示例#12
0
static gchar *get_paste_text(GeanyDocument *doc, gsize *text_len)
{
    gsize len;
    gchar *paste_text;

    if (sci_has_selection(doc->editor->sci))
    {
        len = sci_get_selected_text_length(doc->editor->sci) + 1;
        paste_text = sci_get_selection_contents(doc->editor->sci);
    }
    else
    {
        len = sci_get_length(doc->editor->sci) + 1;
        paste_text = sci_get_contents(doc->editor->sci, len);
    }

    if (text_len)
        *text_len = len;

    return paste_text;
}
示例#13
0
/* Note: this is NOT the Geany function, only similar */
gchar *plugme_editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word,
									const gchar *wordchars)
{
	ScintillaObject *sci = editor->sci;
	gchar *text = NULL;

	if (sci_has_selection(sci))
	{
		if (sci_get_selected_text_length(sci) < GEANY_MAX_WORD_LENGTH)
		{
			text = sci_get_selection_contents(sci);

			if (strchr(text, '\n') != NULL)
				*strchr(text, '\n') = '\0';
		}
	}
	else if (use_current_word)
		text = editor_get_word_at_pos(editor, sci_get_current_position(sci), wordchars);

	return text;
}
示例#14
0
static void find_usage(gboolean in_session)
{
	GeanyFindFlags flags;
	gchar *search_text;
	GeanyDocument *doc = document_get_current();

	g_return_if_fail(doc != NULL);

	if (sci_has_selection(doc->editor->sci))
	{	/* take selected text if there is a selection */
		search_text = sci_get_selection_contents(doc->editor->sci);
		flags = GEANY_FIND_MATCHCASE;
	}
	else
	{
		editor_find_current_word_sciwc(doc->editor, -1,
			editor_info.current_word, GEANY_MAX_WORD_LENGTH);
		search_text = g_strdup(editor_info.current_word);
		flags = GEANY_FIND_MATCHCASE | GEANY_FIND_WHOLEWORD;
	}

	search_find_usage(search_text, search_text, flags, in_session);
	g_free(search_text);
}
示例#15
0
            return FAIL_STRING_ARG(1);
        }
        txt = lua_tostring(L, 1);
        sci_set_text(doc->editor->sci, txt);
        return 0;
    }
}


/* Get or Set the selection text of the currently active Geany document */
static gint glspi_selection(lua_State* L)
{

    DOC_REQUIRED
    if (0 == lua_gettop(L)) { /* Called with no args, GET the selection */
        gchar *txt = sci_get_selection_contents(doc->editor->sci);
        lua_pushstring(L, txt ? txt : "");
        g_free(txt);
        return 1;
    } else { /* Called with one arg, SET the selection */
        const gchar*txt=NULL;
        if (!lua_isstring(L, 1)) {
            return FAIL_STRING_ARG(1);
        }
        txt = lua_tostring(L, 1);
        sci_replace_sel(doc->editor->sci, txt);
        return 0;
    }
}

示例#16
0
/* if type == -1 then we will try to autodetect the type */
void glatex_insert_environment(const gchar *environment, gint type)
{
	GeanyDocument *doc = NULL;

	doc = document_get_current();

	/* Only do anything if it is realy needed to */
	if (doc != NULL && environment != NULL)
	{
		if (sci_has_selection(doc->editor->sci))
		{
			gchar *selection  = NULL;
			gchar *replacement = NULL;
			selection = sci_get_selection_contents(doc->editor->sci);

			sci_start_undo_action(doc->editor->sci);
			if (utils_str_equal(environment, "block") == TRUE)
			{
				replacement = g_strconcat("\\begin{", environment, "}{}\n",
							  selection, "\n\\end{", environment, "}\n", NULL);
			}
			else
			{
				replacement = g_strconcat("\\begin{", environment, "}\n",
							  selection, "\n\\end{", environment, "}\n", NULL);
			}
			sci_replace_sel(doc->editor->sci, replacement);
			sci_end_undo_action(doc->editor->sci);
			g_free(selection);
			g_free(replacement);

		}
		else
		{
			gint indent, pos;
			GString *tmpstring = NULL;
			gchar *tmp = NULL;
			static const GeanyIndentPrefs *indention_prefs = NULL;

			if (type == -1)
			{
				gint i;

				/* First, we check whether we have a known list over here
				 * an reset type to fit new value*/
				for (i = 0; i < GLATEX_LIST_END; i++)
				{
					if (utils_str_equal(glatex_list_environments[i], environment) == TRUE)
					{
						type = GLATEX_ENVIRONMENT_TYPE_LIST;
						break;
					}
				}
			}
			pos = sci_get_current_position(doc->editor->sci);

			sci_start_undo_action(doc->editor->sci);

			tmpstring = g_string_new("\\begin{");
			g_string_append(tmpstring, environment);

			if (utils_str_equal(environment, "block") == TRUE)
			{
				g_string_append(tmpstring, "}{}");
			}
			else
			{
				g_string_append(tmpstring, "}");
			}
			g_string_append(tmpstring, "\n");


			if (type == GLATEX_ENVIRONMENT_TYPE_LIST)
			{
				g_string_append(tmpstring, "\t\\item ");
			}

			tmp = g_string_free(tmpstring, FALSE);
			glatex_insert_string(tmp, TRUE);
			g_free(tmp);

			indent = sci_get_line_indentation(doc->editor->sci,
				sci_get_line_from_position(doc->editor->sci, pos));

			tmp = g_strdup_printf("\n\\end{%s}", environment);
			glatex_insert_string(tmp, FALSE);
			g_free(tmp);

			indention_prefs = editor_get_indent_prefs(doc->editor);
			if (type == GLATEX_ENVIRONMENT_TYPE_LIST)
			{
				sci_set_line_indentation(doc->editor->sci,
					sci_get_current_line(doc->editor->sci),
					indent + indention_prefs->width);
			}
			sci_set_line_indentation(doc->editor->sci,
				sci_get_current_line(doc->editor->sci) + 1, indent);
			sci_end_undo_action(doc->editor->sci);
		}
	}
}
示例#17
0
void sc_speller_check_document(GeanyDocument *doc)
{
	gchar *line;
	gint i;
	gint first_line, last_line;
	gchar *dict_string = NULL;
	gint suggestions_found = 0;

	g_return_if_fail(sc_speller_dict != NULL);
	g_return_if_fail(doc != NULL);

	ui_progress_bar_start(_("Checking"));

	enchant_dict_describe(sc_speller_dict, dict_describe, &dict_string);

	if (sci_has_selection(doc->editor->sci))
	{
		first_line = sci_get_line_from_position(
			doc->editor->sci, sci_get_selection_start(doc->editor->sci));
		last_line = sci_get_line_from_position(
			doc->editor->sci, sci_get_selection_end(doc->editor->sci));

		if (sc_info->use_msgwin)
			msgwin_msg_add(COLOR_BLUE, -1, NULL,
				_("Checking file \"%s\" (lines %d to %d using %s):"),
				DOC_FILENAME(doc), first_line + 1, last_line + 1, dict_string);
		g_message("Checking file \"%s\" (lines %d to %d using %s):",
			DOC_FILENAME(doc), first_line + 1, last_line + 1, dict_string);
	}
	else
	{
		first_line = 0;
		last_line = sci_get_line_count(doc->editor->sci);
		if (sc_info->use_msgwin)
			msgwin_msg_add(COLOR_BLUE, -1, NULL, _("Checking file \"%s\" (using %s):"),
				DOC_FILENAME(doc), dict_string);
		g_message("Checking file \"%s\" (using %s):", DOC_FILENAME(doc), dict_string);
	}
	g_free(dict_string);

	if (first_line == last_line)
	{
		line = sci_get_selection_contents(doc->editor->sci);
		suggestions_found += sc_speller_process_line(doc, first_line, line);
		g_free(line);
	}
	else
	{
		for (i = first_line; i < last_line; i++)
		{
			line = sci_get_line(doc->editor->sci, i);

			suggestions_found += sc_speller_process_line(doc, i, line);

			/* process other GTK events to keep the GUI being responsive */
			while (g_main_context_iteration(NULL, FALSE));

			g_free(line);
		}
	}
	if (suggestions_found == 0 && sc_info->use_msgwin)
		msgwin_msg_add(COLOR_BLUE, -1, NULL, _("The checked text is spelled correctly."));

	ui_progress_bar_stop();
}