-
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.
core: add support for badge decorations
The following commit adds support for a new type of widget decoration called a `badge` which is essentially a notification for which widgets can contribute a counter to for display purposes. The commit includes two new client contributions from: - `scm`: contributes a `badge` counter for number of changes in the working tree. - `markers`: contributes a `badge` counter for the number of problem marker stats. Co-authored-by: Kaiyue Pan <kaiyue.pan@ericsson.com> Co-authored-by: vince-fugnitto <vincent.fugnitto@ericsson.com> Signed-off-by: Kaiyue Pan <kaiyue.pan@ericsson.com> Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
- Loading branch information
1 parent
8ac1e5f
commit 747404b
Showing
9 changed files
with
198 additions
and
14 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
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
55 changes: 55 additions & 0 deletions
55
packages/markers/src/browser/problem/problem-widget-tab-bar-decorator.ts
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,55 @@ | ||
/******************************************************************************** | ||
* 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, postConstruct } from 'inversify'; | ||
import { Event, Emitter } from '@theia/core/lib/common/event'; | ||
import { ProblemManager } from './problem-manager'; | ||
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator'; | ||
import { Title, Widget } from '@theia/core/lib/browser'; | ||
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration'; | ||
|
||
@injectable() | ||
export class ProblemWidgetTabBarDecorator implements TabBarDecorator { | ||
|
||
readonly id = 'theia-problems-widget-tabbar-decorator'; | ||
protected readonly emitter = new Emitter<void>(); | ||
|
||
@inject(ProblemManager) | ||
protected readonly problemManager: ProblemManager; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.problemManager.onDidChangeMarkers(() => this.fireDidChangeDecorations()); | ||
} | ||
|
||
decorate(title: Title<Widget>): WidgetDecoration.Data[] { | ||
if (title.owner.id === 'problems') { | ||
const { infos, warnings, errors } = this.problemManager.getProblemStat(); | ||
const markerCount = infos + warnings + errors; | ||
return markerCount > 0 ? [{ badge: markerCount }] : []; | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
get onDidChangeDecorations(): Event<void> { | ||
return this.emitter.event; | ||
} | ||
|
||
protected fireDidChangeDecorations(): void { | ||
this.emitter.fire(undefined); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/scm/src/browser/decorations/scm-tab-bar-decorator.ts
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,82 @@ | ||
/******************************************************************************** | ||
* 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, postConstruct } from 'inversify'; | ||
import { Event, Emitter } from '@theia/core/lib/common/event'; | ||
import { SCM_VIEW_CONTAINER_ID } from '../scm-contribution'; | ||
import { ScmService } from '../scm-service'; | ||
import { TabBarDecorator } from '@theia/core/lib/browser/shell/tab-bar-decorator'; | ||
import { Title, Widget } from '@theia/core/lib/browser'; | ||
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration'; | ||
import { DisposableCollection } from '@theia/core/lib/common/disposable'; | ||
|
||
@injectable() | ||
export class ScmTabBarDecorator implements TabBarDecorator { | ||
|
||
readonly id = 'theia-scm-tabbar-decorator'; | ||
protected readonly emitter = new Emitter<void>(); | ||
|
||
private readonly toDispose = new DisposableCollection(); | ||
private readonly toDisposeOnDidChange = new DisposableCollection(); | ||
|
||
@inject(ScmService) | ||
protected readonly scmService: ScmService; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.toDispose.push(this.scmService.onDidChangeSelectedRepository(repository => { | ||
this.toDisposeOnDidChange.dispose(); | ||
if (repository) { | ||
this.toDisposeOnDidChange.push( | ||
repository.provider.onDidChange(() => this.fireDidChangeDecorations()) | ||
); | ||
} | ||
this.fireDidChangeDecorations(); | ||
})); | ||
} | ||
|
||
decorate(title: Title<Widget>): WidgetDecoration.Data[] { | ||
if (title.owner.id === SCM_VIEW_CONTAINER_ID) { | ||
const changes = this.collectChangesCount(); | ||
return changes > 0 ? [{ badge: changes }] : []; | ||
} else { | ||
return []; | ||
} | ||
} | ||
|
||
protected collectChangesCount(): number { | ||
const repository = this.scmService.selectedRepository; | ||
let changes = 0; | ||
if (!repository) { | ||
return 0; | ||
} | ||
repository.provider.groups.map(group => { | ||
if (group.id === 'index' || group.id === 'workingTree') { | ||
changes += group.resources.length; | ||
} | ||
}); | ||
return changes; | ||
} | ||
|
||
get onDidChangeDecorations(): Event<void> { | ||
return this.emitter.event; | ||
} | ||
|
||
protected fireDidChangeDecorations(): void { | ||
this.emitter.fire(undefined); | ||
} | ||
|
||
} |
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