here come radio groups... More ViXEn transaction manager work.

NOT PART OF BUILD.


git-svn-id: svn://10.0.0.236/trunk@81567 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
ben%netscape.com
2000-10-21 03:09:18 +00:00
parent 08774b6798
commit bbd12b670d
14 changed files with 254 additions and 129 deletions

View File

@@ -0,0 +1,23 @@
/* -*- 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)
*/

View File

@@ -0,0 +1,53 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://communicator/skin/"?>
<window id="vxHistory" orient="vertical"
windowtype="vixen:history"
title="Edit History for [Form1]"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="vxHistory.startup();">
<!-- utility functions -->
<script src="chrome://global/content/nsJSComponentManager.js"></script>
<script src="chrome://vixen/content/vxUtils.js"></script>
<!-- history -->
<script src="chrome://vixen/content/history/history.js"></script>
<!-- transaction manager -->
<script src="chrome://vixen/content/vfd/vxVFDTransactionManager.js"></script>
<tree id="historyTree" style="width: 0px; height; 0px;"
flex="1" multiple="true" datasources="rdf:null"
ref="urn:mozilla:vixen:transactions">
<treecolgroup>
<treecol flex="1"/>
</treecolgroup>
<template>
<rule>
<conditions>
<content uri="?uri"/>
<triple subject="?uri"
predicate="http://www.mozilla.org/projects/vixen/rdf#transaction-list"
object="?transaction-list"/>
<member container="?transaction-list" child="?transaction"/>
<triple subject="?transaction"
predicate="http://www.mozilla.org/projects/vixen/rdf#command-string"
object="?command-string"/>
</conditions>
<action>
<treechildren>
<treeitem uri="?transaction">
<treerow>
<treecell value="?command-string"/>
</treerow>
</treeitem>
</treechildren>
</action>
</rule>
</template>
</tree>
</window>

View File

