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>2014-01-08 10:39:12 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-08 10:39:12 +0400
commit2dba2e72b76ba2933d6ca7d3e79ad669c430e3a5 (patch)
tree19e2d2af6a5923952d29151d5ae43a69b11508e4 /source/blender/windowmanager
parent3fbd63c52e25344f115b5cd67a218436bc4007cf (diff)
Code Cleanup: de-duplicate text pasting which only used the first line
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h3
-rw-r--r--source/blender/windowmanager/intern/wm_window.c54
2 files changed, 49 insertions, 8 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index d8f558bf2c9..8c4c41be84b 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -409,7 +409,8 @@ void WM_job_main_thread_lock_acquire(struct wmJob *job);
void WM_job_main_thread_lock_release(struct wmJob *job);
/* clipboard */
-char *WM_clipboard_text_get(bool selection);
+char *WM_clipboard_text_get(bool selection, int *r_len);
+char *WM_clipboard_text_get_firstline(bool selection, int *r_len);
void WM_clipboard_text_set(const char *buf, bool selection);
/* progress */
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index d3936ff32e2..19b87766ffd 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1199,31 +1199,71 @@ void WM_event_remove_timer(wmWindowManager *wm, wmWindow *UNUSED(win), wmTimer *
/* ******************* clipboard **************** */
-char *WM_clipboard_text_get(bool selection)
+static char *wm_clipboard_text_get_ex(bool selection, int *r_len,
+ bool firstline)
{
char *p, *p2, *buf, *newbuf;
- if (G.background)
+ if (G.background) {
+ *r_len = 0;
return NULL;
+ }
buf = (char *)GHOST_getClipboard(selection);
- if (!buf)
+ if (!buf) {
+ *r_len = 0;
return NULL;
+ }
/* always convert from \r\n to \n */
- newbuf = MEM_callocN(strlen(buf) + 1, __func__);
+ p2 = newbuf = MEM_mallocN(strlen(buf) + 1, __func__);
- for (p = buf, p2 = newbuf; *p; p++) {
- if (*p != '\r')
- *(p2++) = *p;
+ if (firstline) {
+ /* will return an over-alloc'ed value in the case there are newlines */
+ for (p = buf; *p; p++) {
+ if ((*p != '\n') && (*p != '\r')) {
+ *(p2++) = *p;
+ }
+ else {
+ break;
+ }
+ }
+ }
+ else {
+ for (p = buf; *p; p++) {
+ if (*p != '\r') {
+ *(p2++) = *p;
+ }
+ }
}
+
*p2 = '\0';
free(buf); /* ghost uses regular malloc */
+ *r_len = (p2 - newbuf);
+
return newbuf;
}
+/**
+ * Return text from the clipboard.
+ *
+ * \note Caller needs to check for valid utf8 if this is a requirement.
+ */
+char *WM_clipboard_text_get(bool selection, int *r_len)
+{
+ return wm_clipboard_text_get_ex(selection, r_len, false);
+}
+
+/**
+ * Convenience function for pasting to areas of Blender which don't support newlines.
+ */
+char *WM_clipboard_text_get_firstline(bool selection, int *r_len)
+{
+ return wm_clipboard_text_get_ex(selection, r_len, true);
+}
+
void WM_clipboard_text_set(const char *buf, bool selection)
{
if (!G.background) {