#usercommand @script JScript /////////////////////////////////////////////////////////////////////////////// function OnClick(data) { //https://resource.dopus.com/t/dragndrop-combined-with-scripting-usercommand-issue/43713/5 DOpus.Output("DragnDropReplaceSelectedFileInDest_UC.."); //data = data || createOnClickDataObject(); //var f = data.func, c = f.command, tab = f.sourcetab, path2 = ""+tab.path; //var root = (tab.path.Root() && tab.path) || tab.path, subpath = (""+path2).replace(root,""); //var srcTab = data.func.sourcetab; //dragndrop issue: is DEST tab when used with FileType DragContextMenu //DOpus.Output("srcTab: " + srcTab.path); //var srcTab = data.func.desttab; //dragndrop issue: is undefined when used with FileType DragContextMenu //DOpus.Output("dstTab: " + dstTab.path); //DOpus.Output("data.func.command.sourcetab.path: " + data.func.command.sourcetab.path); //DOpus.Output("data.func.command.desttab.path: " + data.func.command.desttab.path); // undefined! //DOpus.Output("data.func.command.filecount: " + data.func.command.filecount); //DOpus.Output("data.func.command.source: " + data.func.command.source); //DOpus.Output("data.func.command.dest: " + data.func.command.dest); for(var i=0;i<data.func.command.files.count;i++) { DOpus.Output(" dragndrop file["+i+"].name: " + data.func.command.files(i).realpath); } if (data.func.command.files.count != 1) { DOpus.Output(" Not a single item incoming from dragndrop, aborting."); return false; } if (data.func.command.files(0).is_dir) { DOpus.Output(" INFO: Not a file incoming from dragndrop.."); } var dstTab = data.func.command.sourcetab; //using sourcetab from command object to get destination tab //var isDrop = data.func.fromdrop; //BUG?! is FALSE if scripted user command is triggered by dragndrop //if (!isDrop) { DOpus.Output("Not a dragndrop operation, aborting."); return false; } DOpus.Output(" dstTab path: " + dstTab.path); var srcFile = data.func.command.files(0); if (dstTab.selected_files.count != 1) { DOpus.Output(" More or less than 1 file selected in destination, aborting."); return false; } var dstFile = dstTab.selected_files(0); DOpus.Output(" Copy FROM: " + srcFile.realpath); DOpus.Output(" TO : " + dstFile.realpath); if (data.func.command.files(0).is_dir) { DOpus.Output(" Not a file incoming from dragndrop, aborting."); return false; } var cmdNilScope = DOpus.NewCommand(); //var cmdTabScope = DOpus.NewCommand(); cmdTabScope.SetSourceTab(dstTab); //cmdTabScope.RunCommand('SelectEx TOVAR=DragNDropReplace'); //save current selection to var cmdNilScope.RunCommand('ClipboardEx COPYTIMESTAMPS=created FROM="'+dstFile.realpath+'"'); //cmdNilScope.RunCommand('COPY FILE="'+srcFile.realpath+'" TO="'+dstFile.path+'" AS="'+dstFile.name+'" WHENEXISTS=replace MOVEWITHSHIFT'); //using fsoCopy because native DO COPY command tinkers with selection in source tab of lister (which is not necessarily the tab, the item(s) was dragged into!) //using fsoCopy also does not require us to restore selection in affected tab, DO updates the thumbnail a bit slower though fsoCopy(srcFile.realpath, dstFile.realpath); cmdNilScope.RunCommand('ClipboardEx PASTETIMESTAMPS=created TO="'+dstFile.realpath+'"'); //same path for copy/paste is intended //cmdTabScope.RunCommand('Select NONE'); //cmdTabScope.RunCommand('Select "'+dstFile.realpath+'" EXACT'); //restore selection, simple variant //cmdTabScope.RunCommand('SelectEx FROMVAR=DragNDropReplace MAKEVISIBLE GO'); //restore selection from var if (data.func.qualifiers.indexOf("shift")!=-1) { DOpus.Output(" SHIFT pressed, deleting source file.."); cmdNilScope.RunCommand('Delete FILE="'+srcFile.realpath+'" QUIET'); } }; /////////////////////////////////////////////////////////////////////////////// function fsoCopy(srcFilePath, dstFilePath, overwrite) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fle = fso.GetFile(srcFilePath); fle.Copy(dstFilePath); }