-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[badge]: Badge decoration for active debug sessions
Fixes: #8303 Decorates the debug tab-bar with active debug sessions. Co-authored-by: Kaiyue Pan <[email protected]> Co-authored-by: Anas Shahid <[email protected]> Signed-off-by: Kaiyue Pan <[email protected]> Signed-off-by: Anas Shahid <[email protected]>
- Loading branch information
Anas Shahid
committed
Aug 10, 2020
1 parent
e95311d
commit 435f29e
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2020 Ericsson and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject } from 'inversify'; | ||
import { Emitter, Event } from '@theia/core/lib/common/event'; | ||
import { DebugSessionManager } from './debug-session-manager'; | ||
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator'; | ||
import { FrontendApplication, FrontendApplicationContribution, Title, Widget } from '@theia/core/lib/browser'; | ||
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration'; | ||
import { DisposableCollection } from '@theia/core/lib/common'; | ||
|
||
export const DebugSessionManagerGetter = Symbol.for('DebugSessionManagerGetter'); | ||
export type DebugSessionManagerGetter = () => DebugSessionManager; | ||
|
||
@injectable() | ||
export class DebugTabBarDecorator implements TabBarDecorator, FrontendApplicationContribution { | ||
|
||
readonly id = 'theia-debug-tabbar-decorator'; | ||
protected readonly emitter = new Emitter<void>(); | ||
|
||
protected toDispose = new DisposableCollection(); | ||
|
||
@inject(DebugSessionManagerGetter) | ||
protected readonly debugSessionManager: DebugSessionManagerGetter; | ||
|
||
onStart(app: FrontendApplication): void { | ||
this.toDispose.pushAll([ | ||
this.debugSessionManager().onDidStartDebugSession(() => this.fireDidChangeDecorations()), | ||
this.debugSessionManager().onDidStopDebugSession(() => this.fireDidChangeDecorations()), | ||
this.debugSessionManager().onDidDestroyDebugSession(() => this.fireDidChangeDecorations()) | ||
]); | ||
} | ||
|
||
decorate(title: Title<Widget>): WidgetDecoration.Data[] { | ||
if (title.owner.id === 'debug') { | ||
const sessionCount = this.debugSessionManager().sessions.length; | ||
return sessionCount > 0 ? [{ badge: sessionCount }] : []; | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
get onDidChangeDecorations(): Event<void> { | ||
return this.emitter.event; | ||
} | ||
|
||
protected fireDidChangeDecorations(): void { | ||
this.emitter.fire(undefined); | ||
} | ||
} |