/* 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; }
/* 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; }
/* 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; }
/* 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; }