diff options
author | Julian Eisel <julian@blender.org> | 2021-10-27 16:50:14 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-11-03 17:00:17 +0300 |
commit | b73993bcc942cafb8ed4a4610d64286505bb4e11 (patch) | |
tree | 19d679910a4ac15cb52bdb25de9a30e10273ce18 /source/blender/editors/interface/interface_dropboxes.cc | |
parent | 0d8f1414a21a9c7a3498fd65ce5cd02673582eed (diff) |
UI: Refactor how dragging onto text buttons works, fixing issues
There was a bunch of special handling to support dropping data-blocks onto
string or search-menu buttons, to change the value of these. This refactor
makes that case use the normal drop-box design, where an operator is executed
on drop that gets input properties set by the drop-box. This should also make
it easier to add support for dragging assets into these buttons.
In addition this fixes an issue: Two tooltips were shown when dragging assets
over text buttons. None should be shown, because this isn't supported.
Diffstat (limited to 'source/blender/editors/interface/interface_dropboxes.cc')
-rw-r--r-- | source/blender/editors/interface/interface_dropboxes.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc index ab0c7e088e2..81a1354cbe7 100644 --- a/source/blender/editors/interface/interface_dropboxes.cc +++ b/source/blender/editors/interface/interface_dropboxes.cc @@ -24,6 +24,8 @@ #include "MEM_guardedalloc.h" +#include "RNA_access.h" + #include "WM_api.h" #include "UI_interface.h" @@ -59,6 +61,21 @@ static char *ui_tree_view_drop_tooltip(bContext *C, return UI_tree_view_item_drop_tooltip(hovered_tree_item, drag); } +/* ---------------------------------------------------------------------- */ + +static bool ui_drop_name_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(event)) +{ + return UI_but_active_drop_name(C) && (drag->type == WM_DRAG_ID); +} + +static void ui_drop_name_copy(wmDrag *drag, wmDropBox *drop) +{ + const ID *id = WM_drag_get_local_ID(drag, 0); + RNA_string_set(drop->ptr, "string", id->name + 2); +} + +/* ---------------------------------------------------------------------- */ + void ED_dropboxes_ui() { ListBase *lb = WM_dropboxmap_find("User Interface", SPACE_EMPTY, 0); @@ -69,4 +86,10 @@ void ED_dropboxes_ui() nullptr, nullptr, ui_tree_view_drop_tooltip); + WM_dropbox_add(lb, + "UI_OT_drop_name", + ui_drop_name_poll, + ui_drop_name_copy, + WM_drag_free_imported_drag_ID, + nullptr); } |