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:
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r--source/blender/editors/space_text/text_ops.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 8e81336912b..44f7a097a18 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -159,10 +159,24 @@ static int new_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text;
+ PointerRNA ptr, idptr;
+ PropertyRNA *prop;
text= add_empty_text("Text");
- if(st) {
+ /* hook into UI */
+ uiIDContextProperty(C, &ptr, &prop);
+
+ if(prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ text->id.us--;
+
+ RNA_id_pointer_create(&text->id, &idptr);
+ RNA_property_pointer_set(&ptr, prop, idptr);
+ RNA_property_update(C, &ptr, prop);
+ }
+ else if(st) {
st->text= text;
st->top= 0;
}
@@ -186,23 +200,61 @@ void TEXT_OT_new(wmOperatorType *ot)
/******************* open operator *********************/
+static void open_init(bContext *C, wmOperator *op)
+{
+ PropertyPointerRNA *pprop;
+
+ op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
+ uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
+}
+
+static int open_cancel(bContext *C, wmOperator *op)
+{
+ MEM_freeN(op->customdata);
+ return OPERATOR_CANCELLED;
+}
+
static int open_exec(bContext *C, wmOperator *op)
{
SpaceText *st= CTX_wm_space_text(C);
Text *text;
+ PropertyPointerRNA *pprop;
+ PointerRNA idptr;
char str[FILE_MAX];
RNA_string_get(op->ptr, "path", str);
text= add_text(str, G.sce);
- if(st) {
+ if(!text) {
+ if(op->customdata) MEM_freeN(op->customdata);
+ return OPERATOR_CANCELLED;
+ }
+
+ if(!op->customdata)
+ open_init(C, op);
+
+ /* hook into UI */
+ pprop= op->customdata;
+
+ if(pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ text->id.us--;
+
+ RNA_id_pointer_create(&text->id, &idptr);
+ RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+ RNA_property_update(C, &pprop->ptr, pprop->prop);
+ }
+ else if(st) {
st->text= text;
st->top= 0;
}
WM_event_add_notifier(C, NC_TEXT|NA_ADDED, text);
+ MEM_freeN(op->customdata);
+
return OPERATOR_FINISHED;
}
@@ -214,6 +266,7 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
if(RNA_property_is_set(op->ptr, "path"))
return open_exec(C, op);
+ open_init(C, op);
RNA_string_set(op->ptr, "path", path);
WM_event_add_fileselect(C, op);
@@ -230,6 +283,7 @@ void TEXT_OT_open(wmOperatorType *ot)
/* api callbacks */
ot->exec= open_exec;
ot->invoke= open_invoke;
+ ot->cancel= open_cancel;
ot->poll= text_new_poll;
/* properties */