Web Inspector: Provide UIString descriptions to improve localizations
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / SourcesNavigationSidebarPanel.js
index 011ea52..f393ecc 100644 (file)
@@ -111,11 +111,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         this._pauseReasonLinkContainerElement = document.createElement("span");
         this._pauseReasonTextRow = new WI.DetailsSectionTextRow;
         this._pauseReasonGroup = new WI.DetailsSectionGroup([this._pauseReasonTextRow]);
-        let pauseReasonSection = new WI.DetailsSection("paused-reason", WI.UIString("Pause Reason"), [this._pauseReasonGroup], this._pauseReasonLinkContainerElement);
-
-        this._pauseReasonContainer = document.createElement("div");
-        this._pauseReasonContainer.className = "pause-reason-container";
-        this._pauseReasonContainer.appendChild(pauseReasonSection.element);
+        this._pauseReasonSection = new WI.DetailsSection("paused-reason", WI.UIString("Pause Reason"), [this._pauseReasonGroup], this._pauseReasonLinkContainerElement);
 
         this._callStackTreeOutline = this.createContentTreeOutline({suppressFiltering: true});
         this._callStackTreeOutline.addEventListener(WI.TreeOutline.Event.ElementAdded, this._handleCallStackElementAddedOrRemoved, this);
@@ -126,11 +122,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         callStackRow.element.appendChild(this._callStackTreeOutline.element);
 
         let callStackGroup = new WI.DetailsSectionGroup([callStackRow]);
-        let callStackSection = new WI.DetailsSection("call-stack", WI.UIString("Call Stack"), [callStackGroup]);
-
-        this._callStackContainer = document.createElement("div");
-        this._callStackContainer.className = "call-stack-container";
-        this._callStackContainer.appendChild(callStackSection.element);
+        this._callStackSection = new WI.DetailsSection("call-stack", WI.UIString("Call Stack"), [callStackGroup]);
 
         this._mainTargetTreeElement = null;
         this._activeCallFrameTreeElement = null;
@@ -200,15 +192,12 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         breakpointNavigationBar.addNavigationItem(this._createBreakpointButton);
 
         let breakpointsGroup = new WI.DetailsSectionGroup([breakpointsRow]);
-        let breakpointsSection = new WI.DetailsSection("breakpoints", WI.UIString("Breakpoints"), [breakpointsGroup], breakpointNavigationBarWrapper);
-
-        let breakpointsContainer = this.contentView.element.insertBefore(document.createElement("div"), this.contentView.element.firstChild);
-        breakpointsContainer.classList.add("breakpoints-container");
-        breakpointsContainer.appendChild(breakpointsSection.element);
+        this._breakpointsSection = new WI.DetailsSection("breakpoints", WI.UIString("Breakpoints"), [breakpointsGroup], breakpointNavigationBarWrapper);
+        this.contentView.element.insertBefore(this._breakpointsSection.element, this.contentView.element.firstChild);
 
         this._resourcesNavigationBar = new WI.NavigationBar;
         this.contentView.addSubview(this._resourcesNavigationBar);
-        this.contentView.element.insertBefore(this._resourcesNavigationBar.element, breakpointsSection.nextSibling);
+        this.contentView.element.insertBefore(this._resourcesNavigationBar.element, this._breakpointsSection.element.nextSibling);
 
         this._resourcesNavigationBar.addNavigationItem(new WI.FlexibleSpaceNavigationItem);
 
@@ -233,13 +222,11 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         resourceGroupingModeNavigationItem.element.addEventListener("mousedown", this._handleResourceGroupingModeMouseDown.bind(this));
         this._resourcesNavigationBar.addNavigationItem(resourceGroupingModeNavigationItem);
 
-        let resourcesContainer = this.contentView.element.insertBefore(document.createElement("div"), this._resourcesNavigationBar.element.nextSibling);
-        resourcesContainer.classList.add("resources-container");
-
         this._resourcesTreeOutline = this.contentTreeOutline;
+        this._resourcesTreeOutline.element.classList.add("resources");
         this._resourcesTreeOutline.addEventListener(WI.TreeOutline.Event.SelectionDidChange, this._handleTreeSelectionDidChange, this);
         this._resourcesTreeOutline.includeSourceMapResourceChildren = true;
