UI: Superimposed pin icon for workspace scene pinning in the scene switcher

Followup to the previous commit, to display a pin icon in the scene switcher.
This is a good indicator to have and such workspace-wide functionality should
be available in the topbar, close to what it belongs to (scene switching).
Downside is that it makes this already crowded region even more crowded. But
thanks to the use of superimposed icons, it's not too noisy visually.

Differential Revision: https://developer.blender.org/D11890

Reviewed by: Campbell Barton
This commit is contained in:
Julian Eisel 2022-07-07 18:14:05 +02:00
parent e0cc86978c
commit b8605ee458
Notes: blender-bot 2023-02-14 07:45:38 +01:00
Referenced by issue #68321, GPencil: New Workflow for Storyboarding
7 changed files with 88 additions and 24 deletions

View File

@ -1023,6 +1023,26 @@ static const char *template_id_browse_tip(const StructRNA *type)
return N_("Browse ID data to be linked");
}
/**
* Add a superimposed extra icon to \a but, for workspace pinning.
* Rather ugly special handling, but this is really a special case at this point, nothing worth
* generalizing.
*/
static void template_id_workspace_pin_extra_icon(const TemplateID *template_ui, uiBut *but)
{
if ((template_ui->idcode != ID_SCE) || (template_ui->ptr.type != &RNA_Window)) {
return;
}
const wmWindow *win = template_ui->ptr.data;
const WorkSpace *workspace = WM_window_get_active_workspace(win);
UI_but_extra_operator_icon_add(but,
"WORKSPACE_OT_scene_pin_toggle",
WM_OP_INVOKE_DEFAULT,
(workspace->flags & WORKSPACE_USE_PIN_SCENE) ? ICON_PINNED :
ICON_UNPINNED);
}
/**
* \return a type-based i18n context, needed e.g. by "New" button.
* In most languages, this adjective takes different form based on gender of type name...
@ -1220,6 +1240,8 @@ static void template_ID(const bContext *C,
UI_but_flag_enable(but, UI_BUT_REDALERT);
}
template_id_workspace_pin_extra_icon(template_ui, but);
if (ID_IS_LINKED(id)) {
const bool disabled = !BKE_idtype_idcode_is_localizable(GS(id->name));
if (id->tag & LIB_TAG_INDIRECT) {

View File

@ -585,6 +585,35 @@ static void WORKSPACE_OT_reorder_to_front(wmOperatorType *ot)
ot->exec = workspace_reorder_to_front_exec;
}
static int workspace_scene_pin_toggle(bContext *C, wmOperator *UNUSED(op))
{
WorkSpace *workspace = workspace_context_get(C);
/* Trivial. The operator is only needed to display a superimposed extra icon, which
* requires an operator. */
workspace->flags ^= WORKSPACE_USE_PIN_SCENE;
WM_event_add_notifier(C, NC_WORKSPACE, NULL);
return OPERATOR_FINISHED;
}
static void WORKSPACE_OT_scene_pin_toggle(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Pin Scene to Workspace";
ot->description =
"Remember the last used scene for the current workspace and switch to it whenever this "
"workspace is activated again";
ot->idname = "WORKSPACE_OT_scene_pin_toggle";
/* api callbacks */
ot->poll = workspace_context_poll;
ot->exec = workspace_scene_pin_toggle;
ot->flag = OPTYPE_INTERNAL;
}
void ED_operatortypes_workspace(void)
{
WM_operatortype_append(WORKSPACE_OT_duplicate);
@ -593,6 +622,7 @@ void ED_operatortypes_workspace(void)
WM_operatortype_append(WORKSPACE_OT_append_activate);
WM_operatortype_append(WORKSPACE_OT_reorder_to_back);
WM_operatortype_append(WORKSPACE_OT_reorder_to_front);
WM_operatortype_append(WORKSPACE_OT_scene_pin_toggle);
}
/** \} Workspace Operators */

View File

