| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @extends {WebInspector.Object} | |
| 8 */ | |
| 9 WebInspector.ExcludedFolderManager = function() | |
| 10 { | |
| 11 WebInspector.Object.call(this); | |
| 12 this._excludedFoldersSetting = WebInspector.settings.createLocalSetting("wor
kspaceExcludedFolders", {}); | |
| 13 var defaultCommonExcludedFolders = [ | |
| 14 "/\\.git/", | |
| 15 "/\\.sass-cache/", | |
| 16 "/\\.hg/", | |
| 17 "/\\.idea/", | |
| 18 "/\\.svn/", | |
| 19 "/\\.cache/", | |
| 20 "/\\.project/" | |
| 21 ]; | |
| 22 var defaultWinExcludedFolders = [ | |
| 23 "/Thumbs.db$", | |
| 24 "/ehthumbs.db$", | |
| 25 "/Desktop.ini$", | |
| 26 "/\\$RECYCLE.BIN/" | |
| 27 ]; | |
| 28 var defaultMacExcludedFolders = [ | |
| 29 "/\\.DS_Store$", | |
| 30 "/\\.Trashes$", | |
| 31 "/\\.Spotlight-V100$", | |
| 32 "/\\.AppleDouble$", | |
| 33 "/\\.LSOverride$", | |
| 34 "/Icon$", | |
| 35 "/\\._.*$" | |
| 36 ]; | |
| 37 var defaultLinuxExcludedFolders = [ | |
| 38 "/.*~$" | |
| 39 ]; | |
| 40 var defaultExcludedFolders = defaultCommonExcludedFolders; | |
| 41 if (WebInspector.isWin()) | |
| 42 defaultExcludedFolders = defaultExcludedFolders.concat(defaultWinExclude
dFolders); | |
| 43 else if (WebInspector.isMac()) | |
| 44 defaultExcludedFolders = defaultExcludedFolders.concat(defaultMacExclude
dFolders); | |
| 45 else | |
| 46 defaultExcludedFolders = defaultExcludedFolders.concat(defaultLinuxExclu
dedFolders); | |
| 47 var defaultExcludedFoldersPattern = defaultExcludedFolders.join("|"); | |
| 48 this._workspaceFolderExcludePatternSetting = WebInspector.settings.createReg
ExpSetting("workspaceFolderExcludePattern", defaultExcludedFoldersPattern, WebIn
spector.isWin() ? "i" : ""); | |
| 49 /** @type {!Object.<string, !Array.<!WebInspector.ExcludedFolderManager.Entr
y>>} */ | |
| 50 this._excludedFolders = {}; | |
| 51 this._loadFromSettings(); | |
| 52 } | |
| 53 | |
| 54 WebInspector.ExcludedFolderManager.Events = { | |
| 55 ExcludedFolderAdded: "ExcludedFolderAdded", | |
| 56 ExcludedFolderRemoved: "ExcludedFolderRemoved" | |
| 57 } | |
| 58 | |
| 59 WebInspector.ExcludedFolderManager.prototype = { | |
| 60 /** | |
| 61 * @return {!WebInspector.Setting} | |
| 62 */ | |
| 63 workspaceFolderExcludePatternSetting: function() | |
| 64 { | |
| 65 return this._workspaceFolderExcludePatternSetting; | |
| 66 }, | |
| 67 | |
| 68 _loadFromSettings: function() | |
| 69 { | |
| 70 var savedExcludedFolders = this._excludedFoldersSetting.get(); | |
| 71 this._excludedFolders = {}; | |
| 72 for (var fileSystemPath in savedExcludedFolders) { | |
| 73 var savedExcludedFoldersForPath = savedExcludedFolders[fileSystemPat
h]; | |
| 74 | |
| 75 this._excludedFolders[fileSystemPath] = []; | |
| 76 var excludedFolders = this._excludedFolders[fileSystemPath]; | |
| 77 | |
| 78 for (var i = 0; i < savedExcludedFoldersForPath.length; ++i) { | |
| 79 var savedEntry = savedExcludedFoldersForPath[i]; | |
| 80 var entry = new WebInspector.ExcludedFolderManager.Entry(savedEn
try.fileSystemPath, savedEntry.path); | |
| 81 excludedFolders.push(entry); | |
| 82 } | |
| 83 } | |
| 84 }, | |
| 85 | |
| 86 _saveToSettings: function() | |
| 87 { | |
| 88 var savedExcludedFolders = this._excludedFolders; | |
| 89 this._excludedFoldersSetting.set(savedExcludedFolders); | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * @param {string} fileSystemPath | |
| 94 * @param {string} excludedFolderPath | |
| 95 */ | |
| 96 addExcludedFolder: function(fileSystemPath, excludedFolderPath) | |
| 97 { | |
| 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); | |
| 104 }, | |
| 105 | |
| 106 /** | |
| 107 * @param {string} fileSystemPath | |
| 108 * @param {string} path | |
| 109 */ | |
| 110 removeExcludedFolder: function(fileSystemPath, path) | |
| 111 { | |
| 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); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * @param {string} fileSystemPath | |
| 122 */ | |
| 123 removeFileSystem: function(fileSystemPath) | |
| 124 { | |
| 125 delete this._excludedFolders[fileSystemPath]; | |
| 126 this._saveToSettings(); | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 130 * @param {string} fileSystemPath | |
| 131 * @param {string} path | |
| 132 * @return {?WebInspector.ExcludedFolderManager.Entry} | |
| 133 */ | |
| 134 _excludedFolderEntryForPath: function(fileSystemPath, path) | |
| 135 { | |
| 136 var entries = this._excludedFolders[fileSystemPath]; | |
| 137 if (!entries) | |
| 138 return null; | |
| 139 | |
| 140 for (var i = 0; i < entries.length; ++i) { | |
| 141 if (entries[i].path === path) | |
| 142 return entries[i]; | |
| 143 } | |
| 144 return null; | |
| 145 }, | |
| 146 | |
| 147 /** | |
| 148 * @param {string} fileSystemPath | |
| 149 * @param {string} folderPath | |
| 150 * @return {boolean} | |
| 151 */ | |
| 152 isFileExcluded: function(fileSystemPath, folderPath) | |
| 153 { | |
| 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; | |
| 159 } | |
| 160 var regex = this._workspaceFolderExcludePatternSetting.asRegExp(); | |
| 161 return !!(regex && regex.test(folderPath)); | |
| 162 }, | |
| 163 | |
| 164 /** | |
| 165 * @param {string} fileSystemPath | |
| 166 * @return {!Array.<!WebInspector.ExcludedFolderManager.Entry>} | |
| 167 */ | |
| 168 excludedFolders: function(fileSystemPath) | |
| 169 { | |
| 170 var excludedFolders = this._excludedFolders[fileSystemPath]; | |
| 171 return excludedFolders ? excludedFolders.slice() : []; | |
| 172 }, | |
| 173 | |
| 174 __proto__: WebInspector.Object.prototype | |
| 175 } | |
| 176 | |
| 177 /** | |
| 178 * @constructor | |
| 179 * @param {string} fileSystemPath | |
| 180 * @param {string} path | |
| 181 */ | |
| 182 WebInspector.ExcludedFolderManager.Entry = function(fileSystemPath, path) | |
| 183 { | |
| 184 this.fileSystemPath = fileSystemPath; | |
| 185 this.path = path; | |
| 186 } | |
| OLD | NEW |