Implements the back and forward buttons in the Scripts panel.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 May 2008 06:06:11 +0000 (06:06 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 31 May 2008 06:06:11 +0000 (06:06 +0000)
        Reviewed by Adam Roben.

        * page/inspector/ScriptsPanel.js:
        (WebInspector.ScriptsPanel): Add the back and forward button elements
        and remove the FIXMEs.
        (WebInspector.ScriptsPanel.prototype.reset): Reset _backForwardList
        and _currentBackForwardIndex. Then call _updateBackAndForwardButtons().
        (WebInspector.ScriptsPanel.prototype._showScriptOrResource):
        Added a fromBackForwardAction argument. If fromBackForwardAction is false
        then update the _currentBackForwardIndex and _backForwardList.
        (WebInspector.ScriptsPanel.prototype._updateBackAndForwardButtons):
        Update the disabled state of the buttons.
        (WebInspector.ScriptsPanel.prototype._goBack): Update the _currentBackForwardIndex
        and call _showScriptOrResource() and _updateBackAndForwardButtons().
        (WebInspector.ScriptsPanel.prototype._goForward): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@34276 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/page/inspector/ScriptsPanel.js

index 711206b..49ee3e9 100644 (file)
@@ -1,5 +1,25 @@
 2008-05-30  Timothy Hatcher  <timothy@apple.com>
 
+        Implements the back and forward buttons in the Scripts panel.
+
+        Reviewed by Adam Roben.
+
+        * page/inspector/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel): Add the back and forward button elements
+        and remove the FIXMEs.
+        (WebInspector.ScriptsPanel.prototype.reset): Reset _backForwardList
+        and _currentBackForwardIndex. Then call _updateBackAndForwardButtons().
+        (WebInspector.ScriptsPanel.prototype._showScriptOrResource):
+        Added a fromBackForwardAction argument. If fromBackForwardAction is false
+        then update the _currentBackForwardIndex and _backForwardList.
+        (WebInspector.ScriptsPanel.prototype._updateBackAndForwardButtons):
+        Update the disabled state of the buttons.
+        (WebInspector.ScriptsPanel.prototype._goBack): Update the _currentBackForwardIndex
+        and call _showScriptOrResource() and _updateBackAndForwardButtons().
+        (WebInspector.ScriptsPanel.prototype._goForward): Ditto.
+
+2008-05-30  Timothy Hatcher  <timothy@apple.com>
+
         Made clicking a Console message URL originating from a JavaScript
         source show the Resource in the Scripts panel. This only happens
         when the debugger is attached.
index 797acf7..e51c52c 100644 (file)
@@ -40,9 +40,8 @@ WebInspector.ScriptsPanel = function()
     this.backButton.title = WebInspector.UIString("Show the previous script resource.");
     this.backButton.disabled = true;
     this.backButton.appendChild(document.createElement("img"));
-
-    // FIXME: append the back button element to the top status bar when it is implemented.
-    // this.topStatusBar.appendChild(this.backButton);
+    this.backButton.addEventListener("click", this._goBack.bind(this), false);
+    this.topStatusBar.appendChild(this.backButton);
 
     this.forwardButton = document.createElement("button");
     this.forwardButton.className = "status-bar-item";
@@ -50,9 +49,8 @@ WebInspector.ScriptsPanel = function()
     this.forwardButton.title = WebInspector.UIString("Show the next script resource.");
     this.forwardButton.disabled = true;
     this.forwardButton.appendChild(document.createElement("img"));
-
-    // FIXME: append the forward button element to the top status bar when it is implemented.
-    // this.topStatusBar.appendChild(this.forwardButton);
+    this.forwardButton.addEventListener("click", this._goForward.bind(this), false);
+    this.topStatusBar.appendChild(this.forwardButton);
 
     this.filesSelectElement = document.createElement("select");
     this.filesSelectElement.className = "status-bar-item";
@@ -330,6 +328,10 @@ WebInspector.ScriptsPanel.prototype = {
 
         this._clearInterface();
 
+        this._backForwardList = [];
+        this._currentBackForwardIndex = -1;
+        this._updateBackAndForwardButtons();
+
         this._scriptsForURLsInFilesSelect = {};
         this.filesSelectElement.removeChildren();
         this.functionsSelectElement.removeChildren();
@@ -411,7 +413,7 @@ WebInspector.ScriptsPanel.prototype = {
             return this.sourceFrameForScript(scriptOrResource);
     },
 
-    _showScriptOrResource: function(scriptOrResource, line)
+    _showScriptOrResource: function(scriptOrResource, line, fromBackForwardAction)
     {
         if (!scriptOrResource)
             return;
@@ -436,6 +438,25 @@ WebInspector.ScriptsPanel.prototype = {
         if (!view)
             return;
 
+        if (!fromBackForwardAction) {
+            var oldIndex = this._currentBackForwardIndex;
+            if (oldIndex >= 0)
+                this._backForwardList.splice(oldIndex + 1, this._backForwardList.length - oldIndex);
+
+            // Check for a previous entry of the same object in _backForwardList.
+            // If one is found, remove it and update _currentBackForwardIndex to match.
+            var previousEntryIndex = this._backForwardList.indexOf(scriptOrResource);
+            if (previousEntryIndex !== -1) {
+                this._backForwardList.splice(previousEntryIndex, 1);
+                --this._currentBackForwardIndex;
+            }
+
+            this._backForwardList.push(scriptOrResource);
+            ++this._currentBackForwardIndex;
+
+            this._updateBackAndForwardButtons();
+        }
+
         this.visibleView = view;
 
         if (line) {
@@ -602,6 +623,12 @@ WebInspector.ScriptsPanel.prototype = {
         }
     },
 
+    _updateBackAndForwardButtons: function()
+    {
+        this.backButton.disabled = this._currentBackForwardIndex <= 0;
+        this.forwardButton.disabled = this._currentBackForwardIndex >= (this._backForwardList.length - 1);
+    },
+
     _clearInterface: function()
     {
         this.sidebarPanes.callstack.update(null);
@@ -611,6 +638,28 @@ WebInspector.ScriptsPanel.prototype = {
         this._updateDebuggerButtons();
     },
 
+    _goBack: function()
+    {
+        if (this._currentBackForwardIndex <= 0) {
+            console.error("Can't go back from index " + this._currentBackForwardIndex);
+            return;
+        }
+
+        this._showScriptOrResource(this._backForwardList[--this._currentBackForwardIndex], null, true);
+        this._updateBackAndForwardButtons();
+    },
+
+    _goForward: function()
+    {
+        if (this._currentBackForwardIndex >= this._backForwardList.length - 1) {
+            console.error("Can't go forward from index " + this._currentBackForwardIndex);
+            return;
+        }
+
+        this._showScriptOrResource(this._backForwardList[++this._currentBackForwardIndex], null, true);
+        this._updateBackAndForwardButtons();
+    },
+
     _toggleDebugging: function()
     {
         this._paused = false;