Dialog.OpenFile()

Post

Posted
Rating:
#1 (In Topic #536)
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
This is kinda a discussion topic  :D

Can anyone explain the logic of pressing CANCEL  should return TRUE ?
Seems to me that an affirmative response should return true.   

Code (gambas)

  1. If Dialog.OpenFile() Then
  2.   Return ' User pressed Cancel -
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 maybe this comes from the underlying gui kit …
maybe its less typing to use If instead of If Not or IF Else …
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 It's based on the return is an error value I think.

So if true an error has occurred.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’

BruceSteers said

It's based on the return is an error value I think.

So if true an error has occurred.

I think I see where you are coming from Bruce, but I don't think True indicates an error in this case.

I tried some test code yesterday. Here is my code showing breakpoints and object viewers, in case anyone is interested.

Image

(Click to enlarge)


Clearly Dialog.OpenFile() needs to return an indication for the programmer that either the open or cancel button was pressed.
Also note that there is no attempt (internally in the Dialog class) to clear the Dialog.Path or Dialog.Paths array when cancel is pressed.
There is no class property to indicate that Open or Save dialog has been requested, and no Events are raised.
There is no attempt to return error codes via the Return value (as might be the case if the return type was an integer).
The return type is a Boolean which indicates either Open or Cancel (or Save/cancel in the case of the Save method).

So my conclusion is that the logic appears to be reversed from what I would expect. {although I suspect the author had his reasons}


BTW;
I tested using gb.Form.Dialog (the enhanced dialog).

But when I tried to run my code with the standard dialog I started getting this strange error.

Image

(Click to enlarge)


There's probably something nasty in my code, but I can't immediately see what it is.
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
Yeah I guess the mailing list is the place to get real answer for this. Ben would know for sure
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Since I am kinda new at Gambas I was just wondering if I was misunderstanding some thing or using it incorrectly.
Simple enough to use the one-liner    ;)

Code (gambas)

  1. If Dialog.OpenFile() Then Return  ' "True" =  User canceled
  2. ' use the file  

Thank for the feedback

Marv
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
cage is in the usergroup ‘Regular’
This is what I use in a program where I select program names.  If I click on cancel it closes the dialog and returns to the under lying window.  Hope it helps.

Code (gambas)

  1. Public Sub FileChooser1_Activate()
  2.    ' Sends selected name to global variable
  3.    Global.CopyCmd = FileChooser1.Value
  4.    
  5.    Me.Close
  6.    
  7.  
  8. Public Sub FileChooser1_Cancel()
  9.  
  10.    Me.Close
  11.  
  12.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
 I may be missing something … why would you go through all that trouble and extra code ..
when a one-liner does it all ?
Online now: No Back to the top

Post

Posted
Rating:
#9
Avatar
Regular
stevedee is in the usergroup ‘Regular’

grayghost4 said

I may be missing something …

That's a good question.

Take a look at all the Methods, Properties & Events available with the FileChooser compared to a relatively simple dialog box,

Image

(Click to enlarge)


If you don't need any of these, then use a Dialog. But maybe your app needs Bookmarks or you need some of the Events on offer.

There are quite a few directory/file related controls available in Gambas…possibly too many.
Online now: No Back to the top

Post

Posted
Rating:
#10
Avatar
Regular
cage is in the usergroup ‘Regular’
 While the Dialog Openfile works quite well, I have not found that the Dialog Path can be set even though the documentation says it can.  That is why I use FileChooser instead.  It allows me many more options then with the OpenFile dialog.  Otherwise the OpenFile Dialog works extremely well, just not for my application where setting path is really necessary. Depending on your needs either one will do a great job.
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
stevedee is in the usergroup ‘Regular’

cage said

While the Dialog Openfile works quite well, I have not found that the Dialog Path can be set even though the documentation says it can…

It looks like I can set the Dialog.Path property, but it doesn't behave the way I would expect it to.

If I set it like this:-

Code (gambas)

  1. Dialog.Path = User.Home

…or like this:-

Code (gambas)

  1. Dialog.Path = "/home/steve"

…the dialog opens in the /home directory but expands the /home/steve directory like this:-

Image

(Click to enlarge)


But if I do this:-

Code (gambas)

  1. Dialog.Path = "/home/steve/

…it opens correctly in the /home/steve directory (i.e. shows the files for /home/steve in right-hand pane).


In the Help for Dialog.Open() it shows an example with: Dialog.Path = User.Home
Image

(Click to enlarge)


It says that the dialog will show the users home directory (which is does) so I'm not sure if this is a bug or 'by design'.
Online now: No Back to the top

Post

Posted
Rating:
#12
Avatar
Regular
cage is in the usergroup ‘Regular’
 Thanks stevedee I got it working.  I found a thread by Charlie that explained what I was doing wrong.  Seems you need us gb.gui.qt in order for the dialog to work correctly.  It does not work if you use gb.gui, qt5 or gtk.  I incorporated into a test version of my program and got it working. It's now part of my main program. As always I wish to thank you very much for the help.
Online now: No Back to the top
1 guest and 0 members have just viewed this.