Changeset 106238 in webkit


Ignore:
Timestamp:
Jan 30, 2012 5:10:24 AM (12 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: TabbedEditorContainer should save open tabs.
https://bugs.webkit.org/show_bug.cgi?id=76912

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/tabbed-editors-history.html

  • inspector/front-end/ScriptsPanel.js:

(WebInspector.ScriptsPanel.prototype._uiSourceCodeAdded):
(WebInspector.ScriptsPanel.prototype._reset):
(WebInspector.ScriptsPanel.prototype._showFile):
(WebInspector.ScriptsPanel.prototype._updateExecutionLine):
(WebInspector.ScriptsPanel.prototype._editorSelected):
(WebInspector.EditorContainer.prototype.uiSourceCodeAdded):
(WebInspector.ScriptsPanel.SingleFileEditorContainer.prototype.showFile):
(WebInspector.ScriptsPanel.SingleFileEditorContainer.prototype.reset):

  • inspector/front-end/TabbedEditorContainer.js:

(WebInspector.TabbedEditorContainer):
(WebInspector.TabbedEditorContainer.prototype.showFile):
(WebInspector.TabbedEditorContainer.prototype._editorClosedByUserAction):
(WebInspector.TabbedEditorContainer.prototype._editorSelectedByUserAction):
(WebInspector.TabbedEditorContainer.prototype._updateHistory.tabIdToURL):
(WebInspector.TabbedEditorContainer.prototype._updateHistory):
(WebInspector.TabbedEditorContainer.prototype._appendFileTab):
(WebInspector.TabbedEditorContainer.prototype._tabClosed):
(WebInspector.TabbedEditorContainer.prototype._tabSelected):
(WebInspector.TabbedEditorContainer.prototype.reset):
(WebInspector.TabbedEditorContainer.History):
(WebInspector.TabbedEditorContainer.History.prototype.index):
(WebInspector.TabbedEditorContainer.History.prototype.update):
(WebInspector.TabbedEditorContainer.History.prototype.remove):
(WebInspector.TabbedEditorContainer.History.prototype.save):

  • inspector/front-end/TabbedPane.js:

(WebInspector.TabbedPane.prototype.appendTab):
(WebInspector.TabbedPane.prototype.closeTab):
(WebInspector.TabbedPane.prototype._innerCloseTab):
(WebInspector.TabbedPane.prototype.closeAllTabs):
(WebInspector.TabbedPane.prototype.lastOpenedTabIds):
(WebInspector.TabbedPane.prototype._tabsSelectChanged):

LayoutTests:

  • inspector/tabbed-editors-history-expected.txt: Added.
  • inspector/tabbed-editors-history.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106237 r106238  
     12012-01-27  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: TabbedEditorContainer should save open tabs.
     4        https://bugs.webkit.org/show_bug.cgi?id=76912
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/tabbed-editors-history-expected.txt: Added.
     9        * inspector/tabbed-editors-history.html: Added.
     10
    1112012-01-30  Alexander Pavlov  <apavlov@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r106237 r106238  
     12012-01-27  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: TabbedEditorContainer should save open tabs.
     4        https://bugs.webkit.org/show_bug.cgi?id=76912
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Test: inspector/tabbed-editors-history.html
     9
     10        * inspector/front-end/ScriptsPanel.js:
     11        (WebInspector.ScriptsPanel.prototype._uiSourceCodeAdded):
     12        (WebInspector.ScriptsPanel.prototype._reset):
     13        (WebInspector.ScriptsPanel.prototype._showFile):
     14        (WebInspector.ScriptsPanel.prototype._updateExecutionLine):
     15        (WebInspector.ScriptsPanel.prototype._editorSelected):
     16        (WebInspector.EditorContainer.prototype.uiSourceCodeAdded):
     17        (WebInspector.ScriptsPanel.SingleFileEditorContainer.prototype.showFile):
     18        (WebInspector.ScriptsPanel.SingleFileEditorContainer.prototype.reset):
     19        * inspector/front-end/TabbedEditorContainer.js:
     20        (WebInspector.TabbedEditorContainer):
     21        (WebInspector.TabbedEditorContainer.prototype.showFile):
     22        (WebInspector.TabbedEditorContainer.prototype._editorClosedByUserAction):
     23        (WebInspector.TabbedEditorContainer.prototype._editorSelectedByUserAction):
     24        (WebInspector.TabbedEditorContainer.prototype._updateHistory.tabIdToURL):
     25        (WebInspector.TabbedEditorContainer.prototype._updateHistory):
     26        (WebInspector.TabbedEditorContainer.prototype._appendFileTab):
     27        (WebInspector.TabbedEditorContainer.prototype._tabClosed):
     28        (WebInspector.TabbedEditorContainer.prototype._tabSelected):
     29        (WebInspector.TabbedEditorContainer.prototype.reset):
     30        (WebInspector.TabbedEditorContainer.History):
     31        (WebInspector.TabbedEditorContainer.History.prototype.index):
     32        (WebInspector.TabbedEditorContainer.History.prototype.update):
     33        (WebInspector.TabbedEditorContainer.History.prototype.remove):
     34        (WebInspector.TabbedEditorContainer.History.prototype.save):
     35        * inspector/front-end/TabbedPane.js:
     36        (WebInspector.TabbedPane.prototype.appendTab):
     37        (WebInspector.TabbedPane.prototype.closeTab):
     38        (WebInspector.TabbedPane.prototype._innerCloseTab):
     39        (WebInspector.TabbedPane.prototype.closeAllTabs):
     40        (WebInspector.TabbedPane.prototype.lastOpenedTabIds):
     41        (WebInspector.TabbedPane.prototype._tabsSelectChanged):
     42
    1432012-01-30  Alexander Pavlov  <apavlov@chromium.org>
    244
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r106236 r106238  
    257257        }
    258258        this._fileSelector.addUISourceCode(uiSourceCode);
    259 
    260         var lastViewedURL = WebInspector.settings.lastViewedScriptFile.get();
    261         if (!this._initialViewSelectionProcessed) {
    262             this._initialViewSelectionProcessed = true;
    263             // Option we just added is the only option in files select.
    264             // We have to show corresponding source frame immediately.
    265             this._showFile(uiSourceCode);
    266             // Restore original value of lastViewedScriptFile because
    267             // source frame was shown as a result of initial load.
    268             WebInspector.settings.lastViewedScriptFile.set(lastViewedURL);
    269         } else if (uiSourceCode.url === lastViewedURL)
    270             this._showFile(uiSourceCode);
     259        this._editorContainer.uiSourceCodeAdded(uiSourceCode);
    271260    },
    272261
     
    416405        this._debuggerResumed();
    417406
    418         delete this._initialViewSelectionProcessed;
    419407        delete this._curentUISourceCode;
    420        
    421408        this._editorContainer.reset();
    422409        this._updateScriptViewStatusBarItems();
     
    487474        if (!this._fileSelector.isScriptSourceAdded(uiSourceCode))
    488475            return null;
    489        
     476
    490477        var sourceFrame = this._getOrCreateSourceFrame(uiSourceCode);
    491478        if (this._curentUISourceCode === uiSourceCode)
     
    496483        this._editorContainer.showFile(uiSourceCode);
    497484        this._updateScriptViewStatusBarItems();
    498 
    499         if (uiSourceCode.url)
    500             WebInspector.settings.lastViewedScriptFile.set(uiSourceCode.url);
    501485
    502486        return sourceFrame;
     
    618602        // Anonymous scripts are not added to files select by default.
    619603        this._fileSelector.addUISourceCode(uiLocation.uiSourceCode);
    620        
     604
    621605        var sourceFrame = this._showFile(uiLocation.uiSourceCode);
    622606        sourceFrame.setExecutionLine(uiLocation.lineNumber);
     
    11111095     */
    11121096    setFileIsDirty: function(uiSourceCode, isDirty) { },
     1097
     1098    /**
     1099     * @param {WebInspector.UISourceCode} uiSourceCode
     1100     */
     1101    uiSourceCodeAdded: function(uiSourceCode) { },
    11131102
    11141103    /**
     
    15301519            return;
    15311520
     1521        this._innerShowFile(uiSourceCode, true);
     1522    },
     1523
     1524    /**
     1525     * @param {WebInspector.UISourceCode} uiSourceCode
     1526     * @param {boolean} userGesture
     1527     */
     1528    _innerShowFile: function(uiSourceCode, userGesture)
     1529    {
    15321530        if (this._currentSourceFrame)
    15331531            this._currentSourceFrame.detach();
    15341532
     1533        this._initialViewSelectionProcessed = true;
     1534       
     1535        var sourceFrame = this._delegate.viewForFile(uiSourceCode);
    15351536        this._currentSourceFrame = sourceFrame;
    15361537        this._currentFile = uiSourceCode;
     1538       
     1539        if (userGesture) {
     1540            this._userSelectedFiles = true;
     1541            WebInspector.settings.lastViewedScriptFile.set(uiSourceCode.url);
     1542        }
    15371543
    15381544        if (sourceFrame)
    15391545            sourceFrame.show(this.element);
     1546        this.dispatchEventToListeners(WebInspector.EditorContainer.Events.EditorSelected, uiSourceCode);
     1547    },
     1548
     1549    /**
     1550     * @param {WebInspector.UISourceCode} uiSourceCode
     1551     */
     1552    uiSourceCodeAdded: function(uiSourceCode)
     1553    {
     1554        var lastViewedURL = WebInspector.settings.lastViewedScriptFile.get();
     1555        // Show first file that was added or file with the last viewed url.
     1556        if (this._userSelectedFiles)
     1557            return;
     1558        if (uiSourceCode.url === lastViewedURL || !this._initialViewSelectionProcessed)
     1559            this._innerShowFile(uiSourceCode, false);
    15401560    },
    15411561
     
    15651585        this._currentSourceFrame = null;
    15661586        this._currentFile = null;
     1587        delete this._initialViewSelectionProcessed;
     1588        delete this._userSelectedFiles;
    15671589    }
    15681590}
  • trunk/Source/WebCore/inspector/front-end/TabbedEditorContainer.js

    r106112 r106238  
    4444    this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
    4545
    46     this._tabIds = new Map(); 
     46    this._tabIds = new Map();
    4747    this._files = {};
     48    this._loadedURLs = {};
     49
     50    this._previouslyViewedFilesSetting = WebInspector.settings.createSetting("previouslyViewedFiles", []);
     51    this._history = new WebInspector.TabbedEditorContainer.History(this._previouslyViewedFilesSetting.get());
    4852}
    4953
    5054WebInspector.TabbedEditorContainer._tabId = 0;
    5155
     56WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount = 30;
     57
    5258WebInspector.TabbedEditorContainer.prototype = {
    5359    /**
     
    7278    showFile: function(uiSourceCode)
    7379    {
     80        this._innerShowFile(uiSourceCode, true);
     81    },
     82
     83    /**
     84     * @param {WebInspector.UISourceCode} uiSourceCode
     85     * @param {boolean=} userGesture
     86     */
     87    _innerShowFile: function(uiSourceCode, userGesture)
     88    {
    7489        if (this._currentFile === uiSourceCode)
    7590            return;
    76        
    7791        this._currentFile = uiSourceCode;
    78         var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode);
    79         this._tabbedPane.selectTab(tabId);
     92       
     93        var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, userGesture);
     94       
     95        this._tabbedPane.selectTab(tabId, userGesture);
     96        if (userGesture)
     97            this._editorSelectedByUserAction();
     98       
     99        this.dispatchEventToListeners(WebInspector.EditorContainer.Events.EditorSelected, this._currentFile);
    80100    },
    81101
     
    91111    /**
    92112     * @param {WebInspector.UISourceCode} uiSourceCode
     113     */
     114    uiSourceCodeAdded: function(uiSourceCode)
     115    {
     116        if (this._userSelectedFiles || this._loadedURLs[uiSourceCode.url])
     117            return;
     118        this._loadedURLs[uiSourceCode.url] = true;
     119
     120        var index = this._history.index(uiSourceCode.url)
     121        if (index === -1)
     122            return;
     123
     124        var tabId = this._tabIds.get(uiSourceCode) || this._appendFileTab(uiSourceCode, false);
     125
     126        // Select tab if this file was the last to be shown.
     127        if (index === 0)
     128            this._innerShowFile(uiSourceCode, false);
     129    },
     130   
     131    /**
     132     * @param {WebInspector.UISourceCode} uiSourceCode
     133     */
     134    _editorClosedByUserAction: function(uiSourceCode)
     135    {
     136        this._userSelectedFiles = true;
     137        this._history.remove(uiSourceCode.url);
     138        this._updateHistory();
     139    },
     140
     141    _editorSelectedByUserAction: function()
     142    {
     143        this._userSelectedFiles = true;
     144        this._updateHistory();
     145    },
     146
     147    _updateHistory: function()
     148    {
     149        var tabIds = this._tabbedPane.lastOpenedTabIds(WebInspector.TabbedEditorContainer.maximalPreviouslyViewedFilesCount);
     150       
     151        function tabIdToURL(tabId)
     152        {
     153            return this._files[tabId].url;
     154        }
     155       
     156        this._history.update(tabIds.map(tabIdToURL.bind(this)));
     157        this._history.save(this._previouslyViewedFilesSetting);
     158    },
     159
     160    /**
     161     * @param {WebInspector.UISourceCode} uiSourceCode
    93162     * @return {string}
    94163     */
     
    100169    /**
    101170     * @param {WebInspector.UISourceCode} uiSourceCode
    102      */
    103     _appendFileTab: function(uiSourceCode)
     171     * @param {boolean=} userGesture
     172     */
     173    _appendFileTab: function(uiSourceCode, userGesture)
    104174    {
    105175        var view = this._delegate.viewForFile(uiSourceCode);
     
    111181        this._files[tabId] = uiSourceCode;
    112182       
    113         this._tabbedPane.appendTab(tabId, title, view, tooltip);
     183        this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture);
    114184        return tabId;
    115185    },
     
    132202    {
    133203        var tabId = /** @type {string} */ event.data.tabId;
     204        var userGesture = /** @type {boolean} */ event.data.isUserGesture;
    134205
    135206        var uiSourceCode = this._files[tabId];
     
    137208        delete this._files[tabId];
    138209
    139         this.dispatchEventToListeners(WebInspector.ScriptsPanel.EditorContainer.Events.EditorClosed, uiSourceCode);
     210        this.dispatchEventToListeners(WebInspector.EditorContainer.Events.EditorClosed, uiSourceCode);
     211
     212        if (userGesture)
     213            this._editorClosedByUserAction(uiSourceCode);
    140214    },
    141215
     
    146220    {
    147221        var tabId = /** @type {string} */ event.data.tabId;
     222        var userGesture = /** @type {boolean} */ event.data.isUserGesture;
     223
    148224        var uiSourceCode = this._files[tabId];
    149        
    150         if (this._currentFile === uiSourceCode)
    151             return;
    152         this.dispatchEventToListeners(WebInspector.EditorContainer.Events.EditorSelected, uiSourceCode);
     225        this._innerShowFile(uiSourceCode, userGesture);
    153226    },
    154227
     
    218291        this._files = {};
    219292        delete this._currentFile;
     293        delete this._userSelectedFiles;
     294        this._loadedURLs = {};
    220295    },
    221296
     
    230305
    231306WebInspector.TabbedEditorContainer.prototype.__proto__ = WebInspector.Object.prototype;
     307
     308/**
     309 * @constructor
     310 */
     311WebInspector.TabbedEditorContainer.History = function(urls)
     312{
     313    this._urls = urls;
     314}
     315
     316WebInspector.TabbedEditorContainer.History.prototype = {
     317    /**
     318     * @param {string} url
     319     */
     320    index: function(url)
     321    {
     322        return this._urls.indexOf(url);
     323    },
     324
     325    /**
     326     * @param {Array.<string>} urls
     327     */
     328    update: function(urls)
     329    {
     330        for (var i = urls.length - 1; i >= 0; --i) {
     331            var index = this._urls.indexOf(urls[i]);
     332            if (index !== -1)
     333                this._urls.splice(index, 1);
     334            this._urls.unshift(urls[i]);
     335        }
     336    },
     337
     338    /**
     339     * @param {string} url
     340     */
     341    remove: function(url)
     342    {
     343        var index = this._urls.indexOf(url);
     344        if (index !== -1)
     345            this._urls.splice(index, 1);
     346    },
     347   
     348    /**
     349     * @param {WebInspector.Setting} setting
     350     */
     351    save: function(setting)
     352    {
     353        setting.set(this._urls);
     354    }
     355}
     356
     357WebInspector.TabbedEditorContainer.History.prototype.__proto__ = WebInspector.Object.prototype;
  • trunk/Source/WebCore/inspector/front-end/TabbedPane.js

    r105748 r106238  
    9292     * @param {WebInspector.View} view
    9393     * @param {string=} tabTooltip
    94      */
    95     appendTab: function(id, tabTitle, view, tabTooltip)
     94     * @param {boolean=} userGesture
     95     */
     96    appendTab: function(id, tabTitle, view, tabTooltip, userGesture)
    9697    {
    9798        var tab = new WebInspector.TabbedPaneTab(this, this._tabsElement, id, tabTitle, this._closeableTabs, view, tabTooltip);
     99        this._tabsById[id] = tab;
    98100
    99101        this._tabs.push(tab);
    100         this._tabsById[id] = tab;
    101102        this._tabsHistory.push(tab);
     103
     104        if (this._tabsHistory[0] === tab)
     105            this.selectTab(tab.id, userGesture);
     106
    102107        this._updateTabElements();
    103108    },
     
    108113     */
    109114    closeTab: function(id, userGesture)
     115    {
     116        this._innerCloseTab(id, userGesture);
     117
     118        if (this._tabsHistory.length)
     119            this.selectTab(this._tabsHistory[0].id, userGesture);
     120        else
     121            this._updateTabElements();
     122    },
     123
     124    /**
     125     * @param {string} id
     126     * @param {boolean=} userGesture
     127     */
     128    _innerCloseTab: function(id, userGesture)
    110129    {
    111130        if (this._currentTab && this._currentTab.id === id)
     
    120139            this._hideTabElement(tab);
    121140
    122         if (this._tabsHistory.length)
    123             this.selectTab(this._tabsHistory[0].id);
    124         else
    125             this._updateTabElements();
    126 
    127141        var eventData = { tabId: id, view: tab.view, isUserGesture: userGesture };
    128142        this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabClosed, eventData);
     
    130144    },
    131145
    132     closeAllTabs: function()
     146    /**
     147     * @param {boolean=} userGesture
     148     */
     149    closeAllTabs: function(userGesture)
    133150    {
    134151        var tabs = this._tabs.slice();
    135152        for (var i = 0; i < tabs.length; ++i)
    136             this.closeTab(tabs[i].id, false);
     153            this._innerCloseTab(tabs[i].id, userGesture);
     154        this._updateTabElements();
    137155    },
    138156
     
    161179        this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabSelected, eventData);
    162180        return true;
     181    },
     182
     183    /**
     184     * @param {number} tabsCount
     185     * @return {Array.<string>}
     186     */
     187    lastOpenedTabIds: function(tabsCount)
     188    {
     189        function tabToTabId(tab) {
     190            return tab.id;
     191        }
     192
     193        return this._tabsHistory.slice(0, tabsCount).map(tabToTabId);
    163194    },
    164195
     
    297328        var options = this._tabsSelect.options;
    298329        var selectedOption = options[this._tabsSelect.selectedIndex];
    299         this.selectTab(selectedOption.tab.id);
     330        this.selectTab(selectedOption.tab.id, true);
    300331    },
    301332
Note: See TracChangeset for help on using the changeset viewer.