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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 Common.Revealer.reveal(unsavedSourceCodes[i]); | 83 Common.Revealer.reveal(unsavedSourceCodes[i]); |
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 |
93 placeholderElement() { | |
pfeldman
2017/03/28 00:59:34
It should be annotated and private.
luoe
2017/04/22 00:07:03
Done.
| |
94 var shortcuts = [ | |
95 { | |
96 defaultShortcut: Common.UIString('Ctrl+P'), | |
97 macShortcut: Common.UIString('\u2318+P'), | |
98 description: Common.UIString('Open a file') | |
99 }, | |
100 { | |
101 defaultShortcut: Common.UIString('Ctrl+Shift+P'), | |
102 macShortcut: Common.UIString('\u2318+Shift+P'), | |
103 description: Common.UIString('Run command') | |
104 }, | |
105 { | |
106 defaultShortcut: Common.UIString('Esc'), | |
107 macShortcut: Common.UIString('Esc'), | |
108 description: Common.UIString('Toggle console drawer') | |
109 }, | |
110 ]; | |
111 | |
112 var placeholderElement = createElementWithClass('span', 'sources-placeholder '); | |
113 for (var shortcut of shortcuts) { | |
114 var row = placeholderElement.createChild('div', 'sources-placeholder-row') ; | |
115 row.createChild('div', 'sources-placeholder-key') | |
116 .createTextChild(Host.isMac() ? shortcut.macShortcut : shortcut.defaul tShortcut); | |
117 row.createChild('div', 'sources-placeholder-value').createTextChild(shortc ut.description); | |
118 } | |
119 if (Runtime.experiments.isEnabled('persistence2')) { | |
120 placeholderElement.createChild('div', 'sources-placeholder-message').textC ontent = | |
121 Common.UIString('Drop in a folder to add to workspace'); | |
122 } | |
123 | |
124 return placeholderElement; | |
125 } | |
126 | |
97 /** | 127 /** |
98 * @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event= ):boolean)} registerShortcutDelegate | 128 * @param {function(!Array.<!UI.KeyboardShortcut.Descriptor>, function(!Event= ):boolean)} registerShortcutDelegate |
99 */ | 129 */ |
100 registerShortcuts(registerShortcutDelegate) { | 130 registerShortcuts(registerShortcutDelegate) { |
101 /** | 131 /** |
102 * @this {Sources.SourcesView} | 132 * @this {Sources.SourcesView} |
103 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} shortcuts | 133 * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} shortcuts |
104 * @param {function(!Event=):boolean} handler | 134 * @param {function(!Event=):boolean} handler |
105 */ | 135 */ |
106 function registerShortcut(shortcuts, handler) { | 136 function registerShortcut(shortcuts, handler) { |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 * @return {boolean} | 798 * @return {boolean} |
769 */ | 799 */ |
770 handleAction(context, actionId) { | 800 handleAction(context, actionId) { |
771 var sourcesView = UI.context.flavor(Sources.SourcesView); | 801 var sourcesView = UI.context.flavor(Sources.SourcesView); |
772 if (!sourcesView) | 802 if (!sourcesView) |
773 return false; | 803 return false; |
774 sourcesView._editorContainer.closeAllFiles(); | 804 sourcesView._editorContainer.closeAllFiles(); |
775 return true; | 805 return true; |
776 } | 806 } |
777 }; | 807 }; |
OLD | NEW |