Page 1 of 1
					
				How to dynamically call register action
				Posted: Thu Dec 01, 2022 11:04 am
				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
			 
			
					
				Re: How to dynamically call register action
				Posted: Thu Dec 01, 2022 11:54 am
				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.
			 
			
					
				Re: How to dynamically call register action
				Posted: Thu Dec 01, 2022 12:14 pm
				by SmitaPatil
				Hi Bogdan,
I can't go with the first option. 
and for second, I will try it.
Thank you
Thanks,
Smita
			 
			
					
				Re: How to dynamically call register action
				Posted: Thu Dec 01, 2022 12:29 pm
				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
			 
			
					
				Re: How to dynamically call register action
				Posted: Thu Dec 01, 2022 3:14 pm
				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
			 
			
					
				Re: How to dynamically call register action
				Posted: Fri Dec 02, 2022 1:20 pm
				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