I have been struggling with a problem in the subject for a bit longer than I would admit.
I am trying to programmatically perform the same Action that occurs when the user either clicks View > Collapse All , or right-click in the editor window, and then Code Folding > Fold All .
What I tried \ found so far:
String that corresponds to Action can be found in enum com.mathworks.mde.editor.ActionID and is: 'collapse-all-folds' .- When you activate
Action , the following method is org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...) : org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...) (hence the netbeans tag). - This code allows me to get instances of
EditorAction , ActionManager , MatlabEditor :
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor; jAm = com.mathworks.mde.editor.ActionManager(jEd); jAc = com.mathworks.mde.editor.EditorAction('collapse-all-folds');
My problem is that I cannot find a way to actually activate the Action .
Any ideas / alternatives?
EDIT1 : after you worked a little in the βbookβ , I think I came even closer than before (but still not quite there). Quote from the book:
Java GUI components often use ActionMap to store runnable Actions that are called by listeners on the mouse, keyboard, properties, or container events. Unlike object methods, Actions cannot be directly called MATLAB.
And then a workaround is explained that includes something like: getting some Action object; creating an ActionEvent and calling the Action actionPerformed with the ActionEvent as an argument, as shown below:
import java.awt.event.*; jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor; jAm = com.mathworks.mde.editor.ActionManager(jEd); jAc = jAm.getAction(com.mathworks.mde.editor.EditorAction('collapse-all-folds')); jAe = ActionEvent(jAm, ActionEvent.ACTION_PERFORMED, ''); jAc.actionPerformed(jAe);
This code works without errors - but (it seems?) Nothing. I suspect that I am ActionEvent and actionPerformed on the wrong objects (the ActionManager has nothing to do with this problem at all).
PS
I know that there is a hotkey that does this ( Ctrl + = ), but thatβs not what I am looking for (if there is no command to simulate a hotkey, press :)).
java matlab netbeans matlab-java
Dev-il
source share