Cleanup: get rid of BKE_text_unlink(), replace by usage of generic BKE_libblock_... API.

This commit is contained in:
Bastien Montagne 2016-06-25 18:12:23 +02:00
parent 42872656d8
commit 1b6cf7a99b
4 changed files with 2 additions and 190 deletions

View File

@ -53,7 +53,6 @@ struct Text *BKE_text_load_ex(struct Main *bmain, const char *file, const cha
const bool is_internal);
struct Text *BKE_text_load (struct Main *bmain, const char *file, const char *relpath);
struct Text *BKE_text_copy (struct Main *bmain, struct Text *ta);
void BKE_text_unlink (struct Main *bmain, struct Text *text);
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);

View File

@ -498,191 +498,6 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
return tan;
}
void BKE_text_unlink(Main *bmain, Text *text)
{
bScreen *scr;
ScrArea *area;
SpaceLink *sl;
Object *ob;
bController *cont;
bActuator *act;
bConstraint *con;
bNodeTree *ntree;
bNode *node;
Material *mat;
Lamp *la;
Tex *te;
World *wo;
FreestyleLineStyle *linestyle;
Scene *sce;
SceneRenderLayer *srl;
FreestyleModuleConfig *module;
bool update;
for (ob = bmain->object.first; ob; ob = ob->id.next) {
/* game controllers */
for (cont = ob->controllers.first; cont; cont = cont->next) {
if (cont->type == CONT_PYTHON) {
bPythonCont *pc;
pc = cont->data;
if (pc->text == text) pc->text = NULL;
}
}
/* game actuators */
for (act = ob->actuators.first; act; act = act->next) {
if (act->type == ACT_2DFILTER) {
bTwoDFilterActuator *tfa;
tfa = act->data;
if (tfa->text == text) tfa->text = NULL;
}
}
/* pyconstraints */
update = 0;
if (ob->type == OB_ARMATURE && ob->pose) {
bPoseChannel *pchan;
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
for (con = pchan->constraints.first; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text == text) data->text = NULL;
update = 1;
}
}
}
}
for (con = ob->constraints.first; con; con = con->next) {
if (con->type == CONSTRAINT_TYPE_PYTHON) {
bPythonConstraint *data = con->data;
if (data->text == text) data->text = NULL;
update = 1;
}
}
if (update)
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
/* nodes */
for (la = bmain->lamp.first; la; la = la->id.next) {
ntree = la->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_FRAME) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
for (linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
ntree = linestyle->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_FRAME) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
for (mat = bmain->mat.first; mat; mat = mat->id.next) {
ntree = mat->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (ELEM(node->type, SH_NODE_SCRIPT, NODE_FRAME)) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
for (te = bmain->tex.first; te; te = te->id.next) {
ntree = te->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_FRAME) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
for (wo = bmain->world.first; wo; wo = wo->id.next) {
ntree = wo->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_FRAME) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
for (sce = bmain->scene.first; sce; sce = sce->id.next) {
ntree = sce->nodetree;
if (!ntree)
continue;
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == NODE_FRAME) {
Text *ntext = (Text *)node->id;
if (ntext == text) node->id = NULL;
}
}
/* Freestyle (while looping over the scene) */
for (srl = sce->r.layers.first; srl; srl = srl->next) {
for (module = srl->freestyleConfig.modules.first; module; module = module->next) {
if (module->script == text)
module->script = NULL;
}
}
}
for (ntree = bmain->nodetree.first; ntree; ntree = ntree->id.next) {
for (node = ntree->nodes.first; node; node = node->next) {
if (ELEM(node->type, SH_NODE_SCRIPT, NODE_FRAME)) {
if ((Text *)node->id == text) {
node->id = NULL;
}
}
}
}
/* text space */
for (scr = bmain->screen.first; scr; scr = scr->id.next) {
for (area = scr->areabase.first; area; area = area->next) {
for (sl = area->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_TEXT) {
SpaceText *st = (SpaceText *) sl;
if (st->text == text) {
st->text = NULL;
st->top = 0;
}
}
}
}
}
text->id.us = 0;
}
void BKE_text_clear(Text *text) /* called directly from rna */
{
int oldstate;

View File

@ -384,8 +384,7 @@ static int text_unlink_exec(bContext *C, wmOperator *UNUSED(op))
}
}
BKE_text_unlink(bmain, text);
BKE_libblock_free(bmain, text);
BKE_libblock_delete(bmain, text);
text_drawcache_tag_update(st, 1);
WM_event_add_notifier(C, NC_TEXT | NA_REMOVED, NULL);

View File

@ -84,8 +84,7 @@ public:
Text *text = BKE_text_load(&_freestyle_bmain, fn, G.main->name);
if (text) {
ok = BPY_execute_text(_context, text, reports, false);
BKE_text_unlink(&_freestyle_bmain, text);
BKE_libblock_free(&_freestyle_bmain, text);
BKE_libblock_delete(&_freestyle_bmain, text);
}
else {
BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn);