Пример #1
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
  gint current_pos;
  gint current_line;
  gint previous_line;
  gint previous_line_indentation;
  gint previous_line_end;

  current_pos = gtk_scintilla_get_current_pos(sci);
  current_line = gtk_scintilla_line_from_position(sci, current_pos);

  gphpedit_debug (DEBUG_DOCUMENT);

  if (current_line>0) {
    gtk_scintilla_begin_undo_action(sci);
    previous_line = current_line-1;
    previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

    previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
    indent_line(sci, current_line, previous_line_indentation);
    gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
    gint pos;
    gboolean tabs_instead_spaces;
    g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
    if(tabs_instead_spaces){
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
    } else {
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
    }
    gtk_scintilla_goto_pos(sci, pos);
    gtk_scintilla_end_undo_action(sci);
  }
}
Пример #2
0
void syntax_add_lines(gchar *output)
{
	GtkTreeIter   iter;
	gchar *copy;
	gchar *token;
	gchar *line_number;
	gchar *first_error = NULL;
	gint line_start;
	gint line_end;
	gint indent;

	first_error = 0;
	copy = output;

	while ((token = strtok(copy, "\n"))) {
		if ((strncmp(token, "PHP Warning:  ", MIN(strlen(token), 14))!=0) && (strncmp(token, "Content-type", MIN(strlen(token), 12))!=0)) { 
			gtk_list_store_append (main_window.lint_store, &iter);
			gtk_list_store_set (main_window.lint_store, &iter, 0, token, -1);
	
			line_number = strrchr(token, ' ');
			line_number++;
	
			if (atoi(line_number)>0) {
				if (!first_error) {
					first_error = line_number;
				}
				indent = gtk_scintilla_get_line_indentation(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
	
				line_start = gtk_scintilla_position_from_line(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
				line_start += (indent/preferences.indentation_size);
	
				line_end = gtk_scintilla_get_line_end_position(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
			
				gtk_scintilla_start_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_start, 128);
				gtk_scintilla_set_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_end-line_start, INDIC2_MASK);
			}
			else {
				g_print("Line number is 0\n");
			}
		}
		copy = NULL;
	}

	if (first_error) {
		goto_line(first_error);
	}
}
Пример #3
0
void syntax_add_lines(gchar *output){
	GtkTreeIter   iter;
	gchar *copy;
	gchar *token;
	int line_number;
	int first_error;
	gint line_start;
	gint line_end;
	gint indent;
	
	line_number=0;
	first_error=0;
	copy=output;

	Editor *editor=main_window_get_current_editor();
	while( (token = strtok(copy, "\n")) ) {
		if( ((strncmp(token, "PHP Warning:  ", MIN(strlen(token), 14))!=0)) && ((strncmp(token, "Content-type", MIN(strlen(token), 12))!=0)) ) { 
			gtk_list_store_append(main_window_get_lint_store(), &iter);
			gtk_list_store_set(main_window_get_lint_store(), &iter, 0, token, -1);
	
			line_number = (atoi( (strrchr(token, ' ')) )) -1;
	
			if(line_number<=0) g_print("Line number is %d\n", line_number);

			if(!first_error) first_error = line_number;

			indent = gtk_scintilla_get_line_indentation(GTK_SCINTILLA(editor->scintilla), line_number);

			line_start = gtk_scintilla_position_from_line(GTK_SCINTILLA(editor->scintilla), line_number);
			line_start += indent / preferences.indentation_size;
	
			line_end = gtk_scintilla_get_line_end_position(GTK_SCINTILLA(editor->scintilla), line_number);
	
			gtk_scintilla_start_styling(GTK_SCINTILLA(editor->scintilla), line_start, 128);
			gtk_scintilla_set_styling(GTK_SCINTILLA(editor->scintilla), line_end-line_start, INDIC2_MASK);
		}
		copy = NULL;
	}

	if(first_error) goto_line_int(first_error);
}//syntax_add_lines
Пример #4
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
    gint current_pos;
    gint current_line;
    gint previous_line;
    gint previous_line_indentation;
    gint previous_line_start;
    gint previous_line_end;
    gchar *previous_char_buffer;
    gint previous_char_buffer_length;
    gchar *previous_line_buffer;
    gint previous_line_buffer_length;

    current_pos = gtk_scintilla_get_current_pos(sci);
    current_line = gtk_scintilla_line_from_position(sci, current_pos);

    gphpedit_debug (DEBUG_DOCUMENT);

    if (current_line>0) {
        gtk_scintilla_begin_undo_action(sci);
        previous_line = current_line-1;
        previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

        previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
        previous_char_buffer = gtk_scintilla_get_text_range (sci, previous_line_end-1, previous_line_end, &previous_char_buffer_length);
        if (is_css_char_autoindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation+=indentation_size;
        } else if (is_css_char_autounindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation-=indentation_size;
            if (previous_line_indentation < 0) previous_line_indentation = 0;
            previous_line_start = gtk_scintilla_position_from_line(sci, previous_line);
            previous_line_buffer = gtk_scintilla_get_text_range (sci, previous_line_start, previous_line_end, &previous_line_buffer_length);
            gboolean unindent = TRUE;
            gint char_act = 0;
            while (char_act <= previous_line_buffer_length)
            {
                char c = previous_line_buffer[char_act];
                if (!(g_ascii_iscntrl(c) || g_ascii_isspace(c) || is_css_char_autounindent(c))) {
                    unindent = FALSE;
                    break;
                }
                char_act++;
            }
            if (unindent) gtk_scintilla_set_line_indentation(sci, previous_line, previous_line_indentation);
            g_free(previous_line_buffer);
        }
        g_free(previous_char_buffer);
        indent_line(sci, current_line, previous_line_indentation);
        gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
        gint pos;
        gboolean tabs_instead_spaces;
        g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
        if(tabs_instead_spaces) {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
        } else {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
        }
        gtk_scintilla_goto_pos(sci, pos);
        gtk_scintilla_end_undo_action(sci);
    }
}