Add option "Auto Add Fake User" to user preferences #113247

Closed
Hoshinova wants to merge 4 commits from Hoshinova/blender:auto-fake-user into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
9 changed files with 94 additions and 9 deletions

View File

@ -37,6 +37,7 @@ def geometry_node_group_empty_new(name):
def geometry_node_group_empty_modifier_new(name):
group = geometry_node_group_empty_new(data_("Geometry Nodes"))
group.use_fake_user = bpy.context.preferences.edit.node_auto_add_fake_user_id_nt
group.is_modifier = True
return group

View File

@ -445,6 +445,20 @@ class USERPREF_PT_edit_objects_duplicate_data(EditingPanel, CenterAlignMixIn, Pa
row_label.active = getattr(edit, prop)
class USERPREF_PT_edit_data_blocks(EditingPanel, CenterAlignMixIn, Panel):
bl_label = "Data-Blocks"
def draw_centered(self, context, layout):
prefs = context.preferences
edit = prefs.edit
col = layout.column(heading="Auto Add Fake User")
col.prop(edit, "node_auto_add_fake_user_id_ma",text="Material")
col.prop(edit, "node_auto_add_fake_user_id_te",text="Texture")
col.prop(edit, "node_auto_add_fake_user_id_wo",text="World")
col.prop(edit, "node_auto_add_fake_user_id_nt",text="Geometry Nodes Group")
class USERPREF_PT_edit_cursor(EditingPanel, CenterAlignMixIn, Panel):
bl_label = "3D Cursor"
@ -2636,6 +2650,7 @@ classes = (
USERPREF_PT_edit_objects,
USERPREF_PT_edit_objects_new,
USERPREF_PT_edit_objects_duplicate_data,
USERPREF_PT_edit_data_blocks,
USERPREF_PT_edit_cursor,
USERPREF_PT_edit_annotations,
USERPREF_PT_edit_weight_paint,

View File

@ -10,6 +10,7 @@
#include "DNA_collection_types.h"
#include "DNA_freestyle_types.h"
#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_rotation.h"

View File

@ -70,7 +70,7 @@
#include "lib_intern.h"
//#define DEBUG_TIME
// #define DEBUG_TIME
#ifdef DEBUG_TIME
# include "PIL_time_utildefines.h"
@ -948,6 +948,34 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
* will also increment it, decrement it here. */
id_us_min(newid);
bool set_fake_user = false;
switch (GS(id->name)) {
case ID_MA: {
set_fake_user = U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_MA;
break;
}
case ID_TE: {
set_fake_user = U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_TE;
break;
}
case ID_WO: {
set_fake_user = U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_WO;
break;
}
case ID_NT: {
set_fake_user = U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_NT;
break;
}
default: {
set_fake_user = false;
break;
}
}
if (set_fake_user) {
id_fake_user_set(newid);
}
/* assign copy */
PointerRNA idptr = RNA_id_pointer_create(newid);
RNA_property_pointer_set(ptr, prop, idptr, nullptr);

View File

@ -576,8 +576,8 @@ void blo_do_versions_userdef(UserDef *userdef)
}
if (!USER_VERSION_ATLEAST(280, 44)) {
userdef->uiflag &= ~(USER_NO_MULTITOUCH_GESTURES | USER_UIFLAG_UNUSED_1);
userdef->uiflag2 &= ~(USER_UIFLAG2_UNUSED_0);
userdef->uiflag &= ~(USER_NO_MULTITOUCH_GESTURES | USER_NODE_AUTO_ADD_FAKE_USER_ID_MA);
userdef->uiflag2 &= ~(USER_NODE_AUTO_ADD_FAKE_USER_ID_NT);
userdef->gp_settings &= ~(GP_PAINT_UNUSED_0);
}
@ -712,7 +712,7 @@ void blo_do_versions_userdef(UserDef *userdef)
userdef->pixelsize = 1.0f;
}
/* Clear old userdef flag for "Camera Parent Lock". */
userdef->uiflag &= ~USER_UIFLAG_UNUSED_3;
userdef->uiflag &= ~USER_NODE_AUTO_ADD_FAKE_USER_ID_TE;
}
if (!USER_VERSION_ATLEAST(292, 9)) {
@ -874,7 +874,7 @@ void blo_do_versions_userdef(UserDef *userdef)
if (!USER_VERSION_ATLEAST(400, 24)) {
/* Clear deprecated USER_MENUFIXEDORDER user flag for reuse. */
userdef->uiflag &= ~USER_UIFLAG_UNUSED_4;
userdef->uiflag &= ~USER_NODE_AUTO_ADD_FAKE_USER_ID_WO;
}
if (!USER_VERSION_ATLEAST(400, 26)) {

View File

@ -3697,6 +3697,10 @@ static int geometry_node_tree_copy_assign_exec(bContext *C, wmOperator * /*op*/)
nmd->node_group = new_tree;
id_us_min(&tree->id);
if (U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_NT) {
id_fake_user_set(&(new_tree->id));
}
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);

View File

@ -783,6 +783,10 @@ static int new_material_exec(bContext *C, wmOperator * /*op*/)
ma->use_nodes = true;
}
if (U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_MA) {
id_fake_user_set(&(ma->id));
}
if (prop) {
if (ob != nullptr) {
/* Add slot follows user-preferences for creating new slots,
@ -842,6 +846,10 @@ static int new_texture_exec(bContext *C, wmOperator * /*op*/)
tex = BKE_texture_add(bmain, DATA_("Texture"));
}
if (U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_TE) {
id_fake_user_set(&(tex->id));
}
/* hook into UI */
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
@ -899,6 +907,10 @@ static int new_world_exec(bContext *C, wmOperator * /*op*/)
wo->use_nodes = true;
}
if (U.uiflag & USER_NODE_AUTO_ADD_FAKE_USER_ID_WO) {
id_fake_user_set(&(wo->id));
}
/* hook into UI */
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
@ -2259,6 +2271,7 @@ static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
else {
lineset->linestyle = BKE_linestyle_new(bmain, DATA_("LineStyle"));
}
DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);

