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

How to customize icons for a new file extension #5681

Closed
bobbyz007 opened this issue Jul 10, 2019 · 2 comments
Closed

How to customize icons for a new file extension #5681

bobbyz007 opened this issue Jul 10, 2019 · 2 comments
Labels
question user / developer questions

Comments

@bobbyz007
Copy link

In project explorer, I created a new file with extension '.test' and wanna display a customized file icon in left side for it, is LabelProviderContribution the right way? best to show me an example.

@kittaakos kittaakos added the question user / developer questions label Jul 11, 2019
@kittaakos
Copy link
Contributor

In your extension, you have to subclass the WorkspaceUriLabelProviderContribution:

@injectable()
export class YourUriLabelProviderContribution extends WorkspaceUriLabelProviderContribution {

    canHandle(element: object): number {
        if ((element instanceof URI || FileStat.is(element)) && your element) {
            return Number.MAX_SAFE_INTEGER; // Or a higher number than the default one.
        }
        return super.canHandle(element);
    }

    async getIcon(element: URI | FileStat): Promise<string> {
        if (your element) {
            return your icon. // For instance, `fa fa-file`.
        }
        return super.getIcon(element);
    }

}

// where `your element` has to check the file extension of the URI.

Then you have to bind your label provider contribution in your frontend module:

bind(LabelProviderContribution).to(YourUriLabelProviderContribution).inSingletonScope();

I hope this helps. If so, please close the issue. Thank you!

@bobbyz007
Copy link
Author

@kittaakos It works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question user / developer questions
Projects
None yet
Development

No branches or pull requests

2 participants