Automatically generate UUID filename when saving
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Automatically generate UUID filename when saving
Hi Rodrik,
This could be done implementing a plugin for Oxygen using our Plugins SDK:
http://www.oxygenxml.com/oxygen_sdk.htm ... er_Plugins
We have a type of plugin called "Workspace Access", there is a sample implementation + Java sources in the Plugins SDK.
Such a Java-based plugin would basically intercept the save events when a newly created document is untitled and show an alternative chooser dialog to the user, then save the topic with the proper name, the Java code for something like this would be like:
Regards,
Radu
This could be done implementing a plugin for Oxygen using our Plugins SDK:
http://www.oxygenxml.com/oxygen_sdk.htm ... er_Plugins
We have a type of plugin called "Workspace Access", there is a sample implementation + Java sources in the Plugins SDK.
Such a Java-based plugin would basically intercept the save events when a newly created document is untitled and show an alternative chooser dialog to the user, then save the topic with the proper name, the Java code for something like this would be like:
Code: Select all
private static class CustomEdListener extends WSEditorListener{
private final WSEditor editor;
private final StandalonePluginWorkspace pluginWorkspaceAccess;
private boolean saving = false;
public CustomEdListener(StandalonePluginWorkspace pluginWorkspaceAccess, WSEditor editor) {
this.pluginWorkspaceAccess = pluginWorkspaceAccess;
this.editor = editor;
}
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorListener#editorAboutToBeSavedVeto(int)
*/
@Override
public boolean editorAboutToBeSavedVeto(int operationType) {
if(! saving && editor.getEditorLocation().toString().contains("Untitled")) {
File chosenDir = pluginWorkspaceAccess.chooseDirectory();
if(chosenDir != null) {
final File chosenFile = new File(chosenDir, UUID.randomUUID().toString() + ".dita");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
saving = true;
editor.saveAs(new URL(chosenFile.toURI().toASCIIString()));
} catch (MalformedURLException e) {
e.printStackTrace();
} finally {
saving = false;
}
}
});
}
//Reject the original save request.
return false;
}
return true;
}
}
/**
* @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationStarted(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)
*/
@Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorOpened(java.net.URL)
*/
@Override
public void editorOpened(URL editorLocation) {
final WSEditor editor = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
if(editor != null && editor.getEditorLocation().toString().contains("Untitled")) {
//Untitled editor
editor.addEditorListener(new CustomEdListener(pluginWorkspaceAccess, editor));
}
}
}, PluginWorkspace.MAIN_EDITING_AREA);
................................................
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Automatically generate UUID filename when saving
Hi,
Just to update this thread, the API ro.sync.exml.workspace.api.editor.WSEditorBase.isNewDocument() is a more elegant approach that can be used to check if a document is a newly created document or not.
Regards,
Radu
Just to update this thread, the API ro.sync.exml.workspace.api.editor.WSEditorBase.isNewDocument() is a more elegant approach that can be used to check if a document is a newly created document or not.
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