Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / workspace / ExcludedFolderManager.js
blobce6918ffd837e38dbb82c5214d82e6736c62070c
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.
5 /**
6 * @constructor
7 * @extends {WebInspector.Object}
8 */
9 WebInspector.ExcludedFolderManager = function()
11 WebInspector.Object.call(this);
12 this._excludedFoldersSetting = WebInspector.settings.createLocalSetting("workspaceExcludedFolders", {});
13 var defaultCommonExcludedFolders = [
14 "/\\.git/",
15 "/\\.sass-cache/",
16 "/\\.hg/",
17 "/\\.idea/",
18 "/\\.svn/",
19 "/\\.cache/",
20 "/\\.project/"
22 var defaultWinExcludedFolders = [
23 "/Thumbs.db$",
24 "/ehthumbs.db$",
25 "/Desktop.ini$",
26 "/\\$RECYCLE.BIN/"
28 var defaultMacExcludedFolders = [
29 "/\\.DS_Store$",
30 "/\\.Trashes$",
31 "/\\.Spotlight-V100$",
32 "/\\.AppleDouble$",
33 "/\\.LSOverride$",
34 "/Icon$",
35 "/\\._.*$"
37 var defaultLinuxExcludedFolders = [
38 "/.*~$"
40 var defaultExcludedFolders = defaultCommonExcludedFolders;
41 if (WebInspector.isWin())
42 defaultExcludedFolders = defaultExcludedFolders.concat(defaultWinExcludedFolders);
43 else if (WebInspector.isMac())
44 defaultExcludedFolders = defaultExcludedFolders.concat(defaultMacExcludedFolders);
45 else
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 = {
60 /**
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);
92 /**
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);
113 if (!entry)
114 return;
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];
137 if (!entries)
138 return null;
140 for (var i = 0; i < entries.length; ++i) {
141 if (entries[i].path === path)
142 return entries[i];
144 return null;
148 * @param {string} fileSystemPath
149 * @param {string} folderPath
150 * @return {boolean}
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)
158 return true;
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
178 * @constructor
179 * @param {string} fileSystemPath
180 * @param {string} path
182 WebInspector.ExcludedFolderManager.Entry = function(fileSystemPath, path)
184 this.fileSystemPath = fileSystemPath;
185 this.path = path;