Beispiel #1
0
static void
reindent (GeanyDocument  *doc,
          GrindIndenter  *indenter)
{
  if (DOC_VALID (doc)) {
    int               start;
    int               end;
    ScintillaObject  *sci = doc->editor->sci;
    
    if (sci_has_selection (sci)) {
      start = sci_get_line_from_position (sci, sci_get_selection_start (sci));
      end = sci_get_line_from_position (sci, sci_get_selection_end (sci));
    } else {
      start = 0;
      end = sci_get_line_count (sci);
    }
    
    if (start != end) {
      g_debug ("Using indenter \"%s\" by \"%s\"",
               grind_indenter_get_name (indenter),
               grind_indenter_get_author (indenter));
      
      sci_start_undo_action (sci);
      if (grind_indenter_indent (indenter, doc,
                                 sci_get_position_from_line (sci, start),
                                 sci_get_line_end_position (sci, end))) {
        msgwin_status_add ("Reindented \"%s\"", DOC_FILENAME (doc));
      }
      sci_end_undo_action (sci);
    }
  }
}
static PyObject *
Scintilla_get_line_count(Scintilla *self)
{
	gint line_count;
	SCI_RET_IF_FAIL(self);
	line_count = sci_get_line_count(self->sci);
	return Py_BuildValue("i", line_count);
}
Beispiel #3
0
void sc_speller_check_document(GeanyDocument *doc)
{
	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)
	{
		suggestions_found += sc_speller_process_line(doc, first_line);
	}
	else
	{
		for (i = first_line; i < last_line; i++)
		{
			suggestions_found += sc_speller_process_line(doc, i);

			/* process other GTK events to keep the GUI being responsive */
			while (g_main_context_iteration(NULL, FALSE));
		}
	}
	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();
}
static void findMatchingClosingTag(ScintillaObject *sci, gchar *tagName, gint closingBracket)
{
    gint pos;
    gint linesInDocument = sci_get_line_count(sci);
    gint endOfDocument = sci_get_position_from_line(sci, linesInDocument);
    gint openingTagsCount = 1;
    gint closingTagsCount = 0;

    for(pos=closingBracket; pos<endOfDocument; pos++)
    {
        /* are we inside tag? */
        gint lineNumber = sci_get_line_from_position(sci, pos);
        gint lineEnd = sci_get_line_end_position(sci, lineNumber);
        gint matchingOpeningBracket = findBracket(sci, pos, lineEnd, '<', '\0', TRUE);
        gint matchingClosingBracket = findBracket(sci, pos, lineEnd, '>', '\0', TRUE);

        if(-1 != matchingOpeningBracket && -1 != matchingClosingBracket
            && (matchingClosingBracket > matchingOpeningBracket))
        {
            /* we are inside of some tag. Let us check what tag*/
            gboolean isMatchingTagOpening = is_tag_opening(sci, matchingOpeningBracket);
            gchar *matchingTagName = get_tag_name(sci, matchingOpeningBracket,
                                                  matchingClosingBracket,
                                                  isMatchingTagOpening);
            if(matchingTagName && strcmp(tagName, matchingTagName) == 0)
            {
                if(TRUE == isMatchingTagOpening)
                    openingTagsCount++;
                else
                    closingTagsCount++;
            }
            pos = matchingClosingBracket;
            g_free(matchingTagName);
        }

        if(openingTagsCount == closingTagsCount)
        {
            /* matching tag is found */
            highlightedBrackets[2] = matchingOpeningBracket;
            highlightedBrackets[3] = matchingClosingBracket;
            highlight_matching_pair(sci);
            return;
        }
    }
    highlight_tag(sci, highlightedBrackets[0], highlightedBrackets[1],
                  NONMATCHING_PAIR_COLOR);
}
Beispiel #5
0
static void begin_print(GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
{
	DocInfo *dinfo = user_data;
	PangoFontDescription *desc;
	gint i;
	gint style_max;

	if (dinfo == NULL)
		return;

	gtk_widget_show(main_widgets.progressbar);

	desc = pango_font_description_from_string(interface_prefs.editor_font);

	/* init dinfo fields */
	dinfo->lines = sci_get_line_count(dinfo->doc->editor->sci);
	dinfo->lines_per_page = 0;
	dinfo->cur_line = 0;
	dinfo->cur_pos = 0;
	dinfo->long_line = FALSE;
	dinfo->print_time = time(NULL);
	dinfo->max_line_number_margin = get_line_numbers_arity(dinfo->lines) + 1;
	/* increase font width by 1 (looks better) */
	dinfo->font_width = get_font_width(context, desc) + 1;
	/* create a PangoLayout to be commonly used in get_page_count and draw_page */
	dinfo->layout = setup_pango_layout(context, desc);
	/* this is necessary because of possible line breaks on the printed page and then
	 * lines_per_page differs from document line count */
	dinfo->n_pages = get_page_count(context, dinfo);

	/* read all styles from Scintilla */
	style_max = pow(2, scintilla_send_message(dinfo->doc->editor->sci, SCI_GETSTYLEBITS, 0, 0));
	/* if the lexer uses only the first 32 styles(style bits = 5),
	 * we need to add the pre-defined styles */
	if (style_max == 32)
		style_max = STYLE_LASTPREDEFINED;
	for (i = 0; i < style_max; i++)
	{
		dinfo->styles[i][FORE] = ROTATE_RGB(scintilla_send_message(
			dinfo->doc->editor->sci, SCI_STYLEGETFORE, i, 0));
		if (i == STYLE_LINENUMBER)
		{	/* ignore background colour for line number margin to avoid trouble with wrapped lines */
			dinfo->styles[STYLE_LINENUMBER][BACK] = ROTATE_RGB(scintilla_send_message(
				dinfo->doc->editor->sci, SCI_STYLEGETBACK, STYLE_DEFAULT, 0));
		}
		else
		{
			dinfo->styles[i][BACK] = ROTATE_RGB(scintilla_send_message(
				dinfo->doc->editor->sci, SCI_STYLEGETBACK, i, 0));
		}
		/* use white background color unless foreground is white to save ink */
		if (dinfo->styles[i][FORE] != 0xffffff)
			dinfo->styles[i][BACK] = 0xffffff;
		dinfo->styles[i][BOLD] =
			scintilla_send_message(dinfo->doc->editor->sci, SCI_STYLEGETBOLD, i, 0);
		dinfo->styles[i][ITALIC] =
			scintilla_send_message(dinfo->doc->editor->sci, SCI_STYLEGETITALIC, i, 0);
	}

	if (dinfo->n_pages >= 0)
		gtk_print_operation_set_n_pages(operation, dinfo->n_pages);

	pango_font_description_free(desc);
}