@ -778,6 +778,9 @@ static void buttons_area_listener(const wmSpaceTypeListenerParams *params)
sbuts->preview = 1;
}
break;
case NC_WORKSPACE:
buttons_area_redraw(area, BCONTEXT_TOOL);
break;
case NC_SPACE:
if (wmn->data == ND_SPACE_PROPERTIES) {
ED_area_tag_redraw(area);

View File

@ -155,6 +155,9 @@ static void topbar_header_listener(const wmRegionListenerParams *params)
ED_region_tag_redraw(region);
}
break;
case NC_WORKSPACE:
ED_region_tag_redraw(region);
break;
case NC_SPACE:
if (wmn->data == ND_SPACE_INFO) {
ED_region_tag_redraw(region);

View File

@ -1300,6 +1300,10 @@ static void view3d_main_region_listener(const wmRegionListenerParams *params)
ED_region_tag_redraw(region);
}
break;
case NC_WORKSPACE:
/* In case the region displays workspace settings. */
ED_region_tag_redraw(region);
break;
}
}

View File

@ -419,6 +419,7 @@ static void rna_def_workspace(BlenderRNA *brna)
"Pin Scene",
"Remember the last used scene for the workspace and switch to it "
"whenever this workspace is activated again");
RNA_def_property_update(prop, NC_WORKSPACE, NULL);
/* Flags */
prop = RNA_def_property(srna, "use_filter_by_owner", PROP_BOOLEAN, PROP_NONE);

View File

@ -323,34 +323,35 @@ typedef struct wmNotifier {
#define NOTE_CATEGORY 0xFF000000
#define NC_WM (1 << 24)
#define NC_WINDOW (2 << 24)
#define NC_SCREEN (3 << 24)
#define NC_SCENE (4 << 24)
#define NC_OBJECT (5 << 24)
#define NC_MATERIAL (6 << 24)
#define NC_TEXTURE (7 << 24)
#define NC_LAMP (8 << 24)
#define NC_GROUP (9 << 24)
#define NC_IMAGE (10 << 24)
#define NC_BRUSH (11 << 24)
#define NC_TEXT (12 << 24)
#define NC_WORLD (13 << 24)
#define NC_ANIMATION (14 << 24)
#define NC_WORKSPACE (3 << 24)
#define NC_SCREEN (4 << 24)
#define NC_SCENE (5 << 24)
#define NC_OBJECT (6 << 24)
#define NC_MATERIAL (7 << 24)
#define NC_TEXTURE (8 << 24)
#define NC_LAMP (9 << 24)
#define NC_GROUP (10 << 24)
#define NC_IMAGE (11 << 24)
#define NC_BRUSH (12 << 24)
#define NC_TEXT (13 << 24)
#define NC_WORLD (14 << 24)
#define NC_ANIMATION (15 << 24)
/* When passing a space as reference data with this (e.g. `WM_event_add_notifier(..., space)`),
* the notifier will only be sent to this space. That avoids unnecessary updates for unrelated
* spaces. */
#define NC_SPACE (15 << 24)
#define NC_GEOM (16 << 24)
#define NC_NODE (17 << 24)
#define NC_ID (18 << 24)
#define NC_PAINTCURVE (19 << 24)
#define NC_MOVIECLIP (20 << 24)
#define NC_MASK (21 << 24)
#define NC_GPENCIL (22 << 24)
#define NC_LINESTYLE (23 << 24)
#define NC_CAMERA (24 << 24)
#define NC_LIGHTPROBE (25 << 24)
#define NC_SPACE (16 << 24)
#define NC_GEOM (17 << 24)
#define NC_NODE (18 << 24)
#define NC_ID (19 << 24)
#define NC_PAINTCURVE (20 << 24)
#define NC_MOVIECLIP (21 << 24)
#define NC_MASK (22 << 24)
#define NC_GPENCIL (23 << 24)
#define NC_LINESTYLE (24 << 24)
#define NC_CAMERA (25 << 24)
#define NC_LIGHTPROBE (26 << 24)
/* Changes to asset data in the current .blend. */
#define NC_ASSET (26 << 24)
#define NC_ASSET (27 << 24)
/* data type, 256 entries is enough, it can overlap */
#define NOTE_DATA 0x00FF0000