Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:41 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: GetFileDialog Box

     Page 2 of 4    
Author Message
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 09:26am 09 Oct 2020
Copy link to clipboard 
Print this post

I finally got a chance to try out the FileDialog box. I love it!

What's preventing me from using it as-is in HexEdit for example, is that I can't create new files in the dialog. This is needed when opening a new file for instance, or when exporting/saving as.

One possibility is that when the INS key is pressed, a prompt opens at the cursor position so the user can enter the new filename.

Regarding MAR, I think what Michael's suggesting is that using this dialog, I can create a UI based version of MAR that includes both the archive extract and archive create functions. When the user selects a directory, that directory gets archived. When the user selects a .MAR archive, that archive gets extracted.
To do that I need the option to select a directory. One way to go about is to use Enter for file/directory selection, and use cursor-right to enter into a directory.

Finally, a UI based xDel would benefit from having the options to select multiple files and directories, e.g. the Enter key toggles file/directory highlighting, multiple files and dirs can be highlighted this way. Esc takes you out of the dialog. The dialog would then have to return an array of names instead of a single one.

Ruben/Epsilon.
Epsilon CMM2 projects
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 03:47pm 09 Oct 2020
Copy link to clipboard 
Print this post

  twofingers said  Choosing a directory now works as required, but I would prefer a filename blocking option. I think the GetFileName function should have a parameter to make only folders selectable.
I think that will be part of the 'spec' parameter. I'm still pondering...

  epsilon said  having the options to select multiple files and directories
That's an interesting thought. Maybe [space bar] would toggle selections on and off. Font #1 includes an empty and check marked box...

  epsilon said  What's preventing me from using it as-is in HexEdit for example, is that I can't create new files in the dialog
Well, I did create it as GetFileName dialog. But I will examine SaveFile, perhaps as a companion routine, maybe combined with more parameters.
Visit Vegipete's *Mite Library for cool programs.
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 05:02pm 09 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  
  epsilon said  having the options to select multiple files and directories
That's an interesting thought. Maybe [space bar] would toggle selections on and off. Font #1 includes an empty and check marked box...


Yes. That would work.

  vegipete said  
  epsilon said  What's preventing me from using it as-is in HexEdit for example, is that I can't create new files in the dialog
Well, I did create it as GetFileName dialog. But I will examine SaveFile, perhaps as a companion routine, maybe combined with more parameters.



Understood. Currently I'm expecting the user to choose a name for a new file they want to edit _before_ they start editing. Maybe it makes more sense to move that decision to the first save point. This would allow me to use GetFileName as-is and use a simple prompt based SaveFile, until a fancy SaveFile dialog comes along.  
Epsilon CMM2 projects
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 11:12pm 09 Oct 2020
Copy link to clipboard 
Print this post

Here is the latest version of GetFileName dialog.

GetFile12.zip

Changes:
Now the spec$ parameter works:
GetFileName(15,"<dir>") shows everything but only lets you select directories.
GetFileName(15,"*") shows everything but only lets you select files
GetFileName(15,"*.bas") shows directories and BAS files but only lets you select files

Added:
saved directory choices as you tunnel deeper into sub-directories, so that the selected directory is re-selected when you come back up.

Starts from the current working directory, not the root directory. (This aspect can be confusing if you don't realize you are deeper in the hierarchy and need to press left arrow to rise up towards root.)

Also, I made the demo program a bit silly, in the process of showing the features.

============
Features not implemented, but maybe possible:
Multiple Selections: would that be files only, or files and directories? It won't span directory levels though.

Save File: needs a slightly changed dialog box with a text box that allows entering a name. But what about file types?

For now, file saving could be a two step process:
1) let the user select where to save - a directory
2) ask the user for the file name to save to.
Visit Vegipete's *Mite Library for cool programs.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 11:09am 10 Oct 2020
Copy link to clipboard 
Print this post

Hi Pete,

that's more than FANTASTIC!. Completely meets specifications. Thank you very much!
This is a step forward in making better programs for the CMM2.

Even your presentation is an innovation!

Kind regards
Michael
causality ≠ correlation ≠ coincidence
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 10:23am 11 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  
Features not implemented, but maybe possible:
Multiple Selections: would that be files only, or files and directories? It won't span directory levels though.


For xDel it would be files and directories.
But if it were files only, that would be a great starting point. From there I can probably tweak it myself to include directories as well.

  vegipete said  
Save File: needs a slightly changed dialog box with a text box that allows entering a name. But what about file types?

For now, file saving could be a two step process:
1) let the user select where to save - a directory
2) ask the user for the file name to save to.


Exactly. I was thinking of doing step 2) as a small pop-up over the GetFileDiag box, using the same window style as GetFileDialog itself.

I don't understand the question about file types. What are file types?
Epsilon CMM2 projects
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 11:56am 11 Oct 2020
Copy link to clipboard 
Print this post

  epsilon said  I don't understand the question about file types. What are file types?

According to my understanding: "*.*", "*.bas*, "*.BMP" etc

Michael
causality ≠ correlation ≠ coincidence
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 04:43pm 11 Oct 2020
Copy link to clipboard 
Print this post

