How to dynamically call register action

Having trouble installing Oxygen? Got a bug to report? Post it all here.
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

How to dynamically call register action

Post by SmitaPatil »

Hi Team,
I have created on action and registered it using registerAction(id, action, shortcutopt) on click of one button.
After clicking on button we are showing popup which has list of valid element which can be inserted where cursor is present.
for creating popup , I am using workspace.createDialog() method.
but addition to that we have requirement, if suppose popup is open and then user changed cursor position then the element list in popup also should get updated based on current caret offset or cursor position.
Can you please tell is there any way to achieve it? or can we any way to call register action again if change in cursor position.
Please let me know if need any more information on it.

Thanks,
Smita
Bogdan Dumitru
Site Admin
Posts: 142
Joined: Tue Mar 20, 2018 5:28 pm

Re: How to dynamically call register action

Post by Bogdan Dumitru »

Hello Smita,

One easy solution would be to make the dialog modal so that users would be able to interact only with the dialog so that they won't be able to change the selection by clicking or arrow keys. See sync.api.Dialog.setModal API method.
Would that work for you?

If not, you can listen for selection change event, look for sync.api.SelectionModel and sync.api.SelectionModel.EventType.SELECTION_CHANGED.
Bogdan Dumitru
http://www.oxygenxml.com
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How to dynamically call register action

Post by SmitaPatil »

Hi Bogdan,
I can't go with the first option.
and for second, I will try it.
Thank you

Thanks,
Smita
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How to dynamically call register action

Post by SmitaPatil »

Hi Bogdan,

Actually following event listener will call every time when user will make changes even if it is in register action or not.
goog.events.listen(workspace, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
var editor = e.editor;
var selectionModel = editor.getSelectionManager();
var eventHandler = new goog.events.EventHandler(this)
eventHandler.listen(selectionModel, sync.api.SelectionManager.EventType.SELECTION_CHANGED, function() {
var currentSelection = selectionModel.getSelection();
console.log("Selection changed ", currentSelection);
});
I don't want to call it in general. want to call just in case if it is in specific (insert markup) register action.
I am trying to add listener in dialog. do we have any example to add this listener to any html element(eg. button or dialog)
Can we please help me here for listening and unlistening this event.

Thanks,
Smita
SmitaPatil
Posts: 93
Joined: Mon Aug 08, 2022 2:32 pm

Re: How to dynamically call register action

Post by SmitaPatil »

Hi Bogdan,
just wanted to know if there is any callback or something available when dialog get disposed after clicking on X i.e close icon.
I am using workspace.createDialog() method.

Thanks,
Smita
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: How to dynamically call register action

Post by Gabriel Titerlea »

Hello,

You can register the listener when you open the dialog. And you can unlisten when the dialog closes.
Example:

Code: Select all

var dialog = workspace.createDialog();

......

dialog.show();
dialog.onSelect(() -> {
  eventHandler.unlisten(.....);
});
Note that the onSelect callback must be registered again, after the dialog closes [1].

Best,
Gabriel

[1] https://www.oxygenxml.com/maven/com/oxy ... ct__anchor
Post Reply