I've already got a working custom Intellij plugin. I can get and check the existing commit message, but I want to be able to disable the Commit button if the message doesn't contain certain information.
@Override
public void update(AnActionEvent e) {
CheckinProjectPanel checkinPanel = (CheckinProjectPanel) CheckinProjectPanel.PANEL_KEY.getData(e.getDataContext());
if (checkinPanel != null) {
String commitMessage = checkinPanel.getCommitMessage();
boolean isValidMessage = commitMessageIsValid(commitMessage);
// get Commit Button...somehow
JBOptionButton commitButton = checkinPanel.???;
commitButton.setEnabled(isValidMessage);
}
}
I want do disable the below button:
The problem is that I don't know how to gain access to the button. I can see it in the debug Variables panel, but those accessors are protected and cannot be used in compiled code.
This is my debug watch (picture above may not be clear enough):
((CommitChangeListDialog) checkinPanel).getButton(((CommitChangeListDialog) checkinPanel).getOKAction())
So, the button is there, I just don't know how to get it.
Help appreciated. Much thanks in advance.
The standard way to do such things is to implement a CheckinHandler and return CheckinHandler.ReturnResult.CANCEL
if a requirement is not met. Such CheckinHandlers are ran after user presses the Commit button. See GitCheckinHandlerFactory
for example.