Beispiel #1
0
static gboolean check_lines(gpointer data)
{
    GeanyDocument *doc = check_line_data.doc;

    /* since we're in an timeout callback, the document may have been closed */
    if (DOC_VALID (doc))
    {
        gchar *line;
        gint line_number = check_line_data.line_number;
        gint line_count = check_line_data.line_count;
        gint i;

        for (i = 0; i < line_count; i++)
        {
            line = sci_get_line(doc->editor->sci, line_number);
            indicator_clear_on_line(doc, line_number);
            if (sc_speller_process_line(doc, line_number, line) != 0)
            {
                if (sc_info->use_msgwin)
                    msgwin_switch_tab(MSG_MESSAGE, FALSE);
            }
            g_free(line);
        }
    }
    check_line_data.check_while_typing_idle_source_id = 0;
    return FALSE;
}
Beispiel #2
0
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 = g_malloc0(sci_get_selected_text_length(doc->editor->sci) + 1);
		sci_get_selected_text(doc->editor->sci, text);
	}
	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);
}
Beispiel #3
0
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 *
Scintilla_get_line(Scintilla *self, PyObject *args, PyObject *kwargs)
{
	gint line_num = -1;
	gchar *text;
	PyObject *py_text;
	static gchar *kwlist[] = { "line_num", NULL };

	SCI_RET_IF_FAIL(self);

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &line_num))
	{
		if (line_num == -1)
			line_num = sci_get_current_line(self->sci);
		text = sci_get_line(self->sci, line_num);
		if (text == NULL)
			Py_RETURN_NONE;
		py_text = PyString_FromString(text);
		g_free(text);
		return py_text;
	}

	Py_RETURN_NONE;
}
Beispiel #5
0
static gint get_page_count(GtkPrintContext *context, DocInfo *dinfo)
{
	gdouble width, height;
	gint layout_h;
	gint i, j, lines_left;
	gchar *line_buf;

	if (dinfo == NULL)
		return -1;

	width = gtk_print_context_get_width(context);
	height = gtk_print_context_get_height(context);

	if (printing_prefs.print_line_numbers)
		/* remove line number margin space from overall width */
		width -= dinfo->max_line_number_margin * dinfo->font_width;

	pango_layout_set_width(dinfo->layout, width * PANGO_SCALE);

	/* add test text to get line height */
	pango_layout_set_text(dinfo->layout, "Test 1", -1);
	pango_layout_get_size(dinfo->layout, NULL, &layout_h);
	if (layout_h <= 0)
	{
		geany_debug("Invalid layout_h (%d). Falling back to default height (%d)",
			layout_h, 100 * PANGO_SCALE);
		layout_h = 100 * PANGO_SCALE;
	}
	dinfo->line_height = (gdouble)layout_h / PANGO_SCALE;
	dinfo->lines_per_page = ceil((height - dinfo->line_height) / dinfo->line_height);
#ifdef GEANY_PRINT_DEBUG
	geany_debug("max lines_per_page: %d", dinfo->lines_per_page);
#endif
	if (printing_prefs.print_page_numbers)
		dinfo->lines_per_page -= 2;
	if (printing_prefs.print_page_header)
		dinfo->lines_per_page -= 3;

	lines_left = dinfo->lines_per_page;

	i = 0;
	for (j = 0; j < dinfo->lines; j++)
	{
		gint lines = 1;
		gint line_width;

		line_buf = sci_get_line(dinfo->doc->editor->sci, j);
		line_width = (g_utf8_strlen(line_buf, -1) + 1) * dinfo->font_width;
		if (line_width > width)
			lines = ceil(line_width / width);
#ifdef GEANY_PRINT_DEBUG
		if (lines != 1) geany_debug("%d %d", j+1, lines);
#endif

		while (lines_left < lines)
		{
			lines -= lines_left;
			lines_left = dinfo->lines_per_page;
			i++;
		}
		lines_left -= lines;
		g_free(line_buf);
	}

	return i + 1;
}
Beispiel #6
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();
}