ライブラリ更新

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5774 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-01-05 12:36:02 +00:00
parent e3a9dfa4fe
commit 71115d0688

View File

@ -74,7 +74,7 @@
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.test.js http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.test.js
*/ */
(function() { (function() {
const currentRevision = 6; const currentRevision = 8;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -117,6 +117,29 @@
if (!wasInUndoableTask) if (!wasInUndoableTask)
history._inUndoableTask = true; history._inUndoableTask = true;
var data = options.data;
if (!this._doingUndo && data) {
let f = this._getAvailableFunction(data.onRedo, data.onredo, data.redo);
if (!f && !data.onRedo && !data.onredo && !data.redo && options.task)
data.onRedo = options.task;
if (wasInUndoableTask) {
entries[entries.length-1].children.push(data);
}
else {
entries = entries.slice(0, history.index+1);
entries.push({
__proto__ : data,
data : data,
children : []
});
entries = entries.slice(-this.MAX_ENTRIES);
history.entries = entries;
history.index = entries.length;
}
}
try { try {
if (options.task) if (options.task)
options.task.call(this); options.task.call(this);
@ -125,20 +148,6 @@
error = e; error = e;
} }
var data = options.data;
if (!wasInUndoableTask && !this._doingUndo && data) {
let f = this._getAvailableFunction(data.onRedo, data.onredo, data.redo);
if (!f && !data.onRedo && !data.onredo && !data.redo && options.task)
data.onRedo = options.task;
entries = entries.slice(0, history.index+1);
entries.push(data);
entries = entries.slice(-this.MAX_ENTRIES);
history.entries = entries;
history.index = entries.length;
}
if (!wasInUndoableTask) if (!wasInUndoableTask)
delete history._inUndoableTask; delete history._inUndoableTask;
@ -168,13 +177,14 @@
var error; var error;
while (processed === false && history.index > -1) while (processed === false && history.index > -1)
{ {
let data = history.entries[history.index--]; let entry = history.entries[history.index--];
if (!data) continue; if (!entry) continue;
let f = this._getAvailableFunction(data.onUndo, data.onundo, data.undo);
let done = false; let done = false;
[entry.data].concat(entry.children).forEach(function(aData) {
let f = this._getAvailableFunction(aData.onUndo, aData.onundo, aData.undo);
try { try {
if (f) { if (f) {
processed = f.call(data); processed = f.call(aData);
done = true; done = true;
} }
else { else {
@ -184,7 +194,8 @@
catch(e) { catch(e) {
error = e; error = e;
} }
this._dispatchEvent('UIOperationGlobalHistoryUndo', options, data, done); }, this);
this._dispatchEvent('UIOperationGlobalHistoryUndo', options, entry.data, done);
} }
this._doingUndo = false; this._doingUndo = false;
@ -207,13 +218,15 @@
var error; var error;
while (processed === false && history.index < max) while (processed === false && history.index < max)
{ {
let data = history.entries[++history.index]; let entry = history.entries[++history.index];
if (!data) continue; if (!entry) continue;
let f = this._getAvailableFunction(data.onRedo, data.onredo, data.redo); let done = false;
[entry.data].concat(entry.children).forEach(function(aData) {
let f = this._getAvailableFunction(aData.onRedo, aData.onredo, aData.redo);
let done = false; let done = false;
try { try {
if (f) { if (f) {
processed = f.call(data); processed = f.call(entry.data);
done = true; done = true;
} }
else { else {
@ -223,7 +236,8 @@
catch(e) { catch(e) {
error = e; error = e;
} }
this._dispatchEvent('UIOperationGlobalHistoryRedo', options, data, done); }, this);
this._dispatchEvent('UIOperationGlobalHistoryRedo', options, entry.data, done);
} }
this._doingUndo = false; this._doingUndo = false;
@ -233,27 +247,33 @@
return true; return true;
}, },
getWindowId : function(aWindow, aForceNewId) getWindowId : function(aWindow)
{ {
var root = aWindow.document.documentElement; var root = aWindow.document.documentElement;
var windowId = root.getAttribute(this.WINDOW_ID); var id = root.getAttribute(this.WINDOW_ID);
try { try {
if (!windowId) if (!id)
windowId = this.SessionStore.getWindowValue(aWindow, this.WINDOW_ID); id = this.SessionStore.getWindowValue(aWindow, this.WINDOW_ID);
} }
catch(e) { catch(e) {
} }
if (!windowId || aForceNewId) {
windowId = 'window-'+Date.now()+parseInt(Math.random() * 65000); // When the ID has been already used by other window,
// we have to create new ID for this window.
var windows = this._getWindowsById(id);
var forceNewId = (windows.length > 1 || windows[0] != aWindow);
if (!id || forceNewId) {
id = 'window-'+Date.now()+parseInt(Math.random() * 65000);
try { try {
this.SessionStore.setWindowValue(aWindow, this.WINDOW_ID, windowId); this.SessionStore.setWindowValue(aWindow, this.WINDOW_ID, id);
} }
catch(e) { catch(e) {
} }
} }
if (root.getAttribute(this.WINDOW_ID) != windowId) if (root.getAttribute(this.WINDOW_ID) != id)
root.setAttribute(this.WINDOW_ID, windowId); root.setAttribute(this.WINDOW_ID, id);
return windowId; return id;
}, },
getWindowById : function(aId) getWindowById : function(aId)
@ -336,12 +356,6 @@
var windowId = w ? this.getWindowId(w) : null ; var windowId = w ? this.getWindowId(w) : null ;
var table = this._getTable(name, w); var table = this._getTable(name, w);
// Wrongly duplicated ID, so, we have to create new ID for this window.
if (w && table.window && table.window != w) {
windowId = this.getWindowId(w, true);
table = this._getTable(name, w);
}
return { return {
name : name, name : name,
window : w, window : w,
@ -404,6 +418,26 @@
}, this); }, this);
}, },
_getWindowsById : function(aId)
{
var targets = this.WindowMediator.getZOrderDOMWindowEnumerator(null, true);
var windows = [];
while (targets.hasMoreElements())
{
let target = targets.getNext().QueryInterface(Ci.nsIDOMWindowInternal);
let id = target.document.documentElement.getAttribute(this.WINDOW_ID);
try {
if (!id)
id = this.SessionStore.getWindowValue(target, this.WINDOW_ID)
}
catch(e) {
}
if (id == aId)
windows.push(target);
}
return windows;
},
get _doingUndo() get _doingUndo()
{ {
return this._tables._doingUndo; return this._tables._doingUndo;