diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-08-23 17:13:52 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-09-11 13:43:28 +0300 |
commit | e1178266e713ae7184fc60c3ecb93d42d8b28a53 (patch) | |
tree | 5cea7a841344925a7423a3b50205c0acfbd08074 /source/blender/editors | |
parent | 6acf8642e5c464a0879cf37e3f39cd3e526a2019 (diff) |
Workspace: support reordering of workspaces from RMB menu.
Drag and drop will follow later, it's a bit complicated to make this work
reliable in the current UI code.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 9 | ||||
-rw-r--r-- | source/blender/editors/screen/workspace_edit.c | 56 |
2 files changed, 63 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index a72d1df019a..f39f26e0d00 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -850,7 +850,11 @@ static void template_ID_tabs( uiBlock *block = uiLayoutGetBlock(layout); uiStyle *style = UI_style_get_dpi(); - for (ID *id = template->idlb->first; id; id = id->next) { + ListBase ordered; + BKE_id_ordered_list(&ordered, template->idlb); + + for (LinkData *link = ordered.first; link; link = link->next) { + ID *id = link->data; const int name_width = UI_fontstyle_string_width(&style->widgetlabel, id->name + 2); const int but_width = name_width + UI_UNIT_X; @@ -860,11 +864,14 @@ static void template_ID_tabs( sizeof(id->name) - 2, 0.0f, 0.0f, ""); UI_but_funcN_set(&tab->but, template_ID_set_property_cb, MEM_dupallocN(template), id); tab->but.custom_data = (void *)id; + tab->but.dragpoin = id; tab->menu = mt; UI_but_drawflag_enable(&tab->but, but_align); } + BLI_freelistN(&ordered); + if (flag & UI_ID_ADD_NEW) { const bool editable = RNA_property_editable(&template->ptr, template->prop); uiBut *but; diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c index 77fc20a98a5..db60bfc9fb6 100644 --- a/source/blender/editors/screen/workspace_edit.c +++ b/source/blender/editors/screen/workspace_edit.c @@ -272,6 +272,11 @@ static WorkSpace *workspace_context_get(bContext *C) return WM_window_get_active_workspace(win); } +static bool workspace_context_poll(bContext *C) +{ + return workspace_context_get(C) != NULL; +} + static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); @@ -293,8 +298,8 @@ static void WORKSPACE_OT_duplicate(wmOperatorType *ot) ot->idname = "WORKSPACE_OT_duplicate"; /* api callbacks */ + ot->poll = workspace_context_poll; ot->exec = workspace_new_exec; - ot->poll = WM_operator_winactive; } static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op)) @@ -313,6 +318,7 @@ static void WORKSPACE_OT_delete(wmOperatorType *ot) ot->idname = "WORKSPACE_OT_delete"; /* api callbacks */ + ot->poll = workspace_context_poll; ot->exec = workspace_delete_exec; } @@ -519,12 +525,60 @@ static void WORKSPACE_OT_add_menu(wmOperatorType *ot) ot->invoke = workspace_add_invoke; } +static int workspace_reorder_to_back_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Main *bmain = CTX_data_main(C); + WorkSpace *workspace = workspace_context_get(C); + + BKE_id_reorder(&bmain->workspaces, &workspace->id, NULL, true); + WM_event_add_notifier(C, NC_WINDOW, NULL); + + return OPERATOR_INTERFACE; +} + +static void WORKSPACE_OT_reorder_to_back(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Workspace Reorder to Back"; + ot->description = "Reorder workspace to be first in the list"; + ot->idname = "WORKSPACE_OT_reorder_to_back"; + + /* api callbacks */ + ot->poll = workspace_context_poll; + ot->exec = workspace_reorder_to_back_exec; +} + +static int workspace_reorder_to_front_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Main *bmain = CTX_data_main(C); + WorkSpace *workspace = workspace_context_get(C); + + BKE_id_reorder(&bmain->workspaces, &workspace->id, NULL, false); + WM_event_add_notifier(C, NC_WINDOW, NULL); + + return OPERATOR_INTERFACE; +} + +static void WORKSPACE_OT_reorder_to_front(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Workspace Reorder to Front"; + ot->description = "Reorder workspace to be first in the list"; + ot->idname = "WORKSPACE_OT_reorder_to_front"; + + /* api callbacks */ + ot->poll = workspace_context_poll; + ot->exec = workspace_reorder_to_front_exec; +} + void ED_operatortypes_workspace(void) { WM_operatortype_append(WORKSPACE_OT_duplicate); WM_operatortype_append(WORKSPACE_OT_delete); WM_operatortype_append(WORKSPACE_OT_add_menu); WM_operatortype_append(WORKSPACE_OT_append_activate); + WM_operatortype_append(WORKSPACE_OT_reorder_to_back); + WM_operatortype_append(WORKSPACE_OT_reorder_to_front); } /** \} Workspace Operators */ |