Get Project from FileDocumentSynchronizationVetoListener

Hi

I'm listening for when files are saved.
I want to get the project once saved and call methods in a class there.
How can I do this.  My method is below...

FileDocumentManager.getInstance().addFileDocumentSynchronizationVetoer(new FileDocumentSynchronizationVetoListener() {
            public void beforeDocumentSaving(Document document) throws VetoDocumentSavingException {
                VirtualFile vf = FileDocumentManager.getInstance().getFile(document);
                Project project = getProject(?????);
                ForceCompiler fc = project.getComponent(ForceCompiler.class);
                fc.fileChanged(vf);
            }

            public void beforeFileContentReload(VirtualFile virtualFile, Document document) throws VetoDocumentReloadException {
                LOG.debug("beforeFileContentReload: " + document);
            }

        });

9 comments

Hello Mike,

First of all, you should be using FileDocumentManagerListener instead of
the Vetoer API, which has a very specific purpose not related to what you're
trying to achieve.

Second, documents exist in application scope, and the change in a document
affects all projects equally. You should probably get all open projects,
find which of them contain the changed virtual file in the content, and fire
the change notification for all of those projects.

I'm listening for when files are saved.
I want to get the project once saved and call methods in a class
there.
How can I do this.  My method is below...
FileDocumentManager.getInstance().addFileDocumentSynchronizationVetoer
(new FileDocumentSynchronizationVetoListener() {
public void beforeDocumentSaving(Document document) throws
VetoDocumentSavingException {
VirtualFile vf =
FileDocumentManager.getInstance().getFile(document);
Project project = getProject(?????);
ForceCompiler fc =
project.getComponent(ForceCompiler.class);
fc.fileChanged(vf);
}
public void beforeFileContentReload(VirtualFile
virtualFile, Document document) throws VetoDocumentReloadException {
LOG.debug("beforeFileContentReload: " + document);
}
});

---
Original message URL:
http://devnet.jetbrains.net/message/5281641#5281641


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

If I use the FileDocumentManagerListener will it give me notification of files changed on the filesystem outside of the IDE?

For example I have an ant script that takes my javascript and minifies it and then copies it into another directory.
I would like to know when the files in that directory have been copied so I can add them to my list of files to deploy.
Currently with the vetolistener I don't get notified of these changes.

Do you have an example or a pointer to an example on how to register and use the FileDocumentManagerListener?
Or an example if there is another way to achieve what I'm trying to do?

Thanks
Mike

0

I figured it out, changed to use filelistener and all working well.

0

Another question.

How can I detect when new files have been added outside of intellij by just copying files into the directory?
Also same for an action the creates a new file in the project?

Thanks

0

Hello Mike,

The VFS listener allows you to receive notifications about all changes in
the filesystem, regardless of their source.

Another question.

How can I detect when new files have been added outside of intellij by
just copying files into the directory?

Also same for an action the creates a new file in the project?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Hi Dmitry

Is there an example anywhere on how to use VirtualFileManager.VFS_CHANGES topic?
Is see it there but I'm unsure how do I use it?  How do I subscribe to receive topic messages, ie: Is there classes in IntelliJ that I use to do this?

Thanks

0

Hello Mike,

You subscribe to a topic via the MessageBus class. See the FileTemplateManagerImpl
class in the CE source code for a usage example.

Is there an example anywhere on how to use
VirtualFileManager.VFS_CHANGES topic?

Is see it there but I'm unsure how do I use it?  How do I subscribe to
receive topic messages, ie: Is there classes in IntelliJ that I use to
do this?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

So I've got this working.
But I have yet another question. ;)

Can I use this API to stop a deletion.  Basically before the actual delete I want to try to delete the file from server.  If that fails I don't want IntelliJ to delete the file locally?

Thanks

0

Hello Mike,

This can be accomplished via LocalFileOperationsHandler.

So I've got this working.
But I have yet another question.
Can I use this API to stop a deletion.  Basically before the actual
delete I want to try to delete the file from server.  If that fails I
don't want IntelliJ to delete the file locally?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.