How do I mark a file as up-to-date? Follow
My VIM plugin provides its own undo/redo mechanism. If a user uses the plugin to undo all changes made to a file since it was opened last, I would like to mark the file as up-to-date but I can't figure out how to do this.
Anyone have any ideas?
I need this to work whether any VCS has been configured or not and whether Local VCS is enabled or not.
I tried AbstractVcsHelper.markFileAsUpToDate() with no luck.
Thanks,
Rick
Please sign in to leave a comment.
Did you put it in a write action?
Use ApplicationManager.getApplication().runWriteAction(runnable) to do that.
Hopefully this is the problem.
Jacques
It was already in a runWriteAction.
A debug statement in my code verifies I am calling markFileAsUpToDate but nothing happens. The star is still on the tab next to the file and the filename is blue (using CVS).
>The star is still on the tab next to the file
I bet that is why: you need to save the file first before making it up-to-date in LVCS.
Use FileDocumentManager.getInstance().saveAllDocuments().
If that fails try LocalVcs.save(). I am not sure what it does though ;)
Jacques
I forgot. After the markAsUptodate do FileStatusManager.getInstance(project).fileStatusChanged(file);
This is really that that will make the file name go black.
So try to execute all 3 following steps in this order:
1. save document,
2. mark file as uptodate,
3. status change notification
Jacques
Thank you very much - that did it. Though I made one small change:
FileDocumentManager.getInstance().reloadFromDisk(editor.getDocument());
AbstractVcsHelper.getInstance(p).markFileAsUpToDate(vf);
FileStatusManager.getInstance(p).fileStatusChanged(vf);
I used reloadFromDisk instead of save since this prevents the time stamp of the file from changing.
So cool - thanks again.
Rick
I am surprised!
Did you verify that it doesn't discard the unsaved changed in the editor and really perform a "revert"?
If it doesn't do that then the name of that method might not be adequate IMHO. It would be better called saveOrReloadFromDisk or something like that
Jacques
It does not save because the time stamp on the file is not updated. I have no changes in the file at this time - that is the point. The user has undone all changes using the undo features of the VIM plugin.
Revert is was I want - at least enough that Idea thinks the file has never been changed.
I'm happy with the results at this point.
Duh. Somewhere in our exchange I forgot what you were trying to accomplish ;) Obviously that method was the one to use!
Sometimes... I wonder why I still speak.
Jacques
OK - How do I do this with the 3.x API?
I tried the following:
vf.refresh(false, false);
AbstractVcsHelper.getInstance(proj).markFileAsUpToDate(vf);
FileStatusManager.getInstance(proj).refreshFileStatus(vf);
I still end up with the asterisk on the tab and cvs thinking the file has changed.
FileDocumentManager.getInstance().saveDocument(FileDocumentManager.getInstan
ce().getDocument(vf))
>and cvs thinking the file has changed.
CVS does not use local history in order to calculate file status. It's
calculating it comparing file last modified date and the date from file
entry (CVS/Entries file)
--
Olesya Smirnova
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Rick Maddy" <no_mail@jetbrains.com> wrote in message
news:8901826.1075574348674.JavaMail.itn@is.intellij.net...
>
>
>
changed.
Thanks but:
1) I'm looking for a solution for Idea 3.x.
2) I don't want to save the file, I want to reload the editor with the original, unchanged version from disk.
I have it working with Idea 4.x as described earlier in this thread. I am now trying to get my code to work with the older API.
Rick