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:
authorJoshua Leung <aligorith@gmail.com>2009-12-17 13:47:55 +0300
committerJoshua Leung <aligorith@gmail.com>2009-12-17 13:47:55 +0300
commite3a1d044d68000a2e81b662c0cf15bbe17698aa4 (patch)
treeb9f12ad7ca22073cc00f3420114d2d53f7300a55 /source/blender/editors
parent6c006b2ebbaa2d56f7dba0a036910138d864305e (diff)
RNA/UI - Reset Settings to Default Values
Added a new operator for properties which resets RNA-based settings to their 'default' values, as defined in RNA. This currently only works for floats, ints, enums, and booleans (strings and pointers still need to be implemented). The current extensions to the RNA API that I've made here seem a bit excessive, and can be toned down if necessary. In short, I've just added accessor functions for the default-values of the property definitions. For this to be really useful, many properties in RNA will need to get defaults defined, since the current defaults for quite a few properties tested were less than ideal.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/animation/anim_intern.h2
-rw-r--r--source/blender/editors/animation/anim_ops.c2
-rw-r--r--source/blender/editors/animation/drivers.c43
-rw-r--r--source/blender/editors/include/UI_interface.h3
-rw-r--r--source/blender/editors/interface/interface_handlers.c9
-rw-r--r--source/blender/editors/interface/interface_ops.c234
6 files changed, 244 insertions, 49 deletions
diff --git a/source/blender/editors/animation/anim_intern.h b/source/blender/editors/animation/anim_intern.h
index bc4f528d43f..2d363a52248 100644
--- a/source/blender/editors/animation/anim_intern.h
+++ b/source/blender/editors/animation/anim_intern.h
@@ -79,6 +79,4 @@ void ANIM_OT_driver_button_remove(struct wmOperatorType *ot);
void ANIM_OT_copy_driver_button(struct wmOperatorType *ot);
void ANIM_OT_paste_driver_button(struct wmOperatorType *ot);
-void ANIM_OT_copy_clipboard_button(struct wmOperatorType *ot);
-
#endif // ANIM_INTERN_H
diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c
index 6aa638b1ada..9544bb70855 100644
--- a/source/blender/editors/animation/anim_ops.c
+++ b/source/blender/editors/animation/anim_ops.c
@@ -362,8 +362,6 @@ void ED_operatortypes_anim(void)
WM_operatortype_append(ANIM_OT_driver_button_remove);
WM_operatortype_append(ANIM_OT_copy_driver_button);
WM_operatortype_append(ANIM_OT_paste_driver_button);
-
- WM_operatortype_append(ANIM_OT_copy_clipboard_button);
WM_operatortype_append(ANIM_OT_keyingset_button_add);
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index bc7005b82c4..59e52c0d489 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -581,47 +581,4 @@ void ANIM_OT_paste_driver_button (wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
-
-/* Copy to Clipboard Button Operator ------------------------ */
-
-static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
-{
- PointerRNA ptr;
- PropertyRNA *prop= NULL;
- char *path;
- short success= 0;
- int index;
-
- /* try to create driver using property retrieved from UI */
- memset(&ptr, 0, sizeof(PointerRNA));
- uiAnimContextProperty(C, &ptr, &prop, &index);
-
- if (ptr.data && prop) {
- path= RNA_path_from_ID_to_property(&ptr, prop);
-
- if (path) {
- WM_clipboard_text_set(path, FALSE);
- MEM_freeN(path);
- }
- }
-
- /* since we're just copying, we don't really need to do anything else...*/
- return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
-}
-
-void ANIM_OT_copy_clipboard_button(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name= "Copy Data Path";
- ot->idname= "ANIM_OT_copy_clipboard_button";
- ot->description= "Copy the RNA data path for this property to the clipboard.";
-
- /* callbacks */
- ot->exec= copy_clipboard_button_exec;
- //op->poll= ??? // TODO: need to have some valid property before this can be done
-
- /* flags */
- ot->flag= OPTYPE_REGISTER;
-}
-
/* ************************************************** */
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 5b512da55c9..f0e52a13d3f 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -688,6 +688,9 @@ void uiItemMenuF(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func,
void uiItemMenuEnumO(uiLayout *layout, char *name, int icon, char *opname, char *propname);
void uiItemMenuEnumR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, char *propname);
+/* UI Operators */
+void ui_buttons_operatortypes(void);
+
/* Helpers for Operators */
void uiAnimContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index);
void uiFileBrowseContextProperty(const struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop);
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index a43506778d8..9604704dde8 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3499,9 +3499,14 @@ static int ui_but_menu(bContext *C, uiBut *but)
//Copy Property Value
//Paste Property Value
- //uiItemO(layout, "Reset to Default Value", 0, "WM_OT_property_value_reset_button");
+ if(length) {
+ uiItemBooleanO(layout, "Reset All to Default Values", 0, "UI_OT_reset_default_button", "all", 1);
+ uiItemBooleanO(layout, "Reset Single to Default Value", 0, "UI_OT_reset_default_button", "all", 0);
+ }
+ else
+ uiItemO(layout, "Reset to Default Value", 0, "UI_OT_reset_default_button");
- uiItemO(layout, "Copy Data Path", 0, "ANIM_OT_copy_clipboard_button");
+ uiItemO(layout, "Copy Data Path", 0, "UI_OT_copy_clipboard_button");
uiItemS(layout);
}
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
new file mode 100644
index 00000000000..a5caf1c930b
--- /dev/null
+++ b/source/blender/editors/interface/interface_ops.c
@@ -0,0 +1,234 @@
+/**
+ * $Id: interface_ops.c 24699 2009-11-20 10:21:31Z aligorith $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Joshua Leung
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_vec_types.h"
+#include "DNA_view2d_types.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_context.h"
+#include "BKE_utildefines.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BIF_gl.h"
+
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+/* ********************************************************** */
+
+/* Copy to Clipboard Button Operator ------------------------ */
+
+static int copy_clipboard_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop= NULL;
+ char *path;
+ short success= 0;
+ int index;
+
+ /* try to create driver using property retrieved from UI */
+ memset(&ptr, 0, sizeof(PointerRNA));
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop) {
+ path= RNA_path_from_ID_to_property(&ptr, prop);
+
+ if (path) {
+ WM_clipboard_text_set(path, FALSE);
+ MEM_freeN(path);
+ }
+ }
+
+ /* since we're just copying, we don't really need to do anything else...*/
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void UI_OT_copy_clipboard_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Copy Data Path";
+ ot->idname= "UI_OT_copy_clipboard_button";
+ ot->description= "Copy the RNA data path for this property to the clipboard.";
+
+ /* callbacks */
+ ot->exec= copy_clipboard_button_exec;
+ //op->poll= ??? // TODO: need to have some valid property before this can be done
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER;
+}
+
+/* Reset to Default Values Button Operator ------------------------ */
+
+static int reset_default_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop= NULL;
+ short success= 0;
+ int index, len;
+ int all = RNA_boolean_get(op->ptr, "all");
+
+ /* try to reset the nominated setting to its default value */
+ memset(&ptr, 0, sizeof(PointerRNA));
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ /* if there is a valid property that is editable... */
+ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
+ /* get the length of the array to work with */
+ len= RNA_property_array_length(&ptr, prop);
+
+ /* get and set the default values as appropriate for the various types */
+ switch (RNA_property_type(prop)) {
+ case PROP_BOOLEAN:
+ if (len) {
+ if (all) {
+ int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - boolean");
+
+ RNA_property_boolean_get_default_array(&ptr, prop, tmparray);
+ RNA_property_boolean_set_array(&ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ int value= RNA_property_boolean_get_default_index(&ptr, prop, index);
+ RNA_property_boolean_set_index(&ptr, prop, index, value);
+ }
+ }
+ else {
+ int value= RNA_property_boolean_get_default(&ptr, prop);
+ RNA_property_boolean_set(&ptr, prop, value);
+ }
+ break;
+ case PROP_INT:
+ if (len) {
+ if (all) {
+ int *tmparray= MEM_callocN(sizeof(int)*len, "reset_defaults - int");
+
+ RNA_property_int_get_default_array(&ptr, prop, tmparray);
+ RNA_property_int_set_array(&ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ int value= RNA_property_int_get_default_index(&ptr, prop, index);
+ RNA_property_int_set_index(&ptr, prop, index, value);
+ }
+ }
+ else {
+ int value= RNA_property_int_get_default(&ptr, prop);
+ RNA_property_int_set(&ptr, prop, value);
+ }
+ break;
+ case PROP_FLOAT:
+ if (len) {
+ if (all) {
+ float *tmparray= MEM_callocN(sizeof(float)*len, "reset_defaults - float");
+
+ RNA_property_float_get_default_array(&ptr, prop, tmparray);
+ RNA_property_float_set_array(&ptr, prop, tmparray);
+
+ MEM_freeN(tmparray);
+ }
+ else {
+ float value= RNA_property_float_get_default_index(&ptr, prop, index);
+ RNA_property_float_set_index(&ptr, prop, index, value);
+ }
+ }
+ else {
+ float value= RNA_property_float_get_default(&ptr, prop);
+ RNA_property_float_set(&ptr, prop, value);
+ }
+ break;
+ case PROP_ENUM:
+ {
+ int value= RNA_property_enum_get_default(&ptr, prop);
+ RNA_property_enum_set(&ptr, prop, value);
+ }
+ break;
+
+ //case PROP_POINTER:
+ //case PROP_STRING:
+ default:
+ // FIXME: many of the other types such as strings and pointers need this implemented too!
+ break;
+ }
+
+ /* perform updates required for this property */
+ RNA_property_update(C, &ptr, prop);
+
+ success= 1;
+ }
+
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void UI_OT_reset_default_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Reset to Default Value";
+ ot->idname= "UI_OT_reset_default_button";
+ ot->description= "Copy the RNA data path for this property to the clipboard.";
+
+ /* callbacks */
+ ot->exec= reset_default_button_exec;
+ //op->poll= ??? // TODO: need to have some valid property before this can be done
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array.");
+}
+
+/* ********************************************************* */
+/* Registration */
+
+void ui_buttons_operatortypes(void)
+{
+ WM_operatortype_append(UI_OT_copy_clipboard_button);
+ WM_operatortype_append(UI_OT_reset_default_button);
+}
+