Esempio n. 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_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);
    }
}
Esempio n. 2
0
void plugin_exec(gint plugin_num)
{
	Plugin *plugin;
	gchar *stdout = NULL;
	GError *error = NULL;
	gint exit_status;
	GString *command_line = NULL;
	gint wordStart;
	gint wordEnd;
	gchar *current_selection;
	gint ac_length;
	gchar *data;
	
	if (main_window.current_editor == NULL) {
		return;
	}
	
	plugin = (Plugin *)g_list_nth_data(Plugins, plugin_num);
	if (!plugin) {
		g_print(_("Plugin is null!\n"));
	}
	//g_print("Plugin No: %d:%d (%s):%s\n", plugin_num, plugin->type, plugin->name, plugin->filename->str);
	command_line = g_string_new(plugin->filename->str);
	command_line = g_string_prepend(command_line, "'");
	command_line = g_string_append(command_line, "' '");
	
	if (plugin->type == GPHPEDIT_PLUGIN_TYPE_SELECTION) {
		wordStart = gtk_scintilla_get_selection_start(GTK_SCINTILLA(main_window.current_editor->scintilla));
		wordEnd = gtk_scintilla_get_selection_end(GTK_SCINTILLA(main_window.current_editor->scintilla));
		current_selection = gtk_scintilla_get_text_range (GTK_SCINTILLA(main_window.current_editor->scintilla), wordStart, wordEnd, &ac_length);
		
		command_line = g_string_append(command_line, current_selection);
	}
	else if (plugin->type == GPHPEDIT_PLUGIN_TYPE_FILENAME) {
		command_line = g_string_append(command_line, editor_convert_to_local(main_window.current_editor));		
	}
	command_line = g_string_append(command_line, "'");
	
	//g_print("SPAWNING: %s\n", command_line->str);
	
	if (g_spawn_command_line_sync(command_line->str,&stdout,NULL, &exit_status,&error)) {
		data = strstr(stdout, "\n");
		data++;
		
		//g_print("COMMAND: %s\nSTDOUT:%s\nOUTPUT: %s\n", command_line->str, stdout, data);
		
		if (g_strncasecmp(stdout, "INSERT", MIN(strlen(stdout), 6))==0) {
			if (data) {
				gtk_scintilla_insert_text(GTK_SCINTILLA(main_window.current_editor->scintilla), 
					gtk_scintilla_get_current_pos(GTK_SCINTILLA(main_window.current_editor->scintilla)), data);
			}
		}
		else if (g_strncasecmp(stdout, "REPLACE", MIN(strlen(stdout), 7))==0) {
			if (data) {
				gtk_scintilla_replace_sel(GTK_SCINTILLA(main_window.current_editor->scintilla), data);
			}
		}
		else if (g_strncasecmp(stdout, "MESSAGE", MIN(strlen(stdout),7))==0) {
				info_dialog(plugin->name, data);
		}
		else if (g_strncasecmp(stdout, "OPEN", MIN(strlen(stdout), 4))==0) {
			if (DEBUG_MODE) { g_print("DEBUG: main_window.c:plugin_exec: Opening file :date: %s\n", data); }
			switch_to_file_or_open(data, 0);
		}
		else if (g_strncasecmp(stdout, "DEBUG", MIN(strlen(stdout), 5))==0) {
			debug_dump_editors();
			DEBUG_MODE = TRUE;
		}
		
		g_free(stdout);

	}
	else {
		g_print(_("Spawning %s gave error %s\n"), plugin->filename->str, error->message);
	}
}