Detecting new file

Post here questions and problems related to editing and publishing DITA content.
sanGeoff
Posts: 42
Joined: Mon Aug 18, 2014 11:50 pm

Detecting new file

Post by sanGeoff »

Is it possible to detect when a file was just created from a template?

I supposes for unsaved files the title would always be Untitled# and I can use isNewDocument(). But what about documents just created from a template using the DITA Map > insert > New Topic ?

What I am trying to do is always enable track changes, except for when the file has just been created from a template. I suppose I could put some flag or PI in all the template files that get striped off when the file is about to be saved but that seems kind of tweak.
Radu
Posts: 9446
Joined: Fri Jul 09, 2004 5:18 pm

Re: Detecting new file

Post by Radu »

Hi,
I supposes for unsaved files the title would always be Untitled# and I can use isNewDocument().
Right.
But what about documents just created from a template using the DITA Map > insert > New Topic ?
Indeed for such cases the isNewDocument() API returns false because the file was already created and saved on disk before being opened.
What I am trying to do is always enable track changes, except for when the file has just been created from a template. I suppose I could put some flag or PI in all the template files that get striped off when the file is about to be saved but that seems kind of tweak.
So when somebody uses DITA Map > insert > New Topic to insert a topic you would like the newly created and opened topic to have track changes off? Then if the user closes and reopens it you would toggle track changes on it?
But why make this difference between new files and existing files?

One possibility I would see for this would be to add a listener to the DITA Map Editor manager to see when a new DITA Map is opened. Then on the opened DITA Map use the API ro.sync.exml.workspace.api.editor.page.ditamap.WSDITAMapEditorPage.setPopUpMenuCustomizer(DITAMapPopupMenuCustomizer) to set a popup menu customizer which replaces the Append Child->New topic action with your own action which sets a flag, then calls the default action and then resets it.
You would look at that flag when a new topic is opened to see if it was triggered from that action.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sanGeoff
Posts: 42
Joined: Mon Aug 18, 2014 11:50 pm

Re: Detecting new file

Post by sanGeoff »

But why make this difference between new files and existing files?
Because in our current environment, editors know if a file is new or not based on the version history or if there are no tracked changes, then the entire file content is new and needs to be reviewed. Its kinda silly for the entire document to be marked up with inserts. I was able to accomplish what I we need with a PI and the following code in editorOpened():

Code: Select all

AuthorNode an = topNodes.get(0);
if(an.getType() == AuthorNode.NODE_TYPE_PI && an.getTextContent().equals("New Document")) {
if(revCtrlr.isTrackingChanges())
revCtrlr.toggleTrackChanges();
ctrl.deleteNode(an);
}
Post Reply