How to manually set Icon of a file.

For an example : I have a plugin where multiple users can connect and edit the files in the same project. I want to show a dot on top of icons of files currently accessed by other users.

I implemented IconProvider but it doesn't do the job for me. IconProvider gets called only when IDEA wants it to. Is there any way to manually set the icon for files?

3 comments
Comment actions Permalink

When the state of a file changes, you can ask IntelliJ IDEA to refresh its presentation (icon, colors etc.) by calling FileEditorManagerEx.updateFilePresentation().

0
Comment actions Permalink

Hi Dimitry, I tried it as shown in code below. When I run it for the first time getIcon() gets triggered. But after that it doesn't get triggered until some change is done to the file. Am I doing it wrong or is there any other way to refresh the icons whenever needed to?

As I mentioned earlier my primary requirement is to show a dot on top of file icons when a file is currently opened by a remote user and remove the dot when the remote user closes the file.

 
@Nullable
@Override
public Icon getIcon(PsiElement element, int flags) {
    
System.out.println("GET ICON TRIGGERED! "+element.getContainingFile().getName());
    return null;
}

 
@Override
public void actionPerformed(AnActionEvent e) {
    
VirtualFile files[] = FileEditorManager.getInstance(e.getProject()).getOpenFiles();
    for
(VirtualFile file : files){
        System.out.println("FILE NAME: "+file.getName());
        
FileEditorManagerEx.getInstanceEx(e.getProject()).updateFilePresentation(file);
    
}
}
0
Comment actions Permalink

Hi Dmitry,

unfortunately we could not get the feature to work yet. Is it possible at all to trigger the update of an Icon that is not opened in an editor? The method you mentioned (

FileEditorManagerEx.updateFilePresentation) checks whether the file is opened in an editor (see implementation).



Also there seem to be rules how icons are cached or not, even if you reopen editors and the like.

Is there a way I can trigger an update of the project view?

Is it necessary to override PresentationData?

0

Please sign in to leave a comment.