| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * @unrestricted | 27 * @unrestricted |
| 28 */ | 28 */ |
| 29 WebInspector.DatabaseQueryView = class extends WebInspector.VBox { | 29 Resources.DatabaseQueryView = class extends UI.VBox { |
| 30 constructor(database) { | 30 constructor(database) { |
| 31 super(); | 31 super(); |
| 32 | 32 |
| 33 this.database = database; | 33 this.database = database; |
| 34 | 34 |
| 35 this.element.classList.add('storage-view', 'query', 'monospace'); | 35 this.element.classList.add('storage-view', 'query', 'monospace'); |
| 36 this.element.addEventListener('selectstart', this._selectStart.bind(this), f
alse); | 36 this.element.addEventListener('selectstart', this._selectStart.bind(this), f
alse); |
| 37 | 37 |
| 38 this._promptElement = createElement('div'); | 38 this._promptElement = createElement('div'); |
| 39 this._promptElement.className = 'database-query-prompt'; | 39 this._promptElement.className = 'database-query-prompt'; |
| 40 this._promptElement.appendChild(createElement('br')); | 40 this._promptElement.appendChild(createElement('br')); |
| 41 this._promptElement.addEventListener('keydown', this._promptKeyDown.bind(thi
s), true); | 41 this._promptElement.addEventListener('keydown', this._promptKeyDown.bind(thi
s), true); |
| 42 this.element.appendChild(this._promptElement); | 42 this.element.appendChild(this._promptElement); |
| 43 | 43 |
| 44 this._prompt = new WebInspector.TextPrompt(); | 44 this._prompt = new UI.TextPrompt(); |
| 45 this._prompt.initialize(this.completions.bind(this), ' '); | 45 this._prompt.initialize(this.completions.bind(this), ' '); |
| 46 this._proxyElement = this._prompt.attach(this._promptElement); | 46 this._proxyElement = this._prompt.attach(this._promptElement); |
| 47 | 47 |
| 48 this.element.addEventListener('click', this._messagesClicked.bind(this), tru
e); | 48 this.element.addEventListener('click', this._messagesClicked.bind(this), tru
e); |
| 49 } | 49 } |
| 50 | 50 |
| 51 _messagesClicked() { | 51 _messagesClicked() { |
| 52 if (!this._prompt.isCaretInsidePrompt() && this.element.isComponentSelection
Collapsed()) | 52 if (!this._prompt.isCaretInsidePrompt() && this.element.isComponentSelection
Collapsed()) |
| 53 this._prompt.moveCaretToEndOfPrompt(); | 53 this._prompt.moveCaretToEndOfPrompt(); |
| 54 } | 54 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 this.database.getTableNames(tableNamesCallback); | 90 this.database.getTableNames(tableNamesCallback); |
| 91 } | 91 } |
| 92 | 92 |
| 93 _selectStart(event) { | 93 _selectStart(event) { |
| 94 if (this._selectionTimeout) | 94 if (this._selectionTimeout) |
| 95 clearTimeout(this._selectionTimeout); | 95 clearTimeout(this._selectionTimeout); |
| 96 | 96 |
| 97 this._prompt.clearAutocomplete(); | 97 this._prompt.clearAutocomplete(); |
| 98 | 98 |
| 99 /** | 99 /** |
| 100 * @this {WebInspector.DatabaseQueryView} | 100 * @this {Resources.DatabaseQueryView} |
| 101 */ | 101 */ |
| 102 function moveBackIfOutside() { | 102 function moveBackIfOutside() { |
| 103 delete this._selectionTimeout; | 103 delete this._selectionTimeout; |
| 104 if (!this._prompt.isCaretInsidePrompt() && this.element.isComponentSelecti
onCollapsed()) | 104 if (!this._prompt.isCaretInsidePrompt() && this.element.isComponentSelecti
onCollapsed()) |
| 105 this._prompt.moveCaretToEndOfPrompt(); | 105 this._prompt.moveCaretToEndOfPrompt(); |
| 106 this._prompt.autoCompleteSoon(); | 106 this._prompt.autoCompleteSoon(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100); | 109 this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100); |
| 110 } | 110 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 var query = this._prompt.text(); | 124 var query = this._prompt.text(); |
| 125 if (!query.length) | 125 if (!query.length) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 this._prompt.setText(''); | 128 this._prompt.setText(''); |
| 129 | 129 |
| 130 this.database.executeSql(query, this._queryFinished.bind(this, query), this.
_queryError.bind(this, query)); | 130 this.database.executeSql(query, this._queryFinished.bind(this, query), this.
_queryError.bind(this, query)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 _queryFinished(query, columnNames, values) { | 133 _queryFinished(query, columnNames, values) { |
| 134 var dataGrid = WebInspector.SortableDataGrid.create(columnNames, values); | 134 var dataGrid = UI.SortableDataGrid.create(columnNames, values); |
| 135 var trimmedQuery = query.trim(); | 135 var trimmedQuery = query.trim(); |
| 136 | 136 |
| 137 if (dataGrid) { | 137 if (dataGrid) { |
| 138 dataGrid.renderInline(); | 138 dataGrid.renderInline(); |
| 139 this._appendViewQueryResult(trimmedQuery, dataGrid.asWidget()); | 139 this._appendViewQueryResult(trimmedQuery, dataGrid.asWidget()); |
| 140 dataGrid.autoSizeColumns(5); | 140 dataGrid.autoSizeColumns(5); |
| 141 } | 141 } |
| 142 | 142 |
| 143 if (trimmedQuery.match(/^create /i) || trimmedQuery.match(/^drop table /i)) | 143 if (trimmedQuery.match(/^create /i) || trimmedQuery.match(/^drop table /i)) |
| 144 this.dispatchEventToListeners(WebInspector.DatabaseQueryView.Events.Schema
Updated, this.database); | 144 this.dispatchEventToListeners(Resources.DatabaseQueryView.Events.SchemaUpd
ated, this.database); |
| 145 } | 145 } |
| 146 | 146 |
| 147 _queryError(query, errorMessage) { | 147 _queryError(query, errorMessage) { |
| 148 this._appendErrorQueryResult(query, errorMessage); | 148 this._appendErrorQueryResult(query, errorMessage); |
| 149 } | 149 } |
| 150 | 150 |
| 151 /** | 151 /** |
| 152 * @param {string} query | 152 * @param {string} query |
| 153 * @param {!WebInspector.Widget} view | 153 * @param {!UI.Widget} view |
| 154 */ | 154 */ |
| 155 _appendViewQueryResult(query, view) { | 155 _appendViewQueryResult(query, view) { |
| 156 var resultElement = this._appendQueryResult(query); | 156 var resultElement = this._appendQueryResult(query); |
| 157 view.show(resultElement); | 157 view.show(resultElement); |
| 158 this._promptElement.scrollIntoView(false); | 158 this._promptElement.scrollIntoView(false); |
| 159 } | 159 } |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * @param {string} query | 162 * @param {string} query |
| 163 * @param {string} errorText | 163 * @param {string} errorText |
| (...skipping 17 matching lines...) Expand all Loading... |
| 181 element.appendChild(commandTextElement); | 181 element.appendChild(commandTextElement); |
| 182 | 182 |
| 183 var resultElement = createElement('div'); | 183 var resultElement = createElement('div'); |
| 184 resultElement.className = 'database-query-result'; | 184 resultElement.className = 'database-query-result'; |
| 185 element.appendChild(resultElement); | 185 element.appendChild(resultElement); |
| 186 return resultElement; | 186 return resultElement; |
| 187 } | 187 } |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 /** @enum {symbol} */ | 190 /** @enum {symbol} */ |
| 191 WebInspector.DatabaseQueryView.Events = { | 191 Resources.DatabaseQueryView.Events = { |
| 192 SchemaUpdated: Symbol('SchemaUpdated') | 192 SchemaUpdated: Symbol('SchemaUpdated') |
| 193 }; | 193 }; |
| OLD | NEW |