Displaying modified indicator with custom editor (JCEF)

Answered

Hi

 

I am struggling to get the modified indicator (the asterisk in the editor tab), with a custom editor (JCEF based).

I know about `FileEditor.PROP_MODIFIED`, I have implemented the property change listeners as indicated in this comment (and elsewhere)

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206117739/comments/206692809

 

My editor looks like

class ExcalidrawEditor(
private val project: Project,
private val file: VirtualFile
) : FileEditor,
EditorColorsListener,
DumbAware {

...
private val viewController = ... // the component handling JCEF and webapp
private val propertyChangeSupport = PropertyChangeSupport(this)
private var modified = false

init {
...
viewController.changedPayload.adviseNotNull(lifetime) { content ->
modified = true
ApplicationManager.getApplication().invokeLater {
ApplicationManager.getApplication().runWriteAction {
propertyChangeSupport.firePropertyChange(FileEditor.PROP_MODIFIED, false, true)
}
}
}
...

override fun isModified(): Boolean {
return modified
}

override fun addPropertyChangeListener(listener: PropertyChangeListener) {
propertyChangeSupport.addPropertyChangeListener(listener);
}

override fun removePropertyChangeListener(listener: PropertyChangeListener) {
propertyChangeSupport.removePropertyChangeListener(listener);
}
}

The add/remove property change listener are called, when the content is changed in the browser frame the `changedPayload` (an `IPropertyView` from JetBrains/rd project) is notified as expected, and the code execute just fines in the `runWriteAction` lambda.

However the asterisk is still not shown.

Thanks in advance for any guidance.

0
4 comments

And it works for "regular" editors in the same instance? Preferences | Editor | General | Editor Tabs "Mark Modified" is enabled?

1

Facepalm. OK I feel stupid now, it works just fine with the right setting.

I forgot the sand-boxed IDE settings can get reset on various occasions.

 

Thanks for coping with me !

0

Always happy to avoid debugging :)

1

Please sign in to leave a comment.