Custom file editor / save file
已回答
I have a custom editor just implementing FileEditor. It has a JPanel contains 3 textfields. I want to
1. Notify the editor frame that content is dirty, (want the asterisk). Or is there an option for this?
2. When the USER performs Save action, editor will collect and calculate some data and calculate the hash then crypt it using AES. Finally save it to the VirtualFile s path.
If manually save for user is not possible how to hook in save action to implement the second question?
Thanks
请先登录再写评论。
1) You can use `FileEditor#isModified`.
See also `FileEditor#PROP_MODIFIED` and `FileEditor#addPropertyChangeListener`.
2) Probably, you can listen for `FileDocumentManagerListener#beforeAllDocumentsSaving` with `com.intellij.AppTopics#FILE_DOCUMENT_SYNC`.
Hi. Thanks for reply.
1. isModified is a hook where IDEA checks the file modifications. I must return correct state, i see that. But my question was Notifying IDEA to check file modification and perform save actions, since im hiding default editor. I mean the default editor/text editor hidden, the user enters values to the JTextFields. So i must notify IDEA on value change of JTextFields some thing like firePropertyChange(PROP_MODIFIED).....
2. I understand it.
Which part of IDE do you want to notify about this change? What should it do with that notification?
If the file is a text one and changes in JTextFields are not mirrored to corresponding Document, that won't work.
Because even if event is fired, some code in IDE will re-check Document and will find old content in it (and will not update Psi, for example).
Well, i have an FileEditor implementation to modify my custom extension (.dta) which hides default IDEA text editor. It has an XML content and one digest content. When i read the file using path from VirtualFile, first decrypt the file then have a Document. Readed fields presented with 3 JTextFields in the editor area.
And after user modification by using these 3 JTextFields i need to save this data using the reverse of the reading algorithm.
Now the problem comes to play; How i will say IDEA "this file needs to be saved now"?
Probably, by modifying Document and invoking `FileDocumentManager.saveDocument(Document)` on it (to sync Document -> VirtualFile / FS).