Lazarus

Programming => LCL => Topic started by: Windsurfer on September 18, 2013, 03:14:16 pm

Title: [Solved] OpenFile Dialog - Windows and Linux
Post by: Windsurfer on September 18, 2013, 03:14:16 pm
While porting an application form Windows to Linux, (Windows 8 to Mint 15) I noticed that Windows will detect uppercase filenames with a lowercase filter (*.sbn will detect FRED.SBN). However, in Linux this does not work. The filter must also be uppercase.

In Linux I  tried listing two filters (*.sbn, *.SBN) but it did not work.

[Edit: But *.sbn; *.SBN does work. I used the wrong list separator]

Should Windows and Linux work in the same way when using the LCL?

Is there a neat way of detecting filenames in both cases?
Title: Re: OpenFile Dialog - Windows and Linux
Post by: howardpc on September 18, 2013, 04:13:59 pm
Should Windows and Linux work in the same way when using the LCL?
Of course not, since Linux is case sensitive with respect to filenames and Windows is (almost always) case insensitive.
You have to respect each operating system's default mode of file access.
You might wish that aFile.ext was the same file as AFILE.EXT on Linux (as it is on Windows), but the fact is they are two different files, and can coexist in the same folder on Linux.
Title: Re: OpenFile Dialog - Windows and Linux
Post by: taazz on September 18, 2013, 04:42:28 pm
No he actually wishes to find a way to collect all files with a specific extension regardless the case how is that done in linux? using both extensions eg "*.sbn;*.SBN" is not going to help if there are file with the extension *.Sbn so is there any way to define that the filter is case insensitive?
Title: Re: OpenFile Dialog - Windows and Linux
Post by: Windsurfer on September 18, 2013, 04:57:22 pm
Thanks for your comments. They have clarified my thoughts.

What I need is something like the old database trick of using Upper() and Lower() to force consistency. The application is specific for an particular file type (Windows style).

Could that be a useful addition to the dialog?
Title: OpenFile Dialog - Windows and Linux
Post by: fedkad on December 24, 2017, 10:17:19 am
Sorry again to raise an old topic!  :)

I have a similar problem. While porting a Windows application to Linux, I noticed that a filter like "Text File (*.TXT)|*.txt" in the TOpenDialog will show only the file names ending with .txt, and not files ending with .TXT, .Txt, .tXt, .txT, .TXt, etc.

I want a method to show matching file names ending with all lower and upper case combinations of .txt. For example, in LibreOffice Open File dialog, if you select ODF Text Document, the file list will show all the files like this: a.odt, a.ODT, a.OdT, a.oDt, and so on.

I was expecting something like "ofCaseInsensitiveFilter" type of Option in the TOpenDialog dialog.

One solution would be to list *all*combinations in Filter. For a three-letter "extension" we will need 8 of them.

Any other ideas?
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: Windsurfer on March 30, 2018, 04:42:30 pm
I forget how I dealt with the problem. However, I like your option suggestion and it could be a feature request.
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: fedkad on June 10, 2018, 05:19:10 pm
https://bugs.freepascal.org/view.php?id=33846
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: Zoran on June 11, 2018, 01:44:36 pm
I tested on Linux Mint 18.3 with Gtk2 and Qt4 and, surprisingly, these two widgetsets behave differently!
The OpenDialog on Gtk2 lists only the files which match the filter mask case sensitively, whereas on Qt4, all files which match the mask case insensitively are listed!

So, the OpenDialog's behaviour is not even portable between the two widgetsets on same OS!


Digging the widgetset code, I found out that dialogs in Gtk2 use something called "glob pattern (https://en.wikipedia.org/wiki/Glob_(programming))" and that, according to this (http://teaching.idallen.com/cst8207/15w/notes/190_glob_patterns.html#using-to-match-case-insensitive), you will get case-insensitive behaviour with
Code: [Select]
*.txt|*[Tt][Xx][Tt]
So, for now, if you want the dialog to behave case-insensitevely on all platforms, as a workaround you can use something like this:
Code: Pascal  [Select][+][-]
  1.   OpenDialog1.Filter :=
  2.   {$ifdef LCLGtk2}
  3.     '*.txt|*.[Tt][Xx][Tt]'; // Gtk2
  4.   {$else}
  5.     '*.txt|*.txt'; // win32/64 and Qt4
  6.   {$endif}
  7.  
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: fedkad on June 12, 2018, 08:24:44 pm
Digging the widgetset code, I found out that dialogs in Gtk2 use something called "glob pattern (https://en.wikipedia.org/wiki/Glob_(programming))" and that, according to this (http://teaching.idallen.com/cst8207/15w/notes/190_glob_patterns.html#using-to-match-case-insensitive), you will get case-insensitive behaviour with ...

Thanks Zoran. I will give it a try.  :)
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: Windsurfer on July 14, 2018, 07:09:42 pm
Thanks Zoran
Title: Re: [Solved] OpenFile Dialog - Windows and Linux
Post by: fedkad on October 08, 2021, 12:44:15 pm

So, for now, if you want the dialog to behave case-insensitevely on all platforms, as a workaround you can use something like this:
Code: Pascal  [Select][+][-]
  1.   OpenDialog1.Filter :=
  2.   {$ifdef LCLGtk2}
  3.     '*.txt|*.[Tt][Xx][Tt]'; // Gtk2
  4.   {$else}
  5.     '*.txt|*.txt'; // win32/64 and Qt4
  6.   {$endif}
  7.  

Something like

Filter:
Code: Pascal  [Select][+][-]
  1. *.txt;*.TXT;*.[tT][xX][tT]

will also do the job. I tested under Ubuntu (qtk2) and Windows; and it works.

Thanks again!
TinyPortal © 2005-2018