Pondering...
In the windowed world, a [Save As...] dialog lets you choose the location in the directory structure and lets you enter a file name. But it can also let you choose the file type. For example, in paint.net, you can save as .pdn or .png or .jpg or whatever. But maybe a rudimentary SaveFileDialog could ignore that part. The program itself ought to know what type of file it is saving, or the user can override this by entering whatever he wants. So SaveFileDialog would return a string containing the full path of the target save file, that may or may not have the characters ".<type>" on the end. The program must decide what to do with this.

The multiple file selection problem I'm having right now is how to return the results. It's easy to over-fill a single string.
@epsilon: What does xDel use? An array of strings?
Visit Vegipete's *Mite Library for cool programs.
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 08:27am 12 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  Pondering...
In the windowed world, a [Save As...] dialog lets you choose the location in the directory structure and lets you enter a file name. But it can also let you choose the file type. For example, in paint.net, you can save as .pdn or .png or .jpg or whatever. But maybe a rudimentary SaveFileDialog could ignore that part. The program itself ought to know what type of file it is saving, or the user can override this by entering whatever he wants. So SaveFileDialog would return a string containing the full path of the target save file, that may or may not have the characters ".<type>" on the end. The program must decide what to do with this.


Yes, I agree.

  vegipete said  
The multiple file selection problem I'm having right now is how to return the results. It's easy to over-fill a single string.
@epsilon: What does xDel use? An array of strings?


Right now, nothing. It just prompts the user for a single directory to remove.
But in a UI version of xDel I would add the capability to select multiple files and/or dirs.

The current GetFileDialog API is very easy to use. You call it, magic happens, and you get back a simple string. Adding multiple file section to GetFileDialog would make it more complicated to use, so I wouldn't do that.
Instead, I think it makes more sense to create a GetMultiFileDialog variant. To handle the output, I would provide an empty SUB that gets called once for each file/dir in the selection. It's then up to the developer integrating GetMultiFileDialog to provide an implementation for this SUB.
e.g.


'isFile%=1/0 if fileDirname$ is a file/directory.
SUB selectedFileDir(fileDirName$, isFile%)
'Implementation here please.
END SUB


(In other languages this would be handled by passing in a hook/callback/function pointer, but I haven't figured out yet if/how this can be done in MMbasic. I experimented a bit with EVAL where the caller passes in a function to call back as a string, but it didn't work.)
Epsilon CMM2 projects
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 07:33am 16 Oct 2020
Copy link to clipboard 
Print this post

Just to follow up on my own comment re callbacks. I was scanning through the user guide and came across the EXECUTE command, and that one works just fine for executing callbacks:


CONST QUOTE$=CHR$(34)

SUB printTheArg(arg$)
print arg$
END SUB

SUB dontCallMeIllCallYou callback$
PRINT "Hello ";
EXECUTE callback$ + " " + QUOTE$ + "world" + QUOTE$
END SUB

dontCallMeIllCallYou "printTheArg"


Cheers,
Ruben/Epsilon.
Epsilon CMM2 projects
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 11:10am 31 Oct 2020
Copy link to clipboard 
Print this post

vegipete,

For my editors I need the option to specify a new file in the GetFileName dialog. I also need a SaveFileName Dialog.

I added those two features as modifications to GetFile12. I butchered the demo program in the process. My apologies. I leave it up to you to integrate what I'm proposing into a new proper revision, if you agree with my approach that is. There's also a lot of room for code refactoring due to commonality between GetFileDialog and SaveFileDialog. I didn't go there because it's hard to make those changes in other people's code with respect for their design/implementation/style choices.

The extended GetFileName has an 'N' key to specify a new file. When pressed, a line opens up a the cursor to allow the use to enter the file name. A check is added for duplicate file names.

The SaveFileName dialog looks very much like GetFileName, but here Enter is used to open a line at the cursor for the new file name.

Cheers,
Ruben/Epsilon

GetSaveFile13.zip
Epsilon CMM2 projects
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 01:09pm 31 Oct 2020
Copy link to clipboard 
Print this post

Hi Ruben,

are you sure you uploaded the correct file?
I couldn't figure out how it works. *

Regards
Michael

PS
I would think that an additional dialog window should be appended for SAVEFILE.
Just my2c

*This is just a message for information, not a complaint!
Edited 2020-10-31 23:19 by twofingers
causality ≠ correlation ≠ coincidence
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 01:34pm 31 Oct 2020
Copy link to clipboard 
Print this post

Hi Michael,

If that's the case, then this is probably not the right approach.

When you start the program you first see the GetFile Dialog (Select File... in the window header). It works as before, but you may (or may not) notice there's now an 'N(ew)' option in addition to the usual controls (also see window header). So, in addition to selecting an existing file, you can specify a new file.

After making your selection, a 2nd Dialog shows up. That's the SaveFile Dialog. It looks the same as the other one, but the window header says 'Save File...'. You navigate to where you want, press enter and then enter the name of the file to save.

  Quote  
I would think that an additional dialog window should be appended for SAVEFILE.


