Beispiel #1
0
static void
show_parsing_error (GtkCssProvider *provider,
                    GtkCssSection  *section,
                    const GError   *error,
                    GtkTextBuffer  *buffer)
{
  GtkTextIter start, end;
  const char *tag_name;

  gtk_text_buffer_get_iter_at_line_index (buffer,
                                          &start,
                                          gtk_css_section_get_start_line (section),
                                          gtk_css_section_get_start_position (section));
  gtk_text_buffer_get_iter_at_line_index (buffer,
                                          &end,
                                          gtk_css_section_get_end_line (section),
                                          gtk_css_section_get_end_position (section));

  if (g_error_matches (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_DEPRECATED))
    tag_name = "warning";
  else
    tag_name = "error";

  gtk_text_buffer_apply_tag_by_name (buffer, tag_name, &start, &end);
}
Beispiel #2
0
void SourceEditor::unhighlightAllTokens(int beginLine, int beginColumn,
                                        int endLine, int endColumn)
{
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(
        GTK_TEXT_VIEW(gtkSourceView()));
    GtkTextIter begin, end;
    gtk_text_buffer_get_iter_at_line_index(buffer, &begin,
                                           beginLine, beginColumn);
    if (endLine == -1 && endColumn == -1)
        gtk_text_buffer_get_end_iter(buffer, &end);
    else
        gtk_text_buffer_get_iter_at_line_index(buffer, &end,
                                               endLine, endColumn);
    for (int i = 0; i < N_TOKEN_KINDS; ++i)
        gtk_text_buffer_remove_tag(buffer, tokenTags[i],
                                   &begin, &end);
}
Beispiel #3
0
void SourceEditor::highlightToken(int beginLine, int beginColumn,
                                  int endLine, int endColumn,
                                  TokenKind tokenKind)
{
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(
        GTK_TEXT_VIEW(gtkSourceView()));
    GtkTextIter begin, end;
    gtk_text_buffer_get_iter_at_line_index(buffer, &begin,
                                           beginLine, beginColumn);
    if (endLine == -1 && endColumn == -1)
        gtk_text_buffer_get_end_iter(buffer, &end);
    else
        gtk_text_buffer_get_iter_at_line_index(buffer, &end,
                                               endLine, endColumn);
    gtk_text_buffer_apply_tag(buffer,
                              tokenTags[tokenKind],
                              &begin, &end);
}
Beispiel #4
0
/********** 'set_chord_position' function ************************************/
gint set_chord_position(GtkWidget *t_view, GtkTextBuffer *buffer)
{
	GtkTextTag *tag;	

	GtkTextMark *end_chord,
	            *start_chord;	

	GtkTextIter ch,	
	            chord_S,
	            chord_E,
	            match_end,
	            match_start,	
	            start_of_line;
	
	GtkClipboard *clipboard;
		
	gint line_num_1,
	     line_num_2,
	     line_count_V,	
	     line_offset_1,
	     line_offset_2;

	line_count_V = gtk_text_buffer_get_line_count(buffer);
	clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);	
	
	gtk_text_buffer_get_start_iter(buffer, &start_of_line);
	
	if(gtk_text_iter_forward_search(&start_of_line, "[", 1, 
									&match_start, &match_end, NULL))
	{		
		gtk_text_buffer_create_mark(buffer, "start_chord", &match_start, FALSE);
		
		start_chord = gtk_text_buffer_get_mark(buffer, "start_chord");
	}
	else 
	{
		return -1;
	}
	
	if(gtk_text_iter_forward_search(&start_of_line, "]", 1, 
									&match_start, &match_end, NULL))		
	{		
		gtk_text_buffer_create_mark(buffer, "end_chord", &match_end, FALSE);
		
		end_chord = gtk_text_buffer_get_mark(buffer, "end_chord");	
	}	
	else 
	{
		return -1;	
	}

	// Initializes iters at mark.
	gtk_text_buffer_get_iter_at_mark(buffer, &chord_S, start_chord);
	gtk_text_buffer_get_iter_at_mark(buffer, &chord_E, end_chord);
	
	// Get line and line offset of iter. If we just obtain the offset 
	// within buffer then chord_S will not format as desired.
	line_num_1 = gtk_text_iter_get_line(&chord_S);
	line_offset_1 = gtk_text_iter_get_line_index(&chord_S);	
	line_num_2 = gtk_text_iter_get_line(&chord_E);
	line_offset_2 = gtk_text_iter_get_line_index(&chord_E);
	
	// This returns with error if end bracket does not have a 
	// matching start bracket.
	if(line_offset_1 > line_offset_2)
	{
		return -1;	
	}
	
	//g_print("Lineoffset of start:end bracket:\n%d\n%d\n", line_offset_1, line_offset_2);
		
	// If chord found is found more than two lines down
	// refresh global values of 'line_count_C' and 'line_num_C'. 
	if(line_num_1 > (line_num_C + 1))	
	{
		line_num_C = line_num_1;
		line_count_C = line_count_V;
	}
	
	// Copy, cut, and add tags to the section between the marks.
	gtk_text_buffer_select_range(buffer, &chord_S, &chord_E);
	tag = gtk_text_buffer_create_tag(buffer, NULL, "background", "gold",
									 "weight", "500", 
									 "foreground-gdk", "black3", NULL);
	gtk_text_buffer_apply_tag(buffer, tag, &chord_S, &chord_E);
	gtk_text_buffer_cut_clipboard(buffer, clipboard, TRUE);
	
	// This finds first chord of line.
	if(line_count_V == line_count_C) 
	{	
		gtk_text_buffer_get_iter_at_line(buffer, &start_of_line, line_num_1);
		gtk_text_buffer_insert(buffer, &start_of_line, "\n", -1);
	}

	// This finds the rest of the chord_S on the same line as the first. 
	if(line_num_1 == (line_num_C + 1))
	{
		line_num_1 = line_num_1 - 1;		
		line_num_2 = line_num_2 - 1;
	}

	gtk_text_buffer_get_iter_at_line(buffer, &ch, line_num_1);
	
	// Insert 110 blank spaces so we can insert chord_S at higher offsets than 0.
	// GtkTextBuffer does not allow us to insert past a newline character
	// so we move it with spaces to allow us to place chord_S at offsets 
	// past a newline character.
	if(gtk_text_iter_get_char(&ch) == '\n')
	{	
		gtk_text_buffer_insert(buffer, &ch, 
	    "                                                                                                              ",
							    -1);		
	}
	
	// Place iter at the same offset one line above.
	gtk_text_buffer_get_iter_at_line_index(buffer, &ch, line_num_1, line_offset_1);
	
	//g_print("Position after cut: %d\n", line_offset_1);
	gtk_text_buffer_paste_clipboard(buffer, clipboard, &ch, TRUE);	
	
	gtk_text_buffer_get_iter_at_line_offset(buffer, &ch, line_num_1, line_offset_2);
	
	// Deletes the end bracket.	
	gtk_text_buffer_backspace(buffer, &ch, FALSE, TRUE);
	gtk_text_buffer_get_iter_at_line_offset(buffer, &ch, line_num_1, line_offset_1 +1);
	
	// Deletes the start bracket. 	
	gtk_text_buffer_backspace(buffer, &ch, FALSE, TRUE);
	gtk_text_buffer_delete_mark_by_name(buffer, "start_chord");
	gtk_text_buffer_delete_mark_by_name(buffer, "end_chord");
	
	return 0;
}