Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigator-decorator: add symlink icon and tooltip to symlinked files in navigator #10439

Merged
merged 1 commit into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/navigator/src/browser/navigator-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { OpenEditorsTreeDecorator } from './open-editors-widget/navigator-open-e
import { OpenEditorsWidget } from './open-editors-widget/navigator-open-editors-widget';
import { NavigatorTreeDecorator } from './navigator-decorator-service';
import { NavigatorDeletedEditorDecorator } from './open-editors-widget/navigator-deleted-editor-decorator';
import { NavigatorSymlinkDecorator } from './navigator-symlink-decorator';

export default new ContainerModule(bind => {
bindFileNavigatorPreferences(bind);
Expand Down Expand Up @@ -81,4 +82,8 @@ export default new ContainerModule(bind => {
bind(NavigatorTabBarDecorator).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(NavigatorTabBarDecorator);
bind(TabBarDecorator).toService(NavigatorTabBarDecorator);

bind(NavigatorSymlinkDecorator).toSelf().inSingletonScope();
bind(NavigatorTreeDecorator).toService(NavigatorSymlinkDecorator);
bind(OpenEditorsTreeDecorator).toService(NavigatorSymlinkDecorator);
});
68 changes: 68 additions & 0 deletions packages/navigator/src/browser/navigator-symlink-decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/********************************************************************************
* 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, postConstruct } from '@theia/core/shared/inversify';
import { Emitter, Event, nls } from '@theia/core';
import { TreeDecorator, Tree, TreeDecoration, DepthFirstTreeIterator } from '@theia/core/lib/browser';
import { FileStatNode } from '@theia/filesystem/lib/browser';
import { DecorationsService } from '@theia/core/lib/browser/decorations-service';

@injectable()
export class NavigatorSymlinkDecorator implements TreeDecorator {

readonly id = 'theia-navigator-symlink-decorator';

@inject(DecorationsService)
protected readonly decorationsService: DecorationsService;

@postConstruct()
protected init(): void {
this.decorationsService.onDidChangeDecorations(() => {
this.fireDidChangeDecorations((tree: Tree) => this.collectDecorator(tree));
});
}

async decorations(tree: Tree): Promise<Map<string, TreeDecoration.Data>> {
return this.collectDecorator(tree);
}

protected collectDecorator(tree: Tree): Map<string, TreeDecoration.Data> {
const result = new Map<string, TreeDecoration.Data>();
if (tree.root === undefined) {
return result;
}
for (const node of new DepthFirstTreeIterator(tree.root)) {
if (FileStatNode.is(node) && node.fileStat.isSymbolicLink) {
const decorations: TreeDecoration.Data = {
tailDecorations: [{ data: '⤷', tooltip: nls.localizeByDefault('Symbolic Link') }]
};
result.set(node.id, decorations);
}
}
return result;
}

protected readonly onDidChangeDecorationsEmitter = new Emitter<(tree: Tree) => Map<string, TreeDecoration.Data>>();

get onDidChangeDecorations(): Event<(tree: Tree) => Map<string, TreeDecoration.Data>> {
return this.onDidChangeDecorationsEmitter.event;
}

fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
this.onDidChangeDecorationsEmitter.fire(event);
}

}