A fresh DO.Create.Command fetches items from Source

Hello! o)

I have a strange situation here, I have a script that creates a new command object by running DOpus.Create.Command().
I add two internal commands with AddLine() to create a new file collection and to copy items to that collection.
Now, when not adding an item to the command object with AddFile(), DO fetches the currently selected files in the source, even though the source, dest, sourcetab, desttab properties are not set (they are empty or 0 as the documentation describes).

The variable "cmd" is another DO.Command object that already contains files I'd like to copy to the "MyCol" collection if they are not present yet - it is not setup within this snippet.

[code]var cmdCol = DOpus.Create.Command();
cmdCol.AddLine('CreateFolder "coll://MyCol"');
cmdCol.AddLine('Copy COPYTOCOLL=member TO "coll://MyCol"');

for (var iEnum = new Enumerator(cmd.files); !iEnum.atEnd();){
var item = iEnum.item(); iEnum.moveNext();
if (!DOpus.FSUtil.Exists("coll://MyCol/"+item.name)){
DOpus.Output("Not exists..");
Bug, feature, delayed easter egg or just me? o) Thx!

Another easier example, as I experienced the same thing in an OnClick() button.
This happens in a jscript CLI as well, so it is quite easy to reproduce:

var cmd = DOpus.Create.Command(); cmd.AddLine('CreateFolder "coll://AMyTestCol"'); cmd.AddLine('Copy COPYTOCOLL=member TO "coll://AMyTestCol"'); cmd.Run();
The above code copies selected items from the source to the collection "AMyTestCol", even though the current source tab has not been set by SetSourceTab() and I also did not add files to the newly created command object by running "AddFile(..)". My expectation is, that the collection should be created and the copy command should act on nothing, because I did not pass any source-tab-information.
Additionally: If you run above code and there are no items selected, the CreateFolder operation will not run at all, which is kind of irritating as well.

If you make use of "RunCommand()" instead of "Run()", things are more predictable:

var cmd = DOpus.Create.Command(); cmd.RunCommand('CreateFolder "coll://AMyTestCol"'); cmd.RunCommand('Copy COPYTOCOLL=member TO "coll://AMyTestCol"'); cmd.Run();
This always creates the collection and does not fetch any selected items from the source automatically. If there is some intelligent logic injecting the last used source-tab or something into the new command object whenever SetSourceTab() has not been used, then I don't get why RunCommand() won't make use of that magic-source tab as well. The documentation states, that these are equivalent.

I clearly prefer the latter "non-magic" behaviour.
My guess is that the different behaviour for Run() + RunCommand(), and the magic source-tab injection is not desired.

In the RunCommand case, is the new collection being auto-read into the source lister? If so, that would explain why the subsequent copy command does not act on any files.

(From a quick test which just runs "Copy", it doesn't make a difference whether AddLine+Run or RunCommand is used; the selected files in the source are copied in both cases.)

More generally, commands want to have a source, and if one isn't specified then they may find one themselves when they run. If you want them to act on a particular source, it needs to be specified.

If you want commands to act on a list of files from the script rather than the selected files in a tab, then you need to call something that affects the Command object's list of files, so that it knows it is in that mode. Normally it makes sense to call ClearFiles on the Command object as soon as you get hold of it, if you plan to use it that way.

This will not copy any files (apologies for switching to VBScript when the thread was in JScript, I didn't notice until it was all typed up and tested):

set cmd = DOpus.Create.Command() cmd.ClearFiles cmd.RunCommand "Copy"

But, as well as calling cmd.ClearFiles as soon as you get the Command object (which is a always a good habit if you're using the object in that way), it also makes most sense to avoid adding or calling the Copy command at all if the script has nothing for it to do, especially with a multi-line command. The Copy command needs files to work on and will fail if there are none. This won't show the about dialog, as a result:

set cmd = DOpus.Create.Command() cmd.ClearFiles cmd.AddLine "Copy" cmd.AddLine "Help About" cmd.Run