2 * Copyright (C) 2009 Joseph Pecoraro
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * @extends {WebInspector.Panel}
33 WebInspector.ConsolePanel = function()
35 WebInspector.Panel.call(this, "console");
37 WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.EntryAdded, this._consoleMessageAdded, this);
38 WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.ConsoleCleared, this._consoleCleared, this);
39 this._view = WebInspector.consoleView;
42 WebInspector.ConsolePanel.prototype = {
43 get toolbarItemLabel()
45 return WebInspector.UIString("Console");
50 return this._view.statusBarItems;
55 WebInspector.Panel.prototype.wasShown.call(this);
56 if (WebInspector.drawer.visible) {
57 WebInspector.drawer.hide(WebInspector.Drawer.AnimationType.Immediately);
58 this._drawerWasVisible = true;
60 this._view.show(this.element);
65 if (this._drawerWasVisible) {
66 WebInspector.drawer.show(this._view, WebInspector.Drawer.AnimationType.Immediately);
67 delete this._drawerWasVisible;
69 WebInspector.Panel.prototype.willHide.call(this);
72 searchCanceled: function()
74 this._clearCurrentSearchResultHighlight();
75 delete this._searchResults;
76 delete this._searchRegex;
79 performSearch: function(query)
81 WebInspector.searchController.updateSearchMatchesCount(0, this);
82 this.searchCanceled();
83 this._searchRegex = createPlainTextSearchRegex(query, "gi");
85 this._searchResults = [];
86 var messages = WebInspector.consoleView.messages;
87 for (var i = 0; i < messages.length; i++) {
88 if (messages[i].matchesRegex(this._searchRegex)) {
89 this._searchResults.push(messages[i]);
90 this._searchRegex.lastIndex = 0;
93 WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
94 this._currentSearchResultIndex = -1;
95 if (this._searchResults.length)
96 this._jumpToSearchResult(0);
99 jumpToNextSearchResult: function()
101 if (!this._searchResults || !this._searchResults.length)
103 this._jumpToSearchResult((this._currentSearchResultIndex + 1) % this._searchResults.length);
106 jumpToPreviousSearchResult: function()
108 if (!this._searchResults || !this._searchResults.length)
110 var index = this._currentSearchResultIndex - 1;
112 index = this._searchResults.length - 1;
113 this._jumpToSearchResult(index);
116 _clearCurrentSearchResultHighlight: function()
118 if (!this._searchResults)
120 var highlightedMessage = this._searchResults[this._currentSearchResultIndex];
121 if (highlightedMessage)
122 highlightedMessage.clearHighlight();
123 this._currentSearchResultIndex = -1;
126 _jumpToSearchResult: function(index)
128 this._clearCurrentSearchResultHighlight();
129 this._currentSearchResultIndex = index;
130 this._searchResults[index].highlightSearchResults(this._searchRegex);
133 _consoleMessageAdded: function(event)
135 if (!this._searchRegex || !this.isShowing())
137 var message = event.data;
138 this._searchRegex.lastIndex = 0;
139 if (message.matchesRegex(this._searchRegex)) {
140 this._searchResults.push(message);
141 WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
145 _consoleCleared: function()
147 if (!this._searchResults)
149 this._clearCurrentSearchResultHighlight();
150 this._searchResults.length = 0;
151 if (this.isShowing())
152 WebInspector.searchController.updateSearchMatchesCount(0, this);
156 WebInspector.ConsolePanel.prototype.__proto__ = WebInspector.Panel.prototype;