diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-01-08 10:39:12 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-01-08 10:39:12 +0400 |
commit | 2dba2e72b76ba2933d6ca7d3e79ad669c430e3a5 (patch) | |
tree | 19e2d2af6a5923952d29151d5ae43a69b11508e4 /source/blender/editors | |
parent | 3fbd63c52e25344f115b5cd67a218436bc4007cf (diff) |
Code Cleanup: de-duplicate text pasting which only used the first line
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/curve/editfont.c | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 27 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 5 | ||||
-rw-r--r-- | source/blender/editors/util/numinput.c | 10 |
5 files changed, 18 insertions, 31 deletions
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index 56b8c96c60a..b76eaaf47b7 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -515,14 +515,12 @@ static int paste_from_clipboard(bContext *C, ReportList *reports) int filelen; int retval; - strp = WM_clipboard_text_get(false); + strp = WM_clipboard_text_get(false, &filelen); if (strp == NULL) { BKE_report(reports, RPT_ERROR, "Clipboard empty"); return OPERATOR_CANCELLED; } - filelen = strlen(strp); - if ((filelen <= MAXTEXT) && font_paste_utf8(C, strp, filelen)) { text_update_edited(C, scene, obedit, 1, FO_EDIT); retval = OPERATOR_FINISHED; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 470c042e7c7..79ae8536acc 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1402,15 +1402,10 @@ static void ui_but_copy_paste(bContext *C, uiBut *but, uiHandleButtonData *data, if (mode == 'v') { /* extract first line from clipboard in case of multi-line copies */ - char *p, *pbuf = WM_clipboard_text_get(0); - p = pbuf; - if (p) { - int i = 0; - while (*p && *p != '\r' && *p != '\n' && i < UI_MAX_DRAW_STR) { - buf[i++] = *p; - p++; - } - buf[i] = 0; + int pbuf_len; + char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len); + if (pbuf) { + BLI_strncpy(buf, pbuf, sizeof(buf)); MEM_freeN(pbuf); } } @@ -1997,7 +1992,7 @@ enum { static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const int mode) { - char *str, *p, *pbuf; + char *str, *pbuf; int x; bool changed = false; int str_len, buf_len; @@ -2009,17 +2004,13 @@ static bool ui_textedit_copypaste(uiBut *but, uiHandleButtonData *data, const in if (mode == UI_TEXTEDIT_PASTE) { /* TODO, ensure UTF8 ui_is_but_utf8() - campbell */ /* extract the first line from the clipboard */ - p = pbuf = WM_clipboard_text_get(0); + pbuf = WM_clipboard_text_get_firstline(false, &buf_len); - if (p && p[0]) { + if (pbuf) { char buf[UI_MAX_DRAW_STR] = {0}; unsigned int y; - buf_len = 0; - while (*p && *p != '\r' && *p != '\n' && buf_len < UI_MAX_DRAW_STR - 1) { - buf[buf_len++] = *p; - p++; - } - buf[buf_len] = 0; + + buf_len = BLI_strncpy_rlen(buf, pbuf, sizeof(buf)); /* paste over the current selection */ if ((but->selend - but->selsta) > 0) { diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index f24a204912e..0ddaa3444cc 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -970,8 +970,9 @@ static int console_paste_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); + int buf_len; - char *buf_str = WM_clipboard_text_get(0); + char *buf_str = WM_clipboard_text_get(false, &buf_len); char *buf_step, *buf_next; if (buf_str == NULL) diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 2849db7330a..cd4c214e0d6 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -797,11 +797,12 @@ static char *txt_copy_selected(Text *text) static int text_paste_exec(bContext *C, wmOperator *op) { + const bool selection = RNA_boolean_get(op->ptr, "selection"); Text *text = CTX_data_edit_text(C); char *buf; - int selection = RNA_boolean_get(op->ptr, "selection"); + int buf_len; - buf = WM_clipboard_text_get(selection); + buf = WM_clipboard_text_get(selection, &buf_len); if (!buf) return OPERATOR_CANCELLED; diff --git a/source/blender/editors/util/numinput.c b/source/blender/editors/util/numinput.c index 78499dac55b..2828973e91d 100644 --- a/source/blender/editors/util/numinput.c +++ b/source/blender/editors/util/numinput.c @@ -341,17 +341,13 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event) case VKEY: if (event->ctrl) { /* extract the first line from the clipboard */ - char *pbuf = WM_clipboard_text_get(0); + int pbuf_len; + char *pbuf = WM_clipboard_text_get_firstline(false, &pbuf_len); if (pbuf) { bool success; - /* Only copy string until first of this char. */ - char *cr = strchr(pbuf, '\r'); - char *cn = strchr(pbuf, '\n'); - if (cn && cn < cr) cr = cn; - if (cr) *cr = '\0'; - success = editstr_insert_at_cursor(n, pbuf, strlen(pbuf)); + success = editstr_insert_at_cursor(n, pbuf, pbuf_len); MEM_freeN(pbuf); if (!success) { |