Undo for text edit
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 5
- Joined: Mon Mar 09, 2020 2:02 pm
Undo for text edit
Dear Oxygen,
I am working on plugin for Oxygen Editor, which based on some user interaction it replaces text in a document. I done the text replacement logic based on some thread here on your forum ( i am working in author mode), so it looks something like this:
However the undo action does not appear even though beginCompoundEdit and endCompoundEdit is definitely called.
1) My question is that how can i make this work? Or what am i doing wrong here?
2) Another is question is that, can i do something similar in grid/text layout?
Thank you in advance,
Balazs Feher
I am working on plugin for Oxygen Editor, which based on some user interaction it replaces text in a document. I done the text replacement logic based on some thread here on your forum ( i am working in author mode), so it looks something like this:
Code: Select all
AuthorDocumentController docController = authorPageAccess.getDocumentController();
...
docController.beginCompoundEdit();
docController.delete(startOffset, endOffSet);
docController.insertText(startOffset, replaceWith);
docController.endCompoundEdit();
...
1) My question is that how can i make this work? Or what am i doing wrong here?
2) Another is question is that, can i do something similar in grid/text layout?
Thank you in advance,
Balazs Feher
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Undo for text edit
Hi Balasz,
In what context is your code called? On what API callback method? Is it called inside a custom AuthorOperation or on some kind of listener?
For the Text editing mode we do have some API (not as evolved as the one for Author):
https://www.oxygenxml.com/InstData/Edit ... rPage.html
As I do not know exactly your overall plans I do not know if there is enough API or not for what you need.
Regards,
Radu
I cannot find anything wrong with your code. So the undo action does not appear enabled after the code is executed, right?1) My question is that how can i make this work? Or what am i doing wrong here?
In what context is your code called? On what API callback method? Is it called inside a custom AuthorOperation or on some kind of listener?
We have no API at all for the Grid mode and we'll probably never add any.2) Another is question is that, can i do something similar in grid/text layout?
For the Text editing mode we do have some API (not as evolved as the one for Author):
https://www.oxygenxml.com/InstData/Edit ... rPage.html
As I do not know exactly your overall plans I do not know if there is enough API or not for what you need.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Mon Mar 09, 2020 2:02 pm
Re: Undo for text edit
Yes, the undo action does not become enabled.I cannot find anything wrong with your code. So the undo action does not appear enabled after the code is executed, right?
In what context is your code called? On what API callback method? Is it called inside a custom AuthorOperation or on some kind of listener?
It has been called from another thread. I have a web service, which has been called from a thread, response of which can start this replace action.
Regarding text mode, I am looking for something like the AuthorCaretListener in author mode. So some kind of event which occurs on user interaction (edit, caret movement...etc).We have no API at all for the Grid mode and we'll probably never add any.
For the Text editing mode we do have some API (not as evolved as the one for Author):
For grid layout, it is not that important. For text layout i found that there is no such event, but who knows, maybe it is on the road map, or i looked over something.
Thanks for the quick reply!
Balazs
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Undo for text edit
Hi Balasz,
So:
I want to know the entire workflow of the operation, for example:
1. I add a caret listener
2. When the caret moves I start a thread
3. When that thread finishes I use the Author API to makes changes somewhere in the document.
I'm interested to know if you make changes in the Author editor directly on an AuthorDocumentListener callback which you should not.
Also if you are calling Author API from a Thread, the Author model is not thread safe, try to make all calls to methods in the AuthorDocumentController on the AWT thread. For example you can use "SwingUtilities.InvokeAndWait" with a runnable code which makes the changes.
https://www.oxygenxml.com/InstData/Edit ... omponent--
After this, you can cast the editing component to JTextArea and use the regular Swing API to add a caret listener or a document listener.
Regards,
Radu
So:
And are the changes actually made in the editing area?It has been called from another thread. I have a web service, which has been called from a thread, response of which can start this replace action.
I want to know the entire workflow of the operation, for example:
1. I add a caret listener
2. When the caret moves I start a thread
3. When that thread finishes I use the Author API to makes changes somewhere in the document.
I'm interested to know if you make changes in the Author editor directly on an AuthorDocumentListener callback which you should not.
Also if you are calling Author API from a Thread, the Author model is not thread safe, try to make all calls to methods in the AuthorDocumentController on the AWT thread. For example you can use "SwingUtilities.InvokeAndWait" with a runnable code which makes the changes.
You can gain access to the swing JTextArea used to implement the text editing mode:Regarding text mode, I am looking for something like the AuthorCaretListener in author mode. So some kind of event which occurs on user interaction (edit, caret movement...etc).
https://www.oxygenxml.com/InstData/Edit ... omponent--
After this, you can cast the editing component to JTextArea and use the regular Swing API to add a caret listener or a document listener.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Mon Mar 09, 2020 2:02 pm
Re: Undo for text edit
Hi,
Regarding the first part of the issue, you were right the problem was that the model is not thread safe. With SwingUtilities it worked fine.
Regarding the second part, thank you for this information, it was really helpful!
Thanks again for your help and for the quick reply
Bets regards,
Balazs
Regarding the first part of the issue, you were right the problem was that the model is not thread safe. With SwingUtilities it worked fine.
Regarding the second part, thank you for this information, it was really helpful!
Thanks again for your help and for the quick reply
Bets regards,
Balazs
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service