View File

@ -1169,7 +1169,7 @@ typedef enum eWalkNavigation_Flag {
/** #UserDef.uiflag */
typedef enum eUserpref_UI_Flag {
USER_NO_MULTITOUCH_GESTURES = (1 << 0),
USER_UIFLAG_UNUSED_1 = (1 << 1), /* cleared */
USER_NODE_AUTO_ADD_FAKE_USER_ID_MA = (1 << 1), /* cleared */
USER_WHEELZOOMDIR = (1 << 2),
USER_FILTERFILEEXTS = (1 << 3),
USER_DRAWVIEWINFO = (1 << 4),
@ -1188,11 +1188,11 @@ typedef enum eUserpref_UI_Flag {
USER_HIDE_DOT = (1 << 16),
USER_SHOW_GIZMO_NAVIGATE = (1 << 17),
USER_SHOW_VIEWPORTNAME = (1 << 18),
USER_UIFLAG_UNUSED_3 = (1 << 19), /* Cleared. */
USER_NODE_AUTO_ADD_FAKE_USER_ID_TE = (1 << 19), /* Cleared. */
USER_ZOOM_TO_MOUSEPOS = (1 << 20),
USER_SHOW_FPS = (1 << 21),
USER_REGISTER_ALL_USERS = (1 << 22),
USER_UIFLAG_UNUSED_4 = (1 << 23), /* Cleared. */
USER_NODE_AUTO_ADD_FAKE_USER_ID_WO = (1 << 23), /* Cleared. */
USER_CONTINUOUS_MOUSE = (1 << 24),
USER_ZOOM_INVERT = (1 << 25),
USER_ZOOM_HORIZ = (1 << 26), /* for CONTINUE and DOLLY zoom */
@ -1213,7 +1213,7 @@ typedef enum eUserpref_UI_Flag {
* \note don't add new flags here, use 'uiflag' which has flags free.
*/
typedef enum eUserpref_UI_Flag2 {
USER_UIFLAG2_UNUSED_0 = (1 << 0), /* cleared */
USER_NODE_AUTO_ADD_FAKE_USER_ID_NT = (1 << 0), /* cleared */
USER_REGION_OVERLAP = (1 << 1),
USER_UIFLAG2_UNUSED_2 = (1 << 2),
USER_UIFLAG2_UNUSED_3 = (1 << 3), /* dirty */

View File

@ -5630,6 +5630,29 @@ static void rna_def_userdef_edit(BlenderRNA *brna)
"Duplicate Node Tree",
"Make copies of node groups when duplicating nodes in the node editor");
prop = RNA_def_property(srna, "node_auto_add_fake_user_id_ma", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_NODE_AUTO_ADD_FAKE_USER_ID_MA);
RNA_def_property_ui_text(prop,
"Auto Add Fake User Material",
"Automatically add a fake user when creating new materials");
prop = RNA_def_property(srna, "node_auto_add_fake_user_id_te", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_NODE_AUTO_ADD_FAKE_USER_ID_TE);
RNA_def_property_ui_text(prop,
"Auto Add Fake User Texture",
"Automatically add a fake user when creating new textures");
prop = RNA_def_property(srna, "node_auto_add_fake_user_id_wo", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_NODE_AUTO_ADD_FAKE_USER_ID_WO);
RNA_def_property_ui_text(
prop, "Auto Add Fake User World", "Automatically add a fake user when creating new worlds");
prop = RNA_def_property(srna, "node_auto_add_fake_user_id_nt", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_NODE_AUTO_ADD_FAKE_USER_ID_NT);
RNA_def_property_ui_text(prop,
"Auto Add Fake User Geometry Node Group",
"Automatically add a fake user when creating new geometry node groups");
prop = RNA_def_property(srna, "node_use_insert_offset", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_NODE_AUTO_OFFSET);
RNA_def_property_ui_text(prop,