This VB Script should have been pretty simple I thought. But I am missing something...
This is a dialog to add the current folder as an Alias. But for some reason when I click the 'Add' button, it doesn't return with the 'Add' button's return code of 1. It returns nothing.. And the event is not 'click', it's 'focus'.
Option Explicit
' - - - - - ADD AN ALIAS - - - - -'
Function OnClick(ByRef clickData)
' Get the Path to Folder.
Dim sourcePath, ret, x, msg
sourcePath = clickData.func.SourceTab.Path
sourcePath = DOpus.FSUtil.Resolve(sourcePath)
If Trim(sourcePath) = "" then
MsgBox "You cannot use this Folder(" & sourcePath & ") as an Alias.", , "Invalid Folder Error"
Exit Function
End If
' Create a Dialog object.
Dim dlg
Set dlg = DOpus.Dlg
dlg.window = clickData.func.sourcetab
dlg.template = "dlgAddAlias"
' Initialise the Dialog's controls
dlg.Create 'Creates the Window but doesn't show it. Allowing you to initialized controls.
dlg.icon = "question"
dlg.title = "Add Folder Alias?"
dlg.Control("sPath").Title = sourcePath
' dlg.result = 0 'DEFAULT FIRST RESULT TO A CANCEL/CLOSE X WINDOW
dlg.Show 'Displays the Window.
DOpus.Output "ret: >" & ret & "<"
Do
Set msg = dlg.GetMsg
' If msg.event = "click" then
x = x + 1
DOpus.Output "LOOP " & x & "--------------------------------------------------------------------"
DOpus.Output "ret: >" & ret & "<; " & "Result: >" & dlg.result & "<; " & "msg.event: >" & msg.event & "<; " & "msg.control: >" & msg.control & "<"
DOpus.Output ""
If dlg.result = "0" then Exit Function ' 0 THEY CLICKED CANCEL OR THE CLOSE X BUTTON:
If msg.event = "click" And dlg.result = "1" Then ' 1 THEY CLICKED ADD:
DOpus.Output "ADD"
' Did they enter a Name?
If Trim(dlg.Control("sName").Value) = "" then
MsgBox "You must give the Alias a Name." & vbCrLf & vbCrLf & "The name should be all lower case with no spaces.", , "Alias needs a Name?"
ElseIf InStr(" ", Trim(dlg.Control("sName").Value)) Then
MsgBox "You cannot have spaces in an Alias name." & vbCrLf & vbCrLf & "The name should be all lower case with no spaces.", , "Name Error"
Else
' DOpus.aliases.Add dlg.Control("sName").Value, sourcePath ' Now ADD the new Alias..
DOpus.Output "ALIAS WAS ADDED!"
Exit Do
End If
End If
' Prevent Endless Loop while developing.....
If x > 5 then exit Function
Loop
End Function
<resources>
<resource name="dlgAddAlias" type="dialog">
<dialog fontsize="11" height="60" lang="english" title="Add Folder Alias" width="305">
<control halign="left" height="8" name="static1" title="Add Folder as a new Alias?" type="static" valign="top" width="91" x="13" y="6" />
<control case="lower" halign="left" height="10" name="sName" tip="one word, no spaces.." type="edit" width="113" x="31" y="19" />
<control halign="right" height="8" name="static2" title="Name:" type="static" valign="top" width="23" x="6" y="20" />
<control halign="right" height="8" name="static3" title="Path:" type="static" valign="top" width="17" x="12" y="31" />
<control editcontrol="yes" ellipsis="path" halign="left" height="8" name="sPath" resize="t" type="static" valign="top" width="261" x="33" y="31" />
<control close="0" height="14" name="btnCancel" title="Cancel" type="button" width="50" x="246" y="42" />
<control close="1" default="yes" height="14" name="btnAdd" title="Add" type="button" width="50" x="186" y="42" />
<control height="8" icon="1" name="markuptext1" resize="wht" title="<a id="https://docs.dopus.com/doku.php?id=preferences:preferences_categories:frequently_used_paths:folder_aliases"><b>Add Alias</b></a>" type="markuptext" width="50" x="252" y="6" />
</dialog>
</resource>
</resources>