Example #1
0
static void indent_line(GtkScintilla *sci, gint line, gint indent)
{
    gint selStart;
    gint selEnd;
    gint posBefore;
    gint posAfter;
    gint posDifference;

    selStart = gtk_scintilla_get_selection_start(sci);
    selEnd = gtk_scintilla_get_selection_end(sci);
    posBefore = gtk_scintilla_get_line_indentation(sci, line);
    gtk_scintilla_set_line_indentation(sci, line, indent);
    posAfter = gtk_scintilla_get_line_indentation(sci, line);
    posDifference =  posAfter - posBefore;

    if (posAfter > posBefore) {
        // Move selection on
        if (selStart >= posBefore) {
            selStart += posDifference;
        }
        if (selEnd >= posBefore) {
            selEnd += posDifference;
        }
    }
    else if (posAfter < posBefore) {
        // Move selection back
        if (selStart >= posAfter) {
            if (selStart >= posBefore)
                selStart += posDifference;
            else
                selStart = posAfter;
        }
        if (selEnd >= posAfter) {
            if (selEnd >= posBefore)
                selEnd += posDifference;
            else
                selEnd = posAfter;
        }
    }
    gtk_scintilla_set_selection_start(sci, selStart);
    gtk_scintilla_set_selection_end(sci, selEnd);
}
Example #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);
	}
}