Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2003-07

TFileDialog - Filter.

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bob Wingard

Mattias,
Greetings. This will fix the problem with the filter not working properly in the TFileOpen dialog.

diff against gtkobject.inc
4649c4649
< CurDescEnd:=CurDescStart;
---

CurDescEnd:=CurDescStart + 1;

4652c4652
< CurDesc:=copy(Filter,CurDescStart,CurDescEnd-CurDescStart); ---

CurDesc:=copy(Filter,CurDescStart + 1,CurDescEnd-(CurDescStart + 1));

4663c4663
< CurDescStart:=CurMultiMaskEnd+1;
---

CurDescStart:=CurMultiMaskEnd;

The filter and the filter description were not being properly parsed.

I am not sure if the behavior of the file open dialog is standard for a gtk widget. The filter is applied to both the directory list and the file list. Is this normal? The filter is not applied when the current directory changes, but is applied if the filter is re-selected from the drop down list. This is good for now as the only way to see directories with the filter applied is to change the directory.

Bob Wingard
Orange, Texas USA

Reply by email

Bob Wingard
to Bob Wingard
Bob Wingard wrote 35 lines
Mattias, Greetings. This will fix the problem with the filter not working properly in the TFileOpen dialog. diff against gtkobject.inc 4649c4649 < CurDescEnd:=CurDescStart; --- > CurDescEnd:=CurDescStart + 1; 4652c4652 < CurDesc:=copy(Filter,CurDescStart,CurDescEnd-CurDescStart); --- > CurDesc:=copy(Filter,CurDescStart + 1,CurDescEnd-(CurDescStart + 1)); 4663c4663 < CurDescStart:=CurMultiMaskEnd+1; --- > CurDescStart:=CurMultiMaskEnd; The filter and the filter description were not being properly parsed. I am not sure if the behavior of the file open dialog is standard for a gtk widget. The filter is applied to both the directory list and the file list. Is this normal? The filter is not applied when the current directory changes, but is applied if the filter is re-selected from the drop down list. This is good for now as the only way to see directories with the filter applied is to change the directory. Bob Wingard Orange, Texas USA _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Did some checking on the GTK site, best I can tell the bahavior is a bug in GTK, documentation says that the filter is applied to the filelist when gtk_file_selection_complete is called. The documentation does not state what if anything happens to the Directory list.

Bob

Reply by email

Mattias Gaertner
to Bob Wingard: Greetings. This will fix the problem with the filter not working properly in the…
Show quoted text 20 lines
Mattias, Greetings. This will fix the problem with the filter not working properly in the TFileOpen dialog. diff against gtkobject.inc 4649c4649 < CurDescEnd:=CurDescStart; --- > CurDescEnd:=CurDescStart + 1; 4652c4652 < CurDesc:=copy(Filter,CurDescStart,CurDescEnd-CurDescStart); --- > CurDesc:=copy(Filter,CurDescStart + 1,CurDescEnd-(CurDescStart + > 1)); 4663c4663 < CurDescStart:=CurMultiMaskEnd+1; --- > CurDescStart:=CurMultiMaskEnd; The filter and the filter description were not being properly parsed.

What filter were not properly parsed?

Mattias

Show quoted text 14 lines
I am not sure if the behavior of the file open dialog is standard for a gtk widget. The filter is applied to both the directory list and the file list. Is this normal? The filter is not applied when the current directory changes, but is applied if the filter is re-selected from the drop down list. This is good for now as the only way to see directories with the filter applied is to change the directory. Bob Wingard Orange, Texas USA _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Reply by email

Bob Wingard
to Bob Wingard: Greetings. This will fix the problem with the filter not working properly in the…
Mattias Gaertner wrote 5 lines
snip What filter were not properly parsed? snip

The problem was in the section of code that parsed the Filter property of the TFileDialog class. The code extracts a Description and Filter from the string property Filter. According to comments in the code it was looking for a string formated
'|description1|filter1|description2|filter2|....' After parseing you end up with a list of descriptions that go in the pull down menu on the file dialog and a list of masks that go with the description.

