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").textContent = 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 blurHandler = this._onBlur.bind(this);
49 this._input.addEventListener("blur", blurHandler, false);
52 var go = dialogWindow.createChild("button");
53 go.textContent = WebInspector.UIString("Go");
54 go.addEventListener("click", this._onClick.bind(this), false);
55 go.addEventListener("mousedown", function(e) {
56 // Ok button click will close the dialog, removing onBlur listener
57 // to let click event be handled.
58 this._input.removeEventListener("blur", blurHandler, false);
62 view.element.appendChild(this._element);
64 this._previousFocusElement = WebInspector.currentFocusElement;
65 WebInspector.currentFocusElement = this._input;
69 WebInspector.GoToLineDialog.show = function(sourceView)
71 if (!sourceView || typeof sourceView.highlightLine !== "function")
75 this._instance = new WebInspector.GoToLineDialog(sourceView);
78 WebInspector.GoToLineDialog.createShortcut = function()
80 var isMac = WebInspector.isMac();
83 return WebInspector.KeyboardShortcut.makeDescriptor("l", WebInspector.KeyboardShortcut.Modifiers.Meta);
84 return WebInspector.KeyboardShortcut.makeDescriptor("g", WebInspector.KeyboardShortcut.Modifiers.Ctrl);
87 WebInspector.GoToLineDialog.prototype = {
92 this._isHiding = true;
94 WebInspector.currentFocusElement = this._previousFocusElement;
95 WebInspector.GoToLineDialog._instance = null;
96 this._element.parentElement.removeChild(this._element);
99 _onBlur: function(event)
104 _onKeyDown: function(event)
106 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) {
107 event.preventDefault();
111 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code)
112 this._highlightSelectedLine();
114 if (this._closeKeys.indexOf(event.keyCode) >= 0) {
116 event.preventDefault();
117 event.stopPropagation();
121 _onClick: function(event)
123 this._highlightSelectedLine();
127 _highlightSelectedLine: function()
129 var value = this._input.value;
130 var lineNumber = parseInt(value, 10) - 1;
131 if (!isNaN(lineNumber) && lineNumber >= 0)
132 this._view.highlightLine(lineNumber);