DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 168
- Joined: Fri Feb 28, 2020 4:02 pm
DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post by vishwavaranasi »
Hello Team , with our custom insert actions we are inserting a topicref from DITAMAPS Manager -> Insert Before ->{custom insert action} to ditamap opened inside the DITA Maps Manager
this action works fine , inside the insert action method we also calling the the following method() to save the ditamap and reload the map.
but after this method executed , we keep getting the prompt as below
would you please help us here , how do we avoid the prompt
this action works fine , inside the insert action method we also calling the the following method() to save the ditamap and reload the map.
Code: Select all
WSEditor mainEditor = null;
if(DITAAccess.getRootMapURL()==null) {
logger.info("Selected RootMap is null, no map will be updated");
return;
}
String rootMapPath = DITAAccess.getRootMapURL().getPath();
File rootMap = new File(rootMapPath);
boolean isRootmapLocked = !rootMap.canWrite();
rootMap.setWritable(true);
URL[] editorLocations = PluginWorkspaceProvider.getPluginWorkspace().getAllEditorLocations(DITA_MAPS_EDITING_AREA);
mainEditor = PluginWorkspaceProvider.getPluginWorkspace().getCurrentEditorAccess(MAIN_EDITING_AREA);
logger.info(">>>>>Saving file: {}", mainEditor.getEditorLocation().getPath());
mainEditor.save();
URL enabledRootmap = null;
// Update only the references in the .ditamap file since it's not needed to save it at this point
for (URL location : editorLocations) {
WSEditor ditMapsEditor = PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(location, DITA_MAPS_EDITING_AREA);
logger.info("11>>>>>Saving and reloading ditamap: {}", mainEditor.getEditorLocation().getPath());
String path=mainEditor.getEditorLocation().getPath();
String finalName = path.substring(path. lastIndexOf('/'));
if(DITAAccess.getRootMapURL().toString().contains(finalName) && !mainEditor.getCurrentPage().isEditable()){
mainEditor.getCurrentPage().setEditable(true);
enabledRootmap=location;
}
WSDITAMapEditorPage page = (WSDITAMapEditorPage) ditMapsEditor.getCurrentPage();
ditMapsEditor.save();
page.refreshReferences();
}
ActionsProvider actionsProvider = ((StandalonePluginWorkspace)PluginWorkspaceProvider.getPluginWorkspace()).getActionsProvider();
Map<String, Object> globalActions = actionsProvider.getGlobalActions();
AbstractAction reloadAction = (AbstractAction)globalActions.get("File/Reload");
SwingUtilities.invokeLater(() -> actionsProvider.invokeAction(reloadAction));
//actionsProvider.invokeAction(reloadAction);
if(enabledRootmap!=null){
PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(enabledRootmap, DITA_MAPS_EDITING_AREA).getCurrentPage().setEditable(false);;
}
if(isRootmapLocked) {
rootMap.setWritable(false);
}
}
image.png
when we click "NO" then only the newly added topicref showsup , if we click "YES" then it not loads newly added topicrefwould you please help us here , how do we avoid the prompt
You do not have the required permissions to view the files attached to this post.
Thanks,
vishwa
vishwa
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Hi,
I looked a number of times over the code, I do not quite understand your purpose here.
1) DITA Maps opened from the local disk in the DITA Maps Manager view auto-save by default. In the Oxygen Preferences->"DITA / Maps" page there is an "Automatically save local DITA Maps after each modification" checkbox which should be checked by default.
Are you working with files from a content management system that you have brought locally to a cached folder?
Have you considered writing a custom URL protocol to make this local cache not visible to the code?
https://www.oxygenxml.com/doc/ug-editor ... lugin.html
2)
I would recommend you obtain a File from an URL using instead the method:
If the method returns null, it means the URL is remote.
3)
Is the File locked on disk by some other code you have? Is this maybe the reason that Oxygen's auto save for the DITA maps manager view does not work?
4) I assume that your code is called after actions are performed in the DITA Maps Manager view.
Why do you attempt to save the currently selected file from the main editor area?
5)
So you also call save on all other opened DITA Maps from the DITA Maps Manager view? Why?
6)
And now you take the global "File->Reload" action from the main menu and call it? I think this would call the "File/Reload" action for the current editor opened in the main editor area. Is this what you want?
7)
I assume that calling rootMap.setWritable might change the timestamp of the file on disk and when focus is received in the editor, Oxygen detects the timestamp has changed for a local loaded file and asks you to reload.
Maybe something like this might work:
Regards,
Radu
I looked a number of times over the code, I do not quite understand your purpose here.
1) DITA Maps opened from the local disk in the DITA Maps Manager view auto-save by default. In the Oxygen Preferences->"DITA / Maps" page there is an "Automatically save local DITA Maps after each modification" checkbox which should be checked by default.
Are you working with files from a content management system that you have brought locally to a cached folder?
Have you considered writing a custom URL protocol to make this local cache not visible to the code?
https://www.oxygenxml.com/doc/ug-editor ... lugin.html
2)
Code: Select all
String rootMapPath = DITAAccess.getRootMapURL().getPath();
File rootMap = new File(rootMapPath);
Code: Select all
PluginWorkspaceProvider.getPluginWorkspace().getUtilAccess().locateFile(DITAAccess.getRootMapURL());
3)
Code: Select all
boolean isRootmapLocked = !rootMap.canWrite();
rootMap.setWritable(true);
4) I assume that your code is called after actions are performed in the DITA Maps Manager view.
Code: Select all
mainEditor = PluginWorkspaceProvider.getPluginWorkspace().getCurrentEditorAccess(MAIN_EDITING_AREA);
logger.info(">>>>>Saving file: {}", mainEditor.getEditorLocation().getPath());
mainEditor.save();
5)
Code: Select all
for (URL location : editorLocations) {
WSEditor ditMapsEditor = PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(location, DITA_MAPS_EDITING_AREA);
logger.info("11>>>>>Saving and reloading ditamap: {}", mainEditor.getEditorLocation().getPath());
String path=mainEditor.getEditorLocation().getPath();
String finalName = path.substring(path. lastIndexOf('/'));
......
WSDITAMapEditorPage page = (WSDITAMapEditorPage) ditMapsEditor.getCurrentPage();
ditMapsEditor.save();
page.refreshReferences();
}
6)
Code: Select all
ActionsProvider actionsProvider = ((StandalonePluginWorkspace)PluginWorkspaceProvider.getPluginWorkspace()).getActionsProvider();
Map<String, Object> globalActions = actionsProvider.getGlobalActions();
AbstractAction reloadAction = (AbstractAction)globalActions.get("File/Reload");
SwingUtilities.invokeLater(() -> actionsProvider.invokeAction(reloadAction));
7)
Code: Select all
if(isRootmapLocked) {
rootMap.setWritable(false);
}
Maybe something like this might work:
Code: Select all
long lastModified = rootMap.lastModified();
rootMap.setWritable(false);
rootMap.setLastModified(lastModified);
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 168
- Joined: Fri Feb 28, 2020 4:02 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post by vishwavaranasi »
Thanks Radu for your reply.
for the first point , am using oxygen 24 editor and i don't see the checkbox option to save automatically
Thanks for other comments , we will consider to implement the same.
all the code we are attempting to save and File/Reload to make sure that the inserted image when we insert image inside topic or insert reference to ditamap will be resolved automatically with out user to reload the ditamap.
for the first point , am using oxygen 24 editor and i don't see the checkbox option to save automatically
image.png
is this can be achieved programmatically using any oxygen API.Thanks for other comments , we will consider to implement the same.
all the code we are attempting to save and File/Reload to make sure that the inserted image when we insert image inside topic or insert reference to ditamap will be resolved automatically with out user to reload the ditamap.
You do not have the required permissions to view the files attached to this post.
Thanks,
vishwa
vishwa
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Hi,
I think that particular checkbox which auto saves a DITA Map (of course if the file on disk is not read-only) was added around Oxygen 25.
About Oxygen 24 officially we no longer maintain it in any way and we'll drop support for it at the end of this year:
https://www.oxygenxml.com/eol.html
About your remark:
Why would the image reference depend on the DITA Map contents? Is it an image with a keyref to a key that you define in the DITA Map?
Regards,
Radu
I think that particular checkbox which auto saves a DITA Map (of course if the file on disk is not read-only) was added around Oxygen 25.
About Oxygen 24 officially we no longer maintain it in any way and we'll drop support for it at the end of this year:
https://www.oxygenxml.com/eol.html
About your remark:
Could you elaborate? Maybe give me a small set of steps that you took which did not work until you reloaded the XML document in the main editor.all the code we are attempting to save and File/Reload to make sure that the inserted image when we insert image inside topic or insert reference to ditamap will be resolved automatically with out user to reload the ditamap.
Why would the image reference depend on the DITA Map contents? Is it an image with a keyref to a key that you define in the DITA Map?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 168
- Joined: Fri Feb 28, 2020 4:02 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post by vishwavaranasi »
Hi Radu ,
Here is what we are doing , we have our custom inserts for images and topic refs ,
The custom inserts for topic refs works both from DITA menu (from oxygen) and DITA Maps Manager.
The custom inserts for images works from DITA menu only.
within in the rootmap file we have a mapref where we maintain all keydefs to all references of the topics ,images , etc... this file is always there at backmatter
so here , when we insert any topicref and any image inserted to a topic will be created one <keydef> entry to this file , the save and reload of the rootmap what we are doing is to auto resolve the entry without user relaods the rootmap since the keydef file is there at ditamaps manager , we try to relaod the entrie rootmap.
coming to the problem , as you mentioned using last modified time , we could able to get rid-off the oxygen prompt to discard or load dialog. but the problem is the ditamaps manager still not saved. showing like this below (asterisk) even though we try to save both the ditamaps editing area as well the main editing area
Here is what we are doing , we have our custom inserts for images and topic refs ,
The custom inserts for topic refs works both from DITA menu (from oxygen) and DITA Maps Manager.
The custom inserts for images works from DITA menu only.
within in the rootmap file we have a mapref where we maintain all keydefs to all references of the topics ,images , etc... this file is always there at backmatter
image.png
the file having the <keydef> entries as below
Code: Select all
<keydef format="dita" href="file_11011=GUID-6887E6FC-DE36-4B57-8763-EDA7EE11011=2.2.xml" keys="GUID-6887E6FC-DE36-4B57-8763-EDA7EE11011">
<topicmeta>
<navtitle>file 11011</navtitle>
</topicmeta>
</keydef>
<keydef format="dita" href="file_title_31=GUID-A1CB2D1A-DFA0-461E-7EF7-AF89F572C99D=5.xml" keys="GUID-A1CB2D1A-DFA0-461E-7EF7-AF89F572C99D">
<topicmeta>
<navtitle>file title 31</navtitle>
</topicmeta>
</keydef>
coming to the problem , as you mentioned using last modified time , we could able to get rid-off the oxygen prompt to discard or load dialog. but the problem is the ditamaps manager still not saved. showing like this below (asterisk) even though we try to save both the ditamaps editing area as well the main editing area
image.png
You do not have the required permissions to view the files attached to this post.
Thanks,
vishwa
vishwa
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Hi,
As your code looks like this:
The "refreshReferences()" changes again the modified flag of the editor. So maybe you can reverse the lines:
Regards,
Radu
As your code looks like this:
Code: Select all
ditMapsEditor.save();
page.refreshReferencesrefreshReferences();
Code: Select all
page.refreshReferencesrefreshReferences();
ditMapsEditor.save();
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 168
- Joined: Fri Feb 28, 2020 4:02 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post by vishwavaranasi »
Okay Radu , we will try the same.
otherwise do you suggest us anything to be added or to be deleted what we are doing reload/ refreshReferencesrefreshReferences() to resolve the inserted references to inline with the <keydef> file?
Thanks,
vishwa
otherwise do you suggest us anything to be added or to be deleted what we are doing reload/ refreshReferencesrefreshReferences() to resolve the inserted references to inline with the <keydef> file?
Thanks,
vishwa
Thanks,
vishwa
vishwa
-
- Posts: 168
- Joined: Fri Feb 28, 2020 4:02 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Post by vishwavaranasi »
Thanks Radu , the reversing the lines of code worked
page.refreshReferencesrefreshReferences();
ditMapsEditor.save();
what we are doing now
and do we really required the invoke action what we are doing as below after we did the page.refreshReferences() and saved main editor and saved dita maps manager area?
page.refreshReferencesrefreshReferences();
ditMapsEditor.save();
what we are doing now
Code: Select all
WSDITAMapEditorPage page = (WSDITAMapEditorPage) ditaMapsEditor.getCurrentPage();
page.refreshReferences();
rootDitaMap.setLastModified(lastModified);
ditaMapsEditor.save();
Code: Select all
ActionsProvider actionsProvider = ((StandalonePluginWorkspace)PluginWorkspaceProvider.getPluginWorkspace()).getActionsProvider();
Map<String, Object> globalActions = actionsProvider.getGlobalActions();
AbstractAction reloadAction = (AbstractAction)globalActions.get("File/Reload");
actionsProvider.invokeAction(reloadAction);
Thanks,
vishwa
vishwa
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: DITAMAPS Manager custom insert action showing prompt to discard or load changes
Hi,
So:
Regards,
Radu
So:
I don't know, I do not understand your entire flow here. Why did you add that piece of code? Is it because in the main editor you added a keyref to a specific key and then you defined the key in the DITA Map? How about if you have defined the key first in the DITA Map and then used it in the main editor?and do we really required the invoke action what we are doing as below after we did the page.refreshReferences() and saved main editor and saved dita maps manager area?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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