[Bf-blender-cvs] [b13024327ac] asset-engine: Fix several issues found while working on drag and drop linking.

Bastien Montagne noreply at git.blender.org
Wed Oct 11 20:38:48 CEST 2017


Commit: b13024327ac4387d1c4b812a3f35a1cf5b611fe6
Author: Bastien Montagne
Date:   Wed Oct 11 20:28:50 2017 +0200
Branches: asset-engine
https://developer.blender.org/rBb13024327ac4387d1c4b812a3f35a1cf5b611fe6

Fix several issues found while working on drag and drop linking.

Append/link exec code was not handling correctly asset cases in 'single
item' case.

Also, first drag'n'drop code was slitghly too much simple, losing uuid's
on the way, had to make things a bit more convoluted...

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_dragdrop.c
M	source/blender/windowmanager/intern/wm_files_link.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index efaf40fcb11..9aeb4247bde 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -93,6 +93,20 @@ typedef struct uiLayout uiLayout;
 /* use for clamping popups within the screen */
 #define UI_SCREEN_MARGIN 10
 
+/* Needed to handle library data linking/appending drag and drop. */
+typedef struct uiDragLibraryHandle {
+	char ae_idname[64];  /* BKE_ST_MAXNAME */
+	struct {
+		/* WARNING! keep in sync with AssetUUID from DNA_ID.h. */
+		int uuid_repository[4];
+		int uuid_asset[4];
+		int uuid_variant[4];
+		int uuid_revision[4];
+		int uuid_view[4];
+	} uuid;
+	char path[1090];  /* FILE_MAX + MAX_ID_NAME */
+} uiDragLibraryHandle;
+
 /* uiBlock->dt and uiBut->dt */
 enum {
 	UI_EMBOSS               = 0,  /* use widget style for drawing */
@@ -493,11 +507,11 @@ int     UI_but_return_value_get(uiBut *but);
 
 void    UI_but_drag_set_id(uiBut *but, struct ID *id);
 void    UI_but_drag_set_rna(uiBut *but, struct PointerRNA *ptr);
-void    UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free, const bool is_libpath);
+void    UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free);
 void    UI_but_drag_set_name(uiBut *but, const char *name);
 void    UI_but_drag_set_value(uiBut *but);
-void    UI_but_drag_set_image(
-        uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale, const bool use_free, const bool is_libpath);
+void    UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *ima, float scale, const bool use_free);
+void    UI_but_drag_set_library(uiBut *but, const int icon, struct ImBuf *ima, const float scale, const uiDragLibraryHandle *drag_data, const bool use_free);
 
 bool    UI_but_active_drop_name(struct bContext *C);
 bool    UI_but_active_drop_color(struct bContext *C);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 6f292e62880..131b661f591 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -4101,9 +4101,9 @@ void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
 	but->dragpoin = (void *)ptr;
 }
 
-void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free, const bool is_libpath)
+void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free)
 {
-	but->dragtype = is_libpath ? WM_DRAG_LIBPATH : WM_DRAG_PATH;
+	but->dragtype = WM_DRAG_PATH;
 	if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
 		MEM_SAFE_FREE(but->dragpoin);
 		but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
@@ -4130,9 +4130,9 @@ void UI_but_drag_set_value(uiBut *but)
 	but->dragtype = WM_DRAG_VALUE;
 }
 
-void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free, const bool is_libpath)
+void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free)
 {
-	but->dragtype = is_libpath ? WM_DRAG_LIBPATH : WM_DRAG_PATH;
+	but->dragtype = WM_DRAG_PATH;
 	ui_def_but_icon(but, icon, 0);  /* no flag UI_HAS_ICON, so icon doesnt draw in button */
 	if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
 		MEM_SAFE_FREE(but->dragpoin);
@@ -4146,6 +4146,25 @@ void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf
 	but->imb_scale = scale;
 }
 
