同じ名前の履歴の登録中は、同じ名前で履歴項目を登録しないように

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5701 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-01-04 06:23:37 +00:00
parent 1169712794
commit 340adb0863
2 changed files with 54 additions and 21 deletions

View File

@ -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
};
},

View File

@ -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();
},