mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 03:19:06 +00:00
a bunch more ViXEn stuff, not part of build!
This commit is contained in:
parent
e2cbb0585b
commit
6070214c4f
@ -36,8 +36,14 @@ var vxPalette =
|
||||
|
||||
var vfdDocument = focusedWindow.vxVFD.getContent(true).document;
|
||||
_dd(vfdDocument);
|
||||
|
||||
// need to find a way to batch these
|
||||
// create a button
|
||||
var buttontxn = new vxCreateElementTxn(vfdDocument, "button", insertionPoint.parent, insertionPoint.index);
|
||||
var txShell = focusedWindow.vxVFD.mTxMgrShell.doTransaction(buttontxn);
|
||||
var buttonvaluetxn = new vxChangeAttributeTxn(buttontxn.mElement, "value", "Button", false);
|
||||
|
||||
var aggregateTxn = new vxAggregateTxn([buttontxn, buttonvaluetxn]);
|
||||
focusedWindow.vxVFD.mTxMgrShell.doTransaction(aggregateTxn);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
<script src="chrome://vixen/content/palette/vxPalette.js"></script>
|
||||
|
||||
<!-- supported txns -->
|
||||
<script src="chrome://vixen/content/vfd/vxAggregateTxn.js"></script>
|
||||
<script src="chrome://vixen/content/vfd/vxChangeAttributeTxn.js"></script>
|
||||
<script src="chrome://vixen/content/vfd/vxCreateElementTxn.js"></script>
|
||||
|
||||
|
@ -33,6 +33,7 @@ CHROME_CONTENT = \
|
||||
.\scratch.xul \
|
||||
.\vxCreateElementTxn.js \
|
||||
.\vxChangeAttributeTxn.js \
|
||||
.\vxAggregateTxn.js \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
@ -20,7 +20,7 @@
|
||||
<!-- selection manager -->
|
||||
<script src="chrome://vixen/content/vfd/vxVFDSelectionManager.js"></script>
|
||||
|
||||
<tabcontrol class="tabbed-edit" flex="1">
|
||||
<tabcontrol class="tabbed-edit" flex="1" orient="vertical">
|
||||
<tabpanel flex="1">
|
||||
<iframe id="vfdDocument" name="vfdDocument" flex="1"/>
|
||||
<box id="vfdDOMTree" flex="1"/> <!-- from overlay -->
|
||||
|
73
extensions/vixen/resources/content/vfd/vxAggregateTxn.js
Normal file
73
extensions/vixen/resources/content/vfd/vxAggregateTxn.js
Normal file
@ -0,0 +1,73 @@
|
||||
/* -*- 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)
|
||||
*/
|
||||
|
||||
/**
|
||||
* vxAggregateTxn - Transaction that allows individual transactions to be
|
||||
* coalesced and done/undone in one operation
|
||||
*
|
||||
* e.g., create a new element in the VFD document using the palette that
|
||||
* has several attributes set on it.
|
||||
*/
|
||||
|
||||
function vxAggregateTxn (aTransactionList)
|
||||
{
|
||||
this.mTransactionList = aTransactionList;
|
||||
}
|
||||
|
||||
vxAggregateTxn.prototype = {
|
||||
doTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::doTransaction");
|
||||
for (var i = 0; i < this.mTransactionList.length; i++)
|
||||
this.mTransactionList[i].doTransaction();
|
||||
},
|
||||
|
||||
undoTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::undoTransaction");
|
||||
for (var i = 0; i < this.mTransactionList.length; i++)
|
||||
this.mTransactionList[i].undoTransaction();
|
||||
},
|
||||
|
||||
redoTransaction: function ()
|
||||
{
|
||||
_dd("vxAggregateTxn::redoTransaction");
|
||||
for (var i = 0; i < this.mTransactionList.length; i++)
|
||||
this.mTransactionList[i].redoTransaction();
|
||||
},
|
||||
|
||||
get commandString()
|
||||
{
|
||||
var commandString = "aggregate-txn";
|
||||
// XXX TODO: elaborate
|
||||
return commandString;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* txnStack["create-element"]("button", someBox, 3);
|
||||
**/
|
||||
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ function vxChangeAttributeTxn(aElement, aAttribute, aValue, aRemoveFlag)
|
||||
vxChangeAttributeTxn.prototype = {
|
||||
doTransaction: function ()
|
||||
{
|
||||
this.mUndoValue = this.mElement.getAttribute(aAttribute);
|
||||
this.mUndoValue = this.mElement.getAttribute(this.mAttribute);
|
||||
if (!this.mRemoveFlag)
|
||||
this.mElement.setAttribute(this.mAttribute, this.mValue);
|
||||
else
|
||||
|
@ -33,12 +33,12 @@ function vxCreateElementTxn(aDocument, aLocalName, aParentNode, aChildOffset)
|
||||
this.mLocalName = aLocalName;
|
||||
this.mParentNode = aParentNode;
|
||||
this.mChildOffset = aChildOffset;
|
||||
this.mElement = this.mDocument.createElement(this.mLocalName);
|
||||
}
|
||||
|
||||
vxCreateElementTxn.prototype = {
|
||||
doTransaction: function ()
|
||||
{
|
||||
this.mElement = this.mDocument.createElement(this.mLocalName);
|
||||
this.insertNode();
|
||||
},
|
||||
|
||||
|
@ -23,86 +23,67 @@
|
||||
|
||||
function vxVFDTransactionManager()
|
||||
{
|
||||
const kTxMgrContractID = "@mozilla.org/transaction/manager;1";
|
||||
const kTxMgrIID = "nsITransactionManager";
|
||||
this.mTxMgr = nsJSComponentManager.getService(kTxMgrContractID, kTxMgrIID);
|
||||
this.mTxnStack = new vxVFDTransactionStack();
|
||||
}
|
||||
|
||||
vxVFDTransactionManager.prototype =
|
||||
{
|
||||
mTxMgr: null,
|
||||
mDoSeq: null,
|
||||
mUndoSeq: null,
|
||||
mTxnDS: null,
|
||||
mTxMgr: null,
|
||||
mTxnSeq: null,
|
||||
mTxnDS: null,
|
||||
mTxnStack: null,
|
||||
|
||||
doTransaction: function (aTransaction)
|
||||
{
|
||||
// XXX Until the txmgr is fully scriptable, we need to perform the
|
||||
// transaction ourself
|
||||
// perform the transaction
|
||||
aTransaction.doTransaction();
|
||||
|
||||
if (!this.mDoSeq) {
|
||||
if (!this.mTxnSeq) {
|
||||
// If a Transaction Seq does not exist, create one.
|
||||
this.makeSeq(vxVFDDoTransactionSeq);
|
||||
this.mTxnSeq = this.makeSeq(vxVFDTransactionSeq);
|
||||
}
|
||||
|
||||
if (this.mTxnStack.index < this.mTxnStack.mStack.length - 1) {
|
||||
// clear the stack from the index upwards
|
||||
this.mTxnStack.flush(this.mTxnStack.index);
|
||||
|
||||
// likewise with the RDF Seq.
|
||||
var seqCount = this.mTxnSeq.GetCount();
|
||||
for (var i = this.mTxnStack.index; i < seqCount; i++)
|
||||
this.mTxnSeq.RemoveElementAt(i);
|
||||
}
|
||||
_dd("we've successfully made a sequence\n");
|
||||
|
||||
// append the transaction to our list
|
||||
this.mTxnStack.push(aTransaction);
|
||||
|
||||
// add the transaction to the stack
|
||||
this.mDoSeq.AppendElement(aTransaction);
|
||||
this.mTxnSeq.AppendElement(new RDFLiteral(this.mTxnStack.index-1));
|
||||
|
||||
if (!this.mTxMgr) {
|
||||
// If a Transaction Manager does not exist for this VFD,
|
||||
// create one.
|
||||
const kTxMgrCONTRACTID = "@mozilla.org/transaction/manager;1";
|
||||
const kTxMgrIID = "nsITransactionManager";
|
||||
// XXX comment this out until this works
|
||||
// this.mTxMgr = nsJSComponentManager.getService(kTxMgrCONTRACTID, kTxMgrIID);
|
||||
}
|
||||
|
||||
// do the transaction
|
||||
// XXX comment this out until this works
|
||||
// this.mTxMgr.doTransaction(aTransaction);
|
||||
},
|
||||
|
||||
undoTransaction: function ()
|
||||
{
|
||||
// XXX Until the txmgr is fully scriptable, we need to undo the
|
||||
// transaction ourself
|
||||
aTransaction.undoTransaction();
|
||||
|
||||
if (!this.mUndoSeq) {
|
||||
// If a Transaction Undo Seq does not exist, create one
|
||||
this.makeSeq(vxVFDUndoTransactionSeq);
|
||||
}
|
||||
|
||||
// remove the transaction at the top of the do seq
|
||||
var lastIndex = this.mDoSeq.GetCount() - 1;
|
||||
var txn = this.mDoSeq.RemoveElementAt(lastIndex, true);
|
||||
|
||||
// and add it to the undo seq
|
||||
this.mUndoSeq.AppendElement(txn);
|
||||
|
||||
// retrieve the previous transaction
|
||||
var txn = this.mTxnStack.mStack[this.mTxnStack.index-1];
|
||||
|
||||
// undo the transaction
|
||||
// XXX comment this out until this works
|
||||
// this.mTxMgr.undoTransaction();
|
||||
if (txn) {
|
||||
_ddf("going to undo the txn at", this.mTxnStack.index-1);
|
||||
txn.undoTransaction();
|
||||
this.mTxnStack.index--;
|
||||
}
|
||||
},
|
||||
|
||||
redoTransaction: function (aTransaction)
|
||||
{
|
||||
// XXX Until the txmgr is fully scriptable, we need to redo the
|
||||
// transaction ourself
|
||||
aTransaction.redoTransaction();
|
||||
|
||||
// remove the transaction at the top of the undo seq
|
||||
var lastIndex = this.mUndoSeq.GetCount() - 1;
|
||||
var txn = this.mDoSeq.RemoveElementAt(lastIndex, true);
|
||||
|
||||
// and add it to the do seq
|
||||
this.mDoSeq.AppendElement(txn);
|
||||
|
||||
// retrieve the previous transaction
|
||||
var txn = this.mTxnStack.mStack[this.mTxnStack.index+1];
|
||||
|
||||
// redo the transaction
|
||||
// XXX comment this out until this works
|
||||
// this.mTxMgr.redoTransaction();
|
||||
if (txn) {
|
||||
txn.redoTransaction();
|
||||
this.mTxnStack.index++;
|
||||
}
|
||||
},
|
||||
|
||||
makeSeq: function (aResource)
|
||||
@ -110,8 +91,9 @@ vxVFDTransactionManager.prototype =
|
||||
const kContainerUtilsCID = "{d4214e92-fb94-11d2-bdd8-00104bde6048}";
|
||||
const kContainerUtilsIID = "nsIRDFContainerUtils";
|
||||
var utils = nsJSComponentManager.getServiceByID(kContainerUtilsCID, kContainerUtilsIID);
|
||||
this.mDoSeq = utils.MakeSeq(vxVFDTransactionDS, aResource);
|
||||
return utils.MakeSeq(vxVFDTransactionDS, aResource);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -120,15 +102,13 @@ vxVFDTransactionManager.prototype =
|
||||
var vxVFDTransactionDS =
|
||||
{
|
||||
mResources: { },
|
||||
|
||||
|
||||
HasAssertion: function (aSource, aProperty, aValue, aTruthValue)
|
||||
{
|
||||
_ddf("vxtxds::hasassertion", aValue);
|
||||
var res = aSource.Value;
|
||||
if (!res) throw Components.results.NS_ERROR_FAILURE;
|
||||
var prop = aProperty.Value;
|
||||
if (!prop) throw Components.results.NS_ERROR_FAILURE;
|
||||
_ddf("so, the values are", res + ", " + prop);
|
||||
|
||||
if (this.mResources[res] &&
|
||||
this.mResources[res][prop] &&
|
||||
@ -139,27 +119,24 @@ var vxVFDTransactionDS =
|
||||
|
||||
Assert: function (aSource, aProperty, aValue, aTruthVal)
|
||||
{
|
||||
_dd("vxtxds::assert");
|
||||
var res = aSource.Value;
|
||||
if (!res) throw Components.results.NS_ERROR_FAILURE;
|
||||
var prop = aProperty.Value;
|
||||
if (!prop) throw Components.results.NS_ERROR_FAILURE;
|
||||
|
||||
this.mResources[res] = { };
|
||||
_ddf("going to assert into", res + ", " + prop);
|
||||
if (!this.mResources[res])
|
||||
this.mResources[res] = { };
|
||||
this.mResources[res][prop] = aValue;
|
||||
_ddf("value is now", this.mResources[res][prop]);
|
||||
},
|
||||
|
||||
Unassert: function (aSource, aProperty, aValue, aTruthVal)
|
||||
{
|
||||
_dd("vxtxds::unassert");
|
||||
var res = aSource.Value;
|
||||
if (!res) throw Components.results.NS_ERROR_FAILURE;
|
||||
var prop = aSource.Value;
|
||||
var prop = aProperty.Value;
|
||||
if (!prop) throw Components.results.NS_ERROR_FAILURE;
|
||||
if (!aValue) throw Components.results.NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
if (!this.mResources[res][prop])
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
|
||||
@ -168,7 +145,6 @@ var vxVFDTransactionDS =
|
||||
|
||||
GetTarget: function (aSource, aProperty, aTruthValue)
|
||||
{
|
||||
_dd("vxtxds::gettarget");
|
||||
var res = aSource.Value;
|
||||
if (!res) throw Components.results.NS_ERROR_FAILURE;
|
||||
var prop = aProperty.Value;
|
||||
@ -176,26 +152,128 @@ var vxVFDTransactionDS =
|
||||
|
||||
if (this.mResources[res] != undefined &&
|
||||
this.mResources[res][prop] != undefined) {
|
||||
var thang = this.mResources[res][prop].QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
_ddf("prop", thang.Value);
|
||||
return this.mResources[res][prop];
|
||||
return this.mResources[res][prop].QueryInterface(Components.interfaces.nsIRDFNode);
|
||||
}
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
return null;
|
||||
},
|
||||
|
||||
mObservers: [],
|
||||
AddObserver: function (aObserver)
|
||||
{
|
||||
this.mObservers.push(aObserver);
|
||||
},
|
||||
|
||||
RemoveObserver: function (aObserver)
|
||||
{
|
||||
for (var i = 0; i < this.mObservers.length; i++) {
|
||||
if (this.mObservers[i] == aObserver) {
|
||||
this.mObservers.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements nsIRDFResource
|
||||
*/
|
||||
var vxVFDDoTransactionSeq =
|
||||
var vxVFDTransactionSeq =
|
||||
{
|
||||
Value: "vxVFDDoTransactionSeq"
|
||||
Value: "vxVFDTransactionSeq"
|
||||
};
|
||||
|
||||
var vxVFDUndoTransactionSeq =
|
||||
function stripRDFPrefix (aString)
|
||||
{
|
||||
Value: "vxVFDUndoTransactionSeq"
|
||||
var len = "http://www.w3.org/1999/02/22-rdf-syntax-ns#".length;
|
||||
return aString.substring(len, aString.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transaction stack
|
||||
*/
|
||||
function vxVFDTransactionStack()
|
||||
{
|
||||
this.mIndex = 0;
|
||||
|
||||
this.mStack = [];
|
||||
}
|
||||
|
||||
vxVFDTransactionStack.prototype =
|
||||
{
|
||||
get index ()
|
||||
{
|
||||
return this.mIndex;
|
||||
},
|
||||
|
||||
set index (aValue)
|
||||
{
|
||||
_ddf("setting index to", aValue);
|
||||
this.mIndex = aValue;
|
||||
return this.mIndex;
|
||||
},
|
||||
|
||||
push: function (aTransaction)
|
||||
{
|
||||
this.mStack.push(aTransaction);
|
||||
this.index++;
|
||||
},
|
||||
|
||||
pop: function ()
|
||||
{
|
||||
this.index--;
|
||||
return this.mStack.pop();
|
||||
},
|
||||
|
||||
flush: function (aStart)
|
||||
{
|
||||
if (aStart === undefined)
|
||||
aStart = 0;
|
||||
|
||||
this.mStack.splice(aStart, this.mStack.length - aStart);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* RDF Literal object
|
||||
*/
|
||||
function RDFLiteral (aValue)
|
||||
{
|
||||
this.Value = aValue;
|
||||
}
|
||||
|
||||
RDFLiteral.prototype =
|
||||
{
|
||||
EqualsNode: function (aRDFNode)
|
||||
{
|
||||
try {
|
||||
var node = aRDFNode.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (node.Value == this.Value)
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function txnResource(aTransaction)
|
||||
{
|
||||
this.Value = "";
|
||||
this.mTransaction = aTransaction;
|
||||
}
|
||||
|
||||
txnResource.prototype = {
|
||||
QueryInterface: function (aIID)
|
||||
{
|
||||
if (aIID == Components.interfaces.nsIRDFResource ||
|
||||
aIID == Components.interfaces.nsIRDFNode ||
|
||||
aIID == Components.interfaces.nsISupports)
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
|
@ -121,6 +121,22 @@ var vxShell =
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Edit menu functions
|
||||
*/
|
||||
undo: function ()
|
||||
{
|
||||
_dd("undoing transaction");
|
||||
this.mFocusedWindow.vxVFD.mTxMgrShell.undoTransaction();
|
||||
},
|
||||
|
||||
redo: function ()
|
||||
{
|
||||
_dd("redoing transaction");
|
||||
this.mFocusedWindow.vxVFD.mTxMgrShell.redoTransaction();
|
||||
},
|
||||
|
||||
|
||||
appAbout: function ()
|
||||
{
|
||||
|
@ -42,6 +42,11 @@
|
||||
|
||||
<script language="JavaScript" src="chrome://vixen/content/vixen.js"></script>
|
||||
<script language="JavaScript" src="chrome://vixen/content/vxUtils.js"></script>
|
||||
|
||||
<keyset id="vxKeyset">
|
||||
<key id="undo" key="z" xulkey="true" alt="false" shift="false" onkeypress="vxShell.undo();"/>
|
||||
<key id="redo" key="z" xulkey="true" alt="false" shift="true" onkeypress="vxShell.redo();"/>
|
||||
</keyset>
|
||||
|
||||
<toolbox id="xuledit-toolbox" flex="1">
|
||||
<menubar id="xuledit-menubar">
|
||||
@ -51,6 +56,14 @@
|
||||
<menuitem value="Exit" accesskey="x"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="menu_Edit" value="Edit" accesskey="e">
|
||||
<menupopup>
|
||||
<menuitem value="Undo" accesskey="u" oncommand="vxShell.undo();" key="undo"/>
|
||||
<menuitem value="Redo" accesskey="r" oncommand="vxShell.redo();" key="redo"/>
|
||||
<menuseparator/>
|
||||
<menuitem value=" "/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="menu_Help" value="Help" accesskey="h">
|
||||
<menupopup>
|
||||
<menuitem value="About" oncommand="vxShell.appAbout();"/>
|
||||
|
@ -37,7 +37,7 @@ function _ddf(aString, aValue)
|
||||
var vxUtils = {
|
||||
getWindow: function (aWindowType)
|
||||
{
|
||||
const WM_CONTRACTID = "@mozilla.org/rdf/datasource?name=window-mediator;1";
|
||||
const WM_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=window-mediator";
|
||||
var wm = nsJSComponentManager.getService(WM_CONTRACTID, "nsIWindowMediator");
|
||||
return wm.getMostRecentWindow(aWindowType);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user