Link/Append, small changes:

* Added separate menu items for Link and Append.
* Change some OPERATOR_FINISHED to OPERATOR_CANCELLED.
* Remove some IPO specific hacks, these are no longer ID blocks,
  so not necessary to take into account.
* Some comment and code formatting tweaks.
This commit is contained in:
Brecht Van Lommel 2009-09-14 12:30:49 +00:00
parent 6cee5201ec
commit 4539bb9a98
4 changed files with 83 additions and 93 deletions

@ -61,7 +61,8 @@ class INFO_MT_file(bpy.types.Menu):
layout.itemS()
layout.operator_context = "INVOKE_AREA"
layout.itemO("wm.link_append", text="Append or Link")
layout.itemO("wm.link_append", text="Link")
layout.item_booleanO("wm.link_append", "link", False, text="Append")
layout.itemS()
layout.itemM("INFO_MT_file_import")

@ -455,16 +455,14 @@ void flag_all_listbases_ids(short flag, short value)
while(a--) flag_listbase_ids(lbarray[a], flag, value);
}
void recalc_all_library_objects(struct Main *main)
void recalc_all_library_objects(Main *main)
{
/* DISPLISTS? */
Object *ob= main->object.first;
while(ob) {
if(ob->id.lib) {
Object *ob;
/* flag for full recalc */
for(ob=main->object.first; ob; ob=ob->id.next)
if(ob->id.lib)
ob->recalc |= OB_RECALC;
}
ob= ob->id.next;
}
}
/* note: MAX_LIBARRAY define should match this code */

