[Bf-blender-cvs] [558f449f8c4] master: Cleanup: Text: Move to IDTypeInfo and remove unused BKE API.

Dalai Felinto noreply at git.blender.org
Fri Mar 6 20:07:07 CET 2020


Commit: 558f449f8c4b212302a2530daecda9346ea10177
Author: Dalai Felinto
Date:   Fri Mar 6 19:48:18 2020 +0100
Branches: master
https://developer.blender.org/rB558f449f8c4b212302a2530daecda9346ea10177

Cleanup: Text: Move to IDTypeInfo and remove unused BKE API.

===================================================================

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_text.h
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c
M	source/blender/blenkernel/intern/text.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index bd38b21749b..7289ceb95df 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -141,7 +141,7 @@ extern IDTypeInfo IDType_ID_KE;
 extern IDTypeInfo IDType_ID_WO;
 extern IDTypeInfo IDType_ID_SCR;
 // extern IDTypeInfo IDType_ID_VF;
-// extern IDTypeInfo IDType_ID_TXT;
+extern IDTypeInfo IDType_ID_TXT;
 // extern IDTypeInfo IDType_ID_SPK;
 // extern IDTypeInfo IDType_ID_SO;
 extern IDTypeInfo IDType_ID_GR;
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h
index c999a50c48b..51d589e61c3 100644
--- a/source/blender/blenkernel/BKE_text.h
+++ b/source/blender/blenkernel/BKE_text.h
@@ -32,8 +32,6 @@ struct Text;
 struct TextLine;
 
 void BKE_text_free_lines(struct Text *text);
-void BKE_text_free(struct Text *text);
-void BKE_text_init(struct Text *ta);
 struct Text *BKE_text_add(struct Main *bmain, const char *name);
 int txt_extended_ascii_as_utf8(char **str);
 bool BKE_text_reload(struct Text *text);
@@ -42,12 +40,7 @@ struct Text *BKE_text_load_ex(struct Main *bmain,
                               const char *relpath,
                               const bool is_internal);
 struct Text *BKE_text_load(struct Main *bmain, const char *file, const char *relpath);
-void BKE_text_copy_data(struct Main *bmain,
-                        struct Text *ta_dst,
-                        const struct Text *ta_src,
-                        const int flag);
 struct Text *BKE_text_copy(struct Main *bmain, const struct Text *ta);
-void BKE_text_make_local(struct Main *bmain, struct Text *text, const int flags);
 void BKE_text_clear(struct Text *text);
 void BKE_text_write(struct Text *text, const char *str);
 int BKE_text_file_modified_check(struct Text *text);
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 322e1f7e822..3ff8a1bebd5 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -68,7 +68,7 @@ static void id_type_init(void)
   INIT_TYPE(ID_WO);
   INIT_TYPE(ID_SCR);
   // INIT_TYPE(ID_VF);
-  // INIT_TYPE(ID_TXT);
+  INIT_TYPE(ID_TXT);
   // INIT_TYPE(ID_SPK);
   // INIT_TYPE(ID_SO);
   INIT_TYPE(ID_GR);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 252b2499905..b74bb134dd3 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -516,9 +516,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
       }
       return true;
     case ID_TXT:
-      if (!test) {
-        BKE_text_make_local(bmain, (Text *)id, flags);
-      }
+      BLI_assert(0);
       return true;
     case ID_SO:
       if (!test) {
@@ -739,7 +737,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BLI_assert(0);
         break;
       case ID_TXT:
-        BKE_text_copy_data(bmain, (Text *)*r_newid, (Text *)id, flag);
+        BLI_assert(0);
         break;
       case ID_GR:
         BLI_assert(0);
@@ -1363,7 +1361,7 @@ void BKE_libblock_init_empty(ID *id)
       BKE_vfont_init((VFont *)id);
       break;
     case ID_TXT:
-      BKE_text_init((Text *)id);
+      BLI_assert(0);
       break;
     case ID_SO:
       /* Another fuzzy case, think NULLified content is OK here... */
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 492de2b14ef..634e7c59c08 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -187,7 +187,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BKE_vfont_free((VFont *)id);
       break;
     case ID_TXT:
-      BKE_text_free((Text *)id);
+      BLI_assert(0);
       break;
     case ID_SPK:
       BKE_speaker_free((Speaker *)id);
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index c20ef21f486..847cd6841fe 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -37,6 +37,8 @@
 #include "BLI_listbase.h"
 #include "BLI_fileops.h"
 
+#include "BLT_translation.h"
+
 #include "DNA_constraint_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -47,6 +49,7 @@
 #include "DNA_node_types.h"
 #include "DNA_material_types.h"
 
+#include "BKE_idtype.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
 #include "BKE_text.h"
@@ -86,37 +89,100 @@
 
 /***/
 
+/****************************** Prototypes ************************/
+
 static void txt_pop_first(Text *text);
 static void txt_pop_last(Text *text);
 static void txt_delete_line(Text *text, TextLine *line);
 static void txt_delete_sel(Text *text);
 static void txt_make_dirty(Text *text);
 
-/***/
+/****************************** Text Datablock ************************/
+
+static void text_init_data(ID *id)
+{
+  Text *text = (Text *)id;
+  TextLine *tmp;
+
+  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(text, id));
+
+  text->name = NULL;
+
+  text->nlines = 1;
+  text->flags = TXT_ISDIRTY | TXT_ISMEM;
+  if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) {
+    text->flags |= TXT_TABSTOSPACES;
+  }
+
+  BLI_listbase_clear(&text->lines);
+
+  tmp = (TextLine *)MEM_mallocN(sizeof(TextLine), "textline");
+  tmp->line = (char *)MEM_mallocN(1, "textline_string");
+  tmp->format = NULL;
+
+  tmp->line[0] = 0;
+  tmp->len = 0;
+
+  tmp->next = NULL;
+  tmp->prev = NULL;
+
+  BLI_addhead(&text->lines, tmp);
+
+  text->curl = text->lines.first;
+  text->curc = 0;
+  text->sell = text->lines.first;
+  text->selc = 0;
+}
 
 /**
- * \note caller must handle `compiled` member.
+ * Only copy internal data of Text ID from source
+ * to already allocated/initialized destination.
+ * You probably never want to use that directly,
+ * use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
  */
-void BKE_text_free_lines(Text *text)
+static void text_copy_data(Main *UNUSED(bmain),
+                           ID *id_dst,
+                           const ID *id_src,
+                           const int UNUSED(flag))
 {
-  for (TextLine *tmp = text->lines.first, *tmp_next; tmp; tmp = tmp_next) {
-    tmp_next = tmp->next;
-    MEM_freeN(tmp->line);
-    if (tmp->format) {
-      MEM_freeN(tmp->format);
-    }
-    MEM_freeN(tmp);
+  Text *text_dst = (Text *)id_dst;
+  const Text *text_src = (Text *)id_src;
+
+  /* File name can be NULL. */
+  if (text_src->name) {
+    text_dst->name = BLI_strdup(text_src->name);
   }
 
-  BLI_listbase_clear(&text->lines);
+  text_dst->flags |= TXT_ISDIRTY;
 
-  text->curl = text->sell = NULL;
+  BLI_listbase_clear(&text_dst->lines);
+  text_dst->curl = text_dst->sell = NULL;
+  text_dst->compiled = NULL;
+
+  /* Walk down, reconstructing. */
+  for (TextLine *line_src = text_src->lines.first; line_src; line_src = line_src->next) {
+    TextLine *line_dst = MEM_mallocN(sizeof(*line_dst), __func__);
+
+    line_dst->line = BLI_strdup(line_src->line);
+    line_dst->format = NULL;
+    line_dst->len = line_src->len;
+
+    BLI_addtail(&text_dst->lines, line_dst);
+  }
+
+  text_dst->curl = text_dst->sell = text_dst->lines.first;
+  text_dst->curc = text_dst->selc = 0;
 }
 
 /** Free (or release) any data used by this text (does not free the text itself). */
-void BKE_text_free(Text *text)
+static void text_free_data(ID *id)
 {
   /* No animdata here. */
+  Text *text = (Text *)id;
 
   BKE_text_free_lines(text);
 
@@ -126,38 +192,41 @@ void BKE_text_free(Text *text)
 #endif
 }
 
-void BKE_text_init(Text *ta)
-{
-  TextLine *tmp;
+IDTypeInfo IDType_ID_TXT = {
+    .id_code = ID_TXT,
+    .id_filter = FILTER_ID_TXT,
+    .main_listbase_index = INDEX_ID_TXT,
+    .struct_size = sizeof(Text),
+    .name = "Text",
+    .name_plural = "texts",
+    .translation_context = BLT_I18NCONTEXT_ID_TEXT,
+    .flags = 0,
 
-  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ta, id));
+    .init_data = text_init_data,
+    .copy_data = text_copy_data,
+    .free_data = text_free_data,
+    .make_local = NULL,
+};
 
-  ta->name = NULL;
+/***/
 
-  ta->nlines = 1;
-  ta->flags = TXT_ISDIRTY | TXT_ISMEM;
-  if ((U.flag & USER_TXT_TABSTOSPACES_DISABLE) == 0) {
-    ta->flags |= TXT_TABSTOSPACES;
+/**
+ * \note caller must handle `compiled` member.
+ */
+void BKE_text_free_lines(Text *text)
+{
+  for (TextLine *tmp = text->lines.first, *tmp_next; tmp; tmp = tmp_next) {
+    tmp_next = tmp->next;
+    MEM_freeN(tmp->line);
+    if (tmp->format) {
+      MEM_freeN(tmp->format);
+    }
+    MEM_freeN(tmp);
   }
 
-  BLI_listbase_clear(&ta->lines);
-
-  tmp = (TextLine *)MEM_mallocN(sizeof(TextLine), "textline");
-  tmp->line = (char *)MEM_mallocN(1, "textline_string");
-  tmp->format = NULL;
-
-  tmp->line[0] = 0;
-  tmp->len = 0;
-
-  tmp->next = NULL;
-  tmp->prev = NULL;
-
-  BLI_addhead(&ta->lines, tmp);
+  BLI_listbase_clear(&text->lines);
 
-  ta->curl = ta->lines.first;
-  ta->curc = 0;
-  ta->sell = ta->lines.first;
-  ta->selc = 0;
+  text->curl = text->sell = NULL;
 }
 
 Text *BKE_text_add(Main *bmain, const char *name)
@@ -168,7 +237,7 @@ Text *BKE_text_add(Main *bmain, const char *name)
   /* Texts always have 'real' user (see also read code). */
   id_us_ensure_real(&ta->id);
 
-  BKE_text_init(ta);
+  text_init_data(&ta->id);
 
   return ta;
 }
@@ -393,47 +462,6 @@ Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
   return BKE_text_load_ex(bmain, file, relpath, false);
 }
 
-/**
- * Only copy internal data of Text ID from source
- * to already allocated/initialized destination.
- * You probably never want to use that directly,
- * use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
- *
- * WARNING! This function will not handle ID user count!
- *
- * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
- */
-void BKE_text_copy_data(Main *UNUSED(bmain),
-                        Text *ta_dst,
-               

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list