-
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.
Feature: Open editors widget in navigator
Signed-off-by: Kenneth Marut <[email protected]>
- Loading branch information
1 parent
d3cc96f
commit e4cc5d3
Showing
13 changed files
with
696 additions
and
7 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
84 changes: 84 additions & 0 deletions
84
...ges/navigator/src/browser/open-editors-widget/navigator-open-editors-decorator-service.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,84 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2021 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 } from '@theia/core/shared/inversify'; | ||
import { ContributionProvider } from '@theia/core/lib/common/contribution-provider'; | ||
import { TreeDecorator, AbstractTreeDecoratorService, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator'; | ||
import { NavigatorTreeDecorator } from '../navigator-decorator-service'; | ||
import { Tree } from '@theia/core/lib/browser'; | ||
|
||
export const OpenEditorsTreeDecorator = Symbol('OpenEditorsTreeDecorator'); | ||
|
||
@injectable() | ||
export class OpenEditorsTreeDecoratorService extends AbstractTreeDecoratorService { | ||
protected problemDecorator: TreeDecorator | undefined; | ||
|
||
protected globalColorMap = new Map<string, string>(); | ||
|
||
constructor(@inject(ContributionProvider) @named(OpenEditorsTreeDecorator) protected readonly contributions: ContributionProvider<TreeDecorator>, | ||
@inject(ContributionProvider) @named(NavigatorTreeDecorator) protected readonly navigatorContributions: ContributionProvider<TreeDecorator>) { | ||
super([...contributions.getContributions(), ...navigatorContributions.getContributions()]); | ||
this.problemDecorator = this.decorators.find(decorator => decorator.id === 'theia-problem-decorator'); | ||
} | ||
|
||
protected async getColorsFromProblemDecorator(tree: Tree): Promise<Map<string, string>> { | ||
const colorMap = new Map<string, string>(); | ||
const { problemDecorator } = this; | ||
if (problemDecorator) { | ||
const problemDecoratorIterator = (await problemDecorator.decorations(tree)).entries(); | ||
for (const [id, data] of problemDecoratorIterator) { | ||
const colorFromDecorator = data.fontData?.color; | ||
if (colorFromDecorator) { | ||
colorMap.set(id, colorFromDecorator); | ||
} | ||
} | ||
} | ||
return colorMap; | ||
} | ||
|
||
protected addColorToSuffixes(suffixes: TreeDecoration.CaptionAffix[], colorToAdd: string): TreeDecoration.CaptionAffix[] { | ||
const modifiedCaptionSuffixes = suffixes.map(suffix => { | ||
const existingFontData = { ...suffix.fontData }; | ||
return { ...suffix, fontData: { ...existingFontData, color: colorToAdd } }; | ||
}); | ||
return modifiedCaptionSuffixes; | ||
} | ||
|
||
// Theia's problem decorator provides colorization to FileTree's Caption, but not to its caption suffix. | ||
// Since the suffix text is coming from elsewhere (OpenEditorsDecoratorService), the color needs to be manually | ||
// added here | ||
async getDecorations(tree: Tree): Promise<Map<string, TreeDecoration.Data[]>> { | ||
const changes = new Map<string, TreeDecoration.Data[]>(); | ||
const colorsFromProblemDecorator = await this.getColorsFromProblemDecorator(tree); | ||
|
||
for (const decorator of this.decorators) { | ||
for (const [id, data] of (await decorator.decorations(tree)).entries()) { | ||
const decorationCopy = { ...data }; | ||
const existingColor = colorsFromProblemDecorator.get(id); | ||
if (existingColor && decorator.id !== 'theia-problem-decorator' && data.captionSuffixes) { | ||
const modifiedCaptionSuffixes = this.addColorToSuffixes(data.captionSuffixes, existingColor); | ||
decorationCopy.captionSuffixes = modifiedCaptionSuffixes; | ||
} | ||
if (changes.has(id)) { | ||
changes.get(id)!.push(decorationCopy); | ||
} else { | ||
changes.set(id, [decorationCopy]); | ||
} | ||
} | ||
} | ||
return changes; | ||
} | ||
} |
Oops, something went wrong.