Page 1 of 1

Create PopUp Menu Customizer

Posted: Thu Nov 16, 2023 2:24 pm
by Isabelle
Hello,

We use Author web in version 26.0.0, and we are looking for an equivalent of the method :

Code: Select all

((WSAuthorEditorPage) wsEditorAccess.getCurrentPage()).addPopUpMenuCustomizer
For our desktop version, with oxygen sdk, we use a popUpMenuCustomizer which implements AuthorPopupMenuCustomizer.
We use it to provide user grammatical correction.

Here is a use case :
- Open a document
- Add the following sentence : She do something
- Launch our grammatical correction action
- Place cursor on "do" word
- Display popUpMenu with right click
- PopUpMenu show possible corrections elements on the top and common actions underneath.

Is it possible to do the same things in Author Web ?
If yes, can we use the addPopUpMenuCustomizer method or should we use an other API ?

Thanks,
Regards,
Isabelle

Re: Create PopUp Menu Customizer

Posted: Fri Nov 17, 2023 4:39 pm
by Bogdan Dumitru
Hello Isabelle,

There is an API that you can use to customize spelling suggestions, see SpellcheckingEngine and WebappSpellchecker.
This allows you to define and install a custom SpellcheckingEngine, somewhat like this:

Code: Select all

AuthorDocumentModel.getSpellchecker().setSpellcheckingEngine("it", new YourSpellcheckingEngine());
To install it on every AuthorDocumentModel you can use a WorkspaceAccessPluginExtension:

Code: Select all

public class EditorListener implements WorkspaceAccessPluginExtension {
	@Override
	public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
		WebappPluginWorkspace webappPluginWorkspace = (WebappPluginWorkspace) pluginWorkspaceAccess;
		webappPluginWorkspace.addEditingSessionLifecycleListener(new WebappEditingSessionLifecycleListener() {
			@Override
			public void editingSessionStarted(String sessionId, AuthorDocumentModel documentModel) {
				// TODO: install spellcheck engine in the "documentModel".
			}
		});
	}
[...]

Re: Create PopUp Menu Customizer

Posted: Fri Nov 17, 2023 8:13 pm
by Isabelle
Hello Bogdan,

Thank you for your idea, but it does not suit our need.

A SpellCheckingProblemInfoWithSuggestions has only the following attributs :
- startOffset - The start offset of the word.
- endOffset - The end offset of the word.
- lang - ISO Name for the language of the word.
- word - The word found at the offsets.
- suggestions - List of suggestions, should not be null.

But we need the type of the error (Misspelling, Grammar or Other, like style issues, ex : two white space instead of one) and we also need the detail of the error.
Your solution does not provide a way to handle those elements.

That is why we need to manage our own spell checker and we need to implement a PopupMenuCustomizer.

Is it possible or not ?
And if yes, how can we do it ?

Thanks,
Regards,
Isabelle

Re: Create PopUp Menu Customizer

Posted: Mon Nov 20, 2023 4:27 pm
by cosminef
Hello,

For the use case where there are two white spaces instead of one, Web Author automatically detects the empty spaces, and if there is more than one empty space, it automatically corrects the error after saving the document.
Regarding "misspelling", if there are two repeated words one after the other in a paragraph, for example, the duplicated word is considered as misspelled instead of being recognized as a duplicate. Is this the scenario you are referring to ?

Best Regards,
Cosmin

Re: Create PopUp Menu Customizer

Posted: Mon Nov 20, 2023 6:10 pm
by Isabelle
Hello Cosmin,

Not only this scenario, we have a lot of rules for Misspelling, Grammar and style errors.

We are not looking for an other solution, we want to implement our own solution.

And for that we need to customize the pop up menu, like we have done before we the oxygen sdk and the classe : AuthorPopupMenuCustomizer

Regards,
Isabelle

Re: Create PopUp Menu Customizer

Posted: Tue Nov 21, 2023 6:19 pm
by Bogdan Dumitru
Hi Isabelle,

There is no dedicated API that you can use but you might be able to implement your use-case using the non-persistent highlight API.
Render non-persistent highlights for spelling errors with the error type specified as highlight additional data, see the example from this post: "highlighter.addHighlight(startOffset, endOffset, null, attrs)" that adds a custom class.
Then add actions in the contextual menu that get enabled depending on the highlight present on the caret position.

Re: Create PopUp Menu Customizer

Posted: Tue Nov 21, 2023 6:55 pm
by Isabelle
Hello Bogdan,

For information, the link you gave does not work.
Bogdan Dumitru wrote: Tue Nov 21, 2023 6:19 pm Then add actions in the contextual menu that get enabled depending on the highlight present on the caret position.
Can you tell me more on how can I add actions dynamically in contextual menu.

Thanks,
Regards,
Isabelle

Re: Create PopUp Menu Customizer

Posted: Wed Nov 22, 2023 1:47 pm
by Bogdan Dumitru
Hi,

Sorry about the broken link. The correct link is: viewtopic.php?p=72796#p72796

And here you can find a tutorial that shows how to add actions, look for addToContextMenu: https://www.oxygenxml.com/maven/com/oxy ... ction.html