Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2019-08-01 13:31:57 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-08-01 13:31:57 +0300
commit433eb3f35d5cf3933801027e33399923609c6539 (patch)
treebf1eecf7af214c1b2dc6b78c951eb3457ee41e7b /source/blender/editors/space_text
parent3a47fbfac520f6a9c0aaef19e351a1a00cb83af5 (diff)
Text: toggle comment operator
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r--source/blender/editors/space_text/space_text.c1
-rw-r--r--source/blender/editors/space_text/text_intern.h1
-rw-r--r--source/blender/editors/space_text/text_ops.c44
3 files changed, 46 insertions, 0 deletions
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index c5e90cf247d..7d8424a5996 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -199,6 +199,7 @@ static void text_operatortypes(void)
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_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 aab5069f919..400405155f8 100644
--- a/source/blender/editors/space_text/text_intern.h
+++ b/source/blender/editors/space_text/text_intern.h
@@ -121,6 +121,7 @@ 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_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 0c180dc150c..95e7d906b11 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1294,6 +1294,50 @@ void TEXT_OT_uncomment(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
+/** \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;
+}
+
+void TEXT_OT_toggle_comment(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Toggle Comment";
+ ot->idname = "TEXT_OT_toggle_comment";
+
+ /* api callbacks */
+ ot->exec = text_toggle_comment_exec;
+ ot->poll = text_edit_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Convert Whitespace Operator
* \{ */