+void UI_but_drag_set_library(
+        uiBut *but, const int icon, struct ImBuf *ima, const float scale, const uiDragLibraryHandle *drag_data, const bool use_free)
+{
+	but->dragtype = WM_DRAG_LIBRARY;
+	if (icon != ICON_NONE) {
+		ui_def_but_icon(but, icon, 0);  /* no flag UI_HAS_ICON, so icon doesnt draw in button */
+	}
+	if ((but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
+		MEM_SAFE_FREE(but->dragpoin);
+		but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
+	}
+	but->dragpoin = (void *)drag_data;
+	if (use_free) {
+		but->dragflag |= UI_BUT_DRAGPOIN_FREE;
+	}
+	but->imb = ima;
+	but->imb_scale = scale;
+}
+
 PointerRNA *UI_but_operator_ptr_get(uiBut *but)
 {
 	if (but->optype && !but->opptr) {
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 66689ca9134..8ca42506e77 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -75,6 +75,8 @@
 
 #include "file_intern.h"    // own include
 
+#include "MEM_guardedalloc.h"
+
 /* Dummy helper - we need dynamic tooltips here. */
 static char *file_draw_tooltip_func(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
 {
@@ -265,7 +267,7 @@ static void draw_tile(int sx, int sy, int width, int height, int colorid, int sh
 
 
 static void file_draw_icon(
-        uiBlock *block, const char *path, int sx, int sy, int icon, int width, int height, bool drag, const bool is_libpath)
+        uiBlock *block, const char *path, int sx, int sy, int icon, int width, int height, uiDragLibraryHandle *drag_data)
 {
 	uiBut *but;
 	int x, y;
@@ -279,9 +281,9 @@ static void file_draw_icon(
 	but = uiDefIconBut(block, UI_BTYPE_LABEL, 0, icon, x, y, width, height, NULL, 0.0f, 0.0f, 0.0f, 0.0f, NULL);
 	UI_but_func_tooltip_set(but, file_draw_tooltip_func, BLI_strdup(path));
 
-	if (drag) {
+	if (drag_data != NULL) {
 		/* path is no more static, cannot give it directly to but... */
-		UI_but_drag_set_path(but, BLI_strdup(path), true, is_libpath);
+		UI_but_drag_set_library(but, ICON_NONE, NULL, 1.0f, drag_data, true);
 	}
 }
 
@@ -326,7 +328,7 @@ void file_calc_previews(const bContext *C, ARegion *ar)
 static void file_draw_preview(
         uiBlock *block, const char *path, int sx, int sy, const float icon_aspect,
         ImBuf *imb, const int icon, FileLayout *layout, const bool is_icon, const int typeflags,
-        const bool drag, const bool is_libpath)
+        const uiDragLibraryHandle *drag_data)
 {
 	uiBut *but;
 	float fx, fy;
@@ -404,9 +406,8 @@ static void file_draw_preview(
 	UI_but_func_tooltip_set(but, file_draw_tooltip_func, BLI_strdup(path));
 
 	/* dragregion */
-	if (drag) {
-		/* path is no more static, cannot give it directly to but... */
-		UI_but_drag_set_image(but, BLI_strdup(path), icon, imb, scale, true, is_libpath);
+	if (drag_data != NULL) {
+		UI_but_drag_set_library(but, icon, imb, scale, drag_data, true);
 	}
 
 	glDisable(GL_BLEND);
@@ -523,8 +524,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
 	const bool update_stat_strings = small_size != SMALL_SIZE_CHECK(layout->curr_size);
 	const float thumb_icon_aspect = sqrtf(64.0f / (float)(params->thumbnail_size));
 
-	const bool is_libpath = (sfile->params->type == FILE_LOADLIB);
-
 	numfiles = filelist_files_ensure(files, params);
 	
 	if (params->display != FILE_IMGDISPLAY) {
@@ -610,6 +609,22 @@ void file_draw_list(const bContext *C, ARegion *ar)
 
 		/* don't drag parent or refresh items */
 		do_drag = !(FILENAME_IS_CURRPAR(file->relpath));
+		uiDragLibraryHandle *drag_data = NULL;
+
+		if (do_drag) {
+			drag_data = MEM_callocN(sizeof(*drag_data), __func__);
+			BLI_strncpy(drag_data->ae_idname, sfile->asset_engine, sizeof(drag_data->ae_idname));
+			BLI_strncpy(drag_data->path, path, sizeof(drag_data->path));
+			memcpy(drag_data->uuid.uuid_repository, file->uuid_repository, sizeof(drag_data->uuid.uuid_repository));
+			memcpy(drag_data->uuid.uuid_asset, file->uuid, sizeof(drag_data->uuid.uuid_asset));
+			FileDirEntryVariant *var = BLI_findlink(&file->variants, file->act_variant);
+			memcpy(drag_data->uuid.uuid_variant, var->uuid, sizeof(drag_data->uuid.uuid_variant));
+			FileDirEntryRevision *rev = BLI_findlink(&var->revisions, var->act_revision);
+			memcpy(drag_data->uuid.uuid_revision, rev->uuid, sizeof(drag_data->uuid.uuid_revision));
+			FileDirEntryView *vw = BLI_findlink(&rev->views, rev->act_view);
+			BLI_assert(vw == file->entry);
+			memcpy(drag_data->uuid.uuid_view, vw->uuid, sizeof(drag_data->uuid.uuid_view));
+		}
 
 		if (FILE_IMGDISPLAY == params->display) {
 			const int icon = filelist_geticon(files, i, false);
@@ -621,11 +636,11 @@ void file_draw_list(const bContext *C, ARegion *ar)
 			}
 
 			file_draw_preview(block, path, sx, sy, thumb_icon_aspect,
-			                  imb, icon, layout, is_icon, file->typeflag, do_drag, is_libpath);
+			                  imb, icon, layout, is_icon, file->typeflag, drag_data);
 		}
 		else {
 			file_draw_icon(block, path, sx, sy - (UI_UNIT_Y / 6), filelist_geticon(files, i, true),
-			               ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE, do_drag, is_libpath);
+			               ICON_DEFAULT_WIDTH_SCALE, ICON_DEFAULT_HEIGHT_SCALE, drag_data);
 			sx += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
 		}
 
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index f12691e29d8..7d7a5d11757 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -71,6 +71,7 @@
 
 #include "RNA_access.h"
 
+#include "UI_interface.h"
 #include "UI_resources.h"
 
 #ifdef WITH_PYTHON
@@ -590,10 +591,11 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *ar)
 static int view3d_path_link_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *event)
 {
 	if (event->shift == false) {
-		if (drag->type == WM_DRAG_LIBPATH) {
+		if (drag->type == WM_DRAG_LIBRARY) {
+			uiDragLibraryHandle *drag_data = drag->poin;
 			char libname[FILE_MAX];
 			char *group, *name;
-			if (!BLO_library_path_explode(drag->path, libname, &group, &name) /* later... && (!aet || !path_to_idcode(path))*/ ) {
+			if (!BLO_library_path_explode(drag_data->path, libname, &group, &name) /* later... && (!aet || !path_to_idcode(path))*/ ) {
 				return 0;
 			}
 			switch (BKE_idcode_from_name(group)) {
@@ -685,9 +687,15 @@ static int view3d_ima_mesh_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e
 
 static void view3d_path_link_drop_copy(wmDrag *drag, wmDropBox *drop)
 {
-	RNA_string_set(drop->ptr, "asset_engine", drag->ae_idname);
+	uiDragLibraryHandle *drag_data = drag->poin;
+	RNA_string_set(drop->ptr, "asset_engine", drag_data->ae_idna

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list