|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as nls from 'vs/nls'; |
| 7 | +import * as dom from 'vs/base/browser/dom'; |
| 8 | +import * as errors from 'vs/base/common/errors'; |
| 9 | +import { IDisposable, dispose } from 'vs/base/common/lifecycle'; |
| 10 | +import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; |
| 11 | +import { IThemeService } from 'vs/platform/theme/common/themeService'; |
| 12 | +import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar'; |
| 13 | +import { IDebugService } from 'vs/workbench/parts/debug/common/debug'; |
| 14 | +import { Themable, STATUS_BAR_FOREGROUND } from 'vs/workbench/common/theme'; |
| 15 | + |
| 16 | +const $ = dom.$; |
| 17 | +const MAX_LABEL_LENGTH = 17; |
| 18 | + |
| 19 | +export class DebugStatus extends Themable implements IStatusbarItem { |
| 20 | + private toDispose: IDisposable[]; |
| 21 | + private label: HTMLElement; |
| 22 | + private icon: HTMLElement; |
| 23 | + |
| 24 | + constructor( |
| 25 | + @IQuickOpenService private quickOpenService: IQuickOpenService, |
| 26 | + @IDebugService private debugService: IDebugService, |
| 27 | + @IThemeService themeService: IThemeService |
| 28 | + ) { |
| 29 | + super(themeService); |
| 30 | + this.toDispose = []; |
| 31 | + this.toDispose.push(this.debugService.getConfigurationManager().onDidSelectConfiguration(e => { |
| 32 | + this.setLabel(); |
| 33 | + })); |
| 34 | + } |
| 35 | + |
| 36 | + protected updateStyles(): void { |
| 37 | + super.updateStyles(); |
| 38 | + this.icon.style.backgroundColor = this.getColor(STATUS_BAR_FOREGROUND); |
| 39 | + } |
| 40 | + |
| 41 | + public render(container: HTMLElement): IDisposable { |
| 42 | + const statusBarItem = dom.append(container, $('.debug-statusbar-item')); |
| 43 | + this.toDispose.push(dom.addDisposableListener(statusBarItem, 'click', () => { |
| 44 | + this.quickOpenService.show('debug ').done(undefined, errors.onUnexpectedError); |
| 45 | + })); |
| 46 | + statusBarItem.title = nls.localize('debug', "Debug"); |
| 47 | + this.icon = dom.append(statusBarItem, $('.icon')); |
| 48 | + this.label = dom.append(statusBarItem, $('span.label')); |
| 49 | + this.setLabel(); |
| 50 | + this.updateStyles(); |
| 51 | + |
| 52 | + return this; |
| 53 | + } |
| 54 | + |
| 55 | + private setLabel(): void { |
| 56 | + if (this.label) { |
| 57 | + let name = this.debugService.getConfigurationManager().selectedName || ''; |
| 58 | + if (name.length > MAX_LABEL_LENGTH) { |
| 59 | + name = name.substring(0, MAX_LABEL_LENGTH) + '...'; |
| 60 | + } |
| 61 | + this.label.textContent = name; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public dispose(): void { |
| 66 | + super.dispose(); |
| 67 | + this.toDispose = dispose(this.toDispose); |
| 68 | + } |
| 69 | +} |
0 commit comments