blob: 36a865bfe3d6f9df18b00cb5370453f406296761 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5Persistence.WorkspaceSettingsTab = class extends UI.VBox {
6 constructor() {
7 super();
8 this.registerRequiredCSS('persistence/workspaceSettingsTab.css');
9
10 const header = this.element.createChild('header');
11 header.createChild('h3').createTextChild(Common.UIString('Workspace'));
12
13 this.containerElement = this.element.createChild('div', 'settings-container-wrapper')
14 .createChild('div', 'settings-tab settings-content settings-container');
15
16 Persistence.isolatedFileSystemManager.addEventListener(
17 Persistence.IsolatedFileSystemManager.Events.FileSystemAdded,
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0218 event => this._fileSystemAdded(/** @type {!Persistence.PlatformFileSystem} */ (event.data)), this);
Blink Reformat4c46d092018-04-07 15:32:3719 Persistence.isolatedFileSystemManager.addEventListener(
20 Persistence.IsolatedFileSystemManager.Events.FileSystemRemoved,
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0221 event => this._fileSystemRemoved(/** @type {!Persistence.PlatformFileSystem} */ (event.data)), this);
Blink Reformat4c46d092018-04-07 15:32:3722
23 const folderExcludePatternInput = this._createFolderExcludePatternInput();
24 folderExcludePatternInput.classList.add('folder-exclude-pattern');
25 this.containerElement.appendChild(folderExcludePatternInput);
26
27 const div = this.containerElement.createChild('div', 'settings-info-message');
Andrey Lushnikovb1795462018-08-30 14:29:3428 div.createTextChild(Common.UIString('Mappings are inferred automatically.'));
Blink Reformat4c46d092018-04-07 15:32:3729
30 this._fileSystemsListContainer = this.containerElement.createChild('div', '');
31
Joel Einbinder4b9d3502019-03-13 01:43:3832 const addButton = UI.createTextButton(ls`Add folder\u2026`, this._addFileSystemClicked.bind(this));
33 this.containerElement.appendChild(addButton);
34 this.setDefaultFocusedElement(addButton);
Blink Reformat4c46d092018-04-07 15:32:3735
36 /** @type {!Map<string, !Element>} */
37 this._elementByPath = new Map();
38
39 /** @type {!Map<string, !Persistence.EditFileSystemView>} */
40 this._mappingViewByPath = new Map();
41
42 const fileSystems = Persistence.isolatedFileSystemManager.fileSystems();
43 for (let i = 0; i < fileSystems.length; ++i)
44 this._addItem(fileSystems[i]);
45 }
46
47 /**
48 * @return {!Element}
49 */
50 _createFolderExcludePatternInput() {
51 const p = createElement('p');
52 const labelElement = p.createChild('label');
53 labelElement.textContent = Common.UIString('Folder exclude pattern');
54 const inputElement = UI.createInput('', 'text');
55 p.appendChild(inputElement);
56 inputElement.style.width = '270px';
57 const folderExcludeSetting = Persistence.isolatedFileSystemManager.workspaceFolderExcludePatternSetting();
58 const setValue =
59 UI.bindInput(inputElement, folderExcludeSetting.set.bind(folderExcludeSetting), regexValidator, false);
60 folderExcludeSetting.addChangeListener(() => setValue.call(null, folderExcludeSetting.get()));
61 setValue(folderExcludeSetting.get());
62 return p;
63
64 /**
65 * @param {string} value
66 * @return {boolean}
67 */
68 function regexValidator(value) {
69 let regex;
70 try {
71 regex = new RegExp(value);
72 } catch (e) {
73 }
74 return !!regex;
75 }
76 }
77
78 /**
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:0279 * @param {!Persistence.PlatformFileSystem} fileSystem
Blink Reformat4c46d092018-04-07 15:32:3780 */
81 _addItem(fileSystem) {
Andrey Lushnikov30914032018-11-21 07:17:3382 // Support managing only instances of IsolatedFileSystem.
83 if (!(fileSystem instanceof Persistence.IsolatedFileSystem))
84 return;
Blink Reformat4c46d092018-04-07 15:32:3785 const networkPersistenceProject = Persistence.networkPersistenceManager.project();
86 if (networkPersistenceProject &&
87 Persistence.isolatedFileSystemManager.fileSystem(networkPersistenceProject.fileSystemPath()) === fileSystem)
88 return;
89 const element = this._renderFileSystem(fileSystem);
90 this._elementByPath.set(fileSystem.path(), element);
91
92 this._fileSystemsListContainer.appendChild(element);
93
94 const mappingView = new Persistence.EditFileSystemView(fileSystem.path());
95 this._mappingViewByPath.set(fileSystem.path(), mappingView);
96 mappingView.element.classList.add('file-system-mapping-view');
97 mappingView.show(element);
98 }
99
100 /**
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:02101 * @param {!Persistence.PlatformFileSystem} fileSystem
Blink Reformat4c46d092018-04-07 15:32:37102 * @return {!Element}
103 */
104 _renderFileSystem(fileSystem) {
105 const fileSystemPath = fileSystem.path();
106 const lastIndexOfSlash = fileSystemPath.lastIndexOf(Host.isWin() ? '\\' : '/');
107 const folderName = fileSystemPath.substr(lastIndexOfSlash + 1);
108
109 const element = createElementWithClass('div', 'file-system-container');
110 const header = element.createChild('div', 'file-system-header');
111
112 header.createChild('div', 'file-system-name').textContent = folderName;
113 const path = header.createChild('div', 'file-system-path');
114 path.textContent = fileSystemPath;
115 path.title = fileSystemPath;
116
117 const toolbar = new UI.Toolbar('');
118 const button = new UI.ToolbarButton(Common.UIString('Remove'), 'largeicon-delete');
119 button.addEventListener(UI.ToolbarButton.Events.Click, this._removeFileSystemClicked.bind(this, fileSystem));
120 toolbar.appendToolbarItem(button);
121 header.appendChild(toolbar.element);
122
123 return element;
124 }
125
126 /**
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:02127 * @param {!Persistence.PlatformFileSystem} fileSystem
Blink Reformat4c46d092018-04-07 15:32:37128 */
129 _removeFileSystemClicked(fileSystem) {
130 Persistence.isolatedFileSystemManager.removeFileSystem(fileSystem);
131 }
132
133 _addFileSystemClicked() {
134 Persistence.isolatedFileSystemManager.addFileSystem();
135 }
136
137 /**
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:02138 * @param {!Persistence.PlatformFileSystem} fileSystem
Blink Reformat4c46d092018-04-07 15:32:37139 */
140 _fileSystemAdded(fileSystem) {
141 this._addItem(fileSystem);
142 }
143
144 /**
Alexey Kozyatinskiy3a2eb282018-08-21 16:22:02145 * @param {!Persistence.PlatformFileSystem} fileSystem
Blink Reformat4c46d092018-04-07 15:32:37146 */
147 _fileSystemRemoved(fileSystem) {
148 const mappingView = this._mappingViewByPath.get(fileSystem.path());
149 if (mappingView) {
150 mappingView.dispose();
151 this._mappingViewByPath.delete(fileSystem.path());
152 }
153
154 const element = this._elementByPath.get(fileSystem.path());
155 if (element) {
156 this._elementByPath.delete(fileSystem.path());
157 element.remove();
158 }
159 }
160};