diff options
author | Julian Eisel <julian@blender.org> | 2021-10-26 19:48:24 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-10-26 19:55:27 +0300 |
commit | 11e8a2ec5fc95524a59a7422d2715ef1116dbef4 (patch) | |
tree | 709a06d470a2810d140a72599624a7f46a3e6f50 /source/blender/editors/interface | |
parent | 03c0581c6ed6eb98c4c4c7bf42c92d623880dfac (diff) |
UI: Support disabled-hint for dropping in the tree-view API
A tree-view item's drop controller can now return a message for the user
explaining why dropping isn't possible with the dropped data. This is then
displayed in red text next to the cursor.
This isn't actually used yet, the follow up commit will do that.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_dropboxes.cc | 9 | ||||
-rw-r--r-- | source/blender/editors/interface/tree_view.cc | 9 |
2 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc index 1cc06db3a8c..ab0c7e088e2 100644 --- a/source/blender/editors/interface/interface_dropboxes.cc +++ b/source/blender/editors/interface/interface_dropboxes.cc @@ -22,6 +22,8 @@ #include "DNA_space_types.h" +#include "MEM_guardedalloc.h" + #include "WM_api.h" #include "UI_interface.h" @@ -35,7 +37,12 @@ static bool ui_tree_view_drop_poll(bContext *C, wmDrag *drag, const wmEvent *eve return false; } - return UI_tree_view_item_can_drop(hovered_tree_item, drag); + if (drag->free_disabled_info) { + MEM_SAFE_FREE(drag->disabled_info); + } + + drag->free_disabled_info = false; + return UI_tree_view_item_can_drop(hovered_tree_item, drag, &drag->disabled_info); } static char *ui_tree_view_drop_tooltip(bContext *C, diff --git a/source/blender/editors/interface/tree_view.cc b/source/blender/editors/interface/tree_view.cc index da95cad0fc7..0eeb32bcc69 100644 --- a/source/blender/editors/interface/tree_view.cc +++ b/source/blender/editors/interface/tree_view.cc @@ -675,7 +675,9 @@ bool UI_tree_view_item_matches(const uiTreeViewItemHandle *a_handle, return a.matches_including_parents(b); } -bool UI_tree_view_item_can_drop(const uiTreeViewItemHandle *item_, const wmDrag *drag) +bool UI_tree_view_item_can_drop(const uiTreeViewItemHandle *item_, + const wmDrag *drag, + const char **r_disabled_hint) { const AbstractTreeViewItem &item = reinterpret_cast<const AbstractTreeViewItem &>(*item_); const std::unique_ptr<AbstractTreeViewItemDropController> drop_controller = @@ -684,7 +686,7 @@ bool UI_tree_view_item_can_drop(const uiTreeViewItemHandle *item_, const wmDrag return false; } - return drop_controller->can_drop(*drag); + return drop_controller->can_drop(*drag, r_disabled_hint); } char *UI_tree_view_item_drop_tooltip(const uiTreeViewItemHandle *item_, const wmDrag *drag) @@ -709,8 +711,9 @@ bool UI_tree_view_item_drop_handle(uiTreeViewItemHandle *item_, const ListBase * std::unique_ptr<AbstractTreeViewItemDropController> drop_controller = item.create_drop_controller(); + const char *disabled_hint_dummy = nullptr; LISTBASE_FOREACH (const wmDrag *, drag, drags) { - if (drop_controller->can_drop(*drag)) { + if (drop_controller->can_drop(*drag, &disabled_hint_dummy)) { return drop_controller->on_drop(*drag); } } |