Recent

Author Topic: [Solved] OpenFile Dialog - Windows and Linux  (Read 8184 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
[Solved] OpenFile Dialog - Windows and Linux
« 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?
« Last Edit: September 18, 2013, 11:00:26 pm by Windsurfer »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: OpenFile Dialog - Windows and Linux
« Reply #1 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.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: OpenFile Dialog - Windows and Linux
« Reply #2 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?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: OpenFile Dialog - Windows and Linux
« Reply #3 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?

fedkad

  • Full Member
  • ***
  • Posts: 176
OpenFile Dialog - Windows and Linux
« Reply #4 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?
« Last Edit: December 24, 2017, 01:36:33 pm by fedkad »
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: [Solved] OpenFile Dialog - Windows and Linux
« Reply #5 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.

fedkad

  • Full Member
  • ***
  • Posts: 176
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: [Solved] OpenFile Dialog - Windows and Linux
« Reply #7 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" and that, according to this, 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.  

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: [Solved] OpenFile Dialog - Windows and Linux
« Reply #8 on: June 12, 2018, 08:24:44 pm »
Digging the widgetset code, I found out that dialogs in Gtk2 use something called "glob pattern" and that, according to this, you will get case-insensitive behaviour with ...

Thanks Zoran. I will give it a try.  :)
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: [Solved] OpenFile Dialog - Windows and Linux
« Reply #9 on: July 14, 2018, 07:09:42 pm »
Thanks Zoran

fedkad

  • Full Member
  • ***
  • Posts: 176
Re: [Solved] OpenFile Dialog - Windows and Linux
« Reply #10 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!
Lazarus 2.2.6 / FPC 3.2.2 on x86_64-linux-gtk2 (Ubuntu/GNOME) and x86_64-win64-win32/win64 (Windows 11)

 

TinyPortal © 2005-2018