OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** | 4 /** |
5 * @implements {Sources.TabbedEditorContainerDelegate} | 5 * @implements {Sources.TabbedEditorContainerDelegate} |
6 * @implements {UI.Searchable} | 6 * @implements {UI.Searchable} |
7 * @implements {UI.Replaceable} | 7 * @implements {UI.Replaceable} |
8 * @unrestricted | 8 * @unrestricted |
9 */ | 9 */ |
10 Sources.SourcesView = class extends UI.VBox { | 10 Sources.SourcesView = class extends UI.VBox { |
11 /** | 11 /** |
12 * @suppressGlobalPropertiesCheck | 12 * @suppressGlobalPropertiesCheck |
13 */ | 13 */ |
14 constructor() { | 14 constructor() { |
15 super(); | 15 super(); |
16 this.registerRequiredCSS('sources/sourcesView.css'); | 16 this.registerRequiredCSS('sources/sourcesView.css'); |
17 this.element.id = 'sources-panel-sources-view'; | 17 this.element.id = 'sources-panel-sources-view'; |
18 this.setMinimumAndPreferredSizes(80, 52, 150, 100); | 18 this.setMinimumAndPreferredSizes(80, 52, 150, 100); |
19 | 19 |
20 var workspace = Workspace.workspace; | 20 var workspace = Workspace.workspace; |
21 | 21 |
22 this._searchableView = new UI.SearchableView(this, 'sourcesViewSearchConfig' ); | 22 this._searchableView = new UI.SearchableView(this, 'sourcesViewSearchConfig' ); |
23 this._searchableView.setMinimalSearchQuerySize(0); | 23 this._searchableView.setMinimalSearchQuerySize(0); |
24 this._searchableView.show(this.element); | 24 this._searchableView.show(this.element); |
25 | 25 |
26 /** @type {!Map.<!Workspace.UISourceCode, !UI.Widget>} */ | 26 /** @type {!Map.<!Workspace.UISourceCode, !UI.Widget>} */ |
27 this._sourceViewByUISourceCode = new Map(); | 27 this._sourceViewByUISourceCode = new Map(); |
28 | 28 |
29 var tabbedEditorPlaceholderText = | |
30 Host.isMac() ? Common.UIString('Hit \u2318+P to open a file') : Common.U IString('Hit Ctrl+P to open a file'); | |
31 if (Runtime.experiments.isEnabled('persistence2')) | |
32 tabbedEditorPlaceholderText += '\n\n' + Common.UIString('Drop in a folder to add to workspace'); | |
33 this._editorContainer = new Sources.TabbedEditorContainer( | 29 this._editorContainer = new Sources.TabbedEditorContainer( |
34 this, Common.settings.createLocalSetting('previouslyViewedFiles', []), t abbedEditorPlaceholderText); | 30 this, Common.settings.createLocalSetting('previouslyViewedFiles', []), t his._placeholderElement()); |
35 this._editorContainer.show(this._searchableView.element); | 31 this._editorContainer.show(this._searchableView.element); |
36 this._editorContainer.addEventListener( | 32 this._editorContainer.addEventListener( |
37 Sources.TabbedEditorContainer.Events.EditorSelected, this._editorSelecte d, this); | 33 Sources.TabbedEditorContainer.Events.EditorSelected, this._editorSelecte d, this); |
38 this._editorContainer.addEventListener(Sources.TabbedEditorContainer.Events. EditorClosed, this._editorClosed, this); | 34 this._editorContainer.addEventListener(Sources.TabbedEditorContainer.Events. EditorClosed, this._editorClosed, this); |
39 | 35 |
40 this._historyManager = new Sources.EditingLocationHistoryManager(this, this. currentSourceFrame.bind(this)); | 36 this._historyManager = new Sources.EditingLocationHistoryManager(this, this. currentSourceFrame.bind(this)); |
41 | 37 |
42 this._toolbarContainerElement = this.element.createChild('div', 'sources-too lbar'); | 38 this._toolbarContainerElement = this.element.createChild('div', 'sources-too lbar'); |
43 this._toolbarEditorActions = new UI.Toolbar('', this._toolbarContainerElemen t); | 39 this._toolbarEditorActions = new UI.Toolbar('', this._toolbarContainerElemen t); |
44 | 40 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 } | 84 } |
89 | 85 |
90 if (!window.opener) | 86 if (!window.opener) |
91 window.addEventListener('beforeunload', handleBeforeUnload, true); | 87 window.addEventListener('beforeunload', handleBeforeUnload, true); |
92 | 88 |
93 this._shortcuts = {}; | 89 this._shortcuts = {}; |
94 this.element.addEventListener('keydown', this._handleKeyDown.bind(this), fal se); | 90 this.element.addEventListener('keydown', this._handleKeyDown.bind(this), fal se); |
95 } | 91 } |
96 | 92 |
97 /** | 93 /** |
94 * @return {!Element} | |
95 */ | |
96 _placeholderElement() { | |
97 var shortcuts = [ | |
98 { | |
99 defaultShortcut: Common.UIString('Ctrl+P'), | |
pfeldman
2017/04/24 18:29:25
Since shortcuts are defined in quickopen and could
luoe
2017/04/25 23:19:52
Done.
| |
100 macShortcut: Common.UIString('\u2318+P'), | |
101 description: Common.UIString('Open a file') | |
102 }, | |
103 { | |
104 defaultShortcut: Common.UIString('Ctrl+Shift+P'), | |
105 macShortcut: Common.UIString('\u2318+Shift+P'), | |
106 description: Common.UIString('Run a command') | |
107 } | |
108 ]; | |
109 | |
110 var element = createElementWithClass('span', 'tabbed-pane-placeholder'); | |
111 for (var shortcut of shortcuts) { | |
112 var shortcutKeyText = Host.isMac() ? shortcut.macShortcut : shortcut.defau ltShortcut; | |
113 var row = element.createChild('div', 'tabbed-pane-placeholder-row'); | |
114 row.createChild('div', 'tabbed-pane-placeholder-key').textContent = shortc utKeyText; | |
115 row.createChild('div', 'tabbed-pane-placeholder-value').textContent = shor tcut.description; | |
116 } | |
117 if (Runtime.experiments.isEnabled('persistence2')) | |
118 element.createChild('div').textContent = Common.UIString('Drop in a folder to add to workspace'); | |
119 | |
120 return element; | |
121 } | |
122 | |
123 /** | |
98 * @return {!Map.<!Workspace.UISourceCode, number>} | 124 * @return {!Map.<!Workspace.UISourceCode, number>} |
99 */ | 125 */ |
100 static defaultUISourceCodeScores() { | 126 static defaultUISourceCodeScores() { |
101 /** @type {!Map.<!Workspace.UISourceCode, number>} */ | 127 /** @type {!Map.<!Workspace.UISourceCode, number>} */ |
102 var defaultScores = new Map(); | 128 var defaultScores = new Map(); |
103 var sourcesView = UI.context.flavor(Sources.SourcesView); | 129 var sourcesView = UI.context.flavor(Sources.SourcesView); |
104 if (sourcesView) { | 130 if (sourcesView) { |
105 var uiSourceCodes = sourcesView._editorContainer.historyUISourceCodes(); | 131 var uiSourceCodes = sourcesView._editorContainer.historyUISourceCodes(); |
106 for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element | 132 for (var i = 1; i < uiSourceCodes.length; ++i) // Skip current element |
107 defaultScores.set(uiSourceCodes[i], uiSourceCodes.length - i); | 133 defaultScores.set(uiSourceCodes[i], uiSourceCodes.length - i); |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 * @return {boolean} | 781 * @return {boolean} |
756 */ | 782 */ |
757 handleAction(context, actionId) { | 783 handleAction(context, actionId) { |
758 var sourcesView = UI.context.flavor(Sources.SourcesView); | 784 var sourcesView = UI.context.flavor(Sources.SourcesView); |
759 if (!sourcesView) | 785 if (!sourcesView) |
760 return false; | 786 return false; |
761 sourcesView._editorContainer.closeAllFiles(); | 787 sourcesView._editorContainer.closeAllFiles(); |
762 return true; | 788 return true; |
763 } | 789 } |
764 }; | 790 }; |
OLD | NEW |