Part 2 of this tutorial is about the
EditorChangeListener and how we can use it to enable or disable our custom button on different file types. The code can be found in step2 branch in the GitHub repo.
Let’s say, our custom button should only be active/enabled/clickable when there is an XML file opened in the current oXygen editor tab.
First, we add an
EditorChangeListener with a new function in all it’s change methods:
checkCurrentEditorAndChangeButtonStatus() is a new method to check the current editor on any change in the oXygen editor panes. Everytime we change the current tab in oXygen, close a file or open a new one, the
checkCurrentEditorAndChangeButtonStatus() is called to check the current file URL:
First, we retreive the current editor with the method
pluginWorkspaceAccess.getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA) and check whether we have an editor opened or not.
Second, we retreive the file URL of the current editor with
currentEditor.getEditorLocation() and then check the file extension for
Based on these checks we either enable or disable the plugin demo button.
There’s also some other foo we have to change in order to get these changes to work. Check out the whole file CustomButtonPluginExtension.java in the GitHub repo in branch step2.
In part 3 we will learn how to check whether the file is opened in author- or text-mode. Stay tuned…