forked from bartvdbraak/blender
patch [#31359] Py Console: Empty current line
from Sebastian Nell (codemanx), with some edits - Changed key shortcut to Shift+Enter. - made into its own operator since it works differently to delete.
This commit is contained in:
parent
e6a022816c
commit
895e426e26
@ -42,6 +42,7 @@ class CONSOLE_MT_console(Menu):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("console.clear")
|
||||
layout.operator("console.clear_line")
|
||||
layout.operator("console.copy")
|
||||
layout.operator("console.paste")
|
||||
layout.menu("CONSOLE_MT_language")
|
||||
|
@ -58,6 +58,7 @@ void CONSOLE_OT_history_append(struct wmOperatorType *ot);
|
||||
void CONSOLE_OT_scrollback_append(struct wmOperatorType *ot);
|
||||
|
||||
void CONSOLE_OT_clear(struct wmOperatorType *ot);
|
||||
void CONSOLE_OT_clear_line(struct wmOperatorType *ot);
|
||||
void CONSOLE_OT_history_cycle(struct wmOperatorType *ot);
|
||||
void CONSOLE_OT_copy(struct wmOperatorType *ot);
|
||||
void CONSOLE_OT_paste(struct wmOperatorType *ot);
|
||||
|
@ -519,6 +519,39 @@ void CONSOLE_OT_delete(wmOperatorType *ot)
|
||||
RNA_def_enum(ot->srna, "type", console_delete_type_items, DEL_NEXT_CHAR, "Type", "Which part of the text to delete");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void CONSOLE_OT_clear_line(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Clear Line";
|
||||
ot->description = "Clear the line and store in history";
|
||||
ot->idname = "CONSOLE_OT_clear_line";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = console_clear_line_exec;
|
||||
ot->poll = ED_operator_console_active;
|
||||
}
|
||||
|
||||
/* the python exec operator uses this */
|
||||
static int console_clear_exec(bContext *C, wmOperator *op)
|
||||
@ -571,7 +604,7 @@ 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 prevernts crashes when no command line */
|
||||
ConsoleLine *ci = console_history_verify(C); /* TODO - stupid, just prevents crashes when no command line */
|
||||
short reverse = RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
|
||||
int prev_len = ci->len;
|
||||
|
||||
@ -584,7 +617,7 @@ static int console_history_cycle_exec(bContext *C, wmOperator *op)
|
||||
console_history_free(sc, ci_prev);
|
||||
}
|
||||
|
||||
if (reverse) { /* last item in mistory */
|
||||
if (reverse) { /* last item in history */
|
||||
ci = sc->history.last;
|
||||
BLI_remlink(&sc->history, ci);
|
||||
BLI_addhead(&sc->history, ci);
|
||||
|
@ -250,8 +250,9 @@ static void console_operatortypes(void)
|
||||
/* for use by python only */
|
||||
WM_operatortype_append(CONSOLE_OT_history_append);
|
||||
WM_operatortype_append(CONSOLE_OT_scrollback_append);
|
||||
|
||||
WM_operatortype_append(CONSOLE_OT_clear);
|
||||
|
||||
WM_operatortype_append(CONSOLE_OT_clear);
|
||||
WM_operatortype_append(CONSOLE_OT_clear_line);
|
||||
WM_operatortype_append(CONSOLE_OT_history_cycle);
|
||||
WM_operatortype_append(CONSOLE_OT_copy);
|
||||
WM_operatortype_append(CONSOLE_OT_paste);
|
||||
@ -312,6 +313,8 @@ static void console_keymap(struct wmKeyConfig *keyconf)
|
||||
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD);
|
||||
RNA_enum_set(WM_keymap_add_item(keymap, "CONSOLE_OT_delete", BACKSPACEKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_PREV_WORD);
|
||||
|
||||
WM_keymap_add_item(keymap, "CONSOLE_OT_clear_line", RETKEY, KM_PRESS, KM_SHIFT, 0);
|
||||
|
||||
#ifdef WITH_PYTHON
|
||||
WM_keymap_add_item(keymap, "CONSOLE_OT_execute", RETKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
|
||||
WM_keymap_add_item(keymap, "CONSOLE_OT_execute", PADENTER, KM_PRESS, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user