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
3 // found in the LICENSE file.
7 * @extends {WebInspector.Object}
9 WebInspector
.ExcludedFolderManager = function()
11 WebInspector
.Object
.call(this);
12 this._excludedFoldersSetting
= WebInspector
.settings
.createLocalSetting("workspaceExcludedFolders", {});
13 var defaultCommonExcludedFolders
= [
22 var defaultWinExcludedFolders
= [
28 var defaultMacExcludedFolders
= [
31 "/\\.Spotlight-V100$",
37 var defaultLinuxExcludedFolders
= [
40 var defaultExcludedFolders
= defaultCommonExcludedFolders
;
41 if (WebInspector
.isWin())
42 defaultExcludedFolders
= defaultExcludedFolders
.concat(defaultWinExcludedFolders
);
43 else if (WebInspector
.isMac())
44 defaultExcludedFolders
= defaultExcludedFolders
.concat(defaultMacExcludedFolders
);
46 defaultExcludedFolders
= defaultExcludedFolders
.concat(defaultLinuxExcludedFolders
);
47 var defaultExcludedFoldersPattern
= defaultExcludedFolders
.join("|");
48 this._workspaceFolderExcludePatternSetting
= WebInspector
.settings
.createRegExpSetting("workspaceFolderExcludePattern", defaultExcludedFoldersPattern
, WebInspector
.isWin() ? "i" : "");
49 /** @type {!Object.<string, !Array.<!WebInspector.ExcludedFolderManager.Entry>>} */
50 this._excludedFolders
= {};
51 this._loadFromSettings();
54 WebInspector
.ExcludedFolderManager
.Events
= {
55 ExcludedFolderAdded
: "ExcludedFolderAdded",
56 ExcludedFolderRemoved
: "ExcludedFolderRemoved"
59 WebInspector
.ExcludedFolderManager
.prototype = {
61 * @return {!WebInspector.Setting}
63 workspaceFolderExcludePatternSetting: function()
65 return this._workspaceFolderExcludePatternSetting
;
68 _loadFromSettings: function()
70 var savedExcludedFolders
= this._excludedFoldersSetting
.get();
71 this._excludedFolders
= {};
72 for (var fileSystemPath
in savedExcludedFolders
) {
73 var savedExcludedFoldersForPath
= savedExcludedFolders
[fileSystemPath
];
75 this._excludedFolders
[fileSystemPath
] = [];
76 var excludedFolders
= this._excludedFolders
[fileSystemPath
];
78 for (var i
= 0; i
< savedExcludedFoldersForPath
.length
; ++i
) {
79 var savedEntry
= savedExcludedFoldersForPath
[i
];
80 var entry
= new WebInspector
.ExcludedFolderManager
.Entry(savedEntry
.fileSystemPath
, savedEntry
.path
);
81 excludedFolders
.push(entry
);
86 _saveToSettings: function()
88 var savedExcludedFolders
= this._excludedFolders
;
89 this._excludedFoldersSetting
.set(savedExcludedFolders
);
93 * @param {string} fileSystemPath
94 * @param {string} excludedFolderPath
96 addExcludedFolder: function(fileSystemPath
, excludedFolderPath
)
98 if (!this._excludedFolders
[fileSystemPath
])
99 this._excludedFolders
[fileSystemPath
] = [];
100 var entry
= new WebInspector
.ExcludedFolderManager
.Entry(fileSystemPath
, excludedFolderPath
);
101 this._excludedFolders
[fileSystemPath
].push(entry
);
102 this._saveToSettings();
103 this.dispatchEventToListeners(WebInspector
.ExcludedFolderManager
.Events
.ExcludedFolderAdded
, entry
);
107 * @param {string} fileSystemPath
108 * @param {string} path
110 removeExcludedFolder: function(fileSystemPath
, path
)
112 var entry
= this._excludedFolderEntryForPath(fileSystemPath
, path
);
115 this._excludedFolders
[fileSystemPath
].remove(entry
);
116 this._saveToSettings();
117 this.dispatchEventToListeners(WebInspector
.ExcludedFolderManager
.Events
.ExcludedFolderRemoved
, entry
);
121 * @param {string} fileSystemPath
123 removeFileSystem: function(fileSystemPath
)
125 delete this._excludedFolders
[fileSystemPath
];
126 this._saveToSettings();
130 * @param {string} fileSystemPath
131 * @param {string} path
132 * @return {?WebInspector.ExcludedFolderManager.Entry}
134 _excludedFolderEntryForPath: function(fileSystemPath
, path
)
136 var entries
= this._excludedFolders
[fileSystemPath
];
140 for (var i
= 0; i
< entries
.length
; ++i
) {
141 if (entries
[i
].path
=== path
)
148 * @param {string} fileSystemPath
149 * @param {string} folderPath
152 isFileExcluded: function(fileSystemPath
, folderPath
)
154 var excludedFolders
= this._excludedFolders
[fileSystemPath
] || [];
155 for (var i
= 0; i
< excludedFolders
.length
; ++i
) {
156 var entry
= excludedFolders
[i
];
157 if (entry
.path
=== folderPath
)
160 var regex
= this._workspaceFolderExcludePatternSetting
.asRegExp();
161 return !!(regex
&& regex
.test(folderPath
));
165 * @param {string} fileSystemPath
166 * @return {!Array.<!WebInspector.ExcludedFolderManager.Entry>}
168 excludedFolders: function(fileSystemPath
)
170 var excludedFolders
= this._excludedFolders
[fileSystemPath
];
171 return excludedFolders
? excludedFolders
.slice() : [];
174 __proto__
: WebInspector
.Object
.prototype
179 * @param {string} fileSystemPath
180 * @param {string} path
182 WebInspector
.ExcludedFolderManager
.Entry = function(fileSystemPath
, path
)
184 this.fileSystemPath
= fileSystemPath
;