Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Context Menu API, partial implementation #1012

Merged
merged 50 commits into from
Jun 14, 2012
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5daac88
context menu prototype
tvoliter Jun 7, 2012
24d03a8
hack less to make context menus look right
tvoliter Jun 7, 2012
95aa501
Completing first draft of API
tvoliter Jun 7, 2012
37bc9ff
api work
tvoliter Jun 8, 2012
2037256
add missing @extends annotation
tvoliter Jun 8, 2012
7c431a9
code review fixes for context menu API
tvoliter Jun 8, 2012
1795a55
share styles
redmunds Jun 8, 2012
c994b93
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
redmunds Jun 8, 2012
6d6f004
Merge branch 'tvoliter/context-menus' of github.com:adobe/brackets in…
redmunds Jun 8, 2012
1f4dd84
round top corners of context menus
redmunds Jun 8, 2012
a8fb498
round all corners of context-menus
redmunds Jun 9, 2012
9312bbc
working
tvoliter Jun 11, 2012
0b823cb
Merge remote-tracking branch 'origin/tvoliter/context-menus' into tvo…
tvoliter Jun 11, 2012
ef70b24
prevent menus from stealing focus
tvoliter Jun 11, 2012
295b06a
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
tvoliter Jun 11, 2012
c6980ba
Merge remote-tracking branch 'origin/tvoliter/offsetToLineNum-optimiz…
tvoliter Jun 11, 2012
a1b3d82
working on right click selection
tvoliter Jun 12, 2012
6194228
Fixing bug with offsetToLineNum.
tvoliter Jun 12, 2012
a931ca4
id is no longer necessary on MenuItems
redmunds Jun 12, 2012
da61901
merge from origin
redmunds Jun 12, 2012
3e27606
more merge changes
redmunds Jun 12, 2012
a65e5d7
fix merge
redmunds Jun 12, 2012
ff5308c
comment out some code causing exceptions
redmunds Jun 12, 2012
4bfbe71
export getContextMenu
redmunds Jun 12, 2012
0de63fa
Implement selection rules for right clicking on editor
tvoliter Jun 12, 2012
f0bcb13
Merge remote-tracking branch 'origin/tvoliter/context-menus' into tvo…
tvoliter Jun 12, 2012
5c2128b
jslint fixes
tvoliter Jun 13, 2012
70517d8
add extension to test context menus
redmunds Jun 13, 2012
9229e5d
fix alignment
redmunds Jun 13, 2012
554e345
fix comment
redmunds Jun 13, 2012
47d587f
no need to escape id when building a dom node. fix typos.
redmunds Jun 13, 2012
795c1ef
added todo
tvoliter Jun 13, 2012
2ec6641
Merge remote-tracking branch 'origin/tvoliter/context-menus' into tvo…
tvoliter Jun 13, 2012
f2fb32b
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
tvoliter Jun 13, 2012
ee4cfad
add UL container for context menus
redmunds Jun 13, 2012
723183a
udpate comments
redmunds Jun 13, 2012
759390c
code review fixes
tvoliter Jun 13, 2012
fec168c
Merge remote-tracking branch 'origin/tvoliter/context-menus' into tvo…
tvoliter Jun 13, 2012
e1ca09f
review fixes
tvoliter Jun 13, 2012
4ee0aa2
cleanup default context menus
redmunds Jun 13, 2012
cad981e
Merge branch 'tvoliter/context-menus' of github.com:adobe/brackets in…
redmunds Jun 13, 2012
0948a6c
use focused editor in ContextMenuTest
tvoliter Jun 13, 2012
11cc3d3
Merge remote-tracking branch 'origin/tvoliter/context-menus' into tvo…
tvoliter Jun 13, 2012
3b3df72
code review fixes
tvoliter Jun 14, 2012
b26127a
code review fixes
tvoliter Jun 14, 2012
1503b63
keep only project context menu for now
tvoliter Jun 14, 2012
3cb90ff
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
tvoliter Jun 14, 2012
f65b33e
Updating CommandManager and Menu tests since duplicate id's returns n…
tvoliter Jun 14, 2012
5a4d99e
update comment
redmunds Jun 14, 2012
ebb511c
Merge remote-tracking branch 'origin/master' into tvoliter/context-menus
tvoliter Jun 14, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 290 additions & 73 deletions src/command/Menus.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,38 @@ define(function (require, exports, module) {
Editor.prototype.setCursorPos = function (line, ch) {
this._codeMirror.setCursor(line, ch);
};

/**
* @param {line:number, ch:number}
* @return {number}
*/
Editor.prototype.indexFromPos = function (coords) {
return this._codeMirror.indexFromPos(coords);
};

/**
* Returns true if coords is between start and end (inclusive)
* @param {line:number, ch:number} coords
* @param {line:number, ch:number} start
* @param {line:number, ch:number} end
*
*/
Editor.prototype.coordsWithinRange = function (coords, start, end) {
var startIndex = this.indexFromPos(start),
endIndex = this.indexFromPos(end),
coordIndex = this.indexFromPos(coords);

return coordIndex >= startIndex && coordIndex <= endIndex;
};

Editor.prototype.coordsChar = function (coords) {
return this._codeMirror.coordsChar(coords);
};

// TODO TY: move me
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: TODO

Editor.prototype.selectWordAt = function (pos) {
return this._codeMirror.selectWordAt(pos);
};

/**
* Gets the current selection. Start is inclusive, end is exclusive. If there is no selection,
Expand Down
2 changes: 1 addition & 1 deletion src/editor/InlineTextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ define(function (require, exports, module) {

/**
* @constructor
*
* @extends {InlineWidget}
*/
function InlineTextEditor() {
InlineWidget.call(this);
Expand Down
103 changes: 103 additions & 0 deletions src/extensions/disabled/ContextMenuTest/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $ */

define(function (require, exports, module) {
'use strict';

// Brackets modules
var CommandManager = brackets.getModule("command/CommandManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
Menus = brackets.getModule("command/Menus");

function TestCommand1() {
var command1 = CommandManager.get("custom.command1");
if (!command1) {
return;
}
var command2 = CommandManager.get("custom.command2");
if (!command2) {
return;
}

var checked = command1.getChecked();
if (checked) {
alert("Unchecking and Disabling next");
command2.setEnabled(false);
} else {
alert("Checking and Enabling next");
command2.setEnabled(true);
}
command1.setChecked(!checked);
}

function TestCommand2() {
alert("Executing command 2");
}

function TestCommand3() {
alert("Executing command 3");
}

// Create command
var command1 = CommandManager.register("Toggle Checkmark", "custom.command1", TestCommand1);
var command2 = CommandManager.register("Enabled when previous is Checked", "custom.command2", TestCommand2);
var command3 = CommandManager.register("Enabled when text selected", "custom.command3", TestCommand3);

command1.setChecked(true);
command2.setEnabled(true);
command3.setEnabled(false);


var handleDocChanged = function () {
var editor = EditorManager.getCurrentFullEditor();

var handleEnableState = function () {
command3.setEnabled(editor.getSelectedText() !== "");
};

if (editor) {
$(editor).off("cursorActivity", handleEnableState);
$(editor).on("cursorActivity", handleEnableState);
}
};

$(DocumentManager).on("currentDocumentChange", handleDocChanged);
handleDocChanged();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more efficient to listen for the beforeContextMenuOpen event, so this only needs to be run right before context menu is popped up (and not on every document selection change). This would also exercise this new event.



// Get editor context menu
var editor_cmenu = Menus.getContextMenu("editorCo");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update this name after context menu definitions are cleaned up.

Need a more consistent id naming convention. Maybe "editor-context-menu"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Add our MenuItem at the end
if (editor_cmenu) {
editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem("custom.command1");
editor_cmenu.addMenuItem("custom.command2");
editor_cmenu.addMenuItem("custom.command3");
}
});
18 changes: 17 additions & 1 deletion src/styles/brackets_patterns_override.less
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@


/* Menu-related styles */
.toolbar .nav {
.toolbar .nav, .context-menu {
@menubar-top-padding: 8px;
@menubar-bottom-padding: 6px;
@menubar-h-padding: 9px;
Expand Down Expand Up @@ -258,6 +258,22 @@
}
}

/* Context menu styles */

.context-menu {
position: absolute;
z-index: @z-index-brackets-context-menu-base;
list-style-type: none;

.dropdown-menu {
.border-radius(3px);
}

.menu-shortcut {
float: right;
}
}

/* Dialog-related styles */

.modal-footer .btn.left {
Expand Down
2 changes: 2 additions & 0 deletions src/styles/brackets_variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@

@z-index-brackets-sidebar-resizer: @z-index-brackets-ui + 2;
@z-index-brackets-resizer-div: @z-index-brackets-sidebar-resizer + 1;

@z-index-brackets-context-menu-base: 1000;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a relative offset as well (some reference + 1) instead of a constant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intended to be the reference (or base) that all other context menu z-indexes are based off of. Currently, this is the only one. :)

Would be nice to unify this with the main menus, but currently these index values are hard-coded in bootstrap (even though they are using LESS).

9 changes: 8 additions & 1 deletion src/utils/StringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ define(function (require, exports, module) {
return str.replace(/([.?*+\^$\[\]\\(){}|\-])/g, "\\$1");
}

// Periods (aka "dots") are allowed in HTML identifiers, but jQuery interprets
// them as the start of a class selector, so they need to be escaped
function jQueryIdEscape(str) {
return str.replace(/\./g, "\\.");
}

/**
* Splits the text by new line characters and returns an array of lines
* @param {string} text
Expand Down Expand Up @@ -117,6 +123,7 @@ define(function (require, exports, module) {
exports.format = format;
exports.htmlEscape = htmlEscape;
exports.regexEscape = regexEscape;
exports.jQueryIdEscape = jQueryIdEscape;
exports.getLines = getLines;
exports.offsetToLineNum = offsetToLineNum;
});
});
Loading