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
path: root/source
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-06-02 21:52:06 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-06-02 21:52:06 +0400
commitd8c2709414ec3b25c2bdaeea57eb26c2ff91f977 (patch)
tree590b4a6151a11ad2618a834aea2dfc4eafe49761 /source
parent5506ab080d1f03acd9e0e09a43b244b2ccece544 (diff)
Better API design for making text datablocks after loading.
An optional 'internal' argument was added to the bpy.data.texts.load() operator. The changes in revision 57153 were reverted, so that the is_in_memory and is_dirty properties of text datablocks are not editable again. In the C API layer, BKE_text_load_ex() was introduced to allow for optionally making text datablocks internal after loading.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_text.h2
-rw-r--r--source/blender/blenkernel/intern/text.c16
-rw-r--r--source/blender/editors/space_text/text_ops.c9
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c5
-rw-r--r--source/blender/makesrna/intern/rna_text.c2
5 files changed, 21 insertions, 13 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index 8fd712bde72..2406fa51c84 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -48,6 +48,8 @@ int txt_get_undostate (void);
struct Text *BKE_text_add (struct Main *bmain, const char *name);
int txt_extended_ascii_as_utf8(char **str);
int BKE_text_reload (struct Text *text);
+struct Text *BKE_text_load_ex(struct Main *bmain, const char *file, const char *relpath,
+ const bool is_internal);
struct Text *BKE_text_load (struct Main *bmain, const char *file, const char *relpath);
struct Text *BKE_text_copy (struct Text *ta);
void BKE_text_unlink (struct Main *bmain, struct Text *text);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index 470de8a205d..296f25e303e 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -362,7 +362,7 @@ int BKE_text_reload(Text *text)
return 1;
}
-Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
+Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal)
{
FILE *fp;
int i, llen, len;
@@ -392,8 +392,13 @@ Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
len = ftell(fp);
fseek(fp, 0L, SEEK_SET);
- ta->name = MEM_mallocN(strlen(file) + 1, "text_name");
- strcpy(ta->name, file);
+ if (is_internal == false) {
+ ta->name = MEM_mallocN(strlen(file) + 1, "text_name");
+ strcpy(ta->name, file);
+ }
+ else {
+ ta->flags |= TXT_ISMEM | TXT_ISDIRTY;
+ }
init_undo_text(ta);
@@ -460,6 +465,11 @@ Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
return ta;
}
+Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
+{
+ return BKE_text_load_ex(bmain, file, relpath, false);
+}
+
Text *BKE_text_copy(Text *ta)
{
Text *tan;
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 04675430339..ca6bab1d1da 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -238,7 +238,7 @@ static int text_open_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", str);
- text = BKE_text_load(bmain, str, G.main->name);
+ text = BKE_text_load_ex(bmain, str, G.main->name, internal);
if (!text) {
if (op->customdata) MEM_freeN(op->customdata);
@@ -264,13 +264,6 @@ static int text_open_exec(bContext *C, wmOperator *op)
st->text = text;
st->top = 0;
}
-
- if (internal) {
- if (text->name)
- MEM_freeN(text->name);
-
- text->name = NULL;
- }
text_drawcache_tag_update(st, 1);
WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 1e77a799cd4..4c652770e3f 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -725,12 +725,12 @@ static void rna_Main_texts_remove(Main *bmain, PointerRNA *text_ptr)
RNA_POINTER_INVALIDATE(text_ptr);
}
-static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath)
+static Text *rna_Main_texts_load(Main *bmain, ReportList *reports, const char *filepath, int is_internal)
{
Text *txt;
errno = 0;
- txt = BKE_text_load(bmain, filepath, bmain->name);
+ txt = BKE_text_load_ex(bmain, filepath, bmain->name, is_internal);
if (!txt)
BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -1701,6 +1701,7 @@ void RNA_def_main_texts(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_function_ui_description(func, "Add a new text to the main database from a file");
parm = RNA_def_string_file_path(func, "filepath", "Path", FILE_MAX, "", "path for the datablock");
RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_boolean(func, "internal", 0, "Make internal", "Make text file internal after loading");
/* return type */
parm = RNA_def_pointer(func, "text", "Text", "", "New text datablock");
RNA_def_function_return(func, parm);
diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c
index b1eb0bb2228..df6181af4b2 100644
--- a/source/blender/makesrna/intern/rna_text.c
+++ b/source/blender/makesrna/intern/rna_text.c
@@ -148,6 +148,7 @@ static void rna_def_text(BlenderRNA *brna)
prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISDIRTY);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Dirty", "Text file has been edited since last save");
prop = RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE);
@@ -157,6 +158,7 @@ static void rna_def_text(BlenderRNA *brna)
prop = RNA_def_property(srna, "is_in_memory", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISMEM);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Memory", "Text file is in memory, without a corresponding file on disk");
prop = RNA_def_property(srna, "use_module", PROP_BOOLEAN, PROP_NONE);