More ViXEn transaction system love.

NOT PART OF BUILD.
This commit is contained in:
ben%netscape.com 2000-10-20 11:17:09 +00:00
Родитель fdb5df401b
Коммит f5cbbaec62
9 изменённых файлов: 169 добавлений и 57 удалений

Просмотреть файл

@ -81,11 +81,11 @@ var vxPalette =
var txns = [radiogroupTxn, radiogroupAttrTxn, radioTxn, radioAttrTxn]; var txns = [radiogroupTxn, radiogroupAttrTxn, radioTxn, radioAttrTxn];
var aggregateTxn = new vxAggregateTxn(txns); var aggregateTxn = new vxAggregateTxn(txns);
aggregateTxn.init(); aggregateTxn.init();
var txmgr = focusedWindow.vxVFD.mTxMgrShell; var txmgr = focusedWindow.vxVFD.mTxMgrShell;
txmgr.addListener([radioAttrTxn, radioTxn, radioAttrTxn]); aggregateTxn.addListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
txmgr.doTransaction(aggregateTxn); txmgr.doTransaction(aggregateTxn);
txmgr.removeListener([radioAttrTxn, radioTxn, radioAttrTxn]); aggregateTxn.removeListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
}, },
incrementElementCount: function (aNodeName) incrementElementCount: function (aNodeName)
@ -104,9 +104,8 @@ var vxPalette =
// need to check to see if the focused window is a vfd // need to check to see if the focused window is a vfd
var insertionPoint = focusedWindow.vxVFD.getInsertionPoint(); var insertionPoint = focusedWindow.vxVFD.getInsertionPoint();
var vfdDocument = focusedWindow.vxVFD.getContent(true).document; var vfdDocument = focusedWindow.vxVFD.getContent(true).document;
var elementTxn = new vxCreateElementTxn(vfdDocument, aNodeName, insertionPoint.parent, insertionPoint.index); var elementTxn = new vxCreateElementTxn(vfdDocument, aNodeName, insertionPoint.parent, insertionPoint.index);
elementTxn.init(); elementTxn.init();
var elementAttrTxn = new vxChangeAttributeTxn(elementTxn.mID, aAttributes, aValues, false); var elementAttrTxn = new vxChangeAttributeTxn(elementTxn.mID, aAttributes, aValues, false);
@ -120,6 +119,16 @@ var vxPalette =
txmgr.addListener(elementAttrTxn); txmgr.addListener(elementAttrTxn);
txmgr.doTransaction(aggregateTxn); txmgr.doTransaction(aggregateTxn);
txmgr.removeListener(elementAttrTxn); txmgr.removeListener(elementAttrTxn);
},
/**
* Implements nsITransactionListener
*/
didUndo: function (aTransactionManager, aTransaction, aInterrupt)
{
// Register the palette as a transaction listener so that the instance
// count for each type of widget can be decremented when a transaction
// is done.
} }
}; };

Просмотреть файл

@ -14,6 +14,7 @@
<script src="chrome://vixen/content/palette/vxPalette.js"></script> <script src="chrome://vixen/content/palette/vxPalette.js"></script>
<!-- supported txns --> <!-- supported txns -->
<script src="chrome://vixen/content/vfd/vxBaseTxn.js"></script>
<script src="chrome://vixen/content/vfd/vxAggregateTxn.js"></script> <script src="chrome://vixen/content/vfd/vxAggregateTxn.js"></script>
<script src="chrome://vixen/content/vfd/vxChangeAttributeTxn.js"></script> <script src="chrome://vixen/content/vfd/vxChangeAttributeTxn.js"></script>
<script src="chrome://vixen/content/vfd/vxCreateElementTxn.js"></script> <script src="chrome://vixen/content/vfd/vxCreateElementTxn.js"></script>

Просмотреть файл

