DirBox and FileBox Cancel

Post

Posted
Rating:
#1 (In Topic #1302)
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 How can I detect that the user has clicked on the cancel button in a DirBox? This possibly happens with the FileBox also, but I haven't checked.
I want to propagate the cancellation up a couple of levels of the stack trace.  
The only events I know of are _Click and _Change. Neither of which are raised when the Cancel button is clicked?

tia
thatbruce

Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
You can access the internal ButtonBox and override the click event (the ButtonBox Click not the DirBox Click)..

Code (gambas)

  1.  
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   $hObs = New Observer(DirBox1.Children[0]) As "DBox"  ' get the DirBox's ButtonBox events
  6.  
  7.  
  8. '' This is a copy of the DirBox Button_Click() event adapted to not use it's internal variables $sTitle and $sText
  9.  
  10. Public Sub DBox_Click()
  11.  
  12.  
  13.   Dim sSaveTitle As String
  14.   Dim bCancel As Boolean
  15.  
  16.   sSaveTitle = Dialog.Title
  17.  
  18.   Dialog.Title = DirBox1.Title
  19.   Dialog.Path = DirBox1.Path
  20.  
  21.   bCancel = Dialog.SelectDirectory()
  22.  
  23.   Dialog.Title = sSaveTitle
  24.  
  25.   If Not bCancel Then
  26.     DirBox1.Path = Dialog.Path
  27.     Object.Raise(DirBox1, "Click")  ' use Object.Raise to raise normal Click event
  28.   Else
  29.     Debug "cancelled"  ' or it got cancelled
  30.  
  31.  
  32.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Or an Auto-Inherited override ,
Save this as DirBox.class in your project…

Code (gambas)

  1.  
  2. ' Gambas class file
  3.  
  4.  
  5. Event Cancelled
  6.  
  7. Public Sub Button_Click()
  8.  
  9.   Dim sSaveTitle As String
  10.   Dim bCancel As Boolean
  11.  
  12.   sSaveTitle = Dialog.Title
  13.  
  14.   Dialog.Title = Me.Title
  15.   Dialog.Path = Me.Path
  16.  
  17.   bCancel = Dialog.SelectDirectory()
  18.  
  19.   Dialog.Title = sSaveTitle
  20.  
  21.   If Not bCancel Then
  22.     Me.Path = Dialog.Path
  23.     Object.Raise(Me, "Click")
  24.   Else
  25.     Raise Cancelled
  26.  
  27.  
  28.  
  29.  

That will add DirBox1_Cancelled() event


Or a more condensed version…

Code (gambas)

  1. ' Gambas class file  (DirBox.class)
  2.  
  3.  
  4. Event Cancelled
  5.  
  6. Public Sub Button_Click()
  7.  
  8.   ' note the current path, open the dialog, then if path is the same the user must have cancelled.
  9.   Dim sPath As String = Me.Path
  10.   Super.Button_Click
  11.   If sPath = Me.Path Then Raise Cancelled
  12.  
  13.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Well after some testing and soul-searching I finally went with option 2, the auto-inherit.

I discounted the shortened version as there is nothing wrong with them selecting the same directory.

Thanks for the options!
I wonder if the native DirBox should have that event as I can see other cases where it could apply. In fact any control that uses a child control that is cancellable.

b

Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
You're welcome :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.