[Yulup-commits] rev 23898 - in
public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content:
. editor editor/widgets
andi at wyona.com
andi at wyona.com
Thu Apr 19 23:50:35 CEST 2007
Author: andi
Date: 2007-04-19 23:50:34 +0200 (Thu, 19 Apr 2007)
New Revision: 23898
Modified:
public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/common.js
public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/widgets/widget.js
public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/wysiwygmodeview.js
Log:
Implemented element name to multiple command mapping (we used a 1:1 mapping before).
Modified: public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/common.js
===================================================================
--- public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/common.js 2007-04-19 21:47:29 UTC (rev 23897)
+++ public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/common.js 2007-04-19 21:50:34 UTC (rev 23898)
@@ -574,7 +574,70 @@
}
};
+/**
+ * YulupMultiMap constructor. Instantiates a new object of
+ * type YulupMultiMap.
+ *
+ * YulupMultiMap is a map from {key} -> {value1, value2, ...},
+ * i.e. the map can contain multiple values for the same key.
+ *
+ * @constructor
+ * @return {YulupMultiMap}
+ */
+function YulupMultiMap() {
+ this.__map = {};
+}
+YulupMultiMap.prototype = {
+ __map: null,
+
+ /**
+ * Returns the set of keys.
+ *
+ * @return {Object} returns the set of keys
+ */
+ keySet: function () {
+ return this.__map;
+ },
+
+ /**
+ * Puts a value into the map for the given key. The map
+ * can store multiple values for the same key.
+ *
+ * Note though that the map does not check for duplicate
+ * values for the same key.
+ *
+ * @param {String} aKey the key to which the value is associated
+ * @param {Object} aValue the value to store, can be null
+ * @return {Undefined} does not have a return value
+ */
+ add: function (aKey, aValue) {
+ /* DEBUG */ YulupDebug.ASSERT(aKey != null);
+
+ if (!this.__map.hasOwnProperty(aKey))
+ this.__map[aKey] = new Array();
+
+ this.__map[aKey].push(aValue);
+ },
+
+ /**
+ * Returns the values for the given key.
+ *
+ * @param {String} aKey the given for which the value should be retrieved
+ * @return {Array} returns an array of values, or an empty array if no entries exist for the given key
+ */
+ lookup: function (aKey) {
+ var values = null;
+
+ /* DEBUG */ YulupDebug.ASSERT(aKey != null);
+
+ values = this.__map[aKey];
+
+ return (values ? values : []);
+ }
+};
+
+
const YulupDebug = {
/**
* Dumps an exception to stdout, printing its message
Modified: public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/widgets/widget.js
===================================================================
--- public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/widgets/widget.js 2007-04-19 21:47:29 UTC (rev 23897)
+++ public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/widgets/widget.js 2007-04-19 21:50:34 UTC (rev 23898)
@@ -75,7 +75,7 @@
// register a view change listener
aController.addViewChangedListener(WidgetHandler.viewChangedHandler);
- this.surroundCommandList = {};
+ this.surroundCommandList = new YulupMultiMap();
}
WidgetManager.prototype = {
@@ -235,9 +235,9 @@
surroundingElementName = aWidget.getSurroundActionFragment().documentElement;
if (surroundingElementName && surroundingElementName.localName) {
- /* DEBUG */ dump("Yulup:widget.js:WidgetManager.addWidget: registering surrounding action for element name \"" + aWidget.getSurroundActionFragment().documentElement.localName.toLowerCase() + "\"\n");
+ /* DEBUG */ dump("Yulup:widget.js:WidgetManager.addWidget: registering surrounding action for element name \"" + aWidget.getSurroundActionFragment().documentElement.localName.toLowerCase() + "\, widget id = \"" + aWidget.id + "\"\n");
- aSurroundCommandList[aWidget.getSurroundActionFragment().documentElement.localName.toLowerCase()] = widgetCommand;
+ aSurroundCommandList.add(aWidget.getSurroundActionFragment().documentElement.localName.toLowerCase(), widgetCommand);
}
}
@@ -532,26 +532,38 @@
}
},
- activateCommand: function (aCommand) {
- /* DEBUG */ YulupDebug.ASSERT(aCommand != null);
+ activateCommands: function (aCommandList) {
+ /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.activateCommands() invoked\n");
- /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.activateCommand(\"" + aCommand.getAttribute("id") + "\") invoked\n");
+ /* DEBUG */ YulupDebug.ASSERT(aCommandList != null);
- // hack to refire command update
- aCommand.removeAttribute("active");
+ for (var i = 0; i < aCommandList.length; i++) {
+ command = aCommandList[i];
- // mark command as enabled
- aCommand.setAttribute("active", "true");
- aCommand.setAttribute("checked", "true");
+ /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.activateCommands: activate command \"" + command.getAttribute("id") + "\"\n");
+
+ // hack to refire command update
+ command.removeAttribute("active");
+
+ // mark command as enabled
+ command.setAttribute("active", "true");
+ command.setAttribute("checked", "true");
+ }
},
- deactivateCommand: function (aCommand) {
- /* DEBUG */ YulupDebug.ASSERT(aCommand != null);
+ deactivateCommands: function (aCommandList) {
+ /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.deactivateCommands() invoked\n");
- /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.deactivateCommand(\"" + aCommand.getAttribute("id") + "\") invoked\n");
+ /* DEBUG */ YulupDebug.ASSERT(aCommandList != null);
- aCommand.removeAttribute("active");
- aCommand.setAttribute("checked", "false");
+ for (var i = 0; i < aCommandList.length; i++) {
+ command = aCommandList[i];
+
+ /* DEBUG */ dump("Yulup:widget.js:WidgetHandler.deactivateCommands: deactivate command \"" + command.getAttribute("id") + "\"\n");
+
+ command.removeAttribute("active");
+ command.setAttribute("checked", "false");
+ }
},
updateCommandActiveStates: function (aWidgetCommandList, aElemNameList) {
@@ -568,12 +580,13 @@
elemNameMap[aElemNameList[i].name] = true;
}
- // check all commands
- for (var elemName in aWidgetCommandList) {
+ /* Check for all keys (element names) in the command map
+ * if they are contained in the current element name list. */
+ for (var elemName in aWidgetCommandList.keySet()) {
if (elemNameMap.hasOwnProperty(elemName)) {
- WidgetHandler.activateCommand(aWidgetCommandList[elemName]);
+ WidgetHandler.activateCommands(aWidgetCommandList.lookup(elemName));
} else {
- WidgetHandler.deactivateCommand(aWidgetCommandList[elemName]);
+ WidgetHandler.deactivateCommands(aWidgetCommandList.lookup(elemName));
}
}
},
@@ -588,8 +601,8 @@
commandList = aView.controller.widgetManager.surroundCommandList;
// deselect all widgets
- for (var elemName in commandList) {
- WidgetHandler.deactivateCommand(commandList[elemName]);
+ for (var elemName in commandList.keySet()) {
+ WidgetHandler.deactivateCommands(commandList.lookup(elemName));
}
// update all widgets if the view supports reading the DOM
Modified: public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/wysiwygmodeview.js
===================================================================
--- public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/wysiwygmodeview.js 2007-04-19 21:47:29 UTC (rev 23897)
+++ public/yulup/src/branches/WIDGET_REFACTORING_BRANCH/yulup/src/chrome/content/editor/wysiwygmodeview.js 2007-04-19 21:50:34 UTC (rev 23898)
@@ -413,7 +413,9 @@
this.view.setInlineProperty(elemAtom, attrName, attrValue);
- WidgetHandler.activateCommand(aCommand);
+ /* TODO: we should perform a map lookup first to activate
+ * all similar commands (would provide nicer UI behaviour). */
+ WidgetHandler.activateCommands([aCommand]);
}
},
@@ -436,7 +438,9 @@
this.view.removeInlineProperty(elemAtom, null);
- WidgetHandler.deactivateCommand(aCommand);
+ /* TODO: we should perform a map lookup first to deactivate
+ * all similar commands (would provide nicer UI behaviour). */
+ WidgetHandler.deactivateCommands([aCommand]);
}
},
More information about the Yulup-commits
mailing list