Do you mean that after navigating to the proper directory and pressing enter, another pop-up should appear that prompts you to enter the filename?
Edited 2020-10-31 23:35 by epsilon
Epsilon CMM2 projects
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 02:02pm 31 Oct 2020
Copy link to clipboard 
Print this post

  epsilon said  ... It works as before, but you may (or may not) notice there's now an 'N(ew)' option in addition to the usual controls (also see window header). So, in addition to selecting an existing file, you can specify a new file.

I get an input line but it is too far away from the main window and is not deleted after input.


  epsilon said  After making your selection, a 2nd Dialog shows up. That's the SaveFile Dialog. It looks the same as the other one, but the window header says 'Save File...'. You navigate to where you want, press enter and then enter the name of the file to save.
I don't get a blank line to enter my filename. I only get a message: "File Exists!" (sometimes in the wrong position).

Aaaggrhh! It only works when I type in a new filename first.
Okay ...


  epsilon said  
  Quote  I would think that an additional dialog window should be appended for SAVEFILE.


Do you mean that after navigating to the proper directory and pressing enter, another pop-up should appear that prompts you to enter the filename?
NO! The Save File dialog box should be split into two parts: the file selection and an entry line. For example, if you use Save File from Notepad. This is only my (only one!) opinion.

Michael
causality ≠ correlation ≠ coincidence
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 04:03pm 31 Oct 2020
Copy link to clipboard 
Print this post

Well, whichever way I'm going to take this, I'll have to figure out why it's misbehaving so badly for you. That'll teach me, messing with other people's code.

If it's not too much to ask, would you mind giving the attached version a spin, to see if it's any better? It's explicitly setting options, so it's less dependent on the user environment. I also fixed a bug for the 'file exists' case.

GetSaveFile14.zip
Epsilon CMM2 projects
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 04:51pm 31 Oct 2020
Copy link to clipboard 
Print this post

Hi Ruben,
first of all I have to say that I respect you very much. I hope there is no doubt about that.
  epsilon said  ... That'll teach me, messing with other people's code.

I know how difficult it is.  

  epsilon said  If it's not too much to ask, would you mind giving the attached version a spin, to see if it's any better?

Sorry, I did not find a difference. I even compared both files because I believed I got the wrong version.
It's not better now. I'd leave it to Pete. But that's up to you, obviously!

  epsilon said  I also fixed a bug for the 'file exists' case.

But I still get this if I did'nt use the New File option first.

I hope I haven't disheartened you too much. If you do, please ignore me.

Michael
causality ≠ correlation ≠ coincidence
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 06:00pm 31 Oct 2020
Copy link to clipboard 
Print this post

I'm working on this...

I've been expanding GetFile to include more functions. The resulting package may get named "UltraBox."

Possible features: (some are done, some still pondering)
FileDialog (for selecting and saving)
YesNoDialog (or Accept/Cancel? Maybe program selects)
InputStringDialog
MessageBox (timed or 'Press a key to continue...'  Is 255 characters enough?)
ActivityBar ( Horizontal 0 to 100%, difficult because it needs call back by program.)

I'm also looking at mouse awareness of these routines.

The FileDialog routine has the following input at the moment:
Sub FileDialog(result$() [,spec$][,x_position][,y_position][,height][,width])
' Input:  result$(): array to hold results, dim(1) for single result, more for multi
'         spec$: optional - wildcard matching, plus following
'           standard functions:
'             "*"        show all files, allow any file to be selected - default
'             "*.BAS"    show only request file types, standard MMBasic wildcard matching
'             "<DIR>"    show all files, allow only selection of directories
'           multi-select functions:
'             "<M>*"     show and multi-select all file types
'             "<M>*.BAS" show and multi-select specified file types
'             "<MDIR>"   show all, multi-select only directories
'             "<MALL>"   show all, multi-select files and directories
'           save file function:
'             "<SAVE>["starting value"]" show all, returns path of displayed directory + string
'                        from text box, which is initialized with the optional string.
'         x_position:  optional, default = centered dialog
'         y_position:  optional, default = centered dialog
'         height:      optional, height in characters of directory/file list, default 15
'         width:       optional, width in characters of directory/file list, default 32

Visit Vegipete's *Mite Library for cool programs.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 06:14pm 31 Oct 2020
Copy link to clipboard 
Print this post

Hi Pete,

That's good news! I think Ruben will appreciate that too. Many thanks.

Regards
Michael
causality ≠ correlation ≠ coincidence
 
epsilon

Senior Member

Joined: 30/07/2020
Location: Belgium
Posts: 255
Posted: 07:46pm 31 Oct 2020
Copy link to clipboard 
Print this post

I certainly do. Thanks Pete! I'm glad I got a way out of the mess that I appeared to have started here
Epsilon CMM2 projects
 
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 228
Posted: 09:13pm 31 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  I'm working on this...

I've been expanding GetFile to include more functions. The resulting package may get named "UltraBox."



"UltraBox"?  It means nothing to me...
Edited 2020-11-01 07:14 by elk1984
 
     Page 2 of 4    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025