| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @extends {WebInspector.VBox} | 7 * @extends {WebInspector.VBox} |
| 8 * @param {!WebInspector.ListWidget.Delegate} delegate | 8 * @param {!WebInspector.ListWidget.Delegate} delegate |
| 9 */ | 9 */ |
| 10 WebInspector.ListWidget = function(delegate) | 10 WebInspector.ListWidget = function(delegate) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 /** | 31 /** |
| 32 * @interface | 32 * @interface |
| 33 */ | 33 */ |
| 34 WebInspector.ListWidget.Delegate = function() | 34 WebInspector.ListWidget.Delegate = function() |
| 35 { | 35 { |
| 36 } | 36 } |
| 37 | 37 |
| 38 WebInspector.ListWidget.Delegate.prototype = { | 38 WebInspector.ListWidget.Delegate.prototype = { |
| 39 /** | 39 /** |
| 40 * @param {*} item | 40 * @param {*} item |
| 41 * @param {boolean} editable |
| 41 * @return {!Element} | 42 * @return {!Element} |
| 42 */ | 43 */ |
| 43 renderItem: function(item) { }, | 44 renderItem: function(item, editable) { }, |
| 44 | 45 |
| 45 /** | 46 /** |
| 47 * @param {*} item |
| 46 * @param {number} index | 48 * @param {number} index |
| 47 */ | 49 */ |
| 48 removeItemRequested: function(index) { }, | 50 removeItemRequested: function(item, index) { }, |
| 49 | 51 |
| 50 /** | 52 /** |
| 51 * @param {*|null} item | 53 * @param {*} item |
| 52 * @return {!WebInspector.ListWidget.Editor} | 54 * @return {!WebInspector.ListWidget.Editor} |
| 53 */ | 55 */ |
| 54 beginEdit: function(item) { }, | 56 beginEdit: function(item) { }, |
| 55 | 57 |
| 56 /** | 58 /** |
| 57 * @param {*|null} item | 59 * @param {*} item |
| 58 * @param {!WebInspector.ListWidget.Editor} editor | 60 * @param {!WebInspector.ListWidget.Editor} editor |
| 61 * @param {boolean} isNew |
| 59 */ | 62 */ |
| 60 commitEdit: function(item, editor) { } | 63 commitEdit: function(item, editor, isNew) { } |
| 61 } | 64 } |
| 62 | 65 |
| 63 WebInspector.ListWidget.prototype = { | 66 WebInspector.ListWidget.prototype = { |
| 64 clear: function() | 67 clear: function() |
| 65 { | 68 { |
| 66 this._items = []; | 69 this._items = []; |
| 67 this._editable = []; | 70 this._editable = []; |
| 68 this._elements = []; | 71 this._elements = []; |
| 69 this._lastSeparator = false; | 72 this._lastSeparator = false; |
| 70 this._list.removeChildren(); | 73 this._list.removeChildren(); |
| 71 this._updatePlaceholder(); | 74 this._updatePlaceholder(); |
| 72 this._stopEditing(); | 75 this._stopEditing(); |
| 73 }, | 76 }, |
| 74 | 77 |
| 75 /** | 78 /** |
| 76 * @param {*} item | 79 * @param {*} item |
| 77 * @param {boolean} editable | 80 * @param {boolean} editable |
| 78 */ | 81 */ |
| 79 appendItem: function(item, editable) | 82 appendItem: function(item, editable) |
| 80 { | 83 { |
| 81 if (this._lastSeparator && this._items.length) | 84 if (this._lastSeparator && this._items.length) |
| 82 this._list.appendChild(createElementWithClass("div", "list-separator
")); | 85 this._list.appendChild(createElementWithClass("div", "list-separator
")); |
| 83 this._lastSeparator = false; | 86 this._lastSeparator = false; |
| 84 | 87 |
| 85 this._items.push(item); | 88 this._items.push(item); |
| 86 this._editable.push(editable); | 89 this._editable.push(editable); |
| 87 | 90 |
| 88 var element = this._list.createChild("div", "list-item"); | 91 var element = this._list.createChild("div", "list-item"); |
| 89 element.appendChild(this._delegate.renderItem(item)); | 92 element.appendChild(this._delegate.renderItem(item, editable)); |
| 90 if (editable) { | 93 if (editable) { |
| 91 element.classList.add("editable"); | 94 element.classList.add("editable"); |
| 92 element.appendChild(this._createControls(item, element)); | 95 element.appendChild(this._createControls(item, element)); |
| 93 } | 96 } |
| 94 this._elements.push(element); | 97 this._elements.push(element); |
| 95 this._updatePlaceholder(); | 98 this._updatePlaceholder(); |
| 96 }, | 99 }, |
| 97 | 100 |
| 98 appendSeparator: function() | 101 appendSeparator: function() |
| 99 { | 102 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 123 element.remove(); | 126 element.remove(); |
| 124 | 127 |
| 125 this._elements.splice(index, 1); | 128 this._elements.splice(index, 1); |
| 126 this._items.splice(index, 1); | 129 this._items.splice(index, 1); |
| 127 this._editable.splice(index, 1); | 130 this._editable.splice(index, 1); |
| 128 this._updatePlaceholder(); | 131 this._updatePlaceholder(); |
| 129 }, | 132 }, |
| 130 | 133 |
| 131 /** | 134 /** |
| 132 * @param {number} index | 135 * @param {number} index |
| 136 * @param {*} item |
| 133 */ | 137 */ |
| 134 addNewItem: function(index) | 138 addNewItem: function(index, item) |
| 135 { | 139 { |
| 136 this._startEditing(null, null, this._elements[index] || null); | 140 this._startEditing(item, null, this._elements[index] || null); |
| 137 }, | 141 }, |
| 138 | 142 |
| 139 /** | 143 /** |
| 140 * @param {?Element} element | 144 * @param {?Element} element |
| 141 */ | 145 */ |
| 142 setEmptyPlaceholder: function(element) | 146 setEmptyPlaceholder: function(element) |
| 143 { | 147 { |
| 144 this._emptyPlaceholder = element; | 148 this._emptyPlaceholder = element; |
| 145 }, | 149 }, |
| 146 | 150 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 176 this._startEditing(item, element, insertionPoint); | 180 this._startEditing(item, element, insertionPoint); |
| 177 } | 181 } |
| 178 | 182 |
| 179 /** | 183 /** |
| 180 * @param {!Event} event | 184 * @param {!Event} event |
| 181 * @this {WebInspector.ListWidget} | 185 * @this {WebInspector.ListWidget} |
| 182 */ | 186 */ |
| 183 function onRemoveClicked(event) | 187 function onRemoveClicked(event) |
| 184 { | 188 { |
| 185 event.consume(); | 189 event.consume(); |
| 186 this._delegate.removeItemRequested(this._elements.indexOf(element)); | 190 var index = this._elements.indexOf(element); |
| 191 this._delegate.removeItemRequested(this._items[index], index); |
| 187 } | 192 } |
| 188 }, | 193 }, |
| 189 | 194 |
| 190 wasShown: function() | 195 wasShown: function() |
| 191 { | 196 { |
| 192 WebInspector.VBox.prototype.wasShown.call(this); | 197 WebInspector.VBox.prototype.wasShown.call(this); |
| 193 this._stopEditing(); | 198 this._stopEditing(); |
| 194 }, | 199 }, |
| 195 | 200 |
| 196 _updatePlaceholder: function() | 201 _updatePlaceholder: function() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 224 | 229 |
| 225 this._editor = this._delegate.beginEdit(item); | 230 this._editor = this._delegate.beginEdit(item); |
| 226 this._updatePlaceholder(); | 231 this._updatePlaceholder(); |
| 227 this._list.insertBefore(this._editor.element, insertionPoint); | 232 this._list.insertBefore(this._editor.element, insertionPoint); |
| 228 this._editor.beginEdit(element ? WebInspector.UIString("Save") : WebInsp
ector.UIString("Add"), this._commitEditing.bind(this), this._stopEditing.bind(th
is)); | 233 this._editor.beginEdit(element ? WebInspector.UIString("Save") : WebInsp
ector.UIString("Add"), this._commitEditing.bind(this), this._stopEditing.bind(th
is)); |
| 229 }, | 234 }, |
| 230 | 235 |
| 231 _commitEditing: function() | 236 _commitEditing: function() |
| 232 { | 237 { |
| 233 var editItem = this._editItem; | 238 var editItem = this._editItem; |
| 239 var isNew = !this._editElement; |
| 234 var editor = /** @type {!WebInspector.ListWidget.Editor} */ (this._edito
r); | 240 var editor = /** @type {!WebInspector.ListWidget.Editor} */ (this._edito
r); |
| 235 this._stopEditing(); | 241 this._stopEditing(); |
| 236 this._delegate.commitEdit(editItem, editor); | 242 this._delegate.commitEdit(editItem, editor, isNew); |
| 237 }, | 243 }, |
| 238 | 244 |
| 239 _stopEditing: function() | 245 _stopEditing: function() |
| 240 { | 246 { |
| 241 this._list.classList.remove("list-editing"); | 247 this._list.classList.remove("list-editing"); |
| 242 if (this._editElement) | 248 if (this._editElement) |
| 243 this._editElement.classList.remove("hidden"); | 249 this._editElement.classList.remove("hidden"); |
| 244 if (this._editor && this._editor.element.parentElement) | 250 if (this._editor && this._editor.element.parentElement) |
| 245 this._editor.element.remove(); | 251 this._editor.element.remove(); |
| 246 | 252 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 }, | 407 }, |
| 402 | 408 |
| 403 _cancelClicked: function() | 409 _cancelClicked: function() |
| 404 { | 410 { |
| 405 var cancel = this._cancel; | 411 var cancel = this._cancel; |
| 406 this._commit = null; | 412 this._commit = null; |
| 407 this._cancel = null; | 413 this._cancel = null; |
| 408 cancel(); | 414 cancel(); |
| 409 } | 415 } |
| 410 } | 416 } |
| OLD | NEW |