@@ -67,15 +67,19 @@ var vxPalette =
radiogroupAttributes,
radiogroupValues, false);
radiogroupAttrTxn.init();
radiogroupTxn.addListener(radiogroupAttrTxn);
var radioTxn = new vxCreateElementTxn(vfdDocument, "radio", radiogroupTxn.mID, insertionPoint.index);
radioTxn.init();
radiogroupTxn.addListener(radioTxn);
var radioAttributes = ["value", "group", "id"];
var radioValues = ["Radio " + nRadios, "radiogroup_" + nRadiogroups, "radio_" + nRadios];
var radioAttrTxn = new vxChangeAttributeTxn(radioTxn.mID,
radioAttributes,
radioValues, false);
radioAttrTxn.init();
radioTxn.addListener(radioAttrTxn);
// batch the transactions
var txns = [radiogroupTxn, radiogroupAttrTxn, radioTxn, radioAttrTxn];
@@ -83,9 +87,7 @@ var vxPalette =
aggregateTxn.init();
var txmgr = focusedWindow.vxVFD.mTxMgrShell;
aggregateTxn.addListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
txmgr.doTransaction(aggregateTxn);
aggregateTxn.removeListener([radiogroupAttrTxn, radioTxn, radioAttrTxn]);
},
incrementElementCount: function (aNodeName)
@@ -110,15 +112,14 @@ var vxPalette =
elementTxn.init();
var elementAttrTxn = new vxChangeAttributeTxn(elementTxn.mID, aAttributes, aValues, false);
elementAttrTxn.init();
elementTxn.addListener(elementAttrTxn);
// batch the transactions
var aggregateTxn = new vxAggregateTxn([elementTxn, elementAttrTxn]);
aggregateTxn.init();
var txmgr = focusedWindow.vxVFD.mTxMgrShell;
txmgr.addListener(elementAttrTxn);
txmgr.doTransaction(aggregateTxn);
txmgr.removeListener(elementAttrTxn);
},
/**

View File

@@ -59,7 +59,17 @@ var vxVFD =
// for a focused vfd, send "vfd,url"
// vixenMain.vxShell.mFocusObserver.Notify({ }, "window_focus", ("vfd," + this.mParams.documentURL));
vixenMain.vxShell.mFocusedWindow = window;
_ddf("focused window, according to our parent, is", vixenMain.vxShell.mFocusedWindow);
// XXX-HACK until we set up observers
var history = vxUtils.getWindow("vixen:history");
if (history) {
var doc = history.document;
var historyTree = doc.getElementById("historyTree");
if (historyTree) {
historyTree.database.AddDataSource(vxVFDTransactionDS);
historyTree.builder.rebuild();
}
}
},
get vfdDocumentWindowNode()
@@ -79,7 +89,7 @@ var vxVFD =
getInsertionPoint: function ()
{
if (this.mSelection && this.mSelection.selectionExists) {
if (this.mSelection && this.mSelection.selectionExists) { // && this.mSelection.selectionExists) {
// compute the insertion point based on selection
// XXX - TODO
}

View File

@@ -20,16 +20,7 @@
<!-- selection manager -->
<script src="chrome://vixen/content/vfd/vxVFDSelectionManager.js"></script>
<tabcontrol class="tabbed-edit" flex="1" orient="vertical">
<tabbox>
<tab value="Design"/>
<tab value="DOM Tree"/>
</tabbox>
<tabpanel flex="1">
<iframe id="vfdDocument" name="vfdDocument" flex="1"/>
<box id="vfdDOMTree" flex="1"/> <!-- from overlay -->
</tabpanel>
</tabcontrol>
<iframe id="vfdDocument" name="vfdDocument" flex="1"/>
</window>

View File

@@ -36,8 +36,6 @@ function vxAggregateTxn (aTransactionList)
this.mTransactionList[aTransactionList[i].mID] = aTransactionList[i];
this.mID = "aggregate-txn::";
this.mTransactionListeners = [];
}
vxAggregateTxn.prototype = {
@@ -45,32 +43,35 @@ vxAggregateTxn.prototype = {
doTransaction: function ()
{
for (var i in this.mTransactionList) {
var irq = { };
this.notifyListeners("willDo", this.mTransactionList[i], irq);
var irq = { };
this.notifyListeners("willDo", this, irq);
for (var i in this.mTransactionList)
this.mTransactionList[i].doTransaction();
this.notifyListeners("didDo", this.mTransactionList[i], irq);
}
this.notifyListeners("didDo", this, irq);
},
undoTransaction: function ()
{
for (var i in this.mTransactionList) {
var irq = { };
this.notifyListeners("willUndo", this.mTransactionList[i], irq);
var irq = { };
this.notifyListeners("willUndo", this, irq);
for (var i in this.mTransactionList)
this.mTransactionList[i].undoTransaction();
this.notifyListeners("didUndo", this.mTransactionList[i], irq);
}
this.notifyListeners("didUndo", this, irq);
},
redoTransaction: function ()
{
for (var i in this.mTransactionList) {
var irq = { };
this.notifyListeners("willRedo", this.mTransactionList[i], irq);
var irq = { };
this.notifyListeners("willRedo", this, irq);
for (var i in this.mTransactionList)
this.mTransactionList[i].redoTransaction();
this.notifyListeners("didRedo", this.mTransactionList[i], irq);
}
this.notifyListeners("didRedo", this, irq);
},
get commandString()

View File

@@ -32,25 +32,19 @@ vxBaseTxn.prototype = {
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);
if (aEvent in this.mListeners[i])
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++) {
@@ -73,8 +67,7 @@ vxBaseTxn.prototype = {
generateID: function ()
{
var val = ((new Date()).getUTCMilliseconds())*Math.random()*100000;
_ddf("value", val);
return val;
return Math.floor(val);
}
};

View File

@@ -64,33 +64,48 @@ vxChangeAttributeTxn.prototype = {
if (!this.mElementCreated)
return;
var irq = { };
this.notifyListeners("willDo", this, irq);
for (var i = 0; i < this.mAttributes.length; i++) {
this.mUndoValues[i] = this.mElement.getAttribute(this.mAttributes[i]);
if (!this.mRemoveFlags[i])
if ("mRemoveFlags" in this && i < this.mRemoveFlags.length && !this.mRemoveFlags[i])
this.mElement.setAttribute(this.mAttributes[i], this.mValues[i]);
else
this.mElement.removeAttribute(this.mAttributes[i]);
}
this.notifyListeners("didDo", this, irq);
},
undoTransaction: function ()
{
var irq = { };
this.notifyListeners("willUndo", this, irq);
for (var i = 0; i < this.mAttributes.length; i++) {
if (this.mUndoValues[i])
this.mElement.setAttribute(this.mAttributes[i], this.mUndoValues[i]);
else
this.mElement.removeAttribute(this.mAttributes[i]);
}
this.notifyListeners("didUndo", this, irq);
},
redoTransaction: function ()
{
var irq = { };
this.notifyListeners("willRedo", this, irq);
for (var i = 0; i < this.mAttributes.length; i++) {
if (!this.mRemoveFlags[i])
if ("mRemoveFlags" in this && i < this.mRemoveFlags.length && !this.mRemoveFlags[i])
this.mElement.setAttribute(this.mAttributes[i], this.mValues[i]);
else
this.mElement.removeAttribute(this.mAttributes[i]);
}
this.notifyListeners("didRedo", this, irq);
},
// XXX TODO: update to support multiple attribute syntax
@@ -109,18 +124,9 @@ vxChangeAttributeTxn.prototype = {
*/
didDo: function (aTransactionManager, aTransaction, aInterrupt)
{
var prevTxn = null;
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
else
prevTxn = aTransaction;
if (prevTxn.commandString.indexOf("create-element") >= 0) {
_ddf("did create element of", prevTxn.mLocalName);
this.mElement = prevTxn.mElement;
if (aTransaction.commandString.indexOf("create-element") >= 0) {
this.mElement = aTransaction.mElement;
this.mElementCreated = true;
_ddf("going to actually do this transaction now", this.mAttributes);
this.doTransaction();
}
}
};