-        resourcesContainer.appendChild(this._resourcesTreeOutline.element);
+        this.contentView.element.insertBefore(this._resourcesTreeOutline.element, this._resourcesNavigationBar.element.nextSibling);
 
         let onlyShowResourcesWithIssuesFilterFunction = (treeElement) => {
             if (treeElement.treeOutline !== this._resourcesTreeOutline)
@@ -295,8 +282,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         WI.consoleManager.addEventListener(WI.ConsoleManager.Event.IssueAdded, this._handleConsoleIssueAdded, this);
         WI.consoleManager.addEventListener(WI.ConsoleManager.Event.Cleared, this._handleConsoleCleared, this);
 
-        WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingWillStart, this._handleTimelineCapturingWillStart, this);
-        WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStopped, this._handleTimelineCapturingStopped, this);
+        WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, this._handleTimelineCapturingStateChanged, this);
 
         WI.auditManager.addEventListener(WI.AuditManager.Event.TestScheduled, this._handleAuditManagerTestScheduled, this);
         WI.auditManager.addEventListener(WI.AuditManager.Event.TestCompleted, this._handleAuditManagerTestCompleted, this);
@@ -350,8 +336,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
             this._handleDebuggerPaused();
 
         if (WI.debuggerManager.breakpointsDisabledTemporarily) {
-            if (WI.timelineManager.isCapturing())
-                this._handleTimelineCapturingWillStart();
+            this._handleTimelineCapturingStateChanged();
 
             if (WI.auditManager.runningState === WI.AuditManager.RunningState.Active || WI.auditManager.runningState === WI.AuditManager.RunningState.Stopping)
                 this._handleAuditManagerTestScheduled();
@@ -695,15 +680,19 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
                 this._resourcesTreeOutline.insertChild(frameTreeElement, index);
             }
 
+            let resourceTreeElement = null;
+            if (resource instanceof WI.CSSStyleSheet)
+                resourceTreeElement = new WI.CSSStyleSheetTreeElement(resource);
+            else
+                resourceTreeElement = new WI.ResourceTreeElement(resource, resource, {allowDirectoryAsName: true, hideOrigin: true});
+
             let subpath = resource.urlComponents.path;
             if (subpath && subpath[0] === "/")
                 subpath = subpath.substring(1);
 
             let parent = frameTreeElement.createFoldersAsNeededForSubpath(subpath);
