${ask} relative_url enhancements

Are you missing a feature? Request its implementation here.
whyme
Posts: 93
Joined: Fri Mar 08, 2013 8:58 am

${ask} relative_url enhancements

Post by whyme »

I find that I've been using the editor variable ${ask('message', relative_url, 'value')} to prompt a user either to choose a place where to save output, or to select files for supplementary input.

For the first need, it would be nice if users could pick just a directory, and not a file.

For the second, it would be nice if users could pick multiple files.

If these requests would entail the new 2nd parameter options relative_dir and relative_urls, I'm fine with that.

Or if these options are already possible, it would be nice to provide examples here.
alex_jitianu
Posts: 1016
Joined: Wed Nov 16, 2005 11:11 am

Re: ${ask} relative_url enhancements

Post by alex_jitianu »

Hello,

Thank you for reporting these functionality gaps. I've added some issues to enhance the ${ask} variable. Meanwhile, as an workaround, you can contribute custom variables through an workspace access plugin. We have a sample Workspace Access plugin which constitutes a good starting point on GitHub: https://github.com/oxygenxml/sample-plu ... ace-access

If you are more comfortable with Javascript than with Java, then you can opt for the Javascript version of the Workspace Access plugin. Some good examples for that can be found on GitHub: https://github.com/oxygenxml/wsaccess-j ... le-plugins . Actually there is one such sample plugin that actually contributes a custom editor variable: https://github.com/oxygenxml/wsaccess-j ... rVariables

Here is a version of that custom editor variables provider that also contributes a variable ${mFiles} that is expanded to a comma separated enumeration of relative paths. What's not that great is that when the user presses Cancel in the dialog, it throws a runtime exception that stops the execution. This will present a rather unpleasant dialog to the user... By the way, in which contexts are you using ${ask} and you need this additional support? Author actions, transformation scenarios?

Code: Select all

function applicationStarted(pluginWorkspaceAccess) {
resolver = {
resolveEditorVariables: function (contentWithEditorVariables, currentEditedFileURL) {
var clipboardVarName = "clipboard";
var mFilesVarName = "mFiles";
if (contentWithEditorVariables.indexOf("${" + clipboardVarName + "}") != -1) {
clipboard = Packages.java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
try {
return contentWithEditorVariables.replace("${" + clipboardVarName + "}", clipboard.getData(Packages.java.awt.datatransfer.DataFlavor.stringFlavor));
Packages.java.lang.System.err.println("\nIN HERE2 " + clipboard.getData(DataFlavor.stringFlavor));
}
catch (e) {
// error: don't replace variable
return contentWithEditorVariables;
}
}


if (contentWithEditorVariables.indexOf("${" + mFilesVarName + "}") != -1) {
new Packages.java.lang.Exception().printStackTrace();
var canceled = false;
try {
var pluginWorkspace = pluginWorkspaceAccess;
// Present a file explorer with multiple selection.
var currentFileContext = null;
if (currentEditedFileURL != null) {
var base = new Packages.java.net.URL(currentEditedFileURL);
currentFileContext = pluginWorkspace.getUtilAccess().locateFile(base);
}
var files = pluginWorkspace.chooseFiles(currentFileContext, "Title", null, null);

if (files != null) {
var b = new Packages.java.lang.StringBuilder();
var base = null;
if (currentEditedFileURL != null) {
base = new Packages.java.net.URL(currentEditedFileURL);
}
for (var i = 0; i < files.length; i++) {
var makeRelative = pluginWorkspace.getUtilAccess().makeRelative(
base,
pluginWorkspace.getUtilAccess().convertFileToURL(files[i]));
if (b.length() > 0) {
b.append(",");
}
b.append(makeRelative);
}

contentWithEditorVariables = contentWithEditorVariables.replace("${" + mFilesVarName + "}", b.toString());
} else {
canceled = true;
}
}
catch (e) {
e.printStackTrace();
}


if (canceled) {
throw new Packages.java.lang.RuntimeException("operation canceled");
}
}
return contentWithEditorVariables;
}
}
pluginWorkspaceAccess.getUtilAccess().addCustomEditorVariablesResolver(new Packages.ro.sync.exml.workspace.api.util.EditorVariablesResolver(resolver));
}
function applicationClosing(pluginWorkspaceAccess) {
}
Post Reply