Is it possible to get a filehandle with drag and drop from Windows-Explorer to a Servoy Solution?
Thanks for any help.
/**
* Handle a drag over. Determines of a drop is allowed in this location.
*
* Return true is drop is allowed, otherwise false.
*
* @param {JSDNDEvent} event the event that triggered the action
*
* @returns {Boolean}
*
* @protected
*
* @properties={typeid:24,uuid:"F30ED7CA-06DA-4137-AE6C-46FB7024C12E"}
*/
function onDragOver(event) {
var log = scopes.svyLogManager.getLogger('stb.filednd'),
log.debug('onDragOver triggered');
if (event.getSource() && event.data) {
elements.droparea.visible = true;
return true;
}
return false;
}
/**
* Handle a drop.
* Return true if drop has been performed successfully, otherwise false.
*
* @param {JSDNDEvent} event the event that triggered the action
*
* @returns {Boolean}
*
* @protected
*
* @properties={typeid:24,uuid:"A7CA099B-8F5A-4BE6-91E8-992B887A6E14"}
*/
function onDrop(event) {
var log = scopes.svyLogManager.getLogger('stb.filednd'),
result = false,
content,
/** @type {plugins.file.JSFile[]} */
files = [];
log.debug('onDrop triggered');
try {
// check if the dragged stuff is a file
log.debug('Preparing for a drop');
if (event && event.dataMimeType && event.dataMimeType.indexOf('application/x-java-file-list') > -1) {
content = event.data.toArray();
files = content.map(function(f) {
return plugins.file.convertToJSFile(f);
})
files.forEach(/** @param {plugins.file.JSFile} file */
function(file) {
if (file.isDirectory()) {
log.debug('Not saving directory {}', file.getAbsolutePath())
} else if (!file.canRead()) {
log.debug('Cannot read file {}', file.getAbsolutePath())
} else if (file.exists()) {
log.debug('Importing file {}', file.getAbsolutePath())
// save the file
}
});
result = true;
} else {
throw 'Dropped stuff was not recognized as a file.';
}
log.debug('Drop successful');
} catch (ex) {
log.error(ex.toString());
} finally {
elements.droparea.visible = false;
}
return result
}
/**
* Handle end of a drag.
*
* @param {JSDNDEvent} event the event that triggered the action
*
* @protected
*
* @properties={typeid:24,uuid:"F49045DC-B1F1-4A8A-820D-19DF997C1110"}
*/
function onDragEnd(event) {
elements.droparea.visible = false;
}
Return to Programming with Servoy
Users browsing this forum: No registered users and 8 guests