-            if (resource instanceof WI.CSSStyleSheet)
-                parent.appendChild(new WI.CSSStyleSheetTreeElement(resource));
-            else
-                parent.appendChild(new WI.ResourceTreeElement(resource, resource, {allowDirectoryAsName: true, hideOrigin: true}));
+            let index = insertionIndexForObjectInListSortedByFunction(resourceTreeElement, parent.children, this._boundCompareTreeElements);
+            parent.insertChild(resourceTreeElement, index);
         }
 
         if (resource.type === WI.Resource.Type.Document || resource.type === WI.Resource.Type.Script) {
@@ -872,6 +861,9 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
     _addBreakpoint(breakpoint)
     {
+        if (this._breakpointsTreeOutline.findTreeElement(breakpoint))
+            return null;
+
         let constructor = WI.BreakpointTreeElement;
         let options = {};
         let parentTreeElement = this._breakpointsTreeOutline;
@@ -884,20 +876,20 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
             let domNodeTreeElement = this._breakpointsTreeOutline.findTreeElement(domNode);
             if (!domNodeTreeElement) {
                 domNodeTreeElement = new WI.DOMNodeTreeElement(domNode);
-                this._insertDebuggerTreeElement(domNodeTreeElement, parentTreeElement);
+                this._insertDebuggerTreeElement(domNodeTreeElement, this._breakpointsTreeOutline);
             }
             return domNodeTreeElement;
         };
 
         if (breakpoint === WI.debuggerManager.allExceptionsBreakpoint) {
             options.className = "breakpoint-exception-icon";
-            options.title = WI.UIString("All Exceptions");
+            options.title = WI.repeatedUIString.allExceptions();
         } else if (breakpoint === WI.debuggerManager.uncaughtExceptionsBreakpoint) {
             options.className = "breakpoint-exception-icon";
-            options.title = WI.UIString("Uncaught Exceptions");
+            options.title = WI.repeatedUIString.uncaughtExceptions();
         } else if (breakpoint === WI.debuggerManager.assertionFailuresBreakpoint) {
             options.className = "breakpoint-assertion-icon";
-            options.title = WI.UIString("Assertion Failures");
+            options.title = WI.repeatedUIString.assertionFailures();
         } else if (breakpoint instanceof WI.DOMBreakpoint) {
             if (!breakpoint.domNodeIdentifier)
                 return null;
@@ -919,7 +911,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
                     if (!eventTargetTreeElement) {
                         const subtitle = null;
                         eventTargetTreeElement = new WI.GeneralTreeElement(["event-target-window"], WI.unlocalizedString("window"), subtitle, SourcesNavigationSidebarPanel.__windowEventTargetRepresentedObject);
-                        this._insertDebuggerTreeElement(eventTargetTreeElement, parentTreeElement);
+                        this._insertDebuggerTreeElement(eventTargetTreeElement, this._breakpointsTreeOutline);
                     }
                 } else if (breakpoint.eventListener.node)
                     eventTargetTreeElement = getDOMNodeTreeElement(breakpoint.eventListener.node);
@@ -931,16 +923,13 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
             if (breakpoint === WI.domDebuggerManager.allRequestsBreakpoint) {
                 options.className = "breakpoint-assertion-icon";
-                options.title = WI.UIString("All Requests");
+                options.title = WI.repeatedUIString.allRequests();
             }
         } else {
             let sourceCode = breakpoint.sourceCodeLocation && breakpoint.sourceCodeLocation.displaySourceCode;
             if (!sourceCode)
                 return null;
 
-            if (this._breakpointsTreeOutline.findTreeElement(breakpoint))
-                return null;
-
             parentTreeElement = this._addDebuggerTreeElementForSourceCode(sourceCode);
 
             // Mark disabled breakpoints as resolved if there is source code loaded with that URL.
@@ -1041,7 +1030,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
     _addBreakpointsForSourceCode(sourceCode)
     {
         for (let breakpoint of WI.debuggerManager.breakpointsForSourceCode(sourceCode))
-            this._addBreakpoint(breakpoint, sourceCode);
+            this._addBreakpoint(breakpoint);
     }
 
     _addIssuesForSourceCode(sourceCode)
@@ -1513,7 +1502,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         if (InspectorBackend.domains.Debugger.setPauseOnAssertions) {
             let assertionFailuresBreakpointShown = WI.settings.showAssertionFailuresBreakpoint.value;
 
-            contextMenu.appendCheckboxItem(WI.UIString("Assertion Failures"), () => {
+            contextMenu.appendCheckboxItem(WI.repeatedUIString.assertionFailures(), () => {
                 if (assertionFailuresBreakpointShown)
                     WI.debuggerManager.removeBreakpoint(WI.debuggerManager.assertionFailuresBreakpoint);
                 else {
@@ -1535,7 +1524,7 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
             let allRequestsBreakpointShown = WI.settings.showAllRequestsBreakpoint.value;
 
-            contextMenu.appendCheckboxItem(WI.UIString("All Requests"), () => {
+            contextMenu.appendCheckboxItem(WI.repeatedUIString.allRequests(), () => {
                 if (allRequestsBreakpointShown)
                     WI.domDebuggerManager.removeURLBreakpoint(WI.domDebuggerManager.allRequestsBreakpoint);
                 else {
@@ -1697,10 +1686,10 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
     _handleDebuggerPaused(event)
     {
-        this.contentView.element.insertBefore(this._callStackContainer, this.contentView.element.firstChild);
+        this.contentView.element.insertBefore(this._callStackSection.element, this.contentView.element.firstChild);
 
         if (this._updatePauseReason())
-            this.contentView.element.insertBefore(this._pauseReasonContainer, this.contentView.element.firstChild);
+            this.contentView.element.insertBefore(this._pauseReasonSection.element, this.contentView.element.firstChild);
 
         this._debuggerPauseResumeButtonItem.enabled = true;
         this._debuggerPauseResumeButtonItem.toggled = true;
@@ -1713,9 +1702,9 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
 
     _handleDebuggerResumed(event)
     {
-        this._callStackContainer.remove();
+        this._callStackSection.element.remove();
 
-        this._pauseReasonContainer.remove();
+        this._pauseReasonSection.element.remove();
 
         this._debuggerPauseResumeButtonItem.enabled = true;
         this._debuggerPauseResumeButtonItem.toggled = false;
@@ -1770,22 +1759,25 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         let newDebuggerTreeElement = null;
         if (debuggerObject instanceof WI.Breakpoint) {
             oldDebuggerTreeElement = this._breakpointsTreeOutline.findTreeElement(debuggerObject);
-            if (oldDebuggerTreeElement) {
-                newDebuggerTreeElement = this._addBreakpoint(debuggerObject);
+            if (oldDebuggerTreeElement)
                 wasSelected = oldDebuggerTreeElement.selected;
-            }
+
+            newDebuggerTreeElement = this._addBreakpoint(debuggerObject);
         } else if (debuggerObject instanceof WI.IssueMessage) {
             oldDebuggerTreeElement = this._resourcesTreeOutline.findTreeElement(debuggerObject);
-            if (oldDebuggerTreeElement) {
-                newDebuggerTreeElement = this._addIssue(debuggerObject);
+            if (oldDebuggerTreeElement)
                 wasSelected = oldDebuggerTreeElement.selected;
-            }
+
+            newDebuggerTreeElement = this._addIssue(debuggerObject);
         }
 
+        if (!newDebuggerTreeElement)
+            return;
+
         if (oldDebuggerTreeElement)
             this._removeDebuggerTreeElement(oldDebuggerTreeElement);
 
-        if (newDebuggerTreeElement && wasSelected)
+        if (wasSelected)
             newDebuggerTreeElement.revealAndSelect(true, false, true);
     }
 
@@ -1826,34 +1818,33 @@ WI.SourcesNavigationSidebarPanel = class SourcesNavigationSidebarPanel extends W
         issueTreeElements.forEach((treeElement) => treeElement.parent.removeChild(treeElement));
     }
 
-    _handleTimelineCapturingWillStart(event)
+    _handleTimelineCapturingStateChanged(event)
     {
         this._updateTemporarilyDisabledBreakpointsButtons();
 
-        if (!this._timelineRecordingWarningElement) {
-            let stopRecordingButton = document.createElement("button");
-            stopRecordingButton.textContent = WI.UIString("Stop recording");
-            stopRecordingButton.addEventListener("click", () => {
-                WI.timelineManager.stopCapturing();
-            });
-
-            this._timelineRecordingWarningElement = document.createElement("div");
-            this._timelineRecordingWarningElement.classList.add("warning-banner");
-            this._timelineRecordingWarningElement.append(WI.UIString("Debugger disabled during Timeline recording"), document.createElement("br"), stopRecordingButton);
-        }
-
-        this.contentView.element.insertBefore(this._timelineRecordingWarningElement, this.contentView.element.firstChild);
+        switch (WI.timelineManager.capturingState) {
+        case WI.TimelineManager.CapturingState.Starting:
+            if (!this._timelineRecordingWarningElement) {
+                let stopRecordingButton = document.createElement("button");
+                stopRecordingButton.textContent = WI.UIString("Stop recording");
+                stopRecordingButton.addEventListener("click", () => {
+                    WI.timelineManager.stopCapturing();
+                });
 
-        this._updateBreakpointsDisabledBanner();
-    }
+                this._timelineRecordingWarningElement = document.createElement("div");
+                this._timelineRecordingWarningElement.classList.add("warning-banner");
+                this._timelineRecordingWarningElement.append(WI.UIString("Debugger disabled during Timeline recording"), document.createElement("br"), stopRecordingButton);
+            }
 
-    _handleTimelineCapturingStopped(event)
-    {
-        this._updateTemporarilyDisabledBreakpointsButtons();
+            this.contentView.element.insertBefore(this._timelineRecordingWarningElement, this.contentView.element.firstChild);
+            break;
 
-        if (this._timelineRecordingWarningElement) {
-            this._timelineRecordingWarningElement.remove();
-            this._timelineRecordingWarningElement = null;
+        case WI.TimelineManager.CapturingState.Inactive:
+            if (this._timelineRecordingWarningElement) {
+                this._timelineRecordingWarningElement.remove();
+                this._timelineRecordingWarningElement = null;
+            }
+            break;
         }
 
         this._updateBreakpointsDisabledBanner();