diff --git a/content/treestyletab/res/operationHistory.js b/content/treestyletab/res/operationHistory.js index 164c90d0..d1fc88b3 100644 --- a/content/treestyletab/res/operationHistory.js +++ b/content/treestyletab/res/operationHistory.js @@ -6,10 +6,13 @@ // window specific history OH.addEntry( + function() { // the task which should be undo-able. + MyService.myProp = newValue; + }, 'MyAddonFeature', { label : 'Change tabbar position', - onUndo : function() { ... }, - onRedo : function() { ... } }, + onUndo : function() { MyService.myProp = oldValue; }, + onRedo : function() { MyService.myProp = newValue; } }, window ); OH.undo('MyAddonFeature', window); @@ -17,27 +20,31 @@ // global history (not associated to window) OH.addEntry( + function() { ... }, // task 'MyAddonFeature', { ... } ); OH.undo('MyAddonFeature'); // anonymous, window specific - OH.addEntry({ ... }, window); + OH.addEntry(function() { ... }, { ... }, window); OH.undo(window); // anonymous, global - OH.addEntry({ ... }); + OH.addEntry(function() { ... }, { ... }); OH.undo(); // When you want to use "window" object in the global history, // you should use the ID string instead of the "window" object // to reduce memory leak. For example... OH.addEntry({ + function() { + targetWindow.MyAddonService.myProp = newValue; + }, id : OH.getWindowId(targetWindow), onUndo : function() { var w = OH.getWindowById(this.id); - w.MyAddonService.undoSomething(); + w.MyAddonService.myProp = oldValue; }, onRedo : ... }); @@ -56,7 +63,7 @@ http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.js */ (function() { - const currentRevision = 3; + const currentRevision = 4; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; @@ -84,20 +91,37 @@ addEntry : function() { - if (this._doingUndo) - return; - var options = this._getOptionsFromArguments(arguments); - var history = options.history; var entries = history.entries; + var error; + var wasInUndoableTask = history._inUndoableTask; - entries = entries.slice(0, history.index+1); - entries.push(options.data); - entries = entries.slice(-this.kMAX_ENTRIES); + if (!wasInUndoableTask) + history._inUndoableTask = true; - history.entries = entries; - history.index = entries.length-1; + try { + if (options.task) + options.task.call(this); + } + catch(e) { + error = e; + } + + if (!wasInUndoableTask && !this._doingUndo) { + entries = entries.slice(0, history.index+1); + entries.push(options.data); + entries = entries.slice(-this.kMAX_ENTRIES); + + history.entries = entries; + history.index = entries.length-1; + } + + if (!wasInUndoableTask) + delete history._inUndoableTask; + + if (error) + throw e; }, getHistory : function() @@ -255,16 +279,18 @@ _getOptionsFromArguments : function(aArguments) { - var w = null, name, data = null; + var w = null, name, data = null, task = null; Array.slice(aArguments).some(function(aArg) { if (aArg instanceof Ci.nsIDOMWindow) w = aArg; else if (typeof aArg == 'string') name = aArg; + else if (typeof aArg == 'function') + task = aArg; else if (aArg) data = aArg; - return (w && name && data); + return (w && name && data && task); }); if (!name) @@ -289,7 +315,8 @@ window : w, windowId : windowId, data : data, - history : this._tables[tableName] + history : this._tables[tableName], + task : task }; }, diff --git a/content/treestyletab/treestyletabbrowser_tabpanelDNDObserver.js b/content/treestyletab/treestyletabbrowser_tabpanelDNDObserver.js index c079cb56..26c65351 100644 --- a/content/treestyletab/treestyletabbrowser_tabpanelDNDObserver.js +++ b/content/treestyletab/treestyletabbrowser_tabpanelDNDObserver.js @@ -34,9 +34,12 @@ TreeStyleTabBrowserTabpanelDNDObserver.prototype = { let orient = (position == 'left' || position == 'right') ? 'vertical' : 'horizontal' ; sv.setTreePref('tabbar.fixed.'+orient, false); } - var current = sv.currentTabbarPosition; - sv.currentTabbarPosition = position; + var current; window['piro.sakura.ne.jp'].operationHistory.addEntry( + function() { + current = sv.currentTabbarPosition; + sv.currentTabbarPosition = position; + }, 'TabbarDNDOperations', { label : sv.treeBundle.getString('undo_changeTabbarPosition_label'), onUndo : function() { TreeStyleTabService.currentTabbarPosition = current; }, @@ -45,7 +48,10 @@ TreeStyleTabBrowserTabpanelDNDObserver.prototype = { ); } - sv = null; + sv = null; + aEvent = null; + aXferData = null; + aDragSession = null; aEvent.stopPropagation(); },