-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathDefaultMenus.js
More file actions
480 lines (443 loc) · 23.4 KB
/
DefaultMenus.js
File metadata and controls
480 lines (443 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*global Phoenix*/
/**
* Initializes the default brackets menu items.
*/
define(function (require, exports, module) {
var AppInit = require("utils/AppInit"),
Commands = require("command/Commands"),
Menus = require("command/Menus"),
Strings = require("strings"),
MainViewManager = require("view/MainViewManager"),
CommandManager = require("command/CommandManager");
/**
* Disables menu items present in items if enabled is true.
* enabled is true if file is saved and present on user system.
* @param {boolean} enabled
* @param {array} items
*/
function _setContextMenuItemsVisible(enabled, items) {
items.forEach(function (item) {
const command = CommandManager.get(item);
if(command) {
// some commands may be only selectively present in browser or in some oses.
// Eg. NAVIGATE_OPEN_IN_POWERSHELL is only present in Windows desktop apps
command.setEnabled(enabled);
}
});
}
/**
* Checks if file saved and present on system and
* disables menu items accordingly
*/
function _setMenuItemsVisible() {
var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE);
if (file) {
file.exists(function (err, isPresent) {
if (err) {
return err;
}
_setContextMenuItemsVisible(isPresent, [Commands.FILE_RENAME,
Commands.NAVIGATE_SHOW_IN_FILE_TREE, Commands.NAVIGATE_SHOW_IN_OS,
Commands.NAVIGATE_OPEN_IN_TERMINAL, Commands.NAVIGATE_OPEN_IN_POWERSHELL,
Commands.NAVIGATE_OPEN_IN_DEFAULT_APP]);
});
}
}
const isBrowser = !Phoenix.isNativeApp;
const isDesktop = Phoenix.isNativeApp;
const fileNewShortcut = isDesktop ? "Ctrl-N" : ""; // Ctrl-1 universal shortcut is set in keyboard.json
//`Ctrl-Shift-N` - desktop only. In browser, use can do `ctrl-T` and type phcode.dev using browser shortcuts itself. So we dont make a browser shortcut for this.
const fileNewWindowShortcut = isDesktop ? "Ctrl-Shift-N" : "";
const fileCloseShortcut = isDesktop ? "Ctrl-W" : ""; // Ctrl-` universal shortcut is set in keyboard.json
// In browser open file option is not available, so we assign ctrl-o to open folder in browser
// open folder has no shortcut in desktop, as this is not a frequently used workflow
// and only ever used when the user opens a project once in a while.
const fileCloseAllShortcut = isDesktop ? "Ctrl-Shift-W" : ""; // Ctrl-Alt-Shift-W` universal shortcut is set in keyboard.json
const openFileShortcut = isDesktop ? "Ctrl-O" : "";
const openFolderShortcut = isBrowser ? "Ctrl-O" : "";
const reopenClosedShortcut = isBrowser ? "" : "Ctrl-Shift-T";
const nextDocShortcut = isBrowser ? "Alt-PageDown" : "Ctrl-PageDown";
const prevDocShortcut = isBrowser ? "Alt-PageUp" : "Ctrl-PageUp";
AppInit.htmlReady(function () {
/**
* Rules to follow when figuring out default shortcuts:
* 1. Default shortcuts should only be applied for frequently used workflows. If it's rarely used like
* opening a project, etc., we should not allocate a shortcut. Ideally, assign a shortcut if the user is likely
* to use it several times in a five-minute window.
* 2. In Windows, shortcuts cannot start with a `Ctrl-Alt-<something>` as it's reserved for special OS functionalities. See wiki.
* 3. In macOS, shortcuts can't start with a single Alt-key combo as it's used for unicode typing in Eastern European languages.
* 3. Maintain Consistency Across Browser and Desktop Applications: Shortcuts should offer a uniform experience
* in both browser-based and desktop environments, even when accounting for platform-specific restrictions.
* For instance, 'Ctrl-N' is used for creating a new file in the desktop, but this shortcut
* is reserved by the browser, an alternative like 'Ctrl-1' can was used in the browser. To ensure
* consistency, the same 'Ctrl-1' shortcut was also be enabled for creating a new file in the desktop
* app along with `Ctrl-N`. This approach helps users experience predictable across different platforms.
*
* Additional considerations:
* 4. Avoid conflicts with standard OS shortcuts: Ensure that the chosen shortcuts do not conflict with common
* operating system shortcuts. For instance, shortcuts like Alt-F4 in Windows or Cmd-Q in macOS are universally
* used for closing applications and should not be overridden.
* 6. Consistency with similar applications: Where possible, align shortcuts with those used in similar applications
* to reduce the learning curve for new users. For example, using Ctrl/Cmd + S for 'save' is a widely recognized standard.
* 7. Avoid overloading single keys with multiple modifiers: Combining too many modifier keys (like Ctrl-Shift-Alt-Cmd-K)
* can make shortcuts hard to remember and physically challenging to perform.
* 8. Localization and Internationalization: Be aware of how shortcuts might interact with different keyboard layouts
* and languages. For example, what is convenient on a QWERTY keyboard might not be on AZERTY or QWERTZ.
* 9. User Customization: Allow users to customize or reassign shortcuts, as personal preferences and workflows vary.
* This also helps users resolve any unforeseen conflicts with other software they use.
* 10. Document Shortcuts: See keyboard.json for most shortcuts. Other shortcuts may be set programmatically
* by the phoenix extensions.
**/
var menu;
menu = Menus.addMenu(Strings.FILE_MENU, Menus.AppMenuBar.FILE_MENU);
menu.addMenuItem(Commands.FILE_NEW, fileNewShortcut);
menu.addMenuItem(Commands.FILE_NEW_FOLDER);
menu.addMenuItem(Commands.FILE_NEW_WINDOW, fileNewWindowShortcut);
menu.addMenuDivider();
if(Phoenix.isNativeApp){
menu.addMenuItem(Commands.FILE_OPEN, openFileShortcut);
}
menu.addMenuItem(Commands.FILE_OPEN_FOLDER, openFolderShortcut);
menu.addMenuItem(Commands.FILE_CLOSE, fileCloseShortcut);
menu.addMenuItem(Commands.FILE_CLOSE_ALL, fileCloseAllShortcut);
menu.addMenuItem(Commands.FILE_REOPEN_CLOSED, reopenClosedShortcut);
menu.addMenuDivider();
menu.addMenuItem(Commands.FILE_SAVE);
menu.addMenuItem(Commands.FILE_SAVE_ALL);
if(Phoenix.isNativeApp){
menu.addMenuItem(Commands.FILE_SAVE_AS);
// save as is not yet supported in browser as in our vfs implements only open folder, so vfs needs to
// be changed. Also, we dont know how the ux for save as will be in virtual paths.
}
menu.addMenuItem(Commands.FILE_DUPLICATE_FILE);
menu.addMenuItem(Commands.FILE_DOWNLOAD_PROJECT, undefined, undefined, undefined, {
hideWhenCommandDisabled: true
});
// menu.addMenuItem(Commands.FILE_PROJECT_SETTINGS); not yet available in phoenix
menu.addMenuDivider();
menu.addMenuItem(Commands.FILE_EXTENSION_MANAGER);
if(Phoenix.isNativeApp){
menu.addMenuDivider();
menu.addMenuItem(Commands.FILE_QUIT);
}
/*
* Edit menu
*/
menu = Menus.addMenu(Strings.EDIT_MENU, Menus.AppMenuBar.EDIT_MENU);
menu.addMenuItem(Commands.EDIT_UNDO);
menu.addMenuItem(Commands.EDIT_REDO);
menu.addMenuDivider();
// TODO: add js handlers for copy and paste using browser standards.
menu.addMenuItem(Commands.EDIT_CUT);
menu.addMenuItem(Commands.EDIT_COPY);
if(window.Phoenix.isNativeApp || !window.Phoenix.browser.desktop.isFirefox){
menu.addMenuItem(Commands.EDIT_PASTE);
}
menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_SELECT_ALL);
menu.addMenuItem(Commands.EDIT_SELECT_LINE);
menu.addMenuItem(Commands.EDIT_SPLIT_SEL_INTO_LINES);
menu.addMenuItem(Commands.EDIT_ADD_CUR_TO_PREV_LINE);
menu.addMenuItem(Commands.EDIT_ADD_CUR_TO_NEXT_LINE);
menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_INDENT);
menu.addMenuItem(Commands.EDIT_UNINDENT);
menu.addMenuItem(Commands.EDIT_DUPLICATE);
menu.addMenuItem(Commands.EDIT_DELETE_LINES);
menu.addMenuItem(Commands.EDIT_LINE_UP);
menu.addMenuItem(Commands.EDIT_LINE_DOWN);
menu.addMenuDivider();
menu.addMenuItem(Commands.EDIT_LINE_COMMENT);
menu.addMenuItem(Commands.EDIT_BLOCK_COMMENT);
menu.addMenuDivider();
menu.addMenuItem(Commands.SHOW_CODE_HINTS);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_CLOSE_BRACKETS);
menu.addMenuItem(Commands.EDIT_EMMET);
/*
* Find menu
*/
menu = Menus.addMenu(Strings.FIND_MENU, Menus.AppMenuBar.FIND_MENU);
menu.addMenuItem(Commands.CMD_FIND);
menu.addMenuItem(Commands.CMD_FIND_NEXT);
menu.addMenuItem(Commands.CMD_FIND_PREVIOUS);
menu.addMenuItem(Commands.CMD_ADD_NEXT_MATCH);
menu.addMenuItem(Commands.CMD_FIND_ALL_AND_SELECT);
menu.addMenuItem(Commands.CMD_SKIP_CURRENT_MATCH);
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_FIND_IN_FILES);
menu.addMenuItem(Commands.CMD_FIND_ALL_REFERENCES);
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_REPLACE);
menu.addMenuItem(Commands.CMD_REPLACE_IN_FILES);
/*
* View menu
*/
menu = Menus.addMenu(Strings.VIEW_MENU, Menus.AppMenuBar.VIEW_MENU);
menu.addMenuItem(Commands.CMD_THEMES_OPEN_SETTINGS);
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_SPLITVIEW_NONE);
menu.addMenuItem(Commands.CMD_SPLITVIEW_VERTICAL);
menu.addMenuItem(Commands.CMD_SPLITVIEW_HORIZONTAL);
menu.addMenuDivider();
menu.addMenuItem(Commands.VIEW_HIDE_SIDEBAR);
menu.addMenuItem(Commands.TOGGLE_SEARCH_AUTOHIDE);
menu.addMenuDivider();
let subMenu = menu.addSubMenu(Strings.CMD_ZOOM_UI, Commands.VIEW_ZOOM_SUBMENU);
subMenu.addMenuItem(Commands.VIEW_ZOOM_IN);
subMenu.addMenuItem(Commands.VIEW_ZOOM_OUT);
subMenu.addMenuItem(Commands.VIEW_INCREASE_FONT_SIZE);
subMenu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE);
subMenu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_ACTIVE_LINE);
menu.addMenuItem(Commands.TOGGLE_LINE_NUMBERS);
menu.addMenuItem(Commands.TOGGLE_WORD_WRAP);
menu.addMenuItem(Commands.TOGGLE_RULERS);
menu.addMenuDivider();
menu.addMenuItem(Commands.FILE_LIVE_HIGHLIGHT);
menu.addMenuDivider();
menu.addMenuItem(Commands.VIEW_TOGGLE_PROBLEMS);
menu.addMenuItem(Commands.VIEW_TOGGLE_INSPECTION);
/*
* Navigate menu
*/
menu = Menus.addMenu(Strings.NAVIGATE_MENU, Menus.AppMenuBar.NAVIGATE_MENU);
menu.addMenuItem(Commands.NAVIGATE_QUICK_OPEN);
menu.addMenuItem(Commands.NAVIGATE_GOTO_LINE);
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION);
menu.addMenuItem(Commands.NAVIGATE_GOTO_DEFINITION_PROJECT);
menu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
menu.addMenuItem(Commands.NAVIGATE_GOTO_NEXT_PROBLEM);
menu.addMenuItem(Commands.NAVIGATE_GOTO_PREV_PROBLEM);
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC);
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC);
menu.addMenuItem(Commands.NAVIGATE_NEXT_DOC_LIST_ORDER, nextDocShortcut);
menu.addMenuItem(Commands.NAVIGATE_PREV_DOC_LIST_ORDER, prevDocShortcut);
menu.addMenuDivider();
menu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
menu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH);
menu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH);
menu.addMenuItem(Commands.CSS_QUICK_EDIT_NEW_RULE);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_QUICK_DOCS);
/*
* Help menu
*/
menu = Menus.addMenu(Strings.HELP_MENU, Menus.AppMenuBar.HELP_MENU);
menu.addMenuItem(Commands.HELP_DOCS);
menu.addMenuItem(Commands.HELP_SUPPORT);
menu.addMenuDivider();
if (brackets.config.suggest_feature_url) {
menu.addMenuItem(Commands.HELP_SUGGEST);
}
if (brackets.config.report_issue_url) {
menu.addMenuItem(Commands.HELP_REPORT_ISSUE);
}
if (brackets.config.get_involved_url) {
menu.addMenuItem(Commands.HELP_GET_INVOLVED);
}
var hasAboutItem = true;
// Add final divider only if we have a homepage URL or twitter URL or about item
if (hasAboutItem || brackets.config.homepage_url || brackets.config.twitter_url) {
menu.addMenuDivider();
}
menu.addMenuItem(Commands.HELP_YOUTUBE);
menu.addMenuItem(Commands.HELP_TWITTER);
if (brackets.config.homepage_url) {
menu.addMenuItem(Commands.HELP_HOMEPAGE);
}
if (hasAboutItem) {
menu.addMenuItem(Commands.HELP_ABOUT);
}
/*
* Debug menu
*/
Menus.addMenu(Strings.DEBUG_MENU, Menus.AppMenuBar.DEBUG_MENU, Menus.BEFORE, Menus.AppMenuBar.HELP_MENU);
/*
* Context Menus
*/
// WorkingSet context menu - Unlike most context menus, we can't attach
// listeners here because the DOM nodes for each pane's working set are
// created dynamically. Each WorkingSetView attaches its own listeners.
var workingset_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU);
workingset_cmenu.addMenuItem(Commands.FILE_SAVE);
workingset_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE);
if(Phoenix.isNativeApp){
let subMenu = workingset_cmenu.addSubMenu(Strings.CMD_OPEN_IN, Commands.OPEN_IN_SUBMENU_WS);
subMenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_TERMINAL);
if (brackets.platform === "win") {
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_POWERSHELL);
}
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_DEFAULT_APP);
}
workingset_cmenu.addMenuDivider();
workingset_cmenu.addMenuItem(Commands.FILE_COPY);
workingset_cmenu.addMenuItem(Commands.FILE_COPY_PATH);
workingset_cmenu.addMenuItem(Commands.FILE_DUPLICATE);
workingset_cmenu.addMenuItem(Commands.FILE_DOWNLOAD, undefined, undefined, undefined, {
hideWhenCommandDisabled: true
});
workingset_cmenu.addMenuDivider();
workingset_cmenu.addMenuItem(Commands.FILE_RENAME);
workingset_cmenu.addMenuItem(Commands.FILE_DELETE);
workingset_cmenu.addMenuDivider();
workingset_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE);
workingset_cmenu.addMenuItem(Commands.CMD_REPLACE_IN_SUBTREE);
workingset_cmenu.addMenuDivider();
workingset_cmenu.addMenuItem(Commands.FILE_CLOSE);
var splitview_menu = Menus.registerContextMenu(Menus.ContextMenuIds.SPLITVIEW_MENU);
splitview_menu.addMenuItem(Commands.CMD_SPLITVIEW_NONE);
splitview_menu.addMenuItem(Commands.CMD_SPLITVIEW_VERTICAL);
splitview_menu.addMenuItem(Commands.CMD_SPLITVIEW_HORIZONTAL);
splitview_menu.addMenuDivider();
splitview_menu.addMenuItem(Commands.CMD_WORKINGSET_SORT_BY_ADDED);
splitview_menu.addMenuItem(Commands.CMD_WORKINGSET_SORT_BY_NAME);
splitview_menu.addMenuItem(Commands.CMD_WORKINGSET_SORT_BY_TYPE);
splitview_menu.addMenuDivider();
splitview_menu.addMenuItem(Commands.CMD_WORKING_SORT_TOGGLE_AUTO);
splitview_menu.addMenuItem(Commands.FILE_SHOW_FOLDERS_FIRST);
splitview_menu.addMenuDivider();
splitview_menu.addMenuItem(Commands.CMD_TOGGLE_SHOW_WORKING_SET);
splitview_menu.addMenuItem(Commands.CMD_TOGGLE_SHOW_FILE_TABS);
var project_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.PROJECT_MENU);
project_cmenu.addMenuItem(Commands.FILE_NEW);
project_cmenu.addMenuItem(Commands.FILE_NEW_FOLDER);
if(Phoenix.isNativeApp){
let subMenu = project_cmenu.addSubMenu(Strings.CMD_OPEN_IN, Commands.OPEN_IN_SUBMENU);
subMenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_TERMINAL);
if (brackets.platform === "win") {
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_POWERSHELL);
}
subMenu.addMenuItem(Commands.NAVIGATE_OPEN_IN_DEFAULT_APP);
}
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.FILE_CUT);
project_cmenu.addMenuItem(Commands.FILE_COPY);
project_cmenu.addMenuItem(Commands.FILE_COPY_PATH);
project_cmenu.addMenuItem(Commands.FILE_DUPLICATE);
project_cmenu.addMenuItem(Commands.FILE_PASTE);
project_cmenu.addMenuItem(Commands.FILE_DOWNLOAD, undefined, undefined, undefined, {
hideWhenCommandDisabled: true
});
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.FILE_RENAME);
project_cmenu.addMenuItem(Commands.FILE_DELETE);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE);
project_cmenu.addMenuItem(Commands.CMD_REPLACE_IN_SUBTREE);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.FILE_REFRESH);
var editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
// editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_DOCS);
editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
editor_cmenu.addMenuItem(Commands.CMD_FIND_ALL_REFERENCES);
editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem(Commands.EDIT_CUT);
editor_cmenu.addMenuItem(Commands.EDIT_COPY);
if(window.Phoenix.isNativeApp || !window.Phoenix.browser.desktop.isFirefox){
editor_cmenu.addMenuItem(Commands.EDIT_PASTE);
}
editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL);
var inline_editor_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.INLINE_EDITOR_MENU);
inline_editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
inline_editor_cmenu.addMenuItem(Commands.EDIT_SELECT_ALL);
inline_editor_cmenu.addMenuDivider();
inline_editor_cmenu.addMenuItem(Commands.QUICK_EDIT_PREV_MATCH);
inline_editor_cmenu.addMenuItem(Commands.QUICK_EDIT_NEXT_MATCH);
/**
* Context menu for code editors (both full-size and inline)
* Auto selects the word the user clicks if the click does not occur over
* an existing selection
*/
$("#editor-holder").on("contextmenu", function (e) {
require(["editor/EditorManager"], function (EditorManager) {
if ($(e.target).parents(".CodeMirror-gutter").length !== 0) {
return;
}
// Note: on mousedown before this event, CodeMirror automatically checks mouse pos, and
// if not clicking on a selection moves the cursor to click location. When triggered
// from keyboard, no pre-processing occurs and the cursor/selection is left as is.
var editor = EditorManager.getFocusedEditor(),
inlineWidget = EditorManager.getFocusedInlineWidget();
if (editor) {
//if (!editor.hasSelection()) {
// Prevent menu from overlapping text by moving it down a little
// Temporarily backout this change for now to help mitigate issue #1111,
// which only happens if mouse is not over context menu. Better fix
// requires change to bootstrap, which is too risky for now.
//e.pageY += 6;
//}
// Inline text editors have a different context menu (safe to assume it's not some other
// type of inline widget since we already know an Editor has focus)
if (inlineWidget) {
inline_editor_cmenu.open(e);
} else {
editor_cmenu.open(e);
}
}
});
});
/**
* Context menu for folder tree
*/
$("#project-files-container").on("contextmenu", function (e) {
project_cmenu.open(e);
});
// Dropdown menu for view splitting
Menus.ContextMenu.assignContextMenuToSelector(".working-set-splitview-btn", splitview_menu);
// Prevent the browser context menu since Brackets creates a custom context menu
$(window).contextmenu(function (e) {
e.preventDefault();
});
/*
* General menu event processing
*/
// Prevent clicks on top level menus and menu items from taking focus
$(window.document).on("mousedown", ".dropdown", function (e) {
e.preventDefault();
});
// Switch menus when the mouse enters an adjacent menu
// Only open the menu if another one has already been opened
// by clicking
$(window.document).on("mouseenter", "#titlebar .dropdown", function (e) {
var open = $(this).siblings(".open");
if (open.length > 0) {
open.removeClass("open");
$(this).addClass("open");
}
});
// Check the visibility of context menu items before opening the context menu.
// 'Rename', 'Show in file tree' and 'Show in explorer' items will be disabled for files that have not yet been saved to disk.
Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_CONTEXT_MENU).on("beforeContextMenuOpen", _setMenuItemsVisible);
Menus.getContextMenu(Menus.ContextMenuIds.PROJECT_MENU).on("beforeContextMenuOpen", _setMenuItemsVisible);
});
});