@ -36,33 +36,41 @@ function vxAggregateTxn (aTransactionList)
this.mTransactionList[aTransactionList[i].mID] = aTransactionList[i]; this.mTransactionList[aTransactionList[i].mID] = aTransactionList[i];
this.mID = "aggregate-txn::"; this.mID = "aggregate-txn::";
this.mTransactionListeners = [];
} }
vxAggregateTxn.prototype = { vxAggregateTxn.prototype = {
init: function () __proto__: vxBaseTxn.prototype,
{
this.mID += generateID();
},
doTransaction: function () doTransaction: function ()
{ {
_dd("vxAggregateTxn::doTransaction"); for (var i in this.mTransactionList) {
for (var i in this.mTransactionList) var irq = { };
this.notifyListeners("willDo", this.mTransactionList[i], irq);
this.mTransactionList[i].doTransaction(); this.mTransactionList[i].doTransaction();
this.notifyListeners("didDo", this.mTransactionList[i], irq);
}
}, },
undoTransaction: function () undoTransaction: function ()
{ {
_dd("vxAggregateTxn::undoTransaction"); for (var i in this.mTransactionList) {
for (var i in this.mTransactionList) var irq = { };
this.notifyListeners("willUndo", this.mTransactionList[i], irq);
this.mTransactionList[i].undoTransaction(); this.mTransactionList[i].undoTransaction();
this.notifyListeners("didUndo", this.mTransactionList[i], irq);
}
}, },
redoTransaction: function () redoTransaction: function ()
{ {
_dd("vxAggregateTxn::redoTransaction"); for (var i in this.mTransactionList) {
for (var i in this.mTransactionList) var irq = { };
this.notifyListeners("willRedo", this.mTransactionList[i], irq);
this.mTransactionList[i].redoTransaction(); this.mTransactionList[i].redoTransaction();
this.notifyListeners("didRedo", this.mTransactionList[i], irq);
}
}, },
get commandString() get commandString()

Просмотреть файл

@ -0,0 +1,80 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2000 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*/
function vxBaseTxn ()
{
}
vxBaseTxn.prototype = {
mID: null,
mListeners: [],
notifyListeners: function (aEvent, aTransaction, aIRQ)
{
_dd("vxBaseTxn::notifyListeners");
for (var i = 0; i < this.mListeners.length; i++) {
if (aEvent in this.mListeners[i]) {
_ddf("calling listener for transaction complete", aTransaction.commandString);
this.mListeners[i][aEvent](undefined, aTransaction, aIRQ);
}
}
},
addListener: function (aListener)
{
_dd("vxBaseTxn::addListener");
this.mListeners = this.mListeners.concat(aListener);
_ddf("vxBaseTxn::mListeners", this.mListeners);
},
removeListener: function (aListener)
{
_dd("vxBaseTxn::removeListener");
var listeners = [].concat(aListener);
for (var i = 0; i < this.mListeners.length; i++) {
for (var k = 0; k < listeners.length; k++) {
if (this.mListeners[i] == listeners[k]) {
this.mListeners.splice(i,1);
break;
}
}
}
},
init: function ()
{
this.mID += this.generateID();
},
/**
* Generate a unique identifier for a transaction
*/
generateID: function ()
{
var val = ((new Date()).getUTCMilliseconds())*Math.random()*100000;
_ddf("value", val);
return val;
}
};

Просмотреть файл

@ -57,18 +57,14 @@ function vxChangeAttributeTxn(aElement, aAttribute, aValue, aRemoveFlag)
} }
vxChangeAttributeTxn.prototype = { vxChangeAttributeTxn.prototype = {
init: function () __proto__: vxBaseTxn.prototype,
{
this.mID += generateID();
},
doTransaction: function () doTransaction: function ()
{ {
if (!this.mElementCreated) if (!this.mElementCreated)
return; return;
for (var i = 0; i < this.mAttributes.length; i++) { for (var i = 0; i < this.mAttributes.length; i++) {
_ddf("changing attribute", this.mAttributes[i]);
this.mUndoValues[i] = this.mElement.getAttribute(this.mAttributes[i]); this.mUndoValues[i] = this.mElement.getAttribute(this.mAttributes[i]);
if (!this.mRemoveFlags[i]) if (!this.mRemoveFlags[i])
this.mElement.setAttribute(this.mAttributes[i], this.mValues[i]); this.mElement.setAttribute(this.mAttributes[i], this.mValues[i]);
@ -113,16 +109,18 @@ vxChangeAttributeTxn.prototype = {
*/ */
didDo: function (aTransactionManager, aTransaction, aInterrupt) didDo: function (aTransactionManager, aTransaction, aInterrupt)
{ {
_ddf("aTransaction is a", aTransaction.commandString); var prevTxn = null;
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0) { if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
var createElementTxn = aTransaction.mTransactionList[this.mElementTxnID]; prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
_ddf("the transaction ahead of us is", createElementTxn.commandString); else
_ddf("and its element is", createElementTxn.mLocalName); prevTxn = aTransaction;
if (createElementTxn.commandString.indexOf("create-element") >= 0) {
this.mElement = createElementTxn.mElement; if (prevTxn.commandString.indexOf("create-element") >= 0) {
this.mElementCreated = true; _ddf("did create element of", prevTxn.mLocalName);
this.doTransaction(); this.mElement = prevTxn.mElement;
} this.mElementCreated = true;
_ddf("going to actually do this transaction now", this.mAttributes);
this.doTransaction();
} }
} }
}; };

Просмотреть файл

@ -45,17 +45,12 @@ function vxCreateElementTxn(aDocument, aLocalName, aParentNode, aChildOffset)
} }
vxCreateElementTxn.prototype = { vxCreateElementTxn.prototype = {
init: function () __proto__: vxBaseTxn.prototype,
{
this.mID += generateID();
},
doTransaction: function () doTransaction: function ()
{ {
_ddf("creating element", this.mLocalName);
if (!this.mElementCreated) { if (!this.mElementCreated) {
_dd("aParentNode is an id, bailing early"); _dd("element we rely on does not yet exist, so bail for now");
_ddf("localname is", this.mLocalName);
return; return;
} }
@ -96,9 +91,14 @@ vxCreateElementTxn.prototype = {
*/ */
didDo: function (aTransactionManager, aTransaction, aInterrupt) didDo: function (aTransactionManager, aTransaction, aInterrupt)
{ {
var createElementTxn = aTransaction.mTransactionList[this.mElementTxnID]; var prevTxn = null;
if (createElementTxn.commandString.indexOf("create-element") >= 0) { if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
this.mElement = createElementTxn.mElement; prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
else
prevTxn = aTransaction;
if (prevTxn.commandString.indexOf("create-element") >= 0) {
this.mParentNode = prevTxn.mElement;
this.mElementCreated = true; this.mElementCreated = true;
this.doTransaction(); this.doTransaction();
} }

Просмотреть файл

@ -63,8 +63,8 @@ vxVFDTransactionManager.prototype =
// likewise with the RDF Seq. // likewise with the RDF Seq.
var seqCount = this.mTxnSeq.GetCount(); var seqCount = this.mTxnSeq.GetCount();
for (i = this.mTxnStack.index; i < seqCount; i++) for (i = seqCount-1; i >= this.mTxnStack.index; i--)
this.mTxnSeq.RemoveElementAt(i); this.mTxnSeq.RemoveElementAt(i, true);
} }
// append the transaction to our list // append the transaction to our list
@ -76,7 +76,6 @@ vxVFDTransactionManager.prototype =
for (i = 0; i < this.mTransactionListeners.length; i++) { for (i = 0; i < this.mTransactionListeners.length; i++) {
interruptRequest = {}; interruptRequest = {};
if ("didDo" in this.mTransactionListeners[i]) { if ("didDo" in this.mTransactionListeners[i]) {
_ddf("transaction listener " + i, this.mTransactionListeners[i].commandString);
this.mTransactionListeners[i].didDo(this, aTransaction, interruptRequest); this.mTransactionListeners[i].didDo(this, aTransaction, interruptRequest);
// do something with irq here once we figure out what it does. // do something with irq here once we figure out what it does.
} }
@ -98,7 +97,6 @@ vxVFDTransactionManager.prototype =
// undo the transaction // undo the transaction
if (txn) { if (txn) {
_ddf("going to undo the txn at", this.mTxnStack.index-1);
txn.undoTransaction(); txn.undoTransaction();
this.mTxnStack.index--; this.mTxnStack.index--;
} }
@ -232,6 +230,12 @@ var vxVFDTransactionDS =
return null; return null;
}, },
GetTargets: function (aSource, aProperty, aTruthValue)
{
var targets = [].concat(this.GetTarget(aSource, aProperty, aTruthValue));
return new ArrayEnumerator(targets);
},
mObservers: [], mObservers: [],
AddObserver: function (aObserver) AddObserver: function (aObserver)
{ {
@ -282,7 +286,6 @@ vxVFDTransactionStack.prototype =
set index (aValue) set index (aValue)
{ {
_ddf("setting index to", aValue);
this.mIndex = aValue; this.mIndex = aValue;
return this.mIndex; return this.mIndex;
}, },

Просмотреть файл

@ -44,16 +44,6 @@ var vxUtils = {
}; };
/**
* Generate a unique identifier for a transaction
*/
function generateID()
{
var val = ((new Date()).getUTCMilliseconds())*Math.random()*100000;
_ddf("value", val);
return val;
}
/** /**
* dumps the DOM tree under a given node. * dumps the DOM tree under a given node.
*/ */
@ -64,3 +54,25 @@ function dumpDOM(aNode)
dumpDOM(aNode.childNodes[i]); dumpDOM(aNode.childNodes[i]);
} }
/**
* Converts a regular js array into an nsISimpleEnumerator
*/
function ArrayEnumerator(aArray)
{
this.mArray = aArray;
this.mIndex = 0;
}
ArrayEnumerator.prototype = {
getNext: function ()
{
return this.mArray[this.mIndex++];
},
hasMoreElements: function ()
{
if (this.mIndex < this.mArray.length)
return true;
return false;
}
};

Просмотреть файл

@ -18,6 +18,7 @@ vixen.jar:
content/vixen/vfd/vxVFDSelectionManager.js (content/vfd/vxVFDSelectionManager.js) content/vixen/vfd/vxVFDSelectionManager.js (content/vfd/vxVFDSelectionManager.js)
content/vixen/vfd/vxVFDTransactionManager.js (content/vfd/vxVFDTransactionManager.js) content/vixen/vfd/vxVFDTransactionManager.js (content/vfd/vxVFDTransactionManager.js)
content/vixen/vfd/vxAggregateTxn.js (content/vfd/vxAggregateTxn.js) content/vixen/vfd/vxAggregateTxn.js (content/vfd/vxAggregateTxn.js)
content/vixen/vfd/vxBaseTxn.js (content/vfd/vxBaseTxn.js)
skin/modern/vixen/contents.rdf (skin/contents.rdf) skin/modern/vixen/contents.rdf (skin/contents.rdf)
skin/modern/vixen/vfdScratch.css (skin/vfdScratch.css) skin/modern/vixen/vfdScratch.css (skin/vfdScratch.css)
locale/en-US/vixen/contents.rdf (locale/en-US/contents.rdf) locale/en-US/vixen/contents.rdf (locale/en-US/contents.rdf)