doUndoableTask

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5702 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-01-04 06:27:44 +00:00
parent 340adb0863
commit 78dd6ffa74

View File

@ -5,21 +5,28 @@
var OH = window['piro.sakura.ne.jp'].operationHistory; var OH = window['piro.sakura.ne.jp'].operationHistory;
// window specific history // window specific history
OH.addEntry( OH.doUndoableTask(
function() { // the task which should be undo-able. // the task which is undo-able (optional)
function() {
MyService.myProp = newValue; MyService.myProp = newValue;
}, },
// name of history (optional)
'MyAddonFeature', 'MyAddonFeature',
// target window for the history (optional)
window,
// history item
{ label : 'Change tabbar position', { label : 'Change tabbar position',
onUndo : function() { MyService.myProp = oldValue; }, onUndo : function() { MyService.myProp = oldValue; },
onRedo : function() { MyService.myProp = newValue; } }, onRedo : function() { MyService.myProp = newValue; } }
window
); );
OH.undo('MyAddonFeature', window); OH.undo('MyAddonFeature', window);
OH.redo('MyAddonFeature', window); OH.redo('MyAddonFeature', window);
// global history (not associated to window) // global history (not associated to window)
OH.addEntry( OH.doUndoableTask(
function() { ... }, // task function() { ... }, // task
'MyAddonFeature', 'MyAddonFeature',
{ ... } { ... }
@ -27,27 +34,29 @@
OH.undo('MyAddonFeature'); OH.undo('MyAddonFeature');
// anonymous, window specific // anonymous, window specific
OH.addEntry(function() { ... }, { ... }, window); OH.doUndoableTask(function() { ... }, { ... }, window);
OH.undo(window); OH.undo(window);
// anonymous, global // anonymous, global
OH.addEntry(function() { ... }, { ... }); OH.doUndoableTask(function() { ... }, { ... });
OH.undo(); OH.undo();
// When you want to use "window" object in the global history, // When you want to use "window" object in the global history,
// you should use the ID string instead of the "window" object // you should use the ID string instead of the "window" object
// to reduce memory leak. For example... // to reduce memory leak. For example...
OH.addEntry({ OH.doUndoableTask(
function() { function() {
targetWindow.MyAddonService.myProp = newValue; targetWindow.MyAddonService.myProp = newValue;
}, },
id : OH.getWindowId(targetWindow), {
onUndo : function() { id : OH.getWindowId(targetWindow),
var w = OH.getWindowById(this.id); onUndo : function() {
w.MyAddonService.myProp = oldValue; var w = OH.getWindowById(this.id);
}, w.MyAddonService.myProp = oldValue;
onRedo : ... },
}); onRedo : ...
}
);
// enumerate history entries // enumerate history entries
var history = OH.getHistory('MyAddonFeature', window); // options are same to undo/redo var history = OH.getHistory('MyAddonFeature', window); // options are same to undo/redo
@ -89,6 +98,11 @@
kMAX_ENTRIES : 999, kMAX_ENTRIES : 999,
kWINDOW_ID : 'ui-operation-global-history-window-id', kWINDOW_ID : 'ui-operation-global-history-window-id',
doUndoableTask : function()
{
this.addEntry.apply(this, arguments);
},
addEntry : function() addEntry : function()
{ {
var options = this._getOptionsFromArguments(arguments); var options = this._getOptionsFromArguments(arguments);