Comments from the code:
{------------------------------------------------------------------------------ Function: ExtractFilterList

  Params: const Filter: string; var FilterIndex: integer;
          var FilterList: TStringList
  Returns: -

Converts a Delphi file filter of the form
'description1|mask1|description2|mask2|...'
into a TList of PFileSelFilterEntry(s).
Multi masks:
- multi masks like '*.pas;*.pp' are converted into multiple entries.
- if the masks are found in the description they are adjusted
- if the mask is not included in the description it will be concatenated For example:

      'Pascal files (*.pas;*.pp)|*.pas;*.lpr;*.pp;
      is converted to three filter entries:
        'Pascal files (*.pas)' + '*.pas'
        'Pascal files (*.pp)'  + '*.pp'
        'Pascal files (*.lpr)' + '*.lpr'

------------------------------------------------------------------------------} This is the section that had the error.

 procedure ExtractMasks(const MultiMask: string);
  var CurMaskStart, CurMaskEnd: integer;
    s: string;
  begin
    if Masks=nil then
      Masks:=TStringList.Create
    else
      Masks.Clear;
    CurMaskStart:=1;
    while CurMaskStart<=length(MultiMask) do begin
      CurMaskEnd:=CurMaskStart;
      while (CurMaskEnd<=length(MultiMask)) and
(MultiMask[CurMaskEnd]';') do
        inc(CurMaskEnd);
      s:=Trim(copy(MultiMask,CurMaskStart,CurMaskEnd-CurMaskStart));
      if s='*.*' then s:='';
      Masks.Add(s);
      CurMaskStart:=CurMaskEnd+1;
    end;
  end;

Reply by email

Mattias Gaertner
to Bob Wingard: Greetings. This will fix the problem with the filter not working properly in the…
Show quoted text 6 lines
Mattias Gaertner wrote: >snip >What filter were not properly parsed? > >snip

First of all: The filter in TFileDialog does not work very well, because the gtk file selection dialog does not support them. Only very basic globbing. I think, you already noticed that. It can be fixed by connecting to all input events of the gtk file selection dialog, but then we are not far away from writing our own filedialog.

Show quoted text 6 lines
The problem was in the section of code that parsed the Filter property of the TFileDialog class. The code extracts a Description and Filter from the string property Filter. According to comments in the code it was looking for a string formated '|description1|filter1|description2|filter2|....'

^
This is not a valid filter. See comments in the code for an example.

After parseing you end up with a list of descriptions that go in the pull down menu on the file dialog and a list of masks that go with the description.

Mattias

Show quoted text 53 lines
Comments from the code: {------------------------------------------------------------------------ ------ Function: ExtractFilterList Params: const Filter: string; var FilterIndex: integer; var FilterList: TStringList Returns: - Converts a Delphi file filter of the form 'description1|mask1|description2|mask2|...' into a TList of PFileSelFilterEntry(s). Multi masks: - multi masks like '*.pas;*.pp' are converted into multiple entries. - if the masks are found in the description they are adjusted - if the mask is not included in the description it will be concatenated For example: 'Pascal files (*.pas;*.pp)|*.pas;*.lpr;*.pp; is converted to three filter entries: 'Pascal files (*.pas)' + '*.pas' 'Pascal files (*.pp)' + '*.pp' 'Pascal files (*.lpr)' + '*.lpr' ------------------------------------------------------------------------ ------} This is the section that had the error. procedure ExtractMasks(const MultiMask: string); var CurMaskStart, CurMaskEnd: integer; s: string; begin if Masks=nil then Masks:=TStringList.Create else Masks.Clear; CurMaskStart:=1; while CurMaskStart<=length(MultiMask) do begin CurMaskEnd:=CurMaskStart; while (CurMaskEnd<=length(MultiMask)) and (MultiMask[CurMaskEnd]';') do inc(CurMaskEnd); s:=Trim(copy(MultiMask,CurMaskStart,CurMaskEnd-CurMaskStart)); if s='*.*' then s:=''; Masks.Add(s); CurMaskStart:=CurMaskEnd+1; end; end; _________________________________________________________________ To unsubscribe: mail with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives

Reply by email