I want to programatically capture the path of the current tab and present it in a popup.
I have hacked a bit at the sample script and come up with this.
However when I run it nothing happens whatsoever.
What is wrong with this?
Many thanks as always
[code]' Create a Dialog object. You can also obtain dialog objects from the Lister, Tab, Func and Command objects.
Set dlg = DOpus.Dlg
' Initialise the object to display a simple message with three buttons.
dlg.window = DOpus.Listers(0)
'dlg.message = "DOpus.Lister.Tab.Path did not work"
dlg.message = DOpus.Lister.Tab.Path
dlg.title = "Dialog Title"
dlg.buttons = "First Choice|Second Choice|Cancel"
' Show the dialog and print the result to the script log
ret = dlg.Show
DOpus.Output "Dialog.Show returned " & ret[/code]
I guess you want to make the popup show after pressing a button?
Then it's as simple as this (excuse me using JScript, but I generally recommend to leave VBScript behind):
@script jscript
function OnClick(data){
var curPath = data.func.sourcetab.path;
DOpus.Output("Path: " + curPath);
}
If you want to get through to the active tab from the CLI:
//showing path in popup, works for both
var dlg = DOpus.Dlg;
dlg.message = "Path: " + curPath;
dlg.title = "Title";
dlg.buttons = "First Choice|Second Choice|Cancel";
ret = dlg.Show();
[/code]
(This has some overlap with TBone's answer, which came in as this was being written.)
Part of the answer seems to be in your script already:
[quote]dlg.window = DOpus.Listers(0)
'dlg.message = "DOpus.Lister.Tab.Path did not work"
dlg.message = DOpus.Lister.Tab.Path[/quote]
If you want a random lister, use DOpus.Listers(0), as on your first line. DOpus.Lister doesn't mean anything and should be causing errors telling you that line is invalid.
If you want the first tab in that lister, use DOpus.Listers(0).Tabs(0) not DOpus.Listers(0).Tab or DOpus.Lister.Tab.
However, there are not many contexts where it would make sense to use DOpus.Listers(0) (or any other number) to get the 'current path' (outside of testing snippets of code in the CLI script editor). DOpus.Listers(0) could be any open window; your script does not know it is a particular window.
If you are aiming to do this from a toolbar button, menu item, or hotkey, then your script will have an OnClick method and the source and destination tabs are passed to it explicitly. A Dlg object that is already set up is also passed to it.
Technically, you can still use DOpus.Listers(0) in that context, but you'll be picking up a random lister which may not be the one you want (the one where the button or hotkey was pushed). Use the one given to you instead.
Here is an example. I used the Simple Script Function example in the manual as my starting point, then removed most of the code (and adjusted for minor VBScript vs JScript differences):
[code]@script vbscript
Function OnClick(ByRef clickData)
sourcePath = clickData.func.SourceTab.Path
sourcePath = DOpus.FSUtil.Resolve(sourcePath) ' You'll probably want to do this as well.
Set dlg = clickData.func.Dlg
dlg.message = "The source tab's path is " + sourcePath
dlg.buttons = "First Choice|Second Choice|Cancel"
dlg.icon = "info"
dlg.title = "Dialog Title"
ret = dlg.Show
DOpus.Output "Dialog.Show returned " & ret
Thank you gents. TBone you wont mind me running with Leo's answer as what skills I do have are VBscript and I did try (and fail) to start with the sample script function as he did.
Leo - I copied the sample script function into a menu button and it worked perfectly.
I then altered and came up with the mess in my post above.
I then tried your CODE above in the button and it worked perfectly.
I will take a little time and absorb the details of the distinctions you make in referencing objects in the contexts that you outline above. Thank you.
In the mean time I have a button with your code and it works perfectly as shown so I can build on it.
I shall go quiet for a while