Koro request: add 'active layer' and 'selected' options to view3D' paste operator.
Those two are ON by default, since I think it's most common expected behavior (as with append/link ops).
This commit is contained in:
parent
5c69345edc
commit
4ef918d661
Notes:
blender-bot
2023-02-14 08:00:48 +01:00
Referenced by issue #48057, Copy Pasting does not respect layers.
|
@ -107,7 +107,7 @@ extern struct Main *BKE_undo_get_main(struct Scene **r_scene);
|
|||
void BKE_copybuffer_begin(struct Main *bmain);
|
||||
void BKE_copybuffer_tag_ID(struct ID *id);
|
||||
int BKE_copybuffer_save(const char *filename, struct ReportList *reports);
|
||||
int BKE_copybuffer_paste(struct bContext *C, const char *libname, struct ReportList *reports);
|
||||
int BKE_copybuffer_paste(struct bContext *C, const char *libname, const short flag, struct ReportList *reports);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_windowmanager_types.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
|
@ -1044,10 +1045,11 @@ int BKE_copybuffer_save(const char *filename, ReportList *reports)
|
|||
}
|
||||
|
||||
/* return success (1) */
|
||||
int BKE_copybuffer_paste(bContext *C, const char *libname, ReportList *reports)
|
||||
int BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, ReportList *reports)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
Main *mainl = NULL;
|
||||
Library *lib;
|
||||
BlendHandle *bh;
|
||||
|
@ -1070,9 +1072,9 @@ int BKE_copybuffer_paste(bContext *C, const char *libname, ReportList *reports)
|
|||
/* here appending/linking starts */
|
||||
mainl = BLO_library_link_begin(bmain, &bh, libname);
|
||||
|
||||
BLO_library_link_all(mainl, bh);
|
||||
BLO_library_link_all(mainl, bh, flag, scene, v3d);
|
||||
|
||||
BLO_library_link_end(mainl, &bh, 0, scene, CTX_wm_view3d(C));
|
||||
BLO_library_link_end(mainl, &bh, flag, scene, v3d);
|
||||
|
||||
/* mark all library linked objects to be updated */
|
||||
BKE_main_lib_objects_recalc_all(bmain);
|
||||
|
|
|
@ -562,6 +562,7 @@ void BKE_sound_set_scene_sound_pitch(void *handle, float pitch, char animated)
|
|||
|
||||
void BKE_sound_set_scene_sound_pan(void *handle, float pan, char animated)
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,9 @@ struct ID *BLO_library_link_named_part_ex(
|
|||
struct Scene *scene, struct View3D *v3d);
|
||||
void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d);
|
||||
|
||||
void BLO_library_link_all(struct Main *mainl, BlendHandle *bh);
|
||||
void BLO_library_link_all(
|
||||
struct Main *mainl, BlendHandle *bh, const short flag,
|
||||
struct Scene *scene, struct View3D *v3d);
|
||||
|
||||
void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);
|
||||
|
||||
|
|
|
@ -9662,16 +9662,47 @@ static ID *link_named_part(Main *mainl, FileData *fd, const short idcode, const
|
|||
return id;
|
||||
}
|
||||
|
||||
static void link_object_postprocess(ID *id, Scene *scene, View3D *v3d, const short flag)
|
||||
{
|
||||
if (scene) {
|
||||
Base *base;
|
||||
Object *ob;
|
||||
|
||||
base = MEM_callocN(sizeof(Base), "app_nam_part");
|
||||
BLI_addtail(&scene->base, base);
|
||||
|
||||
ob = (Object *)id;
|
||||
|
||||
/* link at active layer (view3d if available in context, else scene one */
|
||||
if (flag & FILE_ACTIVELAY) {
|
||||
ob->lay = BKE_screen_view3d_layer_active(v3d, scene);
|
||||
}
|
||||
|
||||
ob->mode = OB_MODE_OBJECT;
|
||||
base->lay = ob->lay;
|
||||
base->object = ob;
|
||||
base->flag = ob->flag;
|
||||
ob->id.us++;
|
||||
|
||||
if (flag & FILE_AUTOSELECT) {
|
||||
base->flag |= SELECT;
|
||||
base->object->flag = base->flag;
|
||||
/* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple reader for copy/paste buffers.
|
||||
*/
|
||||
void BLO_library_link_all(Main *mainl, BlendHandle *bh)
|
||||
void BLO_library_link_all(Main *mainl, BlendHandle *bh, const short flag, Scene *scene, View3D *v3d)
|
||||
{
|
||||
FileData *fd = (FileData *)(bh);
|
||||
BHead *bhead;
|
||||
ID *id = NULL;
|
||||
|
||||
for (bhead = blo_firstbhead(fd); bhead; bhead = blo_nextbhead(fd, bhead)) {
|
||||
ID *id = NULL;
|
||||
|
||||
if (bhead->code == ENDB)
|
||||
break;
|
||||
if (bhead->code == ID_OB)
|
||||
|
@ -9681,6 +9712,8 @@ void BLO_library_link_all(Main *mainl, BlendHandle *bh)
|
|||
/* sort by name in list */
|
||||
ListBase *lb = which_libbase(mainl, GS(id->name));
|
||||
id_sort_by_name(lb, id);
|
||||
|
||||
link_object_postprocess(id, scene, v3d, flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9692,32 +9725,7 @@ static ID *link_named_part_ex(
|
|||
ID *id = link_named_part(mainl, fd, idcode, name);
|
||||
|
||||
if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
|
||||
if (scene) {
|
||||
Base *base;
|
||||
Object *ob;
|
||||
|
||||
base = MEM_callocN(sizeof(Base), "app_nam_part");
|
||||
BLI_addtail(&scene->base, base);
|
||||
|
||||
ob = (Object *)id;
|
||||
|
||||
/* link at active layer (view3d if available in context, else scene one */
|
||||
if (flag & FILE_ACTIVELAY) {
|
||||
ob->lay = BKE_screen_view3d_layer_active(v3d, scene);
|
||||
}
|
||||
|
||||
ob->mode = OB_MODE_OBJECT;
|
||||
base->lay = ob->lay;
|
||||
base->object = ob;
|
||||
base->flag = ob->flag;
|
||||
ob->id.us++;
|
||||
|
||||
if (flag & FILE_AUTOSELECT) {
|
||||
base->flag |= SELECT;
|
||||
base->object->flag = base->flag;
|
||||
/* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
|
||||
}
|
||||
}
|
||||
link_object_postprocess(id, scene, v3d, flag);
|
||||
}
|
||||
else if (id && (GS(id->name) == ID_GR)) {
|
||||
/* tag as needing to be instantiated */
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "BKE_report.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
#include "RNA_define.h"
|
||||
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
|
@ -102,9 +103,15 @@ static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
|
|||
static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
char str[FILE_MAX];
|
||||
short flag = 0;
|
||||
|
||||
if (RNA_boolean_get(op->ptr, "autoselect"))
|
||||
flag |= FILE_AUTOSELECT;
|
||||
if (RNA_boolean_get(op->ptr, "active_layer"))
|
||||
flag |= FILE_ACTIVELAY;
|
||||
|
||||
BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
|
||||
if (BKE_copybuffer_paste(C, str, op->reports)) {
|
||||
if (BKE_copybuffer_paste(C, str, flag, op->reports)) {
|
||||
WM_event_add_notifier(C, NC_WINDOW, NULL);
|
||||
|
||||
BKE_report(op->reports, RPT_INFO, "Objects pasted from buffer");
|
||||
|
@ -131,6 +138,9 @@ static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
|
|||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
|
||||
RNA_def_boolean(ot->srna, "active_layer", true, "Active Layer", "Put pasted objects on the active layer");
|
||||
}
|
||||
|
||||
/* ************************** registration **********************************/
|
||||
|
|
Loading…
Reference in New Issue