@ -1184,11 +1184,6 @@ void filelist_from_main(struct FileList *filelist)
id= lb->first;
filelist->numfiles= 0;
while(id) {
/* XXXXX TODO: the selection of the ipo blocktype might go somewhere else?
if(filelist->has_func && idcode==ID_IP) {
if(filelist->ipotype== ((Ipo *)id)->blocktype) filelist->numfiles++;
}
else */
if (!filelist->hide_dot || id->name[2] != '.') {
filelist->numfiles++;
}
@ -1214,14 +1209,6 @@ void filelist_from_main(struct FileList *filelist)
totlib= totbl= 0;
while(id) {
#if 0
// XXXXX TODO: this is deprecated, checks for correct IPO block?
ok= 0;
if(filelist->has_func && idcode==ID_IP) {
if(filelist->ipotype== ((Ipo *)id)->blocktype) ok= 1;
}
else ok= 1;
#endif
ok = 1;
if(ok) {
if (!filelist->hide_dot || id->name[2] != '.') {

@ -247,7 +247,7 @@ wmOperatorType *WM_operatortype_append_macro(char *idname, char *name, int flag)
ot->idname= idname;
ot->name= name;
ot->flag= OPTYPE_MACRO | flag;
ot->flag= OPTYPE_MACRO|flag;
ot->exec= wm_macro_exec;
ot->invoke= wm_macro_invoke;
@ -542,7 +542,7 @@ int WM_operator_winactive(bContext *C)
}
/* op->invoke */
static void redo_cb(bContext *C, void *arg_op, void *arg2)
static void redo_cb(bContext *C, void *arg_op, int event)
{
wmOperator *lastop= arg_op;
@ -564,7 +564,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
block= uiBeginBlock(C, ar, "redo_popup", UI_EMBOSS);
uiBlockClearFlag(block, UI_BLOCK_LOOP);
uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN|UI_BLOCK_RET_1);
uiBlockSetFunc(block, redo_cb, arg_op, NULL);
uiBlockSetHandleFunc(block, redo_cb, arg_op);
if(!op->properties) {
IDPropertyTemplate val = {0};
@ -881,21 +881,9 @@ static void WM_OT_open_recentfile(wmOperatorType *ot)
RNA_def_enum_funcs(prop, open_recentfile_itemf);
}
/* ********* main file *********** */
/* *************** open file **************** */
static void untitled(char *name)
{
if (G.save_over == 0 && strlen(name) < FILE_MAX-16) {
char *c= BLI_last_slash(name);
if (c)
strcpy(&c[1], "untitled.blend");
else
strcpy(name, "untitled.blend");
}
}
static void load_set_load_ui(wmOperator *op)
static void open_set_load_ui(wmOperator *op)
{
if(!RNA_property_is_set(op->ptr, "load_ui"))
RNA_boolean_set(op->ptr, "load_ui", !(U.flag & USER_FILENOUI));
@ -904,7 +892,7 @@ static void load_set_load_ui(wmOperator *op)
static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
RNA_string_set(op->ptr, "path", G.sce);
load_set_load_ui(op);
open_set_load_ui(op);
WM_event_add_fileselect(C, op);
@ -916,7 +904,7 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
char path[FILE_MAX];
RNA_string_get(op->ptr, "path", path);
load_set_load_ui(op);
open_set_load_ui(op);
if(RNA_boolean_get(op->ptr, "load_ui"))
G.fileflags &= ~G_FILE_NO_UI;
@ -947,9 +935,11 @@ static void WM_OT_open_mainfile(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "load_ui", 1, "Load UI", "Load user interface setup in the .blend file.");
}
/* **************** link/append *************** */
static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
if (RNA_property_is_set(op->ptr, "path")) {
if(RNA_property_is_set(op->ptr, "path")) {
return WM_operator_call(C, op);
}
else {
@ -962,27 +952,24 @@ static int wm_link_append_invoke(bContext *C, wmOperator *op, wmEvent *event)
static short wm_link_append_flag(wmOperator *op)
{
short flag = 0;
if (RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
if (RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
if (RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
if (RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
short flag= 0;
if(RNA_boolean_get(op->ptr, "autoselect")) flag |= FILE_AUTOSELECT;
if(RNA_boolean_get(op->ptr, "active_layer")) flag |= FILE_ACTIVELAY;
if(RNA_boolean_get(op->ptr, "relative_paths")) flag |= FILE_STRINGCODE;
if(RNA_boolean_get(op->ptr, "link")) flag |= FILE_LINK;
return flag;
}
#define GROUP_MAX 32
static void make_library_local(const char *libname, Main *main)
static void wm_link_make_library_local(Main *main, const char *libname)
{
struct Library *lib;
Library *lib;
/* and now find the latest append lib file */
lib= main->library.first;
while(lib) {
if (BLI_streq(libname, lib->filename)) break;
lib= lib->id.next;
}
for(lib= main->library.first; lib; lib=lib->id.next)
if(BLI_streq(libname, lib->filename))
break;
/* make local */
if(lib) {
@ -995,49 +982,51 @@ static void make_library_local(const char *libname, Main *main)
static int wm_link_append_exec(bContext *C, wmOperator *op)
{
char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[GROUP_MAX];
int idcode;
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Main *mainl= 0;
BlendHandle *bh;
struct Main *mainvar= CTX_data_main(C);
struct Scene *scene= CTX_data_scene(C);
struct Main *mainl= 0;
PropertyRNA *prop;
int totfiles=0;
char name[FILE_MAX], dir[FILE_MAX], libname[FILE_MAX], group[GROUP_MAX];
int idcode, totfiles=0;
short flag;
name[0] = '\0';
RNA_string_get(op->ptr, "filename", name);
RNA_string_get(op->ptr, "directory", dir);
if ( BLO_is_a_library(dir, libname, group)==0 ) {
/* test if we have a valid data */
if(BLO_is_a_library(dir, libname, group) == 0) {
BKE_report(op->reports, RPT_ERROR, "Not a library");
return OPERATOR_FINISHED;
} else if (group[0]==0) {
return OPERATOR_CANCELLED;
}
else if(group[0] == 0) {
BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
return OPERATOR_FINISHED;
} else if (BLI_streq(mainvar->name, libname)) {
return OPERATOR_CANCELLED;
}
else if(BLI_streq(bmain->name, libname)) {
BKE_report(op->reports, RPT_ERROR, "Cannot use current file as library");
return OPERATOR_FINISHED;
return OPERATOR_CANCELLED;
}
/* check if something is indicated for append/link */
prop = RNA_struct_find_property(op->ptr, "files");
if (prop) {
if(prop) {
totfiles= RNA_property_collection_length(op->ptr, prop);
if (totfiles == 0) {
if (name[0] == '\0') {
if(totfiles == 0) {
if(name[0] == '\0') {
BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
return OPERATOR_FINISHED;
return OPERATOR_CANCELLED;
}
}
} else if (name[0] == '\0') {
}
else if(name[0] == '\0') {
BKE_report(op->reports, RPT_ERROR, "Nothing indicated");
return OPERATOR_FINISHED;
return OPERATOR_CANCELLED;
}
/* now we have or selected, or an indicated file */
if (RNA_boolean_get(op->ptr, "autoselect"))
if(RNA_boolean_get(op->ptr, "autoselect"))
scene_deselect_all(scene);
bh = BLO_blendhandle_from_file(libname);
@ -1045,16 +1034,16 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
flag = wm_link_append_flag(op);
if((flag & FILE_LINK)==0) {
/* tag everything, all untagged data can be made local */
/* tag everything, all untagged data can be made local */
if((flag & FILE_LINK)==0)
flag_all_listbases_ids(LIB_APPEND_TAG, 1);
}
/* here appending/linking starts */
mainl = BLO_library_append_begin(C, &bh, libname);
if (totfiles == 0) {
if(totfiles == 0) {
BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
} else {
}
else {
RNA_BEGIN(op->ptr, itemptr, "files") {
RNA_string_get(&itemptr, "name", name);
BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
@ -1063,17 +1052,16 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
}
BLO_library_append_end(C, mainl, &bh, idcode, flag);
/* DISPLISTS? */
recalc_all_library_objects(mainvar);
/* mark all library linked objects to be updated */
recalc_all_library_objects(bmain);
/* Append, rather than linking */
if ((flag & FILE_LINK)==0) {
make_library_local(libname, mainvar);
}
/* append, rather than linking */
if((flag & FILE_LINK)==0)
wm_link_make_library_local(bmain, libname);
/* do we need to do this? */
if(scene)
DAG_scene_sort(scene);
/* recreate dependency graph to include new objects */
DAG_scene_sort(scene);
DAG_ids_flush_update(0);
BLO_blendhandle_close(bh);
BLI_strncpy(G.lib, dir, FILE_MAX);
@ -1103,6 +1091,8 @@ static void WM_OT_link_append(wmOperatorType *ot)
RNA_def_collection_runtime(ot->srna, "files", &RNA_OperatorFileListElement, "Files", "");
}
/* *************** recover last session **************** */
static int wm_recover_last_session_exec(bContext *C, wmOperator *op)
{
char scestr[FILE_MAX], filename[FILE_MAX];
@ -1137,6 +1127,20 @@ static void WM_OT_recover_last_session(wmOperatorType *ot)
ot->poll= WM_operator_winactive;
}
/* *************** save file as **************** */
static void untitled(char *name)
{
if(G.save_over == 0 && strlen(name) < FILE_MAX-16) {
char *c= BLI_last_slash(name);
if(c)
strcpy(&c[1], "untitled.blend");
else
strcpy(name, "untitled.blend");
}
}
static void save_set_compress(wmOperator *op)
{
if(!RNA_property_is_set(op->ptr, "compress")) {
@ -1199,7 +1203,7 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file.");
}
/* *************** Save file directly ******** */
/* *************** save file directly ******** */
static int wm_save_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
@ -2113,7 +2117,7 @@ void wm_window_keymap(wmWindowManager *wm)
WM_keymap_add_item(keymap, "WM_OT_save_homefile", UKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_open_recentfile", OKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_open_mainfile", OKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_link_append", OKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
WM_keymap_add_item(keymap, "WM_OT_link_append", OKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
WM_keymap_add_item(keymap, "WM_OT_save_mainfile", SKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "WM_OT_save_as_mainfile", SKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);