View File

@@ -49,23 +49,30 @@ vxCreateElementTxn.prototype = {
doTransaction: function ()
{
if (!this.mElementCreated) {
_dd("element we rely on does not yet exist, so bail for now");
if (!this.mElementCreated)
return;
}
var irq = { };
this.notifyListeners("willDo", this, irq);
this.mElement = this.mDocument.createElement(this.mLocalName);
this.insertNode();
this.notifyListeners("didDo", this, irq);
},
undoTransaction: function ()
{
var irq = { };
this.notifyListeners("willUndo", this, irq);
this.mParentNode.removeChild(this.mElement);
this.notifyListeners("didUndo", this, irq);
},
redoTransaction: function ()
{
var irq = { };
this.notifyListeners("willRedo", this, irq);
this.insertNode();
this.notifyListeners("didRedo", this, irq);
},
insertNode: function ()
@@ -91,16 +98,9 @@ vxCreateElementTxn.prototype = {
*/
didDo: function (aTransactionManager, aTransaction, aInterrupt)
{
var prevTxn = null;
if (aTransaction.commandString.indexOf("aggregate-txn") >= 0)
prevTxn = aTransaction.mTransactionList[this.mElementTxnID];
else
prevTxn = aTransaction;
if (prevTxn.commandString.indexOf("create-element") >= 0) {
this.mParentNode = prevTxn.mElement;
if (aTransaction.commandString.indexOf("create-element") >= 0) {
this.mParentNode = aTransaction.mElement;
this.mElementCreated = true;
this.doTransaction();
}
}

View File

@@ -23,11 +23,11 @@
function vxVFDSelectionManager ()
{
this.selectionExists = false;
}
vxVFDSelectionManager.prototype =
{
selectionExists: null
};

View File

@@ -21,10 +21,14 @@
* Ben Goodger <ben@netscape.com> (Original Author)
*/
const kTxnPrefix = "urn:mozilla:vixen:transactions:";
function vxVFDTransactionManager()
{
this.mTxnStack = new vxVFDTransactionStack();
vxVFDTransactionDS.init();
// a record of transaction execution listeners that have attached
// themselves to us.
this.mTransactionListeners = [];
@@ -70,8 +74,13 @@ vxVFDTransactionManager.prototype =
// append the transaction to our list
this.mTxnStack.push(aTransaction);
// add the transaction to the stack
this.mTxnSeq.AppendElement(new RDFLiteral(this.mTxnStack.index-1));
// create a resource for the transaction and add to the
// stack
var resource = new RDFResource(kTxnPrefix + (this.mTxnStack.index-1));
var commandProperty = new RDFLiteral(kTxnPrefix + "command-string");
var commandString = new RDFLiteral(aTransaction.commandString);
vxVFDTransactionDS.Assert(resource, commandProperty, commandString, true);
this.mTxnSeq.AppendElement(resource);
for (i = 0; i < this.mTransactionListeners.length; i++) {
interruptRequest = {};
@@ -93,7 +102,9 @@ vxVFDTransactionManager.prototype =
}
// retrieve the previous transaction
var txn = this.mTxnStack.mStack[this.mTxnStack.index-1];
var txn = null;
if (this.mTxnStack.index-1 >= 0)
txn = this.mTxnStack.mStack[this.mTxnStack.index-1];
// undo the transaction
if (txn) {
@@ -121,7 +132,9 @@ vxVFDTransactionManager.prototype =
}
// retrieve the previous transaction
var txn = this.mTxnStack.mStack[this.mTxnStack.index];
var txn = null;
if (this.mTxnStack.index < this.mTxnStack.mStack.length)
txn = this.mTxnStack.mStack[this.mTxnStack.index];
// redo the transaction
if (txn) {
@@ -165,7 +178,7 @@ vxVFDTransactionManager.prototype =
}
}
}
},
}
};
/**
@@ -173,6 +186,12 @@ vxVFDTransactionManager.prototype =
*/
var vxVFDTransactionDS =
{
init: function ()
{
var arc = new RDFResource("http://www.mozilla.org/projects/vixen/rdf#transaction-list");
this.Assert(vxVFDTransactions, arc, vxVFDTransactionSeq, true);
},
mResources: { },
HasAssertion: function (aSource, aProperty, aValue, aTruthValue)
@@ -196,7 +215,7 @@ var vxVFDTransactionDS =
var prop = aProperty.Value;
if (!prop) throw Components.results.NS_ERROR_FAILURE;
if (!this.mResources[res])
if (!(res in this.mResources))
this.mResources[res] = { };
this.mResources[res][prop] = aValue;
},
@@ -254,11 +273,19 @@ var vxVFDTransactionDS =
};
/**
* Implements nsIRDFResource
* The resource that wraps the transaction Seq (urn:mozilla:vixen:transactions)
*/
var vxVFDTransactions =
{
Value: "urn:mozilla:vixen:transactions"
};
/**
* The Transaction Seq
*/
var vxVFDTransactionSeq =
{
Value: "vxVFDTransactionSeq"
Value: "http://www.mozilla.org/projects/vixen/rdf#txnList"
};
function stripRDFPrefix (aString)
@@ -311,46 +338,4 @@ vxVFDTransactionStack.prototype =
}
};
/**
* 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;
}
};
*/

