plugin development | changed file reload

Answered
Hellow!!

I'm developing IntelliJ Plugin.
 
kotlin code : 
val file = File(fullPath)

file.copyTo(File(targetFullPath), true)

Copy file successfully with above code.

Question : If the file is already displayed on the IDE screen, Is there a way to put the file on the screen as soon as it is changed?

If you know, please check and reply. :)
0
6 comments

Hi,

Could you please elaborate more? Your use case is unclear to me.

Do I understand correctly, that you display a file in the editor, change its content and you want to refresh the content in the visible editor? Or maybe you want to activate the editor with the changed file? Or maybe you want to open a new copy of the file in the new editor? Please clarify.

1

Karol Lewandowski  Hi!

That situation.

1. The IDE screen displays the a.txt file.
All of them.
2. Click the button to copy the contents of the b.txt file to a.txt.
3. The contents of a.txt have changed, but will not appear immediately on the IDE screen.

I hope the a.txt will be reloaded immediately and displayed on the IDE screen.

0

Thanks for the clarification.

It is important to understand the Virtual File System used by IntelliJ Platform: https://plugins.jetbrains.com/docs/intellij/virtual-file-system.html
If you work on the physical files level, then it takes time for the platform to detect changes and refresh VFS.

Try to use Virtual File System API, e.g. copy files with VfsUtil.copy*() methods instead of standard files API.

1

Karol Lewandowski

Thank you for your kind reply!

Additionally

Is it not good to create a file and refresh it with the code below?

val currentFilePath: VirtualFile? = event.getData(PlatformDataKeys.VIRTUAL_FILE)
VfsUtil.markDirtyAndRefresh(false, true, false, currentFilePath);

0

Hi,

You can use markDirtyAndRefresh(), but the recommended approach is to use VFS API to operate on files, if possible.

1

Hi

I understood through VFS related documents and searches.
The VirtualFile concept is difficult but fascinating!
Successfully reloaded file after making changes via VirtualFile!

Thank you for your help.

0

Please sign in to leave a comment.