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:
authorNick Samarin <nicks1987@bigmir.net>2011-06-05 22:51:00 +0400
committerNick Samarin <nicks1987@bigmir.net>2011-06-05 22:51:00 +0400
commit5ceb8b3d35706e13580d4eed0f24acc8e57f3464 (patch)
tree8f7a8078b94bc7512abc37baaadedd7ff5fad7f4 /source/blender/editors/util
parenta918040902bdeb7c9793168710871e4a3b7777a3 (diff)
parent08f44adba965dbf4f7c56eb096b0e2709df80e5c (diff)
synched with trunk at revision 37212
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r--source/blender/editors/util/CMakeLists.txt6
-rw-r--r--source/blender/editors/util/editmode_undo.c66
-rw-r--r--source/blender/editors/util/undo.c176
-rw-r--r--source/blender/editors/util/util_intern.h9
4 files changed, 173 insertions, 84 deletions
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index 3b7fc7c7b86..69ede67288a 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -31,6 +31,10 @@ set(INC
../../../../intern/guardedalloc
)
+set(INC_SYS
+
+)
+
set(SRC
ed_util.c
editmode_undo.c
@@ -86,4 +90,4 @@ set(SRC
../include/UI_view2d.h
)
-blender_add_lib(bf_editor_util "${SRC}" "${INC}")
+blender_add_lib(bf_editor_util "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c
index 732e5087af2..bcbc134d06d 100644
--- a/source/blender/editors/util/editmode_undo.c
+++ b/source/blender/editors/util/editmode_undo.c
@@ -296,7 +296,7 @@ void undo_editmode_clear(void)
}
/* based on index nr it does a restore */
-static void undo_number(bContext *C, int nr)
+void undo_editmode_number(bContext *C, int nr)
{
UndoElem *uel;
int a=1;
@@ -337,66 +337,28 @@ int undo_editmode_valid(const char *undoname)
return undobase.last != undobase.first;
}
-/* ************** for interaction with menu/pullown */
-void undo_editmode_menu(bContext *C)
+/* get name of undo item, return null if no item with this index */
+/* if active pointer, set it to 1 if true */
+char *undo_editmode_get_name(bContext *C, int nr, int *active)
{
UndoElem *uel;
- DynStr *ds= BLI_dynstr_new();
- short event= 0;
- char *menu;
-
- undo_clean_stack(C); // removes other objects from it
-
- BLI_dynstr_append(ds, "Editmode Undo History %t");
-
- for(uel= undobase.first; uel; uel= uel->next) {
- BLI_dynstr_append(ds, "|");
- BLI_dynstr_append(ds, uel->name);
- }
-
- menu= BLI_dynstr_get_cstring(ds);
- BLI_dynstr_free(ds);
-
-// XXX event= pupmenu_col(menu, 20);
- MEM_freeN(menu);
- if(event>0) undo_number(C, event);
-}
-
-static void do_editmode_undohistorymenu(bContext *C, void *UNUSED(arg), int event)
-{
- Object *obedit= CTX_data_edit_object(C);
-
- if(obedit==NULL || event<1) return;
-
- undo_number(C, event-1);
+ /* prevent wrong numbers to be returned */
+ undo_clean_stack(C);
-}
-
-uiBlock *editmode_undohistorymenu(bContext *C, ARegion *ar, void *UNUSED(arg))
-{
- uiBlock *block;
- UndoElem *uel;
- short yco = 20, menuwidth = 120;
- short item= 1;
+ if(active) *active= 0;
- undo_clean_stack(C); // removes other objects from it
-
- block= uiBeginBlock(C, ar, "view3d_edit_mesh_undohistorymenu", UI_EMBOSSP);
- uiBlockSetButmFunc(block, do_editmode_undohistorymenu, NULL);
-
- for(uel= undobase.first; uel; uel= uel->next, item++) {
- if (uel==curundo) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, uel->name, 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, (float)item, "");
- if (uel==curundo) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+ uel= BLI_findlink(&undobase, nr);
+ if(uel) {
+ if(active && uel==curundo)
+ *active= 1;
+ return uel->name;
}
-
- uiBlockSetDirection(block, UI_RIGHT);
- uiTextBoundsBlock(block, 60);
- return block;
+ return NULL;
}
+
void *undo_editmode_get_prev(Object *ob)
{
UndoElem *ue= undobase.last;
diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c
index 60f551afa6e..692a19a7198 100644
--- a/source/blender/editors/util/undo.c
+++ b/source/blender/editors/util/undo.c
@@ -68,6 +68,9 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "UI_interface.h"
+#include "UI_resources.h"
+
#include "util_intern.h"
#define MAXUNDONAME 64 /* XXX, make common define */
@@ -111,10 +114,12 @@ void ED_undo_push(bContext *C, const char *str)
if(wm->file_saved) {
wm->file_saved= 0;
+ /* notifier that data changed, for save-over warning or header */
WM_event_add_notifier(C, NC_WM|ND_DATACHANGED, NULL);
}
}
+/* note: also check undo_history_exec() in bottom if you change notifiers */
static int ed_undo_step(bContext *C, int step, const char *undoname)
{
Object *obedit= CTX_data_edit_object(C);
@@ -260,7 +265,7 @@ int ED_undo_valid(const bContext *C, const char *undoname)
static int ed_undo_exec(bContext *C, wmOperator *UNUSED(op))
{
/* "last operator" should disappear, later we can tie ths with undo stack nicer */
- WM_operator_stack_clear(C);
+ WM_operator_stack_clear(CTX_wm_manager(C));
return ed_undo_step(C, 1, NULL);
}
@@ -277,32 +282,6 @@ static int ed_redo_exec(bContext *C, wmOperator *UNUSED(op))
return ed_undo_step(C, -1, NULL);
}
-#if 0 /* UNUSED */
-void ED_undo_menu(bContext *C)
-{
- Object *obedit= CTX_data_edit_object(C);
- Object *obact= CTX_data_active_object(C);
-
- if(obedit) {
- //if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
- // undo_editmode_menu();
- }
- else {
- if(obact && obact->mode & OB_MODE_PARTICLE_EDIT)
- PE_undo_menu(CTX_data_scene(C), CTX_data_active_object(C));
- else if(U.uiflag & USER_GLOBALUNDO) {
- char *menu= BKE_undo_menu_string();
- if(menu) {
- short event= 0; // XXX pupmenu_col(menu, 20);
- MEM_freeN(menu);
- if(event>0) {
- BKE_undo_number(C, event);
- }
- }
- }
- }
-}
-#endif
/* ********************** */
@@ -344,7 +323,7 @@ void ED_OT_redo(wmOperatorType *ot)
}
-/* ui callbacks should call this rather then calling WM_operator_repeat() themselves */
+/* ui callbacks should call this rather than calling WM_operator_repeat() themselves */
int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
{
int ret= 0;
@@ -399,3 +378,144 @@ void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int UNUSED(arg_ev
{
ED_undo_operator_repeat(C, (wmOperator *)arg_op);
}
+
+
+/* ************************** */
+
+#define UNDOSYSTEM_GLOBAL 1
+#define UNDOSYSTEM_EDITMODE 2
+#define UNDOSYSTEM_PARTICLE 3
+
+static int get_undo_system(bContext *C)
+{
+ Object *obedit= CTX_data_edit_object(C);
+
+ /* find out which undo system */
+ if(obedit) {
+ if (ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE))
+ return UNDOSYSTEM_EDITMODE;
+ }
+ else {
+ Object *obact= CTX_data_active_object(C);
+
+ if(obact && obact->mode & OB_MODE_PARTICLE_EDIT)
+ return UNDOSYSTEM_PARTICLE;
+ else if(U.uiflag & USER_GLOBALUNDO)
+ return UNDOSYSTEM_GLOBAL;
+ }
+
+ return 0;
+}
+
+/* create enum based on undo items */
+static EnumPropertyItem *rna_undo_itemf(bContext *C, int undosys, int *totitem)
+{
+ EnumPropertyItem item_tmp= {0}, *item= NULL;
+ int active, i= 0;
+
+ while(TRUE) {
+ char *name= NULL;
+
+ if(undosys==UNDOSYSTEM_PARTICLE) {
+ name= PE_undo_get_name(CTX_data_scene(C), i, &active);
+ }
+ else if(undosys==UNDOSYSTEM_EDITMODE) {
+ name= undo_editmode_get_name(C, i, &active);
+ }
+ else {
+ name= BKE_undo_get_name(i, &active);
+ }
+
+ if(name) {
+ item_tmp.identifier= item_tmp.name= name;
+ if(active)
+ item_tmp.icon= ICON_RESTRICT_VIEW_OFF;
+ else
+ item_tmp.icon= ICON_NONE;
+ item_tmp.value= i++;
+ RNA_enum_item_add(&item, totitem, &item_tmp);
+ }
+ else
+ break;
+ }
+
+ RNA_enum_item_end(&item, totitem);
+
+ return item;
+}
+
+
+static int undo_history_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
+{
+ int undosys, totitem= 0;
+
+ undosys= get_undo_system(C);
+
+ if(undosys) {
+ EnumPropertyItem *item= rna_undo_itemf(C, undosys, &totitem);
+
+ if(totitem > 0) {
+ uiPopupMenu *pup= uiPupMenuBegin(C, op->type->name, ICON_NONE);
+ uiLayout *layout= uiPupMenuLayout(pup);
+ uiLayout *split= uiLayoutSplit(layout, 0, 0), *column;
+ int i, c;
+
+ for(c=0, i=totitem-1; i >= 0; i--, c++) {
+ if( (c % 20)==0 )
+ column= uiLayoutColumn(split, 0);
+ if(item[i].identifier)
+ uiItemIntO(column, item[i].name, item[i].icon, op->type->idname, "item", item[i].value);
+
+ }
+
+ MEM_freeN(item);
+
+ uiPupMenuEnd(C, pup);
+ }
+
+ }
+ return OPERATOR_CANCELLED;
+}
+
+/* note: also check ed_undo_step() in top if you change notifiers */
+static int undo_history_exec(bContext *C, wmOperator *op)
+{
+ if(RNA_property_is_set(op->ptr, "item")) {
+ int undosys= get_undo_system(C);
+ int item= RNA_int_get(op->ptr, "item");
+
+ if(undosys==UNDOSYSTEM_PARTICLE) {
+ PE_undo_number(CTX_data_scene(C), item);
+ }
+ else if(undosys==UNDOSYSTEM_EDITMODE) {
+ undo_editmode_number(C, item+1);
+ WM_event_add_notifier(C, NC_GEOM|ND_DATA, NULL);
+ }
+ else {
+ BKE_undo_number(C, item);
+ WM_event_add_notifier(C, NC_SCENE|ND_LAYER_CONTENT, CTX_data_scene(C));
+ }
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+
+ return OPERATOR_FINISHED;
+ }
+ return OPERATOR_CANCELLED;
+}
+
+void ED_OT_undo_history(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Undo History";
+ ot->description= "Redo specific action in history";
+ ot->idname= "ED_OT_undo_history";
+
+ /* api callbacks */
+ ot->invoke= undo_history_invoke;
+ ot->exec= undo_history_exec;
+ ot->poll= ED_operator_screenactive;
+
+ RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);
+
+}
+
+
diff --git a/source/blender/editors/util/util_intern.h b/source/blender/editors/util/util_intern.h
index 9ecfb07d535..bfa758b3faa 100644
--- a/source/blender/editors/util/util_intern.h
+++ b/source/blender/editors/util/util_intern.h
@@ -37,9 +37,12 @@
/* internal exports only */
/* editmode_undo.c */
-void undo_editmode_clear(void);
-void undo_editmode_name(bContext *C, const char *undoname);
-int undo_editmode_valid(const char *undoname);
+void undo_editmode_name (struct bContext *C, const char *undoname);
+int undo_editmode_valid (const char *undoname);
+char *undo_editmode_get_name (struct bContext *C, int nr, int *active);
+void *undo_editmode_get_prev (struct Object *ob);
+void undo_editmode_step (struct bContext *C, int step);
+void undo_editmode_number (struct bContext *C, int nr);
#endif /* ED_UTIL_INTERN_H */