View File

@@ -49,13 +49,16 @@ var vxShell =
// load the palette
vxShell.loadPalette();
// load the history window
// vxShell.loadHistory();
// load a blank form (until projects come online)
this.focusedWindow = vxShell.loadDocument(null);
vxShell.focusedWindow = vxShell.loadDocument(null);
// initialise the document focus observer
const kObserverServiceCONTRACTID = "@mozilla.org/observer-service;1";
const kObserverServiceIID = "nsIObserverService";
this.mFocusObserver = nsJSComponentManager.getService(kObserverServiceCONTRACTID, kObserverServiceIID);
vxShell.mFocusObserver = nsJSComponentManager.getService(kObserverServiceCONTRACTID, kObserverServiceIID);
},
@@ -81,7 +84,19 @@ var vxShell =
// size the palette window
hPalette.moveTo(0, kMenuHeight + 5);
hPalette.outerWidth = kPropertiesWidth;
hPalette.outerHeight = screen.availHeight - kMenuHeight - 20;
hPalette.outerHeight = screen.availHeight - kMenuHeight - 60;
},
loadHistory: function ()
{
// open the history window
const features = "resizable=no,dependent,chrome,dialog=yes";
var hHistory = openDialog("chrome://vixen/content/history/history.xul", "", features);
// size the history window
hHistory.moveTo(screen.availWidth - kPropertiesWidth - 10, kMenuHeight + 5);
hHistory.outerWidth = kPropertiesWidth;
hHistory.outerHeight = screen.availHeight - kMenuHeight - 60;
},
loadDocument: function (aURL)
@@ -93,11 +108,9 @@ var vxShell =
documentURL: aURL
};
var hVFD = window.openDialog("chrome://vixen/content/vfd/vfd.xul", "", features, params);
_dd("we've opened a dialog succesfully");
hVFD.moveTo(kPropertiesWidth + 5, kMenuHeight + 5);
hVFD.outerWidth = screen.availWidth - kPropertiesWidth - kProjectWidth - 10;
hVFD.outerHeight = screen.availHeight - kMenuHeight - 20;
_dd("by all rights, we should be done");
return hVFD;
},
@@ -127,13 +140,11 @@ var vxShell =
*/
undo: function ()
{
_dd("undoing transaction");
this.mFocusedWindow.vxVFD.mTxMgrShell.undoTransaction();
},
redo: function ()
{
_dd("redoing transaction");
this.mFocusedWindow.vxVFD.mTxMgrShell.redoTransaction();
},

View File

@@ -76,3 +76,52 @@ ArrayEnumerator.prototype = {
return false;
}
};
/**
* RDF Node object
*/
function RDFNode()
{
}
RDFNode.prototype = {
EqualsNode: function (aRDFNode)
{
try {
var node = aRDFNode.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (node.Value == this.Value)
return true;
}
catch (e) {
}
return false;
}
};
/**
* RDF Literal object
*/
function RDFLiteral (aValue)
{
this.Value = aValue;
}
RDFLiteral.prototype =
{
__proto__: RDFNode.prototype
};
/**
* RDF Resource object
*/
function RDFResource (aValue)
{
this.Value = aValue;
}
RDFResource.prototype =
{
__proto__: RDFNode.prototype
};

View File

@@ -19,6 +19,8 @@ vixen.jar:
content/vixen/vfd/vxVFDTransactionManager.js (content/vfd/vxVFDTransactionManager.js)
content/vixen/vfd/vxAggregateTxn.js (content/vfd/vxAggregateTxn.js)
content/vixen/vfd/vxBaseTxn.js (content/vfd/vxBaseTxn.js)
content/vixen/history/history.xul (content/history/history.xul)
content/vixen/history/history.js (content/history/history.js)
skin/modern/vixen/contents.rdf (skin/contents.rdf)
skin/modern/vixen/vfdScratch.css (skin/vfdScratch.css)
locale/en-US/vixen/contents.rdf (locale/en-US/contents.rdf)