Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-09-20 13:10:17 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-09-20 13:10:17 +0400
commit37b82a2d260edc1e719cba845360c0c40a24e241 (patch)
tree9c995fd7d585b0f34610b061a5c5c4e1c94650ce /source/blender/editors/interface/interface_ops.c
parent203c6effd57cdf3ed3b21ed74f80e0a5bc6441a3 (diff)
Fix #36226, Select Linked works not in touch with Prefs.
When setting keymap properties to values equalling the RNA default, they will get "unset" and automatic operator behavior is used. There is no way to explicitly set the default value as a user. 1) To allow distinguishing uninitialized (not set) properties in the keymap items, a few changes to the RNA struct comparison function are needed: Instead of allowing only strict/non-strict comparison of 2 properties A and B in a struct, this now has 3 modes: * STRICT: compare only the actual property values (same as 'strict' before) * UNSET_MATCH_ANY: if either A or B is unset, consider them a match (same as non-strict before) * UNSET_MATCH_NONE: if one property is set and the other not, consider them a mismatch. The new UNSET_MATCH_NONE mode is useful for keymaps, because it allows keeping user-defined property values in the keymap even if they match the default property value (see wm_keymap_diff function in wm_keymap.c) 2) A new operator is added for unsetting ID properties in the RMB context menu and in user preferences next to keymap properties. This only works on ID properties and deletes the ID property storage, so that the default value is used. In the user preferences for keymaps the properties are shown in an inactive layout to indicate that the default value is used (which some operators such as the "select linked" op from the report use to trigger automatic behavior). When the user sets a property it gets set and stays that way until explicitly "unset" using the new operator.
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c88
1 files changed, 63 insertions, 25 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index d714402de9f..d52702c2d51 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -434,6 +434,28 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot)
/* Reset to Default Values Button Operator ------------------------ */
+static int operator_button_property_finish(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
+{
+ ID *id = ptr->id.data;
+
+ /* perform updates required for this property */
+ RNA_property_update(C, ptr, prop);
+
+ /* as if we pressed the button */
+ uiContextActivePropertyHandle(C);
+
+ /* Since we don't want to undo _all_ edits to settings, eg window
+ * edits on the screen or on operator settings.
+ * it might be better to move undo's inline - campbell */
+ if (id && ID_CHECK_UNDO(id)) {
+ /* do nothing, go ahead with undo */
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
+
static int reset_default_button_poll(bContext *C)
{
PointerRNA ptr;
@@ -449,7 +471,6 @@ static int reset_default_button_exec(bContext *C, wmOperator *op)
{
PointerRNA ptr;
PropertyRNA *prop;
- int success = 0;
int index, all = RNA_boolean_get(op->ptr, "all");
/* try to reset the nominated setting to its default value */
@@ -457,32 +478,11 @@ static int reset_default_button_exec(bContext *C, wmOperator *op)
/* if there is a valid property that is editable... */
if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
- if (RNA_property_reset(&ptr, prop, (all) ? -1 : index)) {
- /* perform updates required for this property */
- RNA_property_update(C, &ptr, prop);
-
- /* as if we pressed the button */
- uiContextActivePropertyHandle(C);
-
- success = 1;
- }
- }
-
- /* Since we don't want to undo _all_ edits to settings, eg window
- * edits on the screen or on operator settings.
- * it might be better to move undo's inline - campbell */
- if (success) {
- ID *id = ptr.id.data;
- if (id && ID_CHECK_UNDO(id)) {
- /* do nothing, go ahead with undo */
- }
- else {
- return OPERATOR_CANCELLED;
- }
+ if (RNA_property_reset(&ptr, prop, (all) ? -1 : index))
+ return operator_button_property_finish(C, &ptr, prop);
}
- /* end hack */
- return (success) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+ return OPERATOR_CANCELLED;
}
static void UI_OT_reset_default_button(wmOperatorType *ot)
@@ -503,6 +503,43 @@ static void UI_OT_reset_default_button(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
}
+/* Unset Property Button Operator ------------------------ */
+
+static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ /* try to unset the nominated property */
+ uiContextActiveProperty(C, &ptr, &prop, &index);
+
+ /* if there is a valid property that is editable... */
+ if (ptr.data && prop && RNA_property_editable(&ptr, prop)
+ /*&& RNA_property_is_idprop(prop)*/ && RNA_property_is_set(&ptr, prop))
+ {
+ RNA_property_unset(&ptr, prop);
+ return operator_button_property_finish(C, &ptr, prop);
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void UI_OT_unset_property_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Unset property";
+ ot->idname = "UI_OT_unset_property_button";
+ ot->description = "Clear the property and use default or generated value in operators";
+
+ /* callbacks */
+ ot->poll = ED_operator_regionactive;
+ ot->exec = unset_property_button_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
/* Copy To Selected Operator ------------------------ */
static int copy_to_selected_list(bContext *C, PointerRNA *ptr, ListBase *lb, int *use_path)
@@ -1081,6 +1118,7 @@ void UI_buttons_operatortypes(void)
WM_operatortype_append(UI_OT_reset_default_theme);
WM_operatortype_append(UI_OT_copy_data_path_button);
WM_operatortype_append(UI_OT_reset_default_button);
+ WM_operatortype_append(UI_OT_unset_property_button);
WM_operatortype_append(UI_OT_copy_to_selected_button);
WM_operatortype_append(UI_OT_reports_to_textblock); /* XXX: temp? */