-
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.
Fixed #1278: implemented tabbar decorator & supported error marker in…
… editor tabs - Implemented `TabBarDecorator` that provides tabs with decorations, similar to what we already had for tree nodes. - Supported diagnostic problem markers (error, warning, ...) in editor tabs in the main area. Tabs in side bars can be decorated as well in the future using the same code. - Refactored `TreeDecoration` to a more generic `NodeDecoration`, which is currently used for decorating tree nodes and tabbar tabs. Signed-off-by: fangnx <[email protected]>
- Loading branch information
Showing
12 changed files
with
807 additions
and
415 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
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,83 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 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 { inject, injectable, named, postConstruct } from 'inversify'; | ||
import { Event, Emitter, Disposable, DisposableCollection, ContributionProvider } from '../../common'; | ||
import { Title, Widget } from '@phosphor/widgets'; | ||
import { WidgetDecoration } from '../widget-decoration'; | ||
|
||
export const TabBarDecorator = Symbol('TabBarDecorator'); | ||
|
||
export interface TabBarDecorator { | ||
|
||
/** | ||
* The unique identifier of the tabbar decorator. | ||
*/ | ||
readonly id: string; | ||
|
||
/** | ||
* Event that is fired when any of the available tabbar decorators has changes. | ||
*/ | ||
readonly onDidChangeDecorations: Event<void>; | ||
|
||
/** | ||
* Decorate tabs by the underlying URI. | ||
* @returns A map from URI of the tab to its decoration data. | ||
*/ | ||
decorate(titles: Title<Widget>[]): Map<string, WidgetDecoration.Data>; | ||
} | ||
|
||
@injectable() | ||
export class TabBarDecoratorService implements Disposable { | ||
|
||
protected readonly onDidChangeDecorationsEmitter = new Emitter<void>(); | ||
|
||
readonly onDidChangeDecorations = this.onDidChangeDecorationsEmitter.event; | ||
|
||
protected readonly toDispose = new DisposableCollection(); | ||
|
||
@inject(ContributionProvider) @named(TabBarDecorator) | ||
protected readonly contributions: ContributionProvider<TabBarDecorator>; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
const decorators = this.contributions.getContributions(); | ||
this.toDispose.pushAll(decorators.map(decorator => | ||
decorator.onDidChangeDecorations(data => | ||
this.onDidChangeDecorationsEmitter.fire(undefined) | ||
)) | ||
); | ||
} | ||
|
||
dispose(): void { | ||
this.toDispose.dispose(); | ||
} | ||
|
||
getDecorations(titles: Title<Widget>[]): Map<string, WidgetDecoration.Data[]> { | ||
const decorators = this.contributions.getContributions(); | ||
const changes: Map<string, WidgetDecoration.Data[]> = new Map(); | ||
for (const decorator of decorators) { | ||
for (const [id, data] of (decorator.decorate(titles)).entries()) { | ||
if (changes.has(id)) { | ||
changes.get(id)!.push(data); | ||
} else { | ||
changes.set(id, [data]); | ||
} | ||
} | ||
} | ||
return changes; | ||
} | ||
} |
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
Oops, something went wrong.