Synchronize a folder

hello,

In the project tab it's possible to right click on a folder and click "synchronize". I need to be able to do this with code.
Does anyone know what class in the openapi has this functionality?

thanks.

6 comments

Hello Aaron,

AA> In the project tab it's possible to right click on a folder and
AA> click "synchronize". I need to be able to do this with code.
AA>
AA> Does anyone know what class in the openapi has this functionality?

I don't know what exactly you would like to accomplish, but most likely you
need VirtualFileSystem.refresh() or VirtualFile.refresh() with 'recursive'
parameter set to true.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hello Dmitry,
thanks for your reply.
I'm working on the simpleuml plugin and i'm trying to add buttons to the classdiagram view to allow the addition of new classes. At the moment all you can do is add a class that already exists. I couldnt work out how to create a psiclass properly without a .java file existing on the disk (or even if psiclass is designed for this).
So what i'm doing is creating the .java file and then adding it normally. The problem i'm running into is after i create the file, intellij takes a while to update so when i try to add the class to the diagram it can't find it yet with PsiManager.findClass().
This doesnt seem like a very good way to do things to me but i guess it means that any changes will still be there after a crash.
Can you think of a better way to do this?

thanks.

0

Thanks again. VirtualFileManager.getInstance().refresh( false ) is what i wanted.
There is an assertion failure in diagnostic.Logger but everything still seems to be working ok.

0

Hello Aaron,

AA> I'm working on the simpleuml plugin and i'm trying to add buttons to
AA> the classdiagram view to allow the addition of new classes. At the
AA> moment all you can do is add a class that already exists. I
AA> couldnt work out how to create a psiclass properly without a .java
AA> file existing on the disk (or even if psiclass is designed for
AA> this).

To create a class programmatically, you need to use PsiManager.getInstance(project).getElementFactory().createClassFromText()
to create an in-memory class and then PsiDirectory.add() to save the class
to a directory on disk. After that, you won't need to perform any refreshes
manually.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hello Aaron,

AA> Thanks again. VirtualFileManager.getInstance().refresh( false )
AA> is what i wanted. There is an assertion failure in diagnostic.Logger
AA> but everything still seems to be working ok.

To avoid the assertion, wrap the refresh() call in ApplicationManager.getApplication().runWriteAction(),
and make sure that you call it from the event dispatch thread.

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hello Dmitry,

Whoops i didnt see your post above about the createClassFromText() method. I'll use that instead of writing manually and using refresh.

Thanks again,
Aaron.

0

Please sign in to leave a comment.