Conditional commands inside button: Run different commands depending on whether files are selected

This comes from my post here:

[url]TortoiseSVN: Commit multiple selected files from lister with a button]

In a very simple custom button, I want to run one command (or several commands) if any files were selected when the button was pressed. And if no files were selected, I want to run a different command or set of commands.

I'm looking for a simple way to do this and it'd be nice if the logic all showed inside the button's "Command Editor" box. But if I must get into a custom command (is that a script in Dopus?), that's okay.

Create a new button type "script function" with this code:

Function OnClick(ClickData) Set cmd = ClickData.Func.Command If ClickData.Func.sourcetab.selected.count = 0 Then cmd.AddLine("[first line of a multi line command]") cmd.AddLine("[second line]") cmd.AddLine("[third line]") cmd.Run Else cmd.RunCommand("[single line command]") End If End FunctionReplace the parts with square brackets with your commands. The commands above "Else" will be executed if nothing is selected. The single line command example after "Else" will be executed if something is selected.
It's a bit tricky if your command string contains double quotes because they have to be doubled or separetely added with & """" to the string like this:cmd.AddLine("""" & "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe " & """" & "/command:commit /pathfile:" & """" & "{allfilepath|filem|ucsle|nobom}" & """" & " /closeonend:3")

Thank you, Kundal. That VBScript was very helpful.

Here's the final version, which will work once they add "lfonly" in Opus 12.3.3 soon:

Function OnClick(ClickData) Set cmd = ClickData.Func.Command If ClickData.Func.sourcetab.selected.count = 0 Then cmd.RunCommand("""" & "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe " & """" & "/command:commit /path:" & """" & "{sourcepath$}{file}" & """" & " /closeonend:3") Else cmd.RunCommand("""" & "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe " & """" & "/command:commit /pathfile:" & """" & "{allfilepath|filem|ucsle|nobom|lfonly}" & """" & " /closeonend:3") End If End Function

The "lfonly" thing is documented here: [url]TortoiseSVN: Commit multiple selected files from lister with a button]

Running this script button de-selects my selected files, so I started this discussion:

[url]@NODESELECT in VBScript script button?]