diff --git a/src/vs/workbench/contrib/markers/browser/markers.contribution.ts b/src/vs/workbench/contrib/markers/browser/markers.contribution.ts index 2bda0504826..e6a39eb883f 100644 --- a/src/vs/workbench/contrib/markers/browser/markers.contribution.ts +++ b/src/vs/workbench/contrib/markers/browser/markers.contribution.ts @@ -12,7 +12,7 @@ import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/co import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { localize } from 'vs/nls'; import { Marker, RelatedInformation } from 'vs/workbench/contrib/markers/browser/markersModel'; -import { MarkersPanel, MarkersPane } from 'vs/workbench/contrib/markers/browser/markersPanel'; +import { MarkersPanel, MarkersView, getMarkersView } from 'vs/workbench/contrib/markers/browser/markersPanel'; import { MenuId, MenuRegistry, SyncActionDescriptor, registerAction } from 'vs/platform/actions/common/actions'; import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'vs/workbench/browser/panel'; import { Registry } from 'vs/platform/registry/common/platform'; @@ -42,8 +42,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ primary: KeyMod.WinCtrl | KeyCode.Enter }, handler: (accessor, args: any) => { - const markersPane = (accessor.get(IPanelService).getActivePanel()).getMarkersPane(); - markersPane.openFileAtElement(markersPane.getFocusElement(), false, true, true); + const markersView = getMarkersView(accessor.get(IPanelService))!; + markersView.openFileAtElement(markersView.getFocusElement(), false, true, true); } }); @@ -63,10 +63,10 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ when: Constants.MarkerFocusContextKey, primary: KeyMod.CtrlCmd | KeyCode.US_DOT, handler: (accessor, args: any) => { - const markersPane = (accessor.get(IPanelService).getActivePanel()).getMarkersPane(); - const focusedElement = markersPane.getFocusElement(); + const markersView = getMarkersView(accessor.get(IPanelService))!; + const focusedElement = markersView.getFocusElement(); if (focusedElement instanceof Marker) { - markersPane.showQuickFixes(focusedElement); + markersView.showQuickFixes(focusedElement); } } }); @@ -107,7 +107,7 @@ Registry.as(ViewContainerExtensions.ViewsRegistry).registerViews id: Constants.MARKERS_VIEW_ID, name: Messages.MARKERS_PANEL_TITLE_PROBLEMS, canToggleVisibility: false, - ctorDescriptor: { ctor: MarkersPane }, + ctorDescriptor: { ctor: MarkersView }, }], VIEW_CONTAINER); // workbench @@ -123,8 +123,8 @@ registry.registerWorkbenchAction(SyncActionDescriptor.create(ShowProblemsPanelAc registerAction({ id: Constants.MARKER_COPY_ACTION_ID, title: { value: localize('copyMarker', "Copy"), original: 'Copy' }, - handler(accessor) { - copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyMarker(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -142,8 +142,8 @@ registerAction({ registerAction({ id: Constants.MARKER_COPY_MESSAGE_ACTION_ID, title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' }, - handler(accessor) { - copyMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -154,8 +154,8 @@ registerAction({ registerAction({ id: Constants.RELATED_INFORMATION_COPY_MESSAGE_ACTION_ID, title: { value: localize('copyMessage', "Copy Message"), original: 'Copy Message' }, - handler(accessor) { - copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); + async handler(accessor) { + await copyRelatedInformationMessage(accessor.get(IPanelService), accessor.get(IClipboardService)); }, menu: { menuId: MenuId.ProblemsPanelContext, @@ -192,10 +192,9 @@ registerAction({ registerAction({ id: Constants.MARKERS_PANEL_SHOW_MULTILINE_MESSAGE, handler(accessor) { - const panelService = accessor.get(IPanelService); - const panel = panelService.getActivePanel(); - if (panel instanceof MarkersPanel) { - panel.getMarkersPane().markersViewModel.multiline = true; + const markersView = getMarkersView(accessor.get(IPanelService)); + if (markersView) { + markersView.markersViewModel.multiline = true; } }, title: { value: localize('show multiline', "Show message in multiple lines"), original: 'Problems: Show message in multiple lines' }, @@ -208,10 +207,9 @@ registerAction({ registerAction({ id: Constants.MARKERS_PANEL_SHOW_SINGLELINE_MESSAGE, handler(accessor) { - const panelService = accessor.get(IPanelService); - const panel = panelService.getActivePanel(); - if (panel instanceof MarkersPanel) { - panel.getMarkersPane().markersViewModel.multiline = false; + const markersView = getMarkersView(accessor.get(IPanelService)); + if (markersView) { + markersView.markersViewModel.multiline = false; } }, title: { value: localize('show singleline', "Show message in single line"), original: 'Problems: Show message in single line' }, @@ -222,33 +220,30 @@ registerAction({ } }); -async function copyMarker(panelService: IPanelService, clipboardService: IClipboardService): Promise { - const activePanel = panelService.getActivePanel(); - if (activePanel instanceof MarkersPanel) { - const markersPane = activePanel.getMarkersPane(); - const element = markersPane.getFocusElement(); +async function copyMarker(panelService: IPanelService, clipboardService: IClipboardService) { + const markersView = getMarkersView(panelService); + if (markersView) { + const element = markersView.getFocusElement(); if (element instanceof Marker) { await clipboardService.writeText(`${element}`); } } } -async function copyMessage(panelService: IPanelService, clipboardService: IClipboardService): Promise { - const activePanel = panelService.getActivePanel(); - if (activePanel instanceof MarkersPanel) { - const markersPane = activePanel.getMarkersPane(); - const element = markersPane.getFocusElement(); +async function copyMessage(panelService: IPanelService, clipboardService: IClipboardService) { + const markersView = getMarkersView(panelService); + if (markersView) { + const element = markersView.getFocusElement(); if (element instanceof Marker) { await clipboardService.writeText(element.marker.message); } } } -async function copyRelatedInformationMessage(panelService: IPanelService, clipboardService: IClipboardService): Promise { - const activePanel = panelService.getActivePanel(); - if (activePanel instanceof MarkersPanel) { - const markersPane = activePanel.getMarkersPane(); - const element = markersPane.getFocusElement(); +async function copyRelatedInformationMessage(panelService: IPanelService, clipboardService: IClipboardService) { + const markersView = getMarkersView(panelService); + if (markersView) { + const element = markersView.getFocusElement(); if (element instanceof RelatedInformation) { await clipboardService.writeText(element.raw.message); } @@ -263,9 +258,9 @@ function focusProblemsView(panelService: IPanelService) { } function focusProblemsFilter(panelService: IPanelService): void { - const activePanel = panelService.getActivePanel(); - if (activePanel instanceof MarkersPanel) { - activePanel.getMarkersPane().focusFilter(); + const markersView = getMarkersView(panelService); + if (markersView) { + markersView.focusFilter(); } } diff --git a/src/vs/workbench/contrib/markers/browser/markersPanel.ts b/src/vs/workbench/contrib/markers/browser/markersPanel.ts index 79f2b34a7be..0d73676150a 100644 --- a/src/vs/workbench/contrib/markers/browser/markersPanel.ts +++ b/src/vs/workbench/contrib/markers/browser/markersPanel.ts @@ -50,6 +50,15 @@ import { KeyCode } from 'vs/base/common/keyCodes'; import { editorLightBulbForeground, editorLightBulbAutoFixForeground } from 'vs/platform/theme/common/colorRegistry'; import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { ViewPaneContainer, ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPaneContainer'; +import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; + +export function getMarkersView(panelService: IPanelService): MarkersView | undefined { + const activePanel = panelService.getActivePanel(); + if (activePanel instanceof PaneCompositePanel) { + return activePanel.getViewPaneContainer().getView(Constants.MARKERS_VIEW_ID); + } + return undefined; +} function createResourceMarkersIterator(resourceMarkers: ResourceMarkers): Iterator> { const markersIt = Iterator.fromArray(resourceMarkers.markers); @@ -73,17 +82,13 @@ export class MarkersPanel extends PaneCompositePanel { @IContextMenuService contextMenuService: IContextMenuService, @IExtensionService extensionService: IExtensionService, @IWorkspaceContextService contextService: IWorkspaceContextService) { - super(Constants.MARKERS_PANEL_ID, instantiationService.createInstance(ViewPaneContainer, Constants.MARKERS_PANEL_ID, Constants.MARKERS_PANEL_STORAGE_ID, { showHeaderInTitleWhenSingleView: true }), + super(Constants.MARKERS_PANEL_ID, instantiationService.createInstance(ViewPaneContainer, Constants.MARKERS_PANEL_ID, Constants.MARKERS_PANEL_STORAGE_ID, { showHeaderInTitleWhenSingleView: true, donotShowViewTitleWhenSingleView: true }), telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService); } - getMarkersPane(): MarkersPane { - return this.viewPaneContainer.getView(Constants.MARKERS_VIEW_ID); - } - } -export class MarkersPane extends ViewPane implements IMarkerFilterController { +export class MarkersView extends ViewPane implements IMarkerFilterController { private lastSelectedRelativeTop: number = 0; private currentActiveResource: URI | null = null; @@ -91,11 +96,10 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { private readonly rangeHighlightDecorations: RangeHighlightDecorations; private readonly filter: Filter; - private tree!: MarkersTree; - private filterActionBar!: ActionBar; - private messageBoxContainer!: HTMLElement; - private ariaLabelElement!: HTMLElement; - + private tree: MarkersTree | undefined; + private filterActionBar: ActionBar | undefined; + private messageBoxContainer: HTMLElement | undefined; + private ariaLabelElement: HTMLElement | undefined; private readonly collapseAllAction: IAction; private readonly filterAction: MarkersFilterAction; @@ -174,7 +178,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } })); - this.filterActionBar.push(this.filterAction); + this.filterActionBar!.push(this.filterAction); this.renderContent(); } @@ -187,22 +191,28 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { this.isSmallLayout = width < 600; if (this.isSmallLayout !== wasSmallLayout) { this.updateActions(); - dom.toggleClass(this.filterActionBar.getContainer(), 'hide', !this.isSmallLayout); + if (this.filterActionBar) { + dom.toggleClass(this.filterActionBar.getContainer(), 'hide', !this.isSmallLayout); + } } const contentHeight = this.isSmallLayout ? height - 44 : height; - this.tree.layout(contentHeight, width); - this.messageBoxContainer.style.height = `${contentHeight}px`; + if (this.tree) { + this.tree.layout(contentHeight, width); + } + if (this.messageBoxContainer) { + this.messageBoxContainer.style.height = `${contentHeight}px`; + } this.filterAction.layout(this.isSmallLayout ? width : width - 200); } public focus(): void { - if (this.tree.getHTMLElement() === document.activeElement) { + if (this.tree && this.tree.getHTMLElement() === document.activeElement) { return; } - if (this.isEmpty()) { + if (this.isEmpty() && this.messageBoxContainer) { this.messageBoxContainer.focus(); - } else { + } else if (this.tree) { this.tree.getHTMLElement().focus(); } } @@ -265,7 +275,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private refreshPanel(markerOrChange?: Marker | MarkerChangesEvent): void { - if (this.isVisible()) { + if (this.isVisible() && this.tree) { this.cachedFilterStats = undefined; if (markerOrChange) { @@ -299,6 +309,9 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private resetTree(): void { + if (!this.tree) { + return; + } let resourceMarkers: ResourceMarkers[] = []; if (this.filterAction.activeFile) { if (this.currentActiveResource) { @@ -316,11 +329,15 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { private updateFilter() { this.cachedFilterStats = undefined; this.filter.options = new FilterOptions(this.filterAction.filterText, this.getFilesExcludeExpressions(), this.filterAction.showWarnings, this.filterAction.showErrors, this.filterAction.showInfos); - this.tree.refilter(); + if (this.tree) { + this.tree.refilter(); + } this._onDidFilter.fire(); const { total, filtered } = this.getFilterStats(); - this.tree.toggleVisibility(total === 0 || filtered === 0); + if (this.tree) { + this.tree.toggleVisibility(total === 0 || filtered === 0); + } this.renderMessage(); } @@ -434,7 +451,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { })); this._register(Event.any(this.tree.onDidChangeSelection, this.tree.onDidChangeFocus)(() => { - const elements = [...this.tree.getSelection(), ...this.tree.getFocus()]; + const elements = [...this.tree!.getSelection(), ...this.tree!.getFocus()]; for (const element of elements) { if (element instanceof Marker) { const viewModel = this.markersViewModel.getViewModel(element); @@ -447,11 +464,13 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private collapseAll(): void { - this.tree.collapseAll(); - this.tree.setSelection([]); - this.tree.setFocus([]); - this.tree.getHTMLElement().focus(); - this.tree.focusFirst(); + if (this.tree) { + this.tree.collapseAll(); + this.tree.setSelection([]); + this.tree.setFocus([]); + this.tree.getHTMLElement().focus(); + this.tree.focusFirst(); + } } private createListeners(): void { @@ -462,7 +481,9 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { this.onActiveEditorChanged(); } })); - this._register(this.tree.onDidChangeSelection(() => this.onSelected())); + if (this.tree) { + this._register(this.tree.onDidChangeSelection(() => this.onSelected())); + } this._register(this.filterAction.onDidChange((event: IMarkersFilterActionChangeEvent) => { this.reportFilteringUsed(); if (event.activeFile) { @@ -521,9 +542,11 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private onSelected(): void { - let selection = this.tree.getSelection(); - if (selection && selection.length > 0) { - this.lastSelectedRelativeTop = this.tree.getRelativeTop(selection[0]) || 0; + if (this.tree) { + let selection = this.tree.getSelection(); + if (selection && selection.length > 0) { + this.lastSelectedRelativeTop = this.tree!.getRelativeTop(selection[0]) || 0; + } } } @@ -535,11 +558,16 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { private renderContent(): void { this.cachedFilterStats = undefined; this.resetTree(); - this.tree.toggleVisibility(this.isEmpty()); + if (this.tree) { + this.tree.toggleVisibility(this.isEmpty()); + } this.renderMessage(); } private renderMessage(): void { + if (!this.messageBoxContainer || !this.ariaLabelElement) { + return; + } dom.clearNode(this.messageBoxContainer); const { total, filtered } = this.getFilterStats(); @@ -589,19 +617,19 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { e.stopPropagation(); } }); - this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_FILTERS); + this.ariaLabelElement!.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_FILTERS); } private renderNoProblemsMessageForActiveFile(container: HTMLElement) { const span = dom.append(container, dom.$('span')); span.textContent = Messages.MARKERS_PANEL_NO_PROBLEMS_ACTIVE_FILE_BUILT; - this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_ACTIVE_FILE_BUILT); + this.ariaLabelElement!.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_ACTIVE_FILE_BUILT); } private renderNoProblemsMessage(container: HTMLElement) { const span = dom.append(container, dom.$('span')); span.textContent = Messages.MARKERS_PANEL_NO_PROBLEMS_BUILT; - this.ariaLabelElement.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_BUILT); + this.ariaLabelElement!.setAttribute('aria-label', Messages.MARKERS_PANEL_NO_PROBLEMS_BUILT); } private clearFilters(): void { @@ -614,7 +642,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { private autoReveal(focus: boolean = false): void { // No need to auto reveal if active file filter is on - if (this.filterAction.activeFile) { + if (this.filterAction.activeFile || !this.tree) { return; } let autoReveal = this.configurationService.getValue('problems.autoReveal'); @@ -647,11 +675,13 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private hasSelectedMarkerFor(resource: ResourceMarkers): boolean { - let selectedElement = this.tree.getSelection(); - if (selectedElement && selectedElement.length > 0) { - if (selectedElement[0] instanceof Marker) { - if (resource.resource.toString() === (selectedElement[0]).marker.resource.toString()) { - return true; + if (this.tree) { + let selectedElement = this.tree.getSelection(); + if (selectedElement && selectedElement.length > 0) { + if (selectedElement[0] instanceof Marker) { + if (resource.resource.toString() === (selectedElement[0]).marker.resource.toString()) { + return true; + } } } } @@ -660,13 +690,13 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { private updateRangeHighlights() { this.rangeHighlightDecorations.removeHighlightRange(); - if (this.tree.getHTMLElement() === document.activeElement) { + if (this.tree && this.tree.getHTMLElement() === document.activeElement) { this.highlightCurrentSelectedMarkerRange(); } } private highlightCurrentSelectedMarkerRange() { - const selections = this.tree.getSelection(); + const selections = this.tree ? this.tree.getSelection() : []; if (selections.length !== 1) { return; @@ -702,7 +732,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { }, onHide: (wasCancelled?: boolean) => { if (wasCancelled) { - this.tree.domFocus(); + this.tree!.domFocus(); } } }); @@ -722,7 +752,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } } - const menu = this.menuService.createMenu(MenuId.ProblemsPanelContext, this.tree.contextKeyService); + const menu = this.menuService.createMenu(MenuId.ProblemsPanelContext, this.tree!.contextKeyService); const groups = menu.getActions(); menu.dispose(); @@ -737,7 +767,7 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } public getFocusElement() { - return this.tree.getFocus()[0]; + return this.tree ? this.tree.getFocus()[0] : undefined; } public getActionViewItem(action: IAction): IActionViewItem | undefined { @@ -760,13 +790,15 @@ export class MarkersPane extends ViewPane implements IMarkerFilterController { } private computeFilterStats(): { total: number; filtered: number; } { - const root = this.tree.getNode(); let filtered = 0; + if (this.tree) { + const root = this.tree.getNode(); - for (const resourceMarkerNode of root.children) { - for (const markerNode of resourceMarkerNode.children) { - if (resourceMarkerNode.visible && markerNode.visible) { - filtered++; + for (const resourceMarkerNode of root.children) { + for (const markerNode of resourceMarkerNode.children) { + if (resourceMarkerNode.visible && markerNode.visible) { + filtered++; + } } } } diff --git a/src/vs/workbench/contrib/markers/browser/markersPanelActions.ts b/src/vs/workbench/contrib/markers/browser/markersPanelActions.ts index 39719499d5d..e786f650dcf 100644 --- a/src/vs/workbench/contrib/markers/browser/markersPanelActions.ts +++ b/src/vs/workbench/contrib/markers/browser/markersPanelActions.ts @@ -304,6 +304,7 @@ export class MarkersFilterActionViewItem extends BaseActionViewItem { this.element.className = this.action.class || ''; this.createInput(this.element); this.createControls(this.element); + this.updateClass(); this.adjustInputBox(); }