Displaying a dialog box when the editor content is changed

I want to display a dialog box each time user changes editor contents. I think I have to use a document listener for that! But I do not know how to override the relevant methods inorder to detect the editor changes! how can I do it?

0

Editor switch listener:

MessageBus bus = project.getMessageBus();
bus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
//your code
}
});

Contents of editor changed listener:

Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
editor.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void documentChanged(DocumentEvent event) {
//your code
}
});

 

0
Avatar
Permanently deleted user

Hi thanx in which method do I have to place this?  Is it the project opened?

 

 

0

Yes, you can add e.g. the first listener in the 'projectOpened' method of your ProjectComponent.

0

请先登录再写评论。