diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-08-05 06:54:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-08-05 06:54:27 +0300 |
commit | 91fa07dfb18f35783177db47d4c721e5a03aad43 (patch) | |
tree | db8f50d8dbf65a162090164e39c4c843d3fdb906 /source | |
parent | 8b4f00269c91cff040792717122d959392141ad3 (diff) |
Text: merge toggle comments into a single operator
This allows users to map comment/un-comment to be mapped to keys.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 122 |
3 files changed, 33 insertions, 97 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 945b9190d26..8bfb6c87625 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -197,9 +197,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_duplicate_line); WM_operatortype_append(TEXT_OT_convert_whitespace); - WM_operatortype_append(TEXT_OT_uncomment); - WM_operatortype_append(TEXT_OT_comment); - WM_operatortype_append(TEXT_OT_toggle_comment); + WM_operatortype_append(TEXT_OT_comment_toggle); WM_operatortype_append(TEXT_OT_unindent); WM_operatortype_append(TEXT_OT_indent); diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 400405155f8..7a1dd312d02 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -119,9 +119,7 @@ void TEXT_OT_cut(struct wmOperatorType *ot); void TEXT_OT_duplicate_line(struct wmOperatorType *ot); void TEXT_OT_convert_whitespace(struct wmOperatorType *ot); -void TEXT_OT_uncomment(struct wmOperatorType *ot); -void TEXT_OT_comment(struct wmOperatorType *ot); -void TEXT_OT_toggle_comment(struct wmOperatorType *ot); +void TEXT_OT_comment_toggle(struct wmOperatorType *ot); void TEXT_OT_unindent(struct wmOperatorType *ot); void TEXT_OT_indent(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 95e7d906b11..7c4a403d43d 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1209,12 +1209,13 @@ void TEXT_OT_line_break(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Comment Operator +/** \name Toggle-Comment Operator * \{ */ -static int text_comment_exec(bContext *C, wmOperator *UNUSED(op)) +static int text_comment_exec(bContext *C, wmOperator *op) { Text *text = CTX_data_edit_text(C); + int type = RNA_enum_get(op->ptr, "type"); if (txt_has_sel(text)) { text_drawcache_tag_update(CTX_wm_space_text(C), 0); @@ -1222,49 +1223,21 @@ static int text_comment_exec(bContext *C, wmOperator *UNUSED(op)) ED_text_undo_push_init(C); txt_order_cursors(text, false); - txt_comment(text); - text_update_edited(text); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED; -} - -void TEXT_OT_comment(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Comment"; - ot->idname = "TEXT_OT_comment"; - ot->description = "Convert selected text to comment"; - - /* api callbacks */ - ot->exec = text_comment_exec; - ot->poll = text_edit_poll; - - /* flags */ - ot->flag = OPTYPE_UNDO; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Uncomment Operator - * \{ */ -static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - - if (txt_has_sel(text)) { - text_drawcache_tag_update(CTX_wm_space_text(C), 0); - - ED_text_undo_push_init(C); + switch (type) { + case 1: + txt_comment(text); + break; + case -1: + txt_uncomment(text); + break; + default: + if (txt_uncomment(text) == false) { + txt_comment(text); + } + break; + } - txt_order_cursors(text, false); - txt_uncomment(text); text_update_edited(text); text_update_cursor_moved(C); @@ -1276,63 +1249,30 @@ static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } -void TEXT_OT_uncomment(wmOperatorType *ot) +void TEXT_OT_comment_toggle(wmOperatorType *ot) { - /* identifiers */ - ot->name = "Uncomment"; - ot->idname = "TEXT_OT_uncomment"; - ot->description = "Convert selected comment to text"; - - /* api callbacks */ - ot->exec = text_uncomment_exec; - ot->poll = text_edit_poll; - - /* flags */ - ot->flag = OPTYPE_UNDO; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Toggle-Comment Operator - * \{ */ - -static int text_toggle_comment_exec(bContext *C, wmOperator *UNUSED(op)) -{ - Text *text = CTX_data_edit_text(C); - - if (txt_has_sel(text)) { - text_drawcache_tag_update(CTX_wm_space_text(C), 0); - - ED_text_undo_push_init(C); - - txt_order_cursors(text, false); - if (txt_uncomment(text) == false) { - txt_comment(text); - } - text_update_edited(text); - - text_update_cursor_moved(C); - WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); - - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED; -} + static const EnumPropertyItem comment_items[] = { + {0, "TOGGLE", 0, "Toggle Comments", NULL}, + {1, "COMMENT", 0, "Comment", NULL}, + {-1, "UNCOMMENT", 0, "Un-Comment", NULL}, + {0, NULL, 0, NULL, NULL}, + }; -void TEXT_OT_toggle_comment(wmOperatorType *ot) -{ /* identifiers */ - ot->name = "Toggle Comment"; - ot->idname = "TEXT_OT_toggle_comment"; + ot->name = "Toggle Comments"; + ot->idname = "TEXT_OT_comment_toggle"; /* api callbacks */ - ot->exec = text_toggle_comment_exec; + ot->exec = text_comment_exec; ot->poll = text_edit_poll; /* flags */ ot->flag = OPTYPE_UNDO; + + /* properties */ + PropertyRNA *prop; + prop = RNA_def_enum(ot->srna, "type", comment_items, 0, "Type", "Add or remove comments"); + RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } /** \} */ |