2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 WebInspector.GoToLineDialog = function(view)
33 this._element = document.createElement("div");
34 this._element.className = "go-to-line-dialog";
35 this._element.addEventListener("keydown", this._onKeyDown.bind(this), false);
37 WebInspector.KeyboardShortcut.Keys.Enter.code,
38 WebInspector.KeyboardShortcut.Keys.Esc.code,
41 var dialogWindow = this._element;
43 dialogWindow.createChild("label").innerText = WebInspector.UIString("Go to line: ");
45 this._input = dialogWindow.createChild("input");
46 this._input.setAttribute("type", "text");
47 this._input.setAttribute("size", 6);
48 var linesCount = view.textModel.linesCount;
50 this._input.setAttribute("title", WebInspector.UIString("1 - %d", linesCount));
51 var blurHandler = this._onBlur.bind(this);
52 this._input.addEventListener("blur", blurHandler, false);
55 var go = dialogWindow.createChild("button");
56 go.innerText = WebInspector.UIString("Go");
57 go.addEventListener("click", this._onClick.bind(this), false);
58 go.addEventListener("mousedown", function(e) {
59 // Ok button click will close the dialog, removing onBlur listener
60 // to let click event be handled.
61 this._input.removeEventListener("blur", blurHandler, false);
65 view.element.appendChild(this._element);
67 this._previousFocusElement = WebInspector.currentFocusElement;
68 WebInspector.currentFocusElement = this._input;
72 WebInspector.GoToLineDialog.show = function(sourceView)
76 this._instance = new WebInspector.GoToLineDialog(sourceView);
79 WebInspector.GoToLineDialog.prototype = {
84 this._isHiding = true;
86 WebInspector.currentFocusElement = this._previousFocusElement;
87 WebInspector.GoToLineDialog._instance = null;
88 this._element.parentElement.removeChild(this._element);
91 _onBlur: function(event)
96 _onKeyDown: function(event)
98 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) {
99 event.preventDefault();
103 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code)
104 this._highlightSelectedLine();
106 if (this._closeKeys.indexOf(event.keyCode) >= 0) {
108 event.stopPropagation();
112 _onClick: function(event)
114 this._highlightSelectedLine();
118 _highlightSelectedLine: function()
120 var value = this._input.value;
121 var lineNumber = parseInt(value, 10);
122 if (!isNaN(lineNumber) && lineNumber > 0) {
123 lineNumber = Math.min(lineNumber, this._view.textModel.linesCount);
124 this._view.highlightLine(lineNumber);