Page 1 of 1
Automatically generate UUID filename when saving
Posted: Thu Mar 06, 2014 5:35 pm
by Rodrik
Is it possible using the SDK to get Oxygen Author to automatically generate a filename comprising a UUID plus file extension?
Regards
Rodrik
Re: Automatically generate UUID filename when saving
Posted: Fri Mar 07, 2014 12:03 pm
by Radu
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:
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);
................................................
Regards,
Radu
Re: Automatically generate UUID filename when saving
Posted: Fri Mar 07, 2014 4:20 pm
by Rodrik
Hi Radu
Thank you for your detailed reply. I've passed your response on to one of my developer colleagues.
Regards
Rodrik
Re: Automatically generate UUID filename when saving
Posted: Mon Sep 08, 2014 9:32 am
by Radu
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