Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.Object} | 33 * @extends {WebInspector.Object} |
| 34 */ | 34 */ |
| 35 WebInspector.SnippetStorage = function(settingPrefix, namePrefix) | 35 WebInspector.SnippetStorage = function(settingPrefix, namePrefix) |
| 36 { | 36 { |
| 37 this._snippets = {}; | 37 /** @type {!Map<string,!WebInspector.Snippet>} */ |
| 38 this._snippets = new Map(); | |
| 38 | 39 |
| 39 this._lastSnippetIdentifierSetting = WebInspector.settings.createSetting(set tingPrefix + "Snippets_lastIdentifier", 0); | 40 this._lastSnippetIdentifierSetting = WebInspector.settings.createSetting(set tingPrefix + "Snippets_lastIdentifier", 0); |
| 40 this._snippetsSetting = WebInspector.settings.createSetting(settingPrefix + "Snippets", []); | 41 this._snippetsSetting = WebInspector.settings.createSetting(settingPrefix + "Snippets", []); |
| 41 this._namePrefix = namePrefix; | 42 this._namePrefix = namePrefix; |
| 42 | 43 |
| 43 this._loadSettings(); | 44 this._loadSettings(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 WebInspector.SnippetStorage.prototype = { | 47 WebInspector.SnippetStorage.prototype = { |
| 47 get namePrefix() | 48 get namePrefix() |
| 48 { | 49 { |
| 49 return this._namePrefix; | 50 return this._namePrefix; |
| 50 }, | 51 }, |
| 51 | 52 |
| 52 _saveSettings: function() | 53 _saveSettings: function() |
| 53 { | 54 { |
| 54 var savedSnippets = []; | 55 var savedSnippets = []; |
| 55 for (var id in this._snippets) | 56 for (var snippet of this._snippets.values()) |
| 56 savedSnippets.push(this._snippets[id].serializeToObject()); | 57 savedSnippets.push(snippet.serializeToObject()); |
| 57 this._snippetsSetting.set(savedSnippets); | 58 this._snippetsSetting.set(savedSnippets); |
| 58 }, | 59 }, |
| 59 | 60 |
| 60 /** | 61 /** |
| 61 * @return {!Array.<!WebInspector.Snippet>} | 62 * @return {!Array<!WebInspector.Snippet>} |
| 62 */ | 63 */ |
| 63 snippets: function() | 64 snippets: function() |
| 64 { | 65 { |
| 65 var result = []; | 66 return Array.from(this._snippets.values()); |
|
lushnikov
2016/07/20 03:02:50
valuesArray
kozy
2016/07/20 17:55:19
Done.
| |
| 66 for (var id in this._snippets) | |
| 67 result.push(this._snippets[id]); | |
| 68 return result; | |
| 69 }, | 67 }, |
| 70 | 68 |
| 71 /** | 69 /** |
| 72 * @param {string} id | 70 * @param {string} id |
| 73 * @return {!WebInspector.Snippet} | 71 * @return {?WebInspector.Snippet} |
| 74 */ | 72 */ |
| 75 snippetForId: function(id) | 73 snippetForId: function(id) |
| 76 { | 74 { |
| 77 return this._snippets[id]; | 75 return this._snippets.get(id); |
| 78 }, | 76 }, |
| 79 | 77 |
| 80 /** | 78 /** |
| 81 * @param {string} name | 79 * @param {string} name |
| 82 * @return {?WebInspector.Snippet} | 80 * @return {?WebInspector.Snippet} |
| 83 */ | 81 */ |
| 84 snippetForName: function(name) | 82 snippetForName: function(name) |
| 85 { | 83 { |
| 86 var snippets = Object.values(this._snippets); | 84 for (var snippet of this._snippets.values()) |
|
lushnikov
2016/07/20 03:02:50
braces are missing
kozy
2016/07/20 17:55:18
Done.
| |
| 87 for (var i = 0; i < snippets.length; ++i) | 85 if (snippet.name === name) |
| 88 if (snippets[i].name === name) | 86 return snippet; |
| 89 return snippets[i]; | |
| 90 return null; | 87 return null; |
| 91 }, | 88 }, |
| 92 | 89 |
| 93 _loadSettings: function() | 90 _loadSettings: function() |
| 94 { | 91 { |
| 95 var savedSnippets = this._snippetsSetting.get(); | 92 var savedSnippets = this._snippetsSetting.get(); |
| 96 for (var i = 0; i < savedSnippets.length; ++i) | 93 for (var i = 0; i < savedSnippets.length; ++i) |
| 97 this._snippetAdded(WebInspector.Snippet.fromObject(this, savedSnippe ts[i])); | 94 this._snippetAdded(WebInspector.Snippet.fromObject(this, savedSnippe ts[i])); |
| 98 }, | 95 }, |
| 99 | 96 |
| 100 /** | 97 /** |
| 101 * @param {!WebInspector.Snippet} snippet | 98 * @param {!WebInspector.Snippet} snippet |
| 102 */ | 99 */ |
| 103 deleteSnippet: function(snippet) | 100 deleteSnippet: function(snippet) |
| 104 { | 101 { |
| 105 delete this._snippets[snippet.id]; | 102 this._snippets.delete(snippet.id); |
| 106 this._saveSettings(); | 103 this._saveSettings(); |
| 107 }, | 104 }, |
| 108 | 105 |
| 109 /** | 106 /** |
| 110 * @return {!WebInspector.Snippet} | 107 * @return {!WebInspector.Snippet} |
| 111 */ | 108 */ |
| 112 createSnippet: function() | 109 createSnippet: function() |
| 113 { | 110 { |
| 114 var nextId = this._lastSnippetIdentifierSetting.get() + 1; | 111 var nextId = this._lastSnippetIdentifierSetting.get() + 1; |
| 115 var snippetId = String(nextId); | 112 var snippetId = String(nextId); |
| 116 this._lastSnippetIdentifierSetting.set(nextId); | 113 this._lastSnippetIdentifierSetting.set(nextId); |
| 117 var snippet = new WebInspector.Snippet(this, snippetId); | 114 var snippet = new WebInspector.Snippet(this, snippetId); |
| 118 this._snippetAdded(snippet); | 115 this._snippetAdded(snippet); |
| 119 this._saveSettings(); | 116 this._saveSettings(); |
| 120 return snippet; | 117 return snippet; |
| 121 }, | 118 }, |
| 122 | 119 |
| 123 /** | 120 /** |
| 124 * @param {!WebInspector.Snippet} snippet | 121 * @param {!WebInspector.Snippet} snippet |
| 125 */ | 122 */ |
| 126 _snippetAdded: function(snippet) | 123 _snippetAdded: function(snippet) |
| 127 { | 124 { |
| 128 this._snippets[snippet.id] = snippet; | 125 this._snippets.set(snippet.id, snippet); |
| 129 }, | 126 }, |
| 130 | 127 |
| 131 __proto__: WebInspector.Object.prototype | 128 __proto__: WebInspector.Object.prototype |
| 132 } | 129 } |
| 133 | 130 |
| 134 /** | 131 /** |
| 135 * @constructor | 132 * @constructor |
| 136 * @extends {WebInspector.Object} | 133 * @extends {WebInspector.Object} |
| 137 * @param {!WebInspector.SnippetStorage} storage | 134 * @param {!WebInspector.SnippetStorage} storage |
| 138 * @param {string} id | 135 * @param {string} id |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 { | 204 { |
| 208 var serializedSnippet = {}; | 205 var serializedSnippet = {}; |
| 209 serializedSnippet.id = this.id; | 206 serializedSnippet.id = this.id; |
| 210 serializedSnippet.name = this.name; | 207 serializedSnippet.name = this.name; |
| 211 serializedSnippet.content = this.content; | 208 serializedSnippet.content = this.content; |
| 212 return serializedSnippet; | 209 return serializedSnippet; |
| 213 }, | 210 }, |
| 214 | 211 |
| 215 __proto__: WebInspector.Object.prototype | 212 __proto__: WebInspector.Object.prototype |
| 216 } | 213 } |
| OLD | NEW |