How to ensure that all modified files in project saved to fs from plugin?

Answered

I found that I can call project method for that 

com.intellij.openapi.project.Project.save(isForce = false)

is that right approach?

4 comments
Comment actions Permalink

The `Project.save()` method writes project configuration files (roughly, *.iml and the ones under .idea/). To write other files, use `FileDocumentManager.getInstance().saveAllDocuments()`.

(minor clarification: the method `Project.save()` doesn't have any parameters; the one with the boolean parameter belongs to the `ProjectEx` class; of the two, better use the former)

0
Comment actions Permalink

Thx, when I tried to use it, it fails with:

java.lang.Throwable: Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any"). See TransactionGuard documentation for details.
current modality=ModalityState.NON_MODAL
known modalities:
ModalityState:{}, writingAllowed=true;
ModalityState.NON_MODAL, writingAllowed=true;
ModalityState:{[Loading Project 1356371200: running=false; canceled=false]}, writingAllowed=true
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
at com.intellij.openapi.application.TransactionGuardImpl.assertWriteActionAllowed(TransactionGuardImpl.java:232)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:289)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments(FileDocumentManagerImpl.java:281)
at com.github.clouddevdesktopplugin.actions.BuildAnAction.actualPerform(BuildAnAction.java:26)
at com.github.clouddevdesktopplugin.actions.BasicAnAction.lambda$actionPerformed$0(BasicAnAction.java:48)
at com.intellij.openapi.wm.impl.commands.InvokeLaterCmd.lambda$run$0(InvokeLaterCmd.java:37)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:719)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:668)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:363)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

What does it mean?

0
Comment actions Permalink

Wow. Now I see my problem, thx.

0

Please sign in to leave a comment.