Ejemplo n.º 1
0
/* the python exec operator uses this */
static int console_clear_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	
	const bool scrollback = RNA_boolean_get(op->ptr, "scrollback");
	const bool history = RNA_boolean_get(op->ptr, "history");
	
	/*ConsoleLine *ci = */ console_history_verify(C);
	
	if (scrollback) { /* last item in mistory */
		while (sc->scrollback.first)
			console_scrollback_free(sc, sc->scrollback.first);
	}
	
	if (history) {
		while (sc->history.first)
			console_history_free(sc, sc->history.first);
		console_history_verify(C);
	}

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Ejemplo n.º 2
0
/* the python exec operator uses this */
static int console_scrollback_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci;
	
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, don't free */
	int type = RNA_enum_get(op->ptr, "type");

	console_history_verify(C);
	
	ci = console_scrollback_add_str(sc, str, 1); /* own the string */
	ci->type = type;
	
	console_scrollback_limit(sc);

	/* 'ar' can be null depending on the operator that runs
	 * rendering with invoke default for eg causes this */
	if (ar) {
		console_textview_update_rect(sc, ar);
	}

	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 3
0
static int console_indent_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);
	int spaces;
	int len;

	for (spaces = 0; spaces < ci->len; spaces++) {
		if (ci->line[spaces] != ' ')
			break;
	}

	len = TAB_LENGTH - spaces % TAB_LENGTH;

	console_line_verify_length(ci, ci->len + len);

	memmove(ci->line + len, ci->line, ci->len + 1);
	memset(ci->line, ' ', len);
	ci->len += len;
	BLI_assert(ci->len >= 0);
	console_line_cursor_set(ci, ci->cursor + len);
	console_select_offset(sc, len);

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 4
0
/* the python exec operator uses this */
static int history_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc= CTX_wm_space_console(C);
	ScrArea *sa= CTX_wm_area(C);
	ConsoleLine *ci= console_history_verify(C);
	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
	int cursor= RNA_int_get(op->ptr, "current_character");
	short rem_dupes= RNA_boolean_get(op->ptr, "remove_duplicates");
	int prev_len= ci->len;

	if(rem_dupes) {
		ConsoleLine *cl;

		while((cl= console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		if(strcmp(str, ci->line)==0) {
			MEM_freeN(str);
			return OPERATOR_FINISHED;
		}
	}

	ci= console_history_add_str(sc, str, 1); /* own the string */
	console_select_offset(sc, ci->len - prev_len);
	console_line_cursor_set(ci, cursor);

	ED_area_tag_redraw(sa);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 5
0
static int console_insert_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0);
	int len;

	if (str[0] == '\t' && str[1] == '\0') {
		len = TAB_LENGTH;
		MEM_freeN(str);
		str = MEM_mallocN(len + 1, "insert_exec");
		memset(str, ' ', len);
		str[len] = '\0';
	}

	len = console_line_insert(ci, str);
	
	MEM_freeN(str);
	
	if (len == 0) {
		return OPERATOR_CANCELLED;
	}
	else {
		console_select_offset(sc, len);
	}

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 6
0
static int move_exec(bContext *C, wmOperator *op)
{
	ConsoleLine *ci= console_history_verify(C);
	
	int type= RNA_enum_get(op->ptr, "type");
	int done= 0;
	
	switch(type) {
	case LINE_BEGIN:
		done= console_line_cursor_set(ci, 0);
		break;
	case LINE_END:
		done= console_line_cursor_set(ci, INT_MAX);
		break;
	case PREV_CHAR:
		done= console_line_cursor_set(ci, ci->cursor-1);
		break;
	case NEXT_CHAR:
		done= console_line_cursor_set(ci, ci->cursor+1);
		break;

	/* - if the character is a delimiter then skip delimiters (including white space)
	 * - when jump over the word */
	case PREV_WORD:
		while(text_check_delim(cursor_char_prev(ci)))
			if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
				break;

		while(text_check_delim(cursor_char_prev(ci))==FALSE)
			if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
				break;

		/* This isnt used for NEXT_WORD because when going back
		 * its more useful to have the cursor directly after a word then whitespace */
		while(text_check_whitespace(cursor_char_prev(ci))==TRUE)
			if(console_line_cursor_set(ci, ci->cursor-1)==FALSE)
				break;

		done= 1; /* assume changed */
		break;
	case NEXT_WORD:
		while(text_check_delim(cursor_char(ci))==TRUE)
			if (console_line_cursor_set(ci, ci->cursor+1)==FALSE)
				break;

		while(text_check_delim(cursor_char(ci))==FALSE)
			if (console_line_cursor_set(ci, ci->cursor+1)==FALSE)
				break;

		done= 1; /* assume changed */
		break;
	}
	
	if(done) {
		ED_area_tag_redraw(CTX_wm_area(C));
	}
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 7
0
static int console_paste_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);
	int buf_len;

	char *buf_str = WM_clipboard_text_get(false, &buf_len);
	char *buf_step, *buf_next;

	if (buf_str == NULL)
		return OPERATOR_CANCELLED;

	buf_step = buf_str;

	while ((buf_next = buf_step) && buf_next[0] != '\0') {
		buf_step = strchr(buf_next, '\n');
		if (buf_step) {
			*buf_step = '\0';
			buf_step++;
		}

		if (buf_next != buf_str) {
			WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
			ci = console_history_verify(C);
		}

		console_select_offset(sc, console_line_insert(ci, buf_next));
	}

	MEM_freeN(buf_str);

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 8
0
/* the python exec operator uses this */
static int console_history_cycle_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);

	ConsoleLine *ci = console_history_verify(C); /* TODO - stupid, just prevents crashes when no command line */
	const bool reverse = RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
	int prev_len = ci->len;

	/* keep a copy of the line above so when history is cycled
	 * this is the only function that needs to know about the double-up */
	if (ci->prev) {
		ConsoleLine *ci_prev = (ConsoleLine *)ci->prev;

		if (STREQ(ci->line, ci_prev->line))
			console_history_free(sc, ci_prev);
	}

	if (reverse) { /* last item in history */
		ci = sc->history.last;
		BLI_remlink(&sc->history, ci);
		BLI_addhead(&sc->history, ci);
	}
	else {
		ci = sc->history.first;
		BLI_remlink(&sc->history, ci);
		BLI_addtail(&sc->history, ci);
	}

	{   /* add a duplicate of the new arg and remove all other instances */
		ConsoleLine *cl;
		while ((cl = console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		console_history_add(sc, (ConsoleLine *)sc->history.last);
	}
	
	ci = sc->history.last;
	console_select_offset(sc, ci->len - prev_len);

	/* could be wrapped so update scroll rect */
	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 9
0
static int delete_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc= CTX_wm_space_console(C);
	ARegion *ar= CTX_wm_region(C);
	ConsoleLine *ci= console_history_verify(C);

	const short type= RNA_enum_get(op->ptr, "type");
	int done = 0;
	
	if(ci->len==0) {
		return OPERATOR_CANCELLED;
	}
	
	switch(type) {
	case DEL_NEXT_CHAR:
		if(ci->cursor < ci->len) {
			memmove(ci->line + ci->cursor, ci->line + ci->cursor+1, (ci->len - ci->cursor)+1);
			ci->len--;
			done= 1;
		}
		break;
	case DEL_PREV_CHAR:
		if(ci->cursor > 0) {
			ci->cursor--; /* same as above */
			memmove(ci->line + ci->cursor, ci->line + ci->cursor+1, (ci->len - ci->cursor)+1);
			ci->len--;
			done= 1;
		}
		break;
	}
	
	if(!done) {
		return OPERATOR_CANCELLED;
	}
	else {
		console_select_offset(sc, -1);
	}

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 10
0
/* the python exec operator uses this */
static int scrollback_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc= CTX_wm_space_console(C);
	ARegion *ar= CTX_wm_region(C);
	ConsoleLine *ci;
	
	char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, dont free */
	int type= RNA_enum_get(op->ptr, "type");

	console_history_verify(C);
	
	ci= console_scrollback_add_str(sc, str, 1); /* own the string */
	ci->type= type;
	
	console_scrollback_limit(sc);

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 11
0
static int console_clear_line_exec(bContext *C, wmOperator *UNUSED(op))
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);

	if (ci->len == 0) {
		return OPERATOR_CANCELLED;
	}

	console_history_add(C, ci);
	console_history_add(C, NULL);

	console_textview_update_rect(sc, ar);

	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Ejemplo n.º 12
0
/* the python exec operator uses this */
static int console_history_append_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ScrArea *sa = CTX_wm_area(C);
	ConsoleLine *ci = console_history_verify(C);
	char *str = RNA_string_get_alloc(op->ptr, "text", NULL, 0); /* own this text in the new line, don't free */
	int cursor = RNA_int_get(op->ptr, "current_character");
	const bool rem_dupes = RNA_boolean_get(op->ptr, "remove_duplicates");
	int prev_len = ci->len;

	if (rem_dupes) {
		ConsoleLine *cl;

		while ((cl = console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		if (STREQ(str, ci->line)) {
			MEM_freeN(str);
			return OPERATOR_FINISHED;
		}
	}

	ci = console_history_add_str(sc, str, 1); /* own the string */
	console_select_offset(sc, ci->len - prev_len);
	console_line_cursor_set(ci, cursor);

	ED_area_tag_redraw(sa);

	/* when calling render modally this can be NULL when calling:
	 * bpy.ops.render.render('INVOKE_DEFAULT') */
	if (ar) {
		console_scroll_bottom(ar);
	}

	return OPERATOR_FINISHED;
}
Ejemplo n.º 13
0
static int console_delete_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);
	ConsoleLine *ci = console_history_verify(C);
	int pos;
	int stride;

	const short type = RNA_enum_get(op->ptr, "type");
	bool done = false;
	
	if (ci->len == 0) {
		return OPERATOR_CANCELLED;
	}
	
	switch (type) {
		case DEL_NEXT_CHAR:
		case DEL_NEXT_WORD:
			if (ci->cursor < ci->len) {
				pos = ci->cursor;
				BLI_str_cursor_step_utf8(ci->line, ci->len,
				                         &pos, STRCUR_DIR_NEXT,
				                         (type == DEL_NEXT_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
				stride = pos - ci->cursor;
				if (stride) {
					memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - (ci->cursor + stride)) + 1);
					ci->len -= stride;
					BLI_assert(ci->len >= 0);
					done = true;
				}
			}
			break;
		case DEL_PREV_CHAR:
		case DEL_PREV_WORD:
			if (ci->cursor > 0) {
				pos = ci->cursor;
				BLI_str_cursor_step_utf8(ci->line, ci->len,
				                         &pos, STRCUR_DIR_PREV,
				                         (type == DEL_PREV_CHAR) ? STRCUR_JUMP_NONE : STRCUR_JUMP_DELIM, true);
				stride = ci->cursor - pos;
				if (stride) {
					ci->cursor -= stride; /* same as above */
					memmove(ci->line + ci->cursor, ci->line + ci->cursor + stride, (ci->len - (ci->cursor + stride)) + 1);
					ci->len -= stride;
					BLI_assert(ci->len >= 0);
					done = true;
				}
			}
			break;
	}

	if (!done) {
		return OPERATOR_CANCELLED;
	}
	else {
		console_select_offset(sc, -stride);
	}

	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);
	
	return OPERATOR_FINISHED;
}
Ejemplo n.º 14
0
static int console_move_exec(bContext *C, wmOperator *op)
{
	ConsoleLine *ci = console_history_verify(C);
	
	int type = RNA_enum_get(op->ptr, "type");
	bool done = false;
	int pos;
	
	switch (type) {
		case LINE_BEGIN:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_PREV,
			                         STRCUR_JUMP_ALL, true);
			done = console_line_cursor_set(ci, pos);
			break;
		case LINE_END:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_NEXT,
			                         STRCUR_JUMP_ALL, true);
			done = console_line_cursor_set(ci, pos);
			break;
		case PREV_CHAR:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_PREV,
			                         STRCUR_JUMP_NONE, true);
			done = console_line_cursor_set(ci, pos);
			break;
		case NEXT_CHAR:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_NEXT,
			                         STRCUR_JUMP_NONE, true);
			done = console_line_cursor_set(ci, pos);
			break;

		/* - if the character is a delimiter then skip delimiters (including white space)
		 * - when jump over the word */
		case PREV_WORD:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_PREV,
			                         STRCUR_JUMP_DELIM, true);
			done = console_line_cursor_set(ci, pos);
			break;
		case NEXT_WORD:
			pos = ci->cursor;
			BLI_str_cursor_step_utf8(ci->line, ci->len,
			                         &pos, STRCUR_DIR_NEXT,
			                         STRCUR_JUMP_DELIM, true);
			done = console_line_cursor_set(ci, pos);
			break;
	}
	
	if (done) {
		ScrArea *sa = CTX_wm_area(C);
		ARegion *ar = CTX_wm_region(C);

		ED_area_tag_redraw(sa);
		console_scroll_bottom(ar);
	}


	return OPERATOR_FINISHED;
}