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

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 // window specific history
OH.addEntry( OH.addEntry(
function() { // the task which should be undo-able.
MyService.myProp = newValue;
},
'MyAddonFeature', 'MyAddonFeature',
{ label : 'Change tabbar position', { label : 'Change tabbar position',
onUndo : function() { ... }, onUndo : function() { MyService.myProp = oldValue; },
onRedo : function() { ... } }, onRedo : function() { MyService.myProp = newValue; } },
window window
); );
OH.undo('MyAddonFeature', window); OH.undo('MyAddonFeature', window);
@ -17,27 +20,31 @@
// global history (not associated to window) // global history (not associated to window)
OH.addEntry( OH.addEntry(
function() { ... }, // task
'MyAddonFeature', 'MyAddonFeature',
{ ... } { ... }
); );
OH.undo('MyAddonFeature'); OH.undo('MyAddonFeature');
// anonymous, window specific // anonymous, window specific
OH.addEntry({ ... }, window); OH.addEntry(function() { ... }, { ... }, window);
OH.undo(window); OH.undo(window);
// anonymous, global // anonymous, global
OH.addEntry({ ... }); OH.addEntry(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.addEntry({
function() {
targetWindow.MyAddonService.myProp = newValue;
},
id : OH.getWindowId(targetWindow), id : OH.getWindowId(targetWindow),
onUndo : function() { onUndo : function() {
var w = OH.getWindowById(this.id); var w = OH.getWindowById(this.id);
w.MyAddonService.undoSomething(); w.MyAddonService.myProp = oldValue;
}, },
onRedo : ... onRedo : ...
}); });
@ -56,7 +63,7 @@
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.js http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.js
*/ */
(function() { (function() {
const currentRevision = 3; const currentRevision = 4;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -84,20 +91,37 @@
addEntry : function() addEntry : function()
{ {
if (this._doingUndo)
return;
var options = this._getOptionsFromArguments(arguments); var options = this._getOptionsFromArguments(arguments);
var history = options.history; var history = options.history;
var entries = history.entries; var entries = history.entries;
var error;
var wasInUndoableTask = history._inUndoableTask;
entries = entries.slice(0, history.index+1); if (!wasInUndoableTask)
entries.push(options.data); history._inUndoableTask = true;
entries = entries.slice(-this.kMAX_ENTRIES);
history.entries = entries; try {
history.index = entries.length-1; 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() getHistory : function()
@ -255,16 +279,18 @@
_getOptionsFromArguments : function(aArguments) _getOptionsFromArguments : function(aArguments)
{ {
var w = null, name, data = null; var w = null, name, data = null, task = null;
Array.slice(aArguments).some(function(aArg) { Array.slice(aArguments).some(function(aArg) {
if (aArg instanceof Ci.nsIDOMWindow) if (aArg instanceof Ci.nsIDOMWindow)
w = aArg; w = aArg;
else if (typeof aArg == 'string') else if (typeof aArg == 'string')
name = aArg; name = aArg;
else if (typeof aArg == 'function')
task = aArg;
else if (aArg) else if (aArg)
data = aArg; data = aArg;
return (w && name && data); return (w && name && data && task);
}); });
if (!name) if (!name)
@ -289,7 +315,8 @@
window : w, window : w,
windowId : windowId, windowId : windowId,
data : data, 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' ; let orient = (position == 'left' || position == 'right') ? 'vertical' : 'horizontal' ;
sv.setTreePref('tabbar.fixed.'+orient, false); sv.setTreePref('tabbar.fixed.'+orient, false);
} }
var current = sv.currentTabbarPosition; var current;
sv.currentTabbarPosition = position;
window['piro.sakura.ne.jp'].operationHistory.addEntry( window['piro.sakura.ne.jp'].operationHistory.addEntry(
function() {
current = sv.currentTabbarPosition;
sv.currentTabbarPosition = position;
},
'TabbarDNDOperations', 'TabbarDNDOperations',
{ label : sv.treeBundle.getString('undo_changeTabbarPosition_label'), { label : sv.treeBundle.getString('undo_changeTabbarPosition_label'),
onUndo : function() { TreeStyleTabService.currentTabbarPosition = current; }, onUndo : function() { TreeStyleTabService.currentTabbarPosition = current; },
@ -45,7 +48,10 @@ TreeStyleTabBrowserTabpanelDNDObserver.prototype = {
); );
} }
sv = null; sv = null;
aEvent = null;
aXferData = null;
aDragSession = null;
aEvent.stopPropagation(); aEvent.stopPropagation();
}, },