AuthorDocumentModel features

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

AuthorDocumentModel features

Post by Konstantin »

Hi !!!
I use Webapp 18.0.0.3
I have questions about features AuthorDocumentModel.

I keep map of AuthorDocumentModel for each opened editor and thru it I get access to almost all data. I can get content, show messages on editor, setReadOnly ...
But I can't get status isDirty
I try get it thru

Code: Select all

final AuthorDocumentModel documentModel = getDocumentModel(editorUID);
WSEditor wsEditor = documentModel.getWSEditor().isModified();
for isModified() I get UnsupportedOperationException
The same I get for setModified(isDirty)

Is there way to get isDirty status thru AuthorDocumentModel?

Also I need get Actions and set they to Enable/Disable. The closest that I found documentModel.getActionsManager().getExtensionAction(String)
But array of actions don't contain my custom actions which I added thru JS
cristi_talau
Posts: 489
Joined: Thu Sep 04, 2014 4:22 pm

Re: AuthorDocumentModel features

Post by cristi_talau »

Hello,

We have client-side JS API for managing the "dirty" status of the editor [1]. Can you use that instead?

Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... ditor.html
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Can you use that instead?
No I must use Java.
I have big functionality in Java and I can't divide code
cristi_talau
Posts: 489
Joined: Thu Sep 04, 2014 4:22 pm

Re: AuthorDocumentModel features

Post by cristi_talau »

Hello,

Unfortunately, the dirty flag is designed to be a client-side feature. However, we were able to make use of it in a variety of situations.

Can you describe your use-case in more details? Maybe we can find a workaround.

Best,
Cristian
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

I made keeping state isDirty thru:

Code: Select all



goog.events.listen(editor, sync.api.Editor.EventTypes.DIRTY_STATUS_CHANGED, function(e) {
setDirty(e, editor, function() { });
});

function setDirty(event, editor, callback) {
new sync.ops.ServerOperation("webapp.extention.action.DirtyAction", editor.controller).doOperation(callback, {
"url": editor.options.url,
"isDirty": event.isDirty
}, null);
}

