| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Nokia Inc. All Rights Reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 WebInspector.DOMStorageDataGrid = function(columns, domStorage, keys) | |
| 27 { | |
| 28 WebInspector.DataGrid.call(this, columns); | |
| 29 this.dataTableBody.addEventListener("dblclick", this._ondblclick.bind(this),
false); | |
| 30 this._domStorage = domStorage; | |
| 31 this._keys = keys; | |
| 32 } | |
| 33 | |
| 34 WebInspector.DOMStorageDataGrid.prototype = { | |
| 35 _ondblclick: function(event) | |
| 36 { | |
| 37 if (this._editing) | |
| 38 return; | |
| 39 if (this._editingNode) | |
| 40 return; | |
| 41 this._startEditing(event); | |
| 42 }, | |
| 43 | |
| 44 _startEditingColumnOfDataGridNode: function(node, column) | |
| 45 { | |
| 46 this._editing = true; | |
| 47 this._editingNode = node; | |
| 48 this._editingNode.select(); | |
| 49 | |
| 50 var element = this._editingNode._element.children[column]; | |
| 51 WebInspector.startEditing(element, this._editingCommitted.bind(this), th
is._editingCancelled.bind(this), element.textContent); | |
| 52 window.getSelection().setBaseAndExtent(element, 0, element, 1); | |
| 53 }, | |
| 54 | |
| 55 _startEditing: function(event) | |
| 56 { | |
| 57 var element = event.target.enclosingNodeOrSelfWithNodeName("td"); | |
| 58 if (!element) | |
| 59 return; | |
| 60 | |
| 61 this._editingNode = this.dataGridNodeFromEvent(event); | |
| 62 if (!this._editingNode) { | |
| 63 if (!this.creationNode) | |
| 64 return; | |
| 65 this._editingNode = this.creationNode; | |
| 66 } | |
| 67 | |
| 68 // Force editing the "Key" column when editing the creation node | |
| 69 if (this._editingNode.isCreationNode) | |
| 70 return this._startEditingColumnOfDataGridNode(this._editingNode, 0); | |
| 71 | |
| 72 this._editing = true; | |
| 73 WebInspector.startEditing(element, this._editingCommitted.bind(this), th
is._editingCancelled.bind(this), element.textContent); | |
| 74 window.getSelection().setBaseAndExtent(element, 0, element, 1); | |
| 75 }, | |
| 76 | |
| 77 _editingCommitted: function(element, newText, oldText, context, moveDirectio
n) | |
| 78 { | |
| 79 var columnIdentifier = (element.hasStyleClass("0-column") ? 0 : 1); | |
| 80 var textBeforeEditing = this._editingNode.data[columnIdentifier]; | |
| 81 var currentEditingNode = this._editingNode; | |
| 82 | |
| 83 function moveToNextIfNeeded(wasChange) { | |
| 84 if (!moveDirection) | |
| 85 return; | |
| 86 | |
| 87 if (moveDirection === "forward") { | |
| 88 if (currentEditingNode.isCreationNode && columnIdentifier === 0
&& !wasChange) | |
| 89 return; | |
| 90 | |
| 91 if (columnIdentifier === 0) | |
| 92 return this._startEditingColumnOfDataGridNode(currentEditing
Node, 1); | |
| 93 | |
| 94 var nextDataGridNode = currentEditingNode.traverseNextNode(true,
null, true); | |
| 95 if (nextDataGridNode) | |
| 96 return this._startEditingColumnOfDataGridNode(nextDataGridNo
de, 0); | |
| 97 if (currentEditingNode.isCreationNode && wasChange) { | |
| 98 addCreationNode(false); | |
| 99 return this._startEditingColumnOfDataGridNode(this.creationN
ode, 0); | |
| 100 } | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 if (moveDirection === "backward") { | |
| 105 if (columnIdentifier === 1) | |
| 106 return this._startEditingColumnOfDataGridNode(currentEditing
Node, 0); | |
| 107 var nextDataGridNode = currentEditingNode.traversePreviousNo
de(true, null, true); | |
| 108 | |
| 109 if (nextDataGridNode) | |
| 110 return this._startEditingColumnOfDataGridNode(nextDataGridNo
de, 1); | |
| 111 return; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 if (textBeforeEditing == newText) { | |
| 116 this._editingCancelled(element); | |
| 117 moveToNextIfNeeded.call(this, false); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 var domStorage = this._domStorage; | |
| 122 if (columnIdentifier === 0) { | |
| 123 if (this._keys.indexOf(newText) !== -1) { | |
| 124 element.textContent = this._editingNode.data[0]; | |
| 125 this._editingCancelled(element); | |
| 126 moveToNextIfNeeded.call(this, false); | |
| 127 return; | |
| 128 } | |
| 129 domStorage.removeItem(this._editingNode.data[0]); | |
| 130 domStorage.setItem(newText, this._editingNode.data[1]); | |
| 131 this._editingNode.data[0] = newText; | |
| 132 } else { | |
| 133 domStorage.setItem(this._editingNode.data[0], newText); | |
| 134 this._editingNode.data[1] = newText; | |
| 135 } | |
| 136 | |
| 137 if (this._editingNode.isCreationNode) | |
| 138 this.addCreationNode(false); | |
| 139 | |
| 140 this._editingCancelled(element); | |
| 141 moveToNextIfNeeded.call(this, true); | |
| 142 }, | |
| 143 | |
| 144 _editingCancelled: function(element, context) | |
| 145 { | |
| 146 delete this._editing; | |
| 147 this._editingNode = null; | |
| 148 }, | |
| 149 | |
| 150 deleteSelectedRow: function() | |
| 151 { | |
| 152 var node = this.selectedNode; | |
| 153 if (!node || node.isCreationNode) | |
| 154 return; | |
| 155 | |
| 156 if (this._domStorage) | |
| 157 this._domStorage.removeItem(node.data[0]); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 WebInspector.DOMStorageDataGrid.prototype.__proto__ = WebInspector.DataGrid.prot
otype; | |
| OLD | NEW |