summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorelijahe <elijahe@ca.ibm.com>2014-03-06 16:38:12 -0500
committerMark Macdonald <mamacdon@gmail.com>2014-03-10 17:08:05 -0400
commit0d68d5f76443ce4bb8fa8bea6a3245724982464f (patch)
tree65974f5e916a42b24fbcba96243a2b97b849dba2
parent88a103a698b0e1ec9ec0c7ecd4c392dd706e9f09 (diff)
downloadorg.eclipse.orion.client-origin/contextmenu_temp2.zip
org.eclipse.orion.client-origin/contextmenu_temp2.tar.gz
org.eclipse.orion.client-origin/contextmenu_temp2.tar.bz2
--Signed-off-by: Elijah El-Haddad <elijahe@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.editor/web/orion/editor/textView.js67
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/webui/dropdown.js4
2 files changed, 67 insertions, 4 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/textView.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/textView.js
index 0e2004b..7291bd3 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/textView.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/textView.js
@@ -21,8 +21,10 @@ define("orion/editor/textView", [ //$NON-NLS-0$
'orion/editor/eventTarget', //$NON-NLS-0$
'orion/editor/textTheme', //$NON-NLS-0$
'orion/editor/util', //$NON-NLS-0$
- 'orion/util' //$NON-NLS-0$
-], function(messages, mTextModel, mKeyModes, mEventTarget, mTextTheme, textUtil, util) {
+ 'orion/util', //$NON-NLS-0$
+ 'orion/webui/contextmenu', //$NON-NLS-0$
+ 'orion/webui/dropdown' //$NON-NLS-0$
+], function(messages, mTextModel, mKeyModes, mEventTarget, mTextTheme, textUtil, util, mContextMenu, mDropdown) {
/** @private */
function getWindow(document) {
@@ -4938,6 +4940,66 @@ define("orion/editor/textView", [ //$NON-NLS-0$
}
this._update();
},
+ _createContextMenu: function() {
+ //function called when the context menu is triggered to set the nav selection properly
+ var contextMenuTriggered = function(eventWrapper) {
+// var navHandler = this.getNavHandler();
+// var navDict = this.getNavDict();
+// var event = eventWrapper.event;
+// var item = null;
+//
+// if (event.target) {
+// var node = event.target;
+// while (this._parentNode.contains(node)) {
+// if ("TR" === node.nodeName) { //$NON-NLS-0$ //TODO this is brittle, see if a better way exists
+// var rowId = node.id;
+// item = navDict.getValue(rowId);
+// break;
+// }
+// node = node.parentNode;
+// }
+//
+// if (item && !navHandler.isDisabled(item.rowDomNode)) {
+// // only modify the selection if the item that the context menu
+// // was triggered on isn't already part of the selection
+// var existingSels = navHandler.getSelection();
+// if (-1 === existingSels.indexOf(item.model)) {
+// navHandler.cursorOn(item.model, true, false, true);
+// navHandler.setSelection(item.model, false, true);
+// }
+// } else {
+// // context menu was triggered on sidebar itself,
+// // clear previous selections
+// this.selection.setSelections(null);
+// navHandler.refreshSelection(true, true);
+// }
+// }
+ }.bind(this);
+
+ this._viewContextMenuNode = document.createElement("ul"); //$NON-NLS-0$
+ this._viewContextMenuNode.className = "dropdownMenu"; //$NON-NLS-0$
+ this._viewContextMenuNode.setAttribute("role", "menu"); //$NON-NLS-1$ //$NON-NLS-0$
+ this._viewContextMenuNode.id = this._clientDiv.id + "ContextMenu"; //$NON-NLS-0$
+
+ this._parent.insertBefore(this._viewContextMenuNode, this._parent.firstChild);
+
+ var populateFunction = (function() {
+ var item1 = this._contextMenu.appendMenuItem("test");
+ mDropdown.appendKeyBindingString(item1.firstElementChild, "Ctrl+N");
+ this._contextMenu.appendMenuItem("test2");
+ this._contextMenu.appendMenuItem("test3");
+ }).bind(this);
+
+ var contextMenu = new mContextMenu.ContextMenu({
+ dropdown: this._viewContextMenuNode,
+ triggerNode: this._clientDiv,
+ populate: populateFunction
+ });
+
+ contextMenu.addEventListener("triggered", contextMenuTriggered); //$NON-NLS-0$
+
+ this._contextMenu = contextMenu;
+ },
_defaultOptions: function() {
return {
parent: {value: undefined, update: null},
@@ -5551,6 +5613,7 @@ define("orion/editor/textView", [ //$NON-NLS-0$
/* Create elements */
this._createActions();
this._createView();
+ this._createContextMenu();
},
_modifyContent: function(e, updateCaret) {
if (this._readonly && !e._code) {
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dropdown.js b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dropdown.js
index 346a9ff..8318267 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dropdown.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dropdown.js
@@ -389,11 +389,11 @@ define(['require', 'orion/webui/littlelib', 'orion/EventTarget'], function(requi
* @param submenu The submenu that was opened and should be set as the next this._selectedSubmenu
*/
submenuOpen: function(submenu) {
- if (submenu !== this._selectedSubmenu) {
+ if (this._selectedSubmenu && (submenu !== this._selectedSubmenu)) {
//close the current menu and all its children
this._closeSelectedSubmenu();
- this._selectedSubmenu = submenu;
}
+ this._selectedSubmenu = submenu;
},
_closeSelectedSubmenu: function() {