But I have problems with ReadOnly(Editable) mode in editor, because it implemented very bad. In read only mode I can use all actions (they not disabled but after using shows message that I can't use it).

And more worse when I type a text new letters show and at once hide.
It maybe not very bad but isDirty changes to true.
https://drive.google.com/open?id=0B8kWu ... 2NHY2NyQ0E

Also when I do some changes in text (not in ReadOnly) and press Undo to begin isDirty don't change to false.

Do you have plans to improve ReadOnly mode?
It is important for me and I need do something with it.
cristi_talau
Posts: 489
Joined: Thu Sep 04, 2014 4:22 pm

Re: AuthorDocumentModel features

Post by cristi_talau »

Hello,

In the upcoming release we have some improvements w.r.t dirty flag:
1. When you type in a read-only document the dirty flag is not set. However, the characters that you type will still appear for a second or so and the actions are still enabled - I registered an issue for this.
2. After making a change and pressing Undo, the dirty flag is reset to false.

We plan to have this release in August. This will include only the installation kits, so if you are developing your customization as a plugin, you will be able to use it with the new release.

I also wanted to mention the

Code: Select all

ro.sync.ecss.webapp.access.WebappAuthorEditorAccess.setReadOnly(String)
method that help you customize the message that will appear to the user when typing in a read-only document.

Best,
Cristian
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Ok. Thanks !!!
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Hi

I have problem with refreshing after editing content.
We used this code in Applet and text in AuthorMode was refreshed

Code: Select all


final AuthorAccess authorAccess = getAccess();
final AuthorDocumentController documentController = authorAccess.getDocumentController();

documentController.beginCompoundEdit();

documentController.removeAttribute(attrName, element);
documentController.setAttribute(attrName, new AttrValue(attrValue), element);
documentController.insertXMLFragment("", element.getStartOffset());

documentController.endCompoundEdit();
But in Webapp 18 text inserted in TextMode but there are no changes in AuthorMode.
If I change something in TextMode and return to AuthorMode the all my changes appear

I tried to do something like this but it does not works:

Code: Select all


  authorAccess.getEditorAccess().refresh();
authorAccess.getEditorAccess().refresh(node);
How can I refresh content or part content from AuthorDocumentModel or AuthorAccess?
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Else I found bug

Code: Select all


final AuthorAccess authorAccess = authorDocumentModel.getAuthorAccess()
final AuthorDocumentController documentController = authorAccess.getDocumentController();

int currentOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode node = documentController.getNodeAtOffset(currentOffset);
This code return not that node which shown on AuthorMode-Breadcrumbs for closed tags, like "<p/>" (return <body> node)
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: AuthorDocumentModel features

Post by Gabriel Titerlea »

Konstantin wrote:Hi

I have problem with refreshing after editing content.
We used this code in Applet and text in AuthorMode was refreshed

Code: Select all


final AuthorAccess authorAccess = getAccess();
final AuthorDocumentController documentController = authorAccess.getDocumentController();

documentController.beginCompoundEdit();

documentController.removeAttribute(attrName, element);
documentController.setAttribute(attrName, new AttrValue(attrValue), element);
documentController.insertXMLFragment("", element.getStartOffset());

documentController.endCompoundEdit();
But in Webapp 18 text inserted in TextMode but there are no changes in AuthorMode.
If I change something in TextMode and return to AuthorMode the all my changes appear

I tried to do something like this but it does not works:

Code: Select all


  authorAccess.getEditorAccess().refresh();
authorAccess.getEditorAccess().refresh(node);
How can I refresh content or part content from AuthorDocumentModel or AuthorAccess?
Can you explain in more detail what you want to achieve? How are you inserting the text, how does the user initiate the action of inserting some text?
I'm trying to understand your use-case so that we can implement the required API.
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: AuthorDocumentModel features

Post by Gabriel Titerlea »

Konstantin wrote:Else I found bug

Code: Select all


final AuthorAccess authorAccess = authorDocumentModel.getAuthorAccess()
final AuthorDocumentController documentController = authorAccess.getDocumentController();

int currentOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode node = documentController.getNodeAtOffset(currentOffset);
This code return not that node which shown on AuthorMode-Breadcrumbs for closed tags, like "<p/>" (return <body> node)
It's not a bug. The server does not know where the client-side caret is at all times. The server receives the client-sides caret position whenever an editing action is performed (E.g. inserting text).

Can you tell me what you want to achieve so that we may expose some API for your use-case?
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Gabriel Titerlea wrote: Can you explain in more detail what you want to achieve? How are you inserting the text, how does the user initiate the action of inserting some text?
I'm trying to understand your use-case so that we can implement the required API.
I insert different attributes and tags inside some tags.
For example from "<p/>" I make "<p conkeyref="chunk_xxx/p_topic_body_p_5_1"/> " and I need refresh content and do ReferenseResolving for this.
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Gabriel Titerlea wrote: It's not a bug. The server does not know where the client-side caret is at all times. The server receives the client-sides caret position whenever an editing action is performed (E.g. inserting text).

Can you tell me what you want to achieve so that we may expose some API for your use-case?
I need make something like this:
"<p/>" ---->>> "<p conkeyref="chunk_xxx/p_topic_body_p_5_1"/> "
Gabriel Titerlea
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: AuthorDocumentModel features

Post by Gabriel Titerlea »

Hello Konstantin,

Like I've previously mentioned, the server does not know where the client-side caret is. The server receives the client-sides caret position whenever an editing action is performed (E.g. inserting text or invoking an action). So I'm afraid that you can't do these changes from a different plugin. What you can do is to invoke Author Operations [1] from the client side using javascript. An operation that can help you with setting an attribute is ChangeAttributeOperation. The API for invoking this action also allows you to give it parameters:

Code: Select all


editor.getActionsManager().invokeOperation(
'ro.sync.ecss.extensions.commons.operations.ChangeAttributeOperation',
{
'name': 'conkeyref',
'value': 'chunk_xxx/p_topic_body_p_5_1'
}
);
You can look at our tutorial for adding a custom operation to the webapp toolbar for more information [2]

If the default operations aren't enough for a given situation, you can develop a custom Author Operation and add it to the DITA framework [3]. Make sure you annotate this operation as being Webapp compatible:

Code: Select all


@WebappCompatible
public class InsertFragmentOperation implements AuthorOperation {
}
Once this operation is in the framework, you can invoke it just as before.
The advantage of using this method is that you won't need to refresh the content of the editor, it will be refreshed as needed automatically.
If you will be implementing custom actions in the DITA framework you will need to add the updated framework to Web Author [4].

About the API to send the caret position to the server. We still have not decided whether we will include such API. And if we do it will take a while until it's available.


Let me know if you have other questions,
Gabriel


[1] http://oxygenxml.com/doc/versions/18.0/ ... tions.html
[2] https://www.oxygenxml.com/maven/com/oxy ... ction.html
[3] http://oxygenxml.com/doc/versions/18.0/ ... HowTo.html
[4] https://www.oxygenxml.com/doc/versions/ ... ,framework
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Hello
How can I get cursors offset in JS.
As you wrote I want use:

Code: Select all

editor.getActionsManager().invokeOperation(
'ro.sync.ecss.extensions.commons.operations.ChangeAttributeOperation',
{
'params': params',
'offset': editor.offset <<--- ???
}
);
to change tags attributes and insert text fragments to editor.
But I cant find how can I get cursor offset.
cristi_talau
Posts: 489
Joined: Thu Sep 04, 2014 4:22 pm

Re: AuthorDocumentModel features

Post by cristi_talau »

Hello,

The API for invoking an operation is:

Code: Select all

sync.api.ActionsManager.prototype.invokeOperation = function(className, params, callback, opt_selection) { ... }
The selection is optional, and if you do not pass anything, the current caret position will be used. Currently we have limited API to create selections. For example: editor.getSelectionManager().getSelection() returns the current selection. There are also a couple of methods for working with selections [1].

We are currently working to provide more API to work with the XML DOM and selections. Can you share your use-case, so that we make sure that it is covered by the new API?

Best,
Cristian

[1] https://www.oxygenxml.com/maven/com/oxy ... ction.html
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: AuthorDocumentModel features

Post by Konstantin »

Thanks. All work.
I changed calling Java function which insert new content thru JS but not thru servlet as was early.
And now:

Code: Select all

int currentOffset = authorAccess.getEditorAccess().getCaretOffset();
returns right offset.
cristi_talau
Posts: 489
Joined: Thu Sep 04, 2014 4:22 pm

Re: AuthorDocumentModel features

Post by cristi_talau »

Hello,

I wanted to let you know that we are about to release Web Author 19.1 and that we improved the handling of read-only mode.

You can already test how it works by going to our online demo server: https://www.oxygenxml.com/webapp-demo-a ... xygen.html . In order to switch the document to read-only mode you can use the DevTools to run the following code:

Code: Select all


// DO NOT USE IN PRODUCTION
workspace.currentEditor.setReadOnlyState({readOnly: true, message: 'Document is not checked out.'})
Best,
Cristian
Post Reply