writing to the current editor file?
I've written a cheesy little plugin that optimizes imports in the currently
open editor file the way I like my imports to be. It works, but currently
has an undesired side-effect: when I invoke my plugin on a "dirty" file (one
that hasn't yet been written to disk), I get a "Changes have been made to
(file) in memory and on disk. Reload from disk?" message box. How can I
get rid of that message box?
Currently, I'm reading the contents by doing
VirtualFile file = (VirtualFile)
event.getDataContext().getData(DataConstants.VIRTUAL_FILE);
char[] contents = file.contentsToCharArray();
This gives me the not-yet-written file contents, which is exactly what I
want. I'm writing the new contents by doing
Writer out = file.getWriter(ourClientProperty);
out.write(...);
out.close();
file.refresh(false, false);
(all from inside a runWriteAction() call)
This works, but has the possibly unintended side-effect of saving the
contents of the current editor window. Is there a way I can just muck with
the in-memory editor contents, and let the user actually take care of
saving? Alternatively, can I just force the reload from disk? I thought
that's what the refresh() call was supposed to do...
mike
请先登录再写评论。
Hi,
Call project.saveAllDocuments() before.
--
Best regards,
Mike Aizatsky.
-
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
Beautiful. That did the trick.
Will there be a mechanism for writing to the currently-edited files without
writing to disk? Basically the reverse of
VirtualFile.contentsToCharArray()...
Is there (or will there be) any way for me to make sure my plugin gets
called when writing a file to disk? My plugin could work more transparently
if I could just "hook" the save action and muck with the code before it's
actually saved.
mike
"Mike Aizatsky" <mike@intellij.com> wrote in message
news:afv1g4$97r$1@is.intellij.net...
>
>
>
>
>
I think that would be a bit TOO transparent.
If you are planning to release this, I think users
want to reformat only when they ask for it.
Would be really cool if you could hook into the Optimize
Imports command. I have thought about an action listener that gets
called when the action you are listening to gets invoked.
schmoe wrote:
>>Hi,
>>
>>
>>>How can I get rid of that message box?
>>
>>Call project.saveAllDocuments() before.
>>
>>--
>>Best regards,
>>Mike Aizatsky.
>>----
>>JetBrains, Inc / IntelliJ Software
>>http://www.intellij.com
>>"Develop with pleasure!"
>>
>>
--
Erb
==============================================================
"Most of you are familiar with the virtues of a programmer.
There are three, of course: laziness, impatience, and hubris."
- Larry Wall
==============================================================
Hi,
without
Sure... It's on the way.
Consider using VirtualFileListener.
--
Best regards,
Mike Aizatsky.
-
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"