diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 23 | ||||
-rw-r--r-- | source/blender/editors/space_text/space_text.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 30 |
5 files changed, 60 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 0a94d89a121..b1902c75afb 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -96,6 +96,7 @@ void txt_unindent (struct Text *text); void txt_comment (struct Text *text); void txt_indent (struct Text *text); void txt_uncomment (struct Text *text); +void txt_duplicate_line (struct Text *text); int setcurr_tab_spaces (struct Text *text, int space); void txt_add_marker (struct Text *text, struct TextLine *line, int start, int end, const unsigned char color[4], int group, int flags); @@ -169,6 +170,8 @@ int text_check_whitespace(const char ch); #define UNDO_COMMENT 034 #define UNDO_UNCOMMENT 035 +#define UNDO_DUPLICATE 040 + /* Marker flags */ #define TMARK_TEMP 0x01 /* Remove on non-editing events, don't save */ #define TMARK_EDITALL 0x02 /* Edit all markers of the same group as one */ diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 27501b6a589..31278ab53aa 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2207,6 +2207,9 @@ void txt_do_undo(Text *text) text->undo_pos--; break; + case UNDO_DUPLICATE: + txt_delete_line(text, text->curl->next); + break; default: //XXX error("Undo buffer error - resetting"); text->undo_pos= -1; @@ -2404,6 +2407,9 @@ void txt_do_redo(Text *text) txt_uncomment(text); } break; + case UNDO_DUPLICATE: + txt_duplicate_line(text); + break; default: //XXX error("Undo buffer error - resetting"); text->undo_pos= -1; @@ -2545,6 +2551,23 @@ static void txt_combine_lines (Text *text, TextLine *linea, TextLine *lineb) txt_clean_text(text); } +void txt_duplicate_line(Text *text) +{ + TextLine *textline; + + if (!text || !text->curl) return; + + if (text->curl == text->sell) { + textline = txt_new_line(text->curl->line); + BLI_insertlinkafter(&text->lines, text->curl, textline); + + txt_make_dirty(text); + txt_clean_text(text); + + if (!undoing) txt_undo_add_op(text, UNDO_DUPLICATE); + } +} + void txt_delete_char(Text *text) { unsigned int c='\n'; diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index beccca51265..032cc4ecbf2 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -187,6 +187,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_paste); WM_operatortype_append(TEXT_OT_copy); WM_operatortype_append(TEXT_OT_cut); + WM_operatortype_append(TEXT_OT_duplicate_line); WM_operatortype_append(TEXT_OT_convert_whitespace); WM_operatortype_append(TEXT_OT_uncomment); @@ -297,6 +298,8 @@ static void text_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "TEXT_OT_cut", DELKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "TEXT_OT_copy", INSERTKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "TEXT_OT_paste", INSERTKEY, KM_PRESS, KM_SHIFT, 0); + + WM_keymap_add_item(keymap, "TEXT_OT_duplicate_line", DKEY, KM_PRESS, KM_CTRL, 0); if (U.uiflag & USER_MMB_PASTE) { // XXX not dynamic kmi = WM_keymap_add_item(keymap, "TEXT_OT_paste", MIDDLEMOUSE, KM_PRESS, 0, 0); @@ -353,7 +356,6 @@ static void text_keymap(struct wmKeyConfig *keyconf) RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_move_select", ENDKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)->ptr, "type", FILE_BOTTOM); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_NEXT_CHAR); - RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_CHAR); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, 0, 0)->ptr, "type", DEL_PREV_CHAR); RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", BACKSPACEKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "type", DEL_PREV_CHAR); /* same as above [#26623] */ RNA_enum_set(WM_keymap_add_item(keymap, "TEXT_OT_delete", DELKEY, KM_PRESS, KM_CTRL, 0)->ptr, "type", DEL_NEXT_WORD); diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index 2d297dd20d7..07d2dffb95b 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -118,6 +118,7 @@ void TEXT_OT_refresh_pyconstraints(struct wmOperatorType *ot); void TEXT_OT_paste(struct wmOperatorType *ot); void TEXT_OT_copy(struct wmOperatorType *ot); 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); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 730dfb7d979..f60217ba8ac 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -826,6 +826,36 @@ void TEXT_OT_paste(wmOperatorType *ot) RNA_def_boolean(ot->srna, "selection", 0, "Selection", "Paste text selected elsewhere rather than copied (X11 only)"); } +/**************** duplicate operator *******************/ + +static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Text *text= CTX_data_edit_text(C); + + txt_duplicate_line(text); + + WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + + /* run the script while editing, evil but useful */ + if (CTX_wm_space_text(C)->live_edit) { + text_run_script(C, NULL); + } + + return OPERATOR_FINISHED; +} + +void TEXT_OT_duplicate_line(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Duplicate Line"; + ot->idname = "TEXT_OT_duplicate_line"; + ot->description = "Duplicate the current line"; + + /* api callbacks */ + ot->exec = text_duplicate_line_exec; + ot->poll = text_edit_poll; +} + /******************* copy operator *********************/ static void txt_copy_clipboard(Text *text) |