Page 1 of 1

Action Disable

Posted: Wed May 11, 2016 6:13 pm
by Konstantin
Hello !

I use WebApp 18.0.0

I need disable action when there is changes in editor.
Actions does not have property Enable.
I tried write something like this, but it not works:

Code: Select all

goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
window.editor = e.editor;

goog.events.listen(window.editor, sync.api.Editor.EventTypes.DIRTY_STATUS_CHANGED, function(e) {
CheckInAction.isEnabled = function() {
return !e.isDirty;
};
});
});
How could I do this?

Re: Action Disable

Posted: Wed May 11, 2016 6:27 pm
by cristi_talau
Hello,

The status (enabled or disabled) of the actions is not updated automatically. You should call the "refreshActionsStatus" method of the actions manager to trigger a status refresh.

Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... ionsStatus

Re: Action Disable

Posted: Thu May 12, 2016 11:38 am
by Konstantin
I did as you said but it does not work. Could you correct me

I signed to Editor after editor load.

Code: Select all

goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
window.editor = e.editor;
});
I created new action.

Code: Select all

CheckInAction = function(editor, docId, problemReporter) {
this.editor = editor;
this.docId = docId;
this.problemReporter = problemReporter;
};
Then I override method isEnabled

Code: Select all

CheckInAction.prototype.isEnabled = function() {
return !this.editor.isDirty();
};
Then I added the action to toolbar

Code: Select all

goog.events.listen(workspace,
sync.api.Workspace.EventType.BEFORE_EDITOR_LOADED, function(e) {
var editor = e.editor;
var preventLeave = e.preventLeave;
var docId = e.docId;
var problemReporter = e.problemReporter;
// Register the newly created action.
editor.getActionsManager().registerAction('checkIn.action',
new CheckInAction(editor, docId, problemReporter));
addToDitaToolbar(editor, 'checkIn.action');
});
Then I try refresh status action by Click on button or by Changing content in editor but nothing happen.

Code: Select all

CheckInAction.prototype.actionPerformed = function(callback) {

this.actionsManager.refreshActionsStatus(["checkIn.action"]);

......
};

goog.events.listen(window.editor, sync.api.Editor.EventTypes.DIRTY_STATUS_CHANGED, function(e) {
this.actionsManager.refreshActionsStatus(["checkIn.action"]);-
});
By click button the refresh does nothing.
And listener does not called.

Re: Action Disable

Posted: Thu May 12, 2016 12:00 pm
by Konstantin
All right
I found error for button click (not right scope of variables)
Thanks )