-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Context Menu API, partial implementation #1012
Changes from 34 commits
5daac88
24d03a8
95aa501
37bc9ff
2037256
7c431a9
1795a55
c994b93
6d6f004
1f4dd84
a8fb498
9312bbc
0b823cb
ef70b24
295b06a
c6980ba
a1b3d82
6194228
a931ca4
da61901
3e27606
a65e5d7
ff5308c
4bfbe71
0de63fa
f0bcb13
5c2128b
70517d8
9229e5d
554e345
47d587f
795c1ef
2ec6641
f2fb32b
ee4cfad
723183a
759390c
fec168c
e1ca09f
4ee0aa2
cad981e
0948a6c
11cc3d3
3b3df72
b26127a
1503b63
3cb90ff
f65b33e
5a4d99e
ebb511c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder: TODO