WebInspector.InspectorView = function()
{
WebInspector.View.call(this);
this.markAsRoot();
this.element.id = "main-panels";
this.element.setAttribute("spellcheck", false);
this._history = [];
this._historyIterator = -1;
document.addEventListener("keydown", this._keyDown.bind(this), false);
this._panelOrder = [];
}
WebInspector.InspectorView.Events = {
PanelSelected: "panel-selected"
}
WebInspector.InspectorView.prototype = {
addPanel: function(panel)
{
this._panelOrder.push(panel);
WebInspector.toolbar.addPanel(panel);
},
currentPanel: function()
{
return this._currentPanel;
},
setCurrentPanel: function(x)
{
if (this._currentPanel === x)
return;
if (this._currentPanel)
this._currentPanel.detach();
this._currentPanel = x;
if (x) {
x.show();
this.dispatchEventToListeners(WebInspector.InspectorView.Events.PanelSelected);
WebInspector.searchController.activePanelChanged();
}
for (var panelName in WebInspector.panels) {
if (WebInspector.panels[panelName] === x) {
WebInspector.settings.lastActivePanel.set(panelName);
this._pushToHistory(panelName);
WebInspector.userMetrics.panelShown(panelName);
}
}
},
_keyDown: function(event)
{
switch (event.keyIdentifier) {
case "U+005B":
case "U+00DB": var isRotateLeft = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !event.shiftKey && !event.altKey;
if (isRotateLeft) {
var index = this._panelOrder.indexOf(this.currentPanel());
index = (index === 0) ? this._panelOrder.length - 1 : index - 1;
this._panelOrder[index].toolbarItem.click();
event.consume();
return;
}
var isGoBack = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && event.altKey;
if (isGoBack && this._canGoBackInHistory()) {
this._goBackInHistory();
event.consume();
}
break;
case "U+005D":
case "U+00DD": var isRotateRight = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !event.shiftKey && !event.altKey;
if (isRotateRight) {
var index = this._panelOrder.indexOf(this.currentPanel());
index = (index + 1) % this._panelOrder.length;
this._panelOrder[index].toolbarItem.click();
event.consume();
return;
}
var isGoForward = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && event.altKey;
if (isGoForward && this._canGoForwardInHistory()) {
this._goForwardInHistory();
event.consume();
}
break;
}
},
_canGoBackInHistory: function()
{
return this._historyIterator > 0;
},
_goBackInHistory: function()
{
this._inHistory = true;
this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIterator]]);
delete this._inHistory;
},
_canGoForwardInHistory: function()
{
return this._historyIterator < this._history.length - 1;
},
_goForwardInHistory: function()
{
this._inHistory = true;
this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIterator]]);
delete this._inHistory;
},
_pushToHistory: function(panelName)
{
if (this._inHistory)
return;
this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
if (!this._history.length || this._history[this._history.length - 1] !== panelName)
this._history.push(panelName);
this._historyIterator = this._history.length - 1;
}
}
WebInspector.InspectorView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.inspectorView = null;