[Bf-blender-cvs] [7722fcd] tmp_text_copy_paste: Merge clipboard and internal copy/paste systems for font objects
Dalai Felinto
noreply at git.blender.org
Thu Feb 11 16:35:12 CET 2016
Commit: 7722fcd42bf6ce7f1f809b23fb78022a44f79c15
Author: Dalai Felinto
Date: Thu Feb 11 13:35:01 2016 -0200
Branches: tmp_text_copy_paste
https://developer.blender.org/rB7722fcd42bf6ce7f1f809b23fb78022a44f79c15
Merge clipboard and internal copy/paste systems for font objects
Untested commit, I think it is crashing at the moment, I will check on it soon
===================================================================
M source/blender/blenkernel/BKE_global.h
M source/blender/blenkernel/intern/curve.c
M source/blender/editors/curve/curve_intern.h
M source/blender/editors/curve/curve_ops.c
M source/blender/editors/curve/editfont.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index 26a4059..b8ccede 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -38,6 +38,7 @@
*/
#include "DNA_listBase.h"
+#include "DNA_curve_types.h"
#ifdef __cplusplus
extern "C" {
@@ -90,6 +91,10 @@ typedef struct Global {
/* message to use when autoexec fails */
char autoexec_fail[200];
+
+ /* font objects copy/paste texts */
+ wchar_t copybuf[32766 + 4]; /* 32766 + 4 = MAXTEXT + 4 */
+ struct CharInfo copybufinfo[32766 + 4]; /* 32766 + 4 = MAXTEXT + 4 */
} Global;
/* **************** GLOBAL ********************* */
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index b518a1f..79199f8 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -109,10 +109,6 @@ void BKE_curve_editfont_free(Curve *cu)
MEM_freeN(ef->textbuf);
if (ef->textbufinfo)
MEM_freeN(ef->textbufinfo);
- if (ef->copybuf)
- MEM_freeN(ef->copybuf);
- if (ef->copybufinfo)
- MEM_freeN(ef->copybufinfo);
if (ef->selboxes)
MEM_freeN(ef->selboxes);
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index 6987aa3..1af0b49 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -76,12 +76,9 @@ void FONT_OT_style_set(struct wmOperatorType *ot);
void FONT_OT_select_all(struct wmOperatorType *ot);
void FONT_OT_text_copy(struct wmOperatorType *ot);
-void FONT_OT_text_copy_to_clipboard(struct wmOperatorType *ot);
void FONT_OT_text_cut(struct wmOperatorType *ot);
-void FONT_OT_text_cut_to_clipboard(struct wmOperatorType *ot);
void FONT_OT_text_paste(struct wmOperatorType *ot);
void FONT_OT_text_paste_from_file(struct wmOperatorType *ot);
-void FONT_OT_text_paste_from_clipboard(struct wmOperatorType *ot);
void FONT_OT_move(struct wmOperatorType *ot);
void FONT_OT_move_select(struct wmOperatorType *ot);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index ad44c61..1fbd57d 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -63,12 +63,9 @@ void ED_operatortypes_curve(void)
WM_operatortype_append(FONT_OT_select_all);
WM_operatortype_append(FONT_OT_text_copy);
- WM_operatortype_append(FONT_OT_text_copy_to_clipboard);
WM_operatortype_append(FONT_OT_text_cut);
- WM_operatortype_append(FONT_OT_text_cut_to_clipboard);
WM_operatortype_append(FONT_OT_text_paste);
WM_operatortype_append(FONT_OT_text_paste_from_file);
- WM_operatortype_append(FONT_OT_text_paste_from_clipboard);
WM_operatortype_append(FONT_OT_move);
WM_operatortype_append(FONT_OT_move_select);
@@ -213,18 +210,12 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "FONT_OT_select_all", AKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_copy_to_clipboard", CKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_cut_to_clipboard", XKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_paste_from_clipboard", VKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
#ifdef __APPLE__
WM_keymap_add_item(keymap, "FONT_OT_text_copy", CKEY, KM_PRESS, KM_OSKEY, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_copy_to_clipboard", CKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_cut", XKEY, KM_PRESS, KM_OSKEY, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_cut_to_clipboard", XKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0);
WM_keymap_add_item(keymap, "FONT_OT_text_paste", VKEY, KM_PRESS, KM_OSKEY, 0);
- WM_keymap_add_item(keymap, "FONT_OT_text_paste_from_clipboard", VKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0);
#endif
WM_keymap_add_item(keymap, "FONT_OT_line_break", RETKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index 34969fc..84e214f 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -51,6 +51,7 @@
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_font.h"
+#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
@@ -414,65 +415,6 @@ void FONT_OT_text_paste_from_file(wmOperatorType *ot)
WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
}
-
-/* -------------------------------------------------------------------- */
-/* Paste From Clipboard */
-
-static int paste_from_clipboard(bContext *C, ReportList *reports)
-{
- Object *obedit = CTX_data_edit_object(C);
- char *strp;
- int filelen;
- int retval;
-
- strp = WM_clipboard_text_get(false, &filelen);
- if (strp == NULL) {
- BKE_report(reports, RPT_ERROR, "Clipboard empty");
- return OPERATOR_CANCELLED;
- }
-
- if ((filelen <= MAXTEXT) && font_paste_utf8(C, strp, filelen)) {
- text_update_edited(C, obedit, FO_EDIT);
- retval = OPERATOR_FINISHED;
- }
- else {
- BKE_report(reports, RPT_ERROR, "Clipboard too long");
- retval = OPERATOR_CANCELLED;
- }
- MEM_freeN(strp);
-
- return retval;
-}
-
-static int paste_from_clipboard_exec(bContext *C, wmOperator *op)
-{
- int retval;
-
- retval = paste_from_clipboard(C, op->reports);
-
- return retval;
-}
-
-void FONT_OT_text_paste_from_clipboard(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Paste Clipboard";
- ot->description = "Paste contents from system clipboard";
- ot->idname = "FONT_OT_text_paste_from_clipboard";
-
- /* api callbacks */
- ot->exec = paste_from_clipboard_exec;
- ot->poll = ED_operator_editfont;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_TEXT, FILE_SPECIAL, FILE_OPENFILE,
- WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
-}
-
/******************* text to object operator ********************/
static void txt_add_object(bContext *C, TextLine *firstline, int totline, const float offset[3])
@@ -757,78 +699,49 @@ void FONT_OT_select_all(wmOperatorType *ot)
static void copy_selection(Object *obedit)
{
int selstart, selend;
-
- if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
- Curve *cu = obedit->data;
- EditFont *ef = cu->editfont;
-
- memcpy(ef->copybuf, ef->textbuf + selstart, ((selend - selstart) + 1) * sizeof(wchar_t));
- ef->copybuf[(selend - selstart) + 1] = 0;
- memcpy(ef->copybufinfo, ef->textbufinfo + selstart, ((selend - selstart) + 1) * sizeof(CharInfo));
- }
-}
-
-static int copy_text_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *obedit = CTX_data_edit_object(C);
-
- copy_selection(obedit);
-
- return OPERATOR_FINISHED;
-}
-
-void FONT_OT_text_copy(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Copy Text";
- ot->description = "Copy selected text to clipboard";
- ot->idname = "FONT_OT_text_copy";
-
- /* api callbacks */
- ot->exec = copy_text_exec;
- ot->poll = ED_operator_editfont;
-}
-
-/* Copy To Clipboard */
-
-static void copy_selection_to_clipboard(Object *obedit)
-{
- int selstart, selend;
size_t len;
char *buf = NULL;
-
+
if (BKE_vfont_select_get(obedit, &selstart, &selend)) {
Curve *cu = obedit->data;
EditFont *ef = cu->editfont;
len = selend - selstart + 1;
+
+ /* internal clipboard (for style) */
+ memcpy(&G.copybuf[0], ef->textbuf + selstart, len * sizeof(wchar_t));
+ G.copybuf[(selend - selstart) + 1] = 0;
+ memcpy(&G.copybufinfo[0], ef->textbufinfo + selstart, ((selend - selstart) + 1) * sizeof(CharInfo));
+
+ /* system clipboard */
buf = MEM_mallocN(len * sizeof(char), __func__);
BLI_strncpy_wchar_as_utf8(buf, ef->textbuf + selstart, len - 1);
WM_clipboard_text_set(buf, false);
}
- if (buf)
+ if (buf) {
MEM_freeN(buf);
+ }
}
-static int copy_to_clipboard_exec(bContext *C, wmOperator *UNUSED(op))
+static int copy_text_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *obedit = CTX_data_edit_object(C);
- copy_selection_to_clipboard(obedit);
+ copy_selection(obedit);
return OPERATOR_FINISHED;
}
-void FONT_OT_text_copy_to_clipboard(wmOperatorType *ot)
+void FONT_OT_text_copy(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Copy Text";
- ot->description = "Copy selected text to system clipboard";
- ot->idname = "FONT_OT_text_copy_to_clipboard";
-
+ ot->description = "Copy selected text to clipboard";
+ ot->idname = "FONT_OT_text_copy";
+
/* api callbacks */
- ot->exec = copy_to_clipboard_exec;
+ ot->exec = copy_text_exec;
ot->poll = ED_operator_editfont;
}
@@ -865,39 +778,6 @@ void FONT_OT_text_cut(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/* Cut To Clipboard */
-
-static int cut_to_clipboard_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *obedit = CTX_data_edit_object(C);
- int selstart, selend;
-
- if (!BKE_vfont_select_get(obedit, &selstart, &selend))
- return OPERATOR_CANCELLED;
-
- copy_selection_to_clipboard(obedit);
- kill_selection(obedit, 0);
-
- text_update_edited(C, obedit, FO_EDIT);
-
- return OPERATOR_FINISHED;
-}
-
-void FONT_OT_text_cut_to_clipboard(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Cut Text";
- ot->description = "Cut selected text to system clipboard";
- ot->idname = "FONT_OT_text_cut_to_clipboard";
-
- /* api callbacks */
- ot->exec = cut_to_clipboard_exec;
- ot->poll = ED_operator_editfont;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
/******************* paste text operator ********************/
static bool paste_selection(Object *obedit, ReportList *reports)
@@ -906,7 +786,7 @@ static bool paste_selection(Object *obedit, ReportList *reports)
EditFont *ef = cu->editfont;
int len = wcslen(ef->copybuf);
- if (font_paste_wchar(obedit, ef->copybuf, len, ef->copybufinfo)) {
+ if (font_paste_wchar(obedit, &G.copybuf[
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list