1+ /*
2+ * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+ *
4+ * Permission is hereby granted, free of charge, to any person obtaining a
5+ * copy of this software and associated documentation files (the "Software"),
6+ * to deal in the Software without restriction, including without limitation
7+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+ * and/or sell copies of the Software, and to permit persons to whom the
9+ * Software is furnished to do so, subject to the following conditions:
10+ *
11+ * The above copyright notice and this permission notice shall be included in
12+ * all copies or substantial portions of the Software.
13+ *
14+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+ * DEALINGS IN THE SOFTWARE.
21+ *
22+ */
23+
24+
25+ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */
26+ /*global define, $, brackets, window */
27+
28+ /**
29+ * Initializes the default brackets menu items.
30+ */
31+ define ( function ( require , exports , module ) {
32+ "use strict" ;
33+
34+ var AppInit = require ( "utils/AppInit" ) ,
35+ Commands = require ( "command/Commands" ) ,
36+ EditorManager = require ( "editor/EditorManager" ) ,
37+ Menus = require ( "command/Menus" ) ,
38+ Strings = require ( "strings" ) ;
39+
40+ AppInit . htmlReady ( function ( ) {
41+ /*
42+ * File menu
43+ */
44+ var menu ;
45+ menu = Menus . addMenu ( Strings . FILE_MENU , Menus . AppMenuBar . FILE_MENU ) ;
46+ menu . addMenuItem ( Commands . FILE_NEW ) ;
47+ menu . addMenuItem ( Commands . FILE_NEW_FOLDER ) ;
48+ menu . addMenuItem ( Commands . FILE_OPEN ) ;
49+ menu . addMenuItem ( Commands . FILE_OPEN_FOLDER ) ;
50+ menu . addMenuItem ( Commands . FILE_CLOSE ) ;
51+ menu . addMenuItem ( Commands . FILE_CLOSE_ALL ) ;
52+ menu . addMenuDivider ( ) ;
53+ menu . addMenuItem ( Commands . FILE_SAVE ) ;
54+ menu . addMenuItem ( Commands . FILE_SAVE_ALL ) ;
55+ menu . addMenuDivider ( ) ;
56+ menu . addMenuItem ( Commands . FILE_LIVE_FILE_PREVIEW ) ;
57+ menu . addMenuItem ( Commands . FILE_LIVE_HIGHLIGHT ) ;
58+ menu . addMenuItem ( Commands . FILE_PROJECT_SETTINGS ) ;
59+
60+ // supress redundant quit menu item on mac
61+ if ( brackets . platform !== "mac" && ! brackets . inBrowser ) {
62+ menu . addMenuDivider ( ) ;
63+ menu . addMenuItem ( Commands . FILE_QUIT ) ;
64+ }
65+
66+ /*
67+ * Edit menu
68+ */
69+ menu = Menus . addMenu ( Strings . EDIT_MENU , Menus . AppMenuBar . EDIT_MENU ) ;
70+ menu . addMenuItem ( Commands . EDIT_UNDO ) ;
71+ menu . addMenuItem ( Commands . EDIT_REDO ) ;
72+ menu . addMenuDivider ( ) ;
73+ menu . addMenuItem ( Commands . EDIT_CUT ) ;
74+ menu . addMenuItem ( Commands . EDIT_COPY ) ;
75+ menu . addMenuItem ( Commands . EDIT_PASTE ) ;
76+ menu . addMenuDivider ( ) ;
77+ menu . addMenuItem ( Commands . EDIT_SELECT_ALL ) ;
78+ menu . addMenuItem ( Commands . EDIT_SELECT_LINE ) ;
79+ menu . addMenuDivider ( ) ;
80+ menu . addMenuItem ( Commands . EDIT_FIND ) ;
81+ menu . addMenuItem ( Commands . EDIT_FIND_IN_FILES ) ;
82+ menu . addMenuItem ( Commands . EDIT_FIND_NEXT ) ;
83+
84+ menu . addMenuItem ( Commands . EDIT_FIND_PREVIOUS ) ;
85+
86+ menu . addMenuDivider ( ) ;
87+ menu . addMenuItem ( Commands . EDIT_REPLACE ) ;
88+ menu . addMenuDivider ( ) ;
89+ menu . addMenuItem ( Commands . EDIT_INDENT ) ;
90+ menu . addMenuItem ( Commands . EDIT_UNINDENT ) ;
91+ menu . addMenuItem ( Commands . EDIT_DUPLICATE ) ;
92+ menu . addMenuItem ( Commands . EDIT_DELETE_LINES ) ;
93+ menu . addMenuItem ( Commands . EDIT_LINE_UP ) ;
94+ menu . addMenuItem ( Commands . EDIT_LINE_DOWN ) ;
95+ menu . addMenuDivider ( ) ;
96+ menu . addMenuItem ( Commands . EDIT_LINE_COMMENT ) ;
97+ menu . addMenuItem ( Commands . EDIT_BLOCK_COMMENT ) ;
98+
99+ /*
100+ * View menu
101+ */
102+ menu = Menus . addMenu ( Strings . VIEW_MENU , Menus . AppMenuBar . VIEW_MENU ) ;
103+ menu . addMenuItem ( Commands . VIEW_HIDE_SIDEBAR ) ;
104+ menu . addMenuDivider ( ) ;
105+ menu . addMenuItem ( Commands . VIEW_INCREASE_FONT_SIZE ) ;
106+ menu . addMenuItem ( Commands . VIEW_DECREASE_FONT_SIZE ) ;
107+ menu . addMenuItem ( Commands . VIEW_RESTORE_FONT_SIZE ) ;
108+ menu . addMenuDivider ( ) ;
109+ menu . addMenuItem ( Commands . TOGGLE_JSLINT ) ;
110+
111+ /*
112+ * Navigate menu
113+ */
114+ menu = Menus . addMenu ( Strings . NAVIGATE_MENU , Menus . AppMenuBar . NAVIGATE_MENU ) ;
115+ menu . addMenuItem ( Commands . NAVIGATE_QUICK_OPEN ) ;
116+ menu . addMenuItem ( Commands . NAVIGATE_GOTO_LINE ) ;
117+
118+ menu . addMenuItem ( Commands . NAVIGATE_GOTO_DEFINITION ) ;
119+ menu . addMenuItem ( Commands . NAVIGATE_GOTO_JSLINT_ERROR ) ;
120+ menu . addMenuDivider ( ) ;
121+ menu . addMenuItem ( Commands . NAVIGATE_NEXT_DOC ) ;
122+ menu . addMenuItem ( Commands . NAVIGATE_PREV_DOC ) ;
123+ menu . addMenuDivider ( ) ;
124+ menu . addMenuItem ( Commands . NAVIGATE_SHOW_IN_FILE_TREE ) ;
125+ menu . addMenuDivider ( ) ;
126+ menu . addMenuItem ( Commands . TOGGLE_QUICK_EDIT ) ;
127+ menu . addMenuItem ( Commands . QUICK_EDIT_PREV_MATCH ) ;
128+ menu . addMenuItem ( Commands . QUICK_EDIT_NEXT_MATCH ) ;
129+
130+ /*
131+ * Help menu
132+ */
133+ menu = Menus . addMenu ( Strings . HELP_MENU , Menus . AppMenuBar . HELP_MENU ) ;
134+ menu . addMenuItem ( Commands . HELP_CHECK_FOR_UPDATE ) ;
135+
136+ menu . addMenuDivider ( ) ;
137+ if ( brackets . config . how_to_use_url ) {
138+ menu . addMenuItem ( Commands . HELP_HOW_TO_USE_BRACKETS ) ;
139+ }
140+ if ( brackets . config . forum_url ) {
141+ menu . addMenuItem ( Commands . HELP_FORUM ) ;
142+ }
143+ if ( brackets . config . release_notes_url ) {
144+ menu . addMenuItem ( Commands . HELP_RELEASE_NOTES ) ;
145+ }
146+ if ( brackets . config . report_issue_url ) {
147+ menu . addMenuItem ( Commands . HELP_REPORT_AN_ISSUE ) ;
148+ }
149+
150+ menu . addMenuDivider ( ) ;
151+ menu . addMenuItem ( Commands . HELP_SHOW_EXT_FOLDER ) ;
152+
153+
154+ var hasAboutItem = ( brackets . platform !== "mac" || brackets . inBrowser ) ;
155+
156+ // Add final divider only if we have a twitter URL or about item
157+ if ( hasAboutItem || brackets . config . twitter_url ) {
158+ menu . addMenuDivider ( ) ;
159+ }
160+
161+ if ( brackets . config . twitter_url ) {
162+ menu . addMenuItem ( Commands . HELP_TWITTER ) ;
163+ }
164+ // supress redundant about menu item in mac shell
165+ if ( hasAboutItem ) {
166+ menu . addMenuItem ( Commands . HELP_ABOUT ) ;
167+ }
168+
169+ /*
170+ * Context Menus
171+ */
172+ var project_cmenu = Menus . registerContextMenu ( Menus . ContextMenuIds . PROJECT_MENU ) ;
173+ project_cmenu . addMenuItem ( Commands . FILE_NEW ) ;
174+ project_cmenu . addMenuItem ( Commands . FILE_NEW_FOLDER ) ;
175+ project_cmenu . addMenuItem ( Commands . FILE_RENAME ) ;
176+ project_cmenu . addMenuDivider ( ) ;
177+ project_cmenu . addMenuItem ( Commands . EDIT_FIND_IN_SUBTREE ) ;
178+
179+ var working_set_cmenu = Menus . registerContextMenu ( Menus . ContextMenuIds . WORKING_SET_MENU ) ;
180+ working_set_cmenu . addMenuItem ( Commands . FILE_CLOSE ) ;
181+ working_set_cmenu . addMenuItem ( Commands . FILE_SAVE ) ;
182+ working_set_cmenu . addMenuItem ( Commands . FILE_RENAME ) ;
183+ working_set_cmenu . addMenuItem ( Commands . NAVIGATE_SHOW_IN_FILE_TREE ) ;
184+ working_set_cmenu . addMenuDivider ( ) ;
185+ working_set_cmenu . addMenuItem ( Commands . EDIT_FIND_IN_SUBTREE ) ;
186+ working_set_cmenu . addMenuDivider ( ) ;
187+ working_set_cmenu . addMenuItem ( Commands . SORT_WORKINGSET_BY_ADDED ) ;
188+ working_set_cmenu . addMenuItem ( Commands . SORT_WORKINGSET_BY_NAME ) ;
189+ working_set_cmenu . addMenuItem ( Commands . SORT_WORKINGSET_BY_TYPE ) ;
190+ working_set_cmenu . addMenuDivider ( ) ;
191+ working_set_cmenu . addMenuItem ( Commands . SORT_WORKINGSET_AUTO ) ;
192+
193+ var editor_cmenu = Menus . registerContextMenu ( Menus . ContextMenuIds . EDITOR_MENU ) ;
194+ editor_cmenu . addMenuItem ( Commands . TOGGLE_QUICK_EDIT ) ;
195+ editor_cmenu . addMenuItem ( Commands . EDIT_SELECT_ALL ) ;
196+
197+ var inline_editor_cmenu = Menus . registerContextMenu ( Menus . ContextMenuIds . INLINE_EDITOR_MENU ) ;
198+ inline_editor_cmenu . addMenuItem ( Commands . TOGGLE_QUICK_EDIT ) ;
199+ inline_editor_cmenu . addMenuItem ( Commands . EDIT_SELECT_ALL ) ;
200+ inline_editor_cmenu . addMenuDivider ( ) ;
201+ inline_editor_cmenu . addMenuItem ( Commands . QUICK_EDIT_PREV_MATCH ) ;
202+ inline_editor_cmenu . addMenuItem ( Commands . QUICK_EDIT_NEXT_MATCH ) ;
203+
204+ /**
205+ * Context menu for code editors (both full-size and inline)
206+ * Auto selects the word the user clicks if the click does not occur over
207+ * an existing selection
208+ */
209+ $ ( "#editor-holder" ) . on ( "contextmenu" , function ( e ) {
210+ if ( $ ( e . target ) . parents ( ".CodeMirror-gutter" ) . length !== 0 ) {
211+ return ;
212+ }
213+
214+ // Note: on mousedown before this event, CodeMirror automatically checks mouse pos, and
215+ // if not clicking on a selection moves the cursor to click location. When triggered
216+ // from keyboard, no pre-processing occurs and the cursor/selection is left as is.
217+
218+ var editor = EditorManager . getFocusedEditor ( ) ,
219+ inlineWidget = EditorManager . getFocusedInlineWidget ( ) ;
220+
221+ if ( editor ) {
222+ // If there's just an insertion point select the word token at the cursor pos so
223+ // it's more clear what the context menu applies to.
224+ if ( ! editor . hasSelection ( ) ) {
225+ editor . selectWordAt ( editor . getCursorPos ( ) ) ;
226+
227+ // Prevent menu from overlapping text by moving it down a little
228+ // Temporarily backout this change for now to help mitigate issue #1111,
229+ // which only happens if mouse is not over context menu. Better fix
230+ // requires change to bootstrap, which is too risky for now.
231+ //e.pageY += 6;
232+ }
233+
234+ // Inline text editors have a different context menu (safe to assume it's not some other
235+ // type of inline widget since we already know an Editor has focus)
236+ if ( inlineWidget ) {
237+ inline_editor_cmenu . open ( e ) ;
238+ } else {
239+ editor_cmenu . open ( e ) ;
240+ }
241+ }
242+ } ) ;
243+
244+ /**
245+ * Context menus for folder tree & working set list
246+ */
247+ $ ( "#project-files-container" ) . on ( "contextmenu" , function ( e ) {
248+ project_cmenu . open ( e ) ;
249+ } ) ;
250+
251+ $ ( "#open-files-container" ) . on ( "contextmenu" , function ( e ) {
252+ working_set_cmenu . open ( e ) ;
253+ } ) ;
254+
255+ // Prevent the browser context menu since Brackets creates a custom context menu
256+ $ ( window ) . contextmenu ( function ( e ) {
257+ e . preventDefault ( ) ;
258+ } ) ;
259+
260+ /*
261+ * General menu event processing
262+ */
263+ // Prevent clicks on top level menus and menu items from taking focus
264+ $ ( window . document ) . on ( "mousedown" , ".dropdown" , function ( e ) {
265+ e . preventDefault ( ) ;
266+ } ) ;
267+
268+ // Switch menus when the mouse enters an adjacent menu
269+ // Only open the menu if another one has already been opened
270+ // by clicking
271+ $ ( window . document ) . on ( "mouseenter" , "#main-toolbar .dropdown" , function ( e ) {
272+ var open = $ ( this ) . siblings ( ".open" ) ;
273+ if ( open . length > 0 ) {
274+ open . removeClass ( "open" ) ;
275+ $ ( this ) . addClass ( "open" ) ;
276+ }
277+ } ) ;
278+ } ) ;
279+ } ) ;
0 commit comments