Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/snippets/SnippetStorage.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 WebInspector.SnippetStorage = class extends WebInspector.Object { 34 Snippets.SnippetStorage = class extends Common.Object {
35 constructor(settingPrefix, namePrefix) { 35 constructor(settingPrefix, namePrefix) {
36 super(); 36 super();
37 /** @type {!Map<string,!WebInspector.Snippet>} */ 37 /** @type {!Map<string,!Snippets.Snippet>} */
38 this._snippets = new Map(); 38 this._snippets = new Map();
39 39
40 this._lastSnippetIdentifierSetting = 40 this._lastSnippetIdentifierSetting =
41 WebInspector.settings.createSetting(settingPrefix + 'Snippets_lastIdenti fier', 0); 41 Common.settings.createSetting(settingPrefix + 'Snippets_lastIdentifier', 0);
42 this._snippetsSetting = WebInspector.settings.createSetting(settingPrefix + 'Snippets', []); 42 this._snippetsSetting = Common.settings.createSetting(settingPrefix + 'Snipp ets', []);
43 this._namePrefix = namePrefix; 43 this._namePrefix = namePrefix;
44 44
45 this._loadSettings(); 45 this._loadSettings();
46 } 46 }
47 47
48 get namePrefix() { 48 get namePrefix() {
49 return this._namePrefix; 49 return this._namePrefix;
50 } 50 }
51 51
52 _saveSettings() { 52 _saveSettings() {
53 var savedSnippets = []; 53 var savedSnippets = [];
54 for (var snippet of this._snippets.values()) 54 for (var snippet of this._snippets.values())
55 savedSnippets.push(snippet.serializeToObject()); 55 savedSnippets.push(snippet.serializeToObject());
56 this._snippetsSetting.set(savedSnippets); 56 this._snippetsSetting.set(savedSnippets);
57 } 57 }
58 58
59 /** 59 /**
60 * @return {!Array<!WebInspector.Snippet>} 60 * @return {!Array<!Snippets.Snippet>}
61 */ 61 */
62 snippets() { 62 snippets() {
63 return this._snippets.valuesArray(); 63 return this._snippets.valuesArray();
64 } 64 }
65 65
66 /** 66 /**
67 * @param {string} id 67 * @param {string} id
68 * @return {?WebInspector.Snippet} 68 * @return {?Snippets.Snippet}
69 */ 69 */
70 snippetForId(id) { 70 snippetForId(id) {
71 return this._snippets.get(id); 71 return this._snippets.get(id);
72 } 72 }
73 73
74 /** 74 /**
75 * @param {string} name 75 * @param {string} name
76 * @return {?WebInspector.Snippet} 76 * @return {?Snippets.Snippet}
77 */ 77 */
78 snippetForName(name) { 78 snippetForName(name) {
79 for (var snippet of this._snippets.values()) { 79 for (var snippet of this._snippets.values()) {
80 if (snippet.name === name) 80 if (snippet.name === name)
81 return snippet; 81 return snippet;
82 } 82 }
83 return null; 83 return null;
84 } 84 }
85 85
86 _loadSettings() { 86 _loadSettings() {
87 var savedSnippets = this._snippetsSetting.get(); 87 var savedSnippets = this._snippetsSetting.get();
88 for (var i = 0; i < savedSnippets.length; ++i) 88 for (var i = 0; i < savedSnippets.length; ++i)
89 this._snippetAdded(WebInspector.Snippet.fromObject(this, savedSnippets[i]) ); 89 this._snippetAdded(Snippets.Snippet.fromObject(this, savedSnippets[i]));
90 } 90 }
91 91
92 /** 92 /**
93 * @param {!WebInspector.Snippet} snippet 93 * @param {!Snippets.Snippet} snippet
94 */ 94 */
95 deleteSnippet(snippet) { 95 deleteSnippet(snippet) {
96 this._snippets.delete(snippet.id); 96 this._snippets.delete(snippet.id);
97 this._saveSettings(); 97 this._saveSettings();
98 } 98 }
99 99
100 /** 100 /**
101 * @return {!WebInspector.Snippet} 101 * @return {!Snippets.Snippet}
102 */ 102 */
103 createSnippet() { 103 createSnippet() {
104 var nextId = this._lastSnippetIdentifierSetting.get() + 1; 104 var nextId = this._lastSnippetIdentifierSetting.get() + 1;
105 var snippetId = String(nextId); 105 var snippetId = String(nextId);
106 this._lastSnippetIdentifierSetting.set(nextId); 106 this._lastSnippetIdentifierSetting.set(nextId);
107 var snippet = new WebInspector.Snippet(this, snippetId); 107 var snippet = new Snippets.Snippet(this, snippetId);
108 this._snippetAdded(snippet); 108 this._snippetAdded(snippet);
109 this._saveSettings(); 109 this._saveSettings();
110 return snippet; 110 return snippet;
111 } 111 }
112 112
113 /** 113 /**
114 * @param {!WebInspector.Snippet} snippet 114 * @param {!Snippets.Snippet} snippet
115 */ 115 */
116 _snippetAdded(snippet) { 116 _snippetAdded(snippet) {
117 this._snippets.set(snippet.id, snippet); 117 this._snippets.set(snippet.id, snippet);
118 } 118 }
119 }; 119 };
120 120
121 /** 121 /**
122 * @unrestricted 122 * @unrestricted
123 */ 123 */
124 WebInspector.Snippet = class extends WebInspector.Object { 124 Snippets.Snippet = class extends Common.Object {
125 /** 125 /**
126 * @param {!WebInspector.SnippetStorage} storage 126 * @param {!Snippets.SnippetStorage} storage
127 * @param {string} id 127 * @param {string} id
128 * @param {string=} name 128 * @param {string=} name
129 * @param {string=} content 129 * @param {string=} content
130 */ 130 */
131 constructor(storage, id, name, content) { 131 constructor(storage, id, name, content) {
132 super(); 132 super();
133 this._storage = storage; 133 this._storage = storage;
134 this._id = id; 134 this._id = id;
135 this._name = name || storage.namePrefix + id; 135 this._name = name || storage.namePrefix + id;
136 this._content = content || ''; 136 this._content = content || '';
137 } 137 }
138 138
139 /** 139 /**
140 * @param {!WebInspector.SnippetStorage} storage 140 * @param {!Snippets.SnippetStorage} storage
141 * @param {!Object} serializedSnippet 141 * @param {!Object} serializedSnippet
142 * @return {!WebInspector.Snippet} 142 * @return {!Snippets.Snippet}
143 */ 143 */
144 static fromObject(storage, serializedSnippet) { 144 static fromObject(storage, serializedSnippet) {
145 return new WebInspector.Snippet(storage, serializedSnippet.id, serializedSni ppet.name, serializedSnippet.content); 145 return new Snippets.Snippet(storage, serializedSnippet.id, serializedSnippet .name, serializedSnippet.content);
146 } 146 }
147 147
148 /** 148 /**
149 * @return {string} 149 * @return {string}
150 */ 150 */
151 get id() { 151 get id() {
152 return this._id; 152 return this._id;
153 } 153 }
154 154
155 /** 155 /**
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 * @return {!Object} 192 * @return {!Object}
193 */ 193 */
194 serializeToObject() { 194 serializeToObject() {
195 var serializedSnippet = {}; 195 var serializedSnippet = {};
196 serializedSnippet.id = this.id; 196 serializedSnippet.id = this.id;
197 serializedSnippet.name = this.name; 197 serializedSnippet.name = this.name;
198 serializedSnippet.content = this.content; 198 serializedSnippet.content = this.content;
199 return serializedSnippet; 199 return serializedSnippet;
200 } 200 }
201 }; 201 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698