View Issue Details

IDProjectCategoryView StatusLast Update
0028687LazarusWidgetsetpublic2018-01-09 15:53
ReporterChris Rorden Assigned ToFelipe Monteiro de Carvalho  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformMacBook RetinaOSDarwin OSX 
Product Version1.5 (SVN) 
Summary0028687: Cocoa Feature Request: SaveDialog Filter
DescriptionIt would be great if the Cocoa TSaveDialog component would provide extension filters, just like Carbon and the other widget sets
Steps To Reproduce

     SaveDialog1.Filter := 'Bitmap (bmp)|*.bmp|NIfTI|*.nii|NIfTI compressed|*.nii.gz';
     if not SaveDialog1.execute then exit;
     Caption := SaveDialog1.FileName+' '+inttostr(SaveDialog1.filterIndex);
TagsNo tags attached.
Fixed in Revision55405, 55407
LazTarget-
WidgetsetCocoa
Attached Files

Relationships

related to 0032069 closedDmitry Boyarintsev File filters should handle double extensions 

Activities

CudaText man

2017-05-02 18:48

reporter   ~0100064

Seems it cannot be made
So "wont fix"

--
  Filters := TStringList.Create;

  // Cocoa doesn't supports a filter list selector like we know from windows. So we add all the masks into one filter list.

  ParsedFilter := TParseStringList.Create(FileDialog.Filter, '|');

  for i := 1 to ParsedFilter.Count div 2 do
  begin
    filterext := ParsedFilter[i * 2 - 1];
    Masks := TParseStringList.Create(filterext, ';');
    for m := 0 to Masks.Count - 1 do
    begin
      if Masks[m] = '*.*' then
        continue;

      Extensions := TParseStringList.Create(Masks[m], '.');

      if Extensions.Count > 0 then
        extension := Extensions[Extensions.Count - 1]
      else
        extension := Masks[m];

      Filters.Add(lowercase(extension));
      Filters.Add(uppercase(extension));
      //debugln('Filters: ' + extension);
      Extensions.Free;
    end;

    Masks.Free;
  end;

  ParsedFilter.Free;

Juha Manninen

2017-05-10 12:02

developer   ~0100193

Mac users please confirm the diagnosis from AlexeyT.
Can it be resolved as "won't fix"?

Chris Rorden

2017-06-23 16:02

reporter   ~0101309

I would like to re-open this issue. I think it is challenging but is fixable with "setAccessoryView". To see solutions please see:

http://codefromabove.com/2015/01/nssavepanel-adding-an-accessory-view/

https://developer.apple.com/library/content/samplecode/CustomSave/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004201

This seems like an issue that will need to be addressed eventually.

CudaText man

2017-06-23 16:43

reporter   ~0101310

Last edited: 2017-06-23 16:44

View 2 revisions

@Chris
Your 1st link-- shows its possible:

>Adding an Accessory View Programmatically
To add a control for the file type, we’ll use an NSPopUpButton, along with a label, and embed this in a view for layout purposes. This can done programmatically, or by loading UI elements from a Xib file. Here’s a bare-bones programmatic approach

http://codefromabove.com/wp-content/uploads/2015/01/FinalSaveDialog.jpg

Felipe Monteiro de Carvalho

2017-06-27 10:04

developer   ~0101361

Qt file dialog implementation where we can get ideas: http://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm

Felipe Monteiro de Carvalho

2017-06-27 10:41

developer   ~0101362

As usual Cocoa is filled with bugs, I just hit this one:

changing the filter will not work before 10.3 (I happen to have 10.2 with no possibility of update to 10.3 AFAIK), due to some bug:

https://bugreports.qt.io/browse/QTBUG-33530

https://stackoverflow.com/questions/19373298/setallowedfiletypes-while-nsopenpanel-is-displayed

Eiola hack solution:

https://stackoverflow.com/questions/18192986/nsopenpanel-doesnt-validatevisiblecolumns

Its a big problem :/

Felipe Monteiro de Carvalho

2017-06-27 13:23

developer   ~0101363

Last edited: 2017-06-27 13:25

View 3 revisions

We need to manually reload the right component, so here is a dump of all controls inside a NSSavePanel in Mac OS X 10.10.2:

NSTextField/NSBox/NSBox/NSView/NSView/NSProgressIndicator/NSButton/NSButton
/NSButton/NSButton/NSButton/NSButton/NSBox/NSNavFinderViewFileBrowser
/FIFinderView/NSView/NSView/NSSegmentedControl/NSSegmentedControl
/NSSegmentedControl/FILocationPopUp/SGTSearchField/NSBox/NSBox
/NSView/FI_TSidebarSplitView/NSView/FI_TSidebarScrollView/NSVisualEffectView
/NSClipView/FI_TSidebarView/NSScroller/NSScroller/NSView/FI_TSplitView
/FI_TBrowserBackgroundView/FI_TListScrollView/NSClipView/NSTableBackgroundView
/NSTableBackgroundView/NSTableBackgroundView/NSTableBackgroundView/FI_TListView
/NSTableBackgroundView/NSClipView/NSVisualEffectView/FI_TTableHeaderView/NSTableHeaderCellView
/NSTableHeaderCellView/NSTableHeaderCellView/NSTableHeaderCellView
/NSTableHeaderCellView/NSTableHeaderCellView/NSTableHeaderCellView
/NSTableHeaderCellView/NSTableHeaderCellView
/NSTableHeaderCellView/_NSScrollViewFloatingSubviewsContainerView
/FI_TListHeaderRowView/NSVisualEffectView/FI_TUpdateLayerView/FI_TListHeaderCellView
/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView
/FI_TUpdateLayerView/FI_TListHeaderCellView
/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView
/FI_TUpdateLayerView/FI_TListHeaderCellView/FI_TTextField/FI_TImageView
/NSImageViewContainerView/FI_TImageView/FI_TUpdateLayerView/FI_TListHeaderCellView
/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView
/FI_TUpdateLayerView/FI_TListHeaderCellView/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView/FI_TUpdateLayerView
/FI_TListHeaderCellView/FI_TTextField/FI_TImageView/NSImageViewContainerView
/FI_TImageView/FI_TUpdateLayerView/FI_TListHeaderCellView/FI_TTextField
/FI_TImageView/NSImageViewContainerView/FI_TImageView/FI_TUpdateLayerView
/FI_TListHeaderCellView/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView/FI_TUpdateLayerView/FI_TListHeaderCellView
/FI_TTextField/FI_TImageView/NSImageViewContainerView/FI_TImageView
/FI_TUpdateLayerView
/FI_TListHeaderCellView/FI_TTextField/FI_TImageView/NSImageViewContainerView
/FI_TImageView/FI_TUpdateLayerView/FI_TListHeaderCellView/FI_TTextField/FI_TImageView
/NSImageViewContainerView/FI_TImageView/FI_TUpdateLayerView/FI_TUpdateLayerView
/FI_TListVerticalScroller/FI_TListHorizontalScroller/_NSCornerView/NSView/NSView
/NSView/NSButton/NSTextField/NSTextField/NSView/NSTextField/FILocationPopUp
/_NSSavePanelTagEditorContainer/_NSSavePanelTagEditorLabel/FITagEditorView/FI_TTaggingTokenField/NSButton

Felipe Monteiro de Carvalho

2017-06-27 13:50

developer   ~0101364

I commited a initial implementation in rev 55405

Some issues:

1> Upon changing the filter it will instantaneously change the enabled status only if you are using the non-tree view in TOpenDialog
2> For the tree view it will only change when you change directory
3> In TSaveDialog I was not able to make the filter do anything, it doesn't seam to do anything in Carbon either. It just pretends to do anything by being there.

Chris Rorden

2017-06-27 16:18

reporter   ~0101365

Last edited: 2017-06-27 16:51

View 2 revisions

Felipe-

Great work. Two minor edits

1.) Set the filter index when you show the panel:
    lFilter.lastSelectedItemIndex:= FileDialog.FilterIndex - 1; //CR add
    lFilter.updateFilterList();
    //lFilter.setDialogFilter(0); //CR delete
….

2.) For TSaveDialog, set the filter when the user presses "OK"

    if saveDlg.runModal = NSOKButton then
    begin
      FileDialog.FileName := NSStringToString(saveDlg.URL.path);
      if FileDialog.Filter <> '' then //CR add
        FileDialog.FilterIndex:= lFilter.indexOfSelectedItem+1; //CR add


(Note, the +1 and -1, as Cocoa arrays indexed from 0 not 1)

Felipe Monteiro de Carvalho

2017-06-27 22:52

developer   ~0101370

I added your changes in rev 55407

Except for deleting the call to lFilter.setDialogFilter(0);
I changed it to lFilter.setDialogFilter(lFilter.lastSelectedItemIndex);

Or do you really think it should be deleted? why?

Chris Rorden

2018-01-09 15:53

reporter   ~0105518

Fixed. Thanks.

Issue History

Date Modified Username Field Change
2015-09-16 16:16 Chris Rorden New Issue
2017-05-02 18:48 CudaText man Note Added: 0100064
2017-05-10 12:02 Juha Manninen Note Added: 0100193
2017-05-11 10:38 Felipe Monteiro de Carvalho Assigned To => Felipe Monteiro de Carvalho
2017-05-11 10:38 Felipe Monteiro de Carvalho Status new => assigned
2017-05-11 10:38 Felipe Monteiro de Carvalho LazTarget => -
2017-05-11 10:38 Felipe Monteiro de Carvalho Status assigned => resolved
2017-05-11 10:38 Felipe Monteiro de Carvalho Resolution open => not fixable
2017-06-23 16:02 Chris Rorden Note Added: 0101309
2017-06-23 16:02 Chris Rorden Status resolved => assigned
2017-06-23 16:02 Chris Rorden Resolution not fixable => reopened
2017-06-23 16:43 CudaText man Note Added: 0101310
2017-06-23 16:44 CudaText man Note Edited: 0101310 View Revisions
2017-06-27 10:04 Felipe Monteiro de Carvalho Note Added: 0101361
2017-06-27 10:41 Felipe Monteiro de Carvalho Note Added: 0101362
2017-06-27 13:23 Felipe Monteiro de Carvalho Note Added: 0101363
2017-06-27 13:24 Felipe Monteiro de Carvalho Note Edited: 0101363 View Revisions
2017-06-27 13:25 Felipe Monteiro de Carvalho Note Edited: 0101363 View Revisions
2017-06-27 13:50 Felipe Monteiro de Carvalho Note Added: 0101364
2017-06-27 16:18 Chris Rorden Note Added: 0101365
2017-06-27 16:51 Chris Rorden Note Edited: 0101365 View Revisions
2017-06-27 22:52 Felipe Monteiro de Carvalho Note Added: 0101370
2017-06-27 22:52 Felipe Monteiro de Carvalho Fixed in Revision => 55405, 55407
2017-06-27 22:52 Felipe Monteiro de Carvalho Status assigned => resolved
2017-06-27 22:52 Felipe Monteiro de Carvalho Resolution reopened => fixed
2018-01-07 01:32 Dmitry Boyarintsev Relationship added related to 0032069
2018-01-09 15:53 Chris Rorden Note Added: 0105518
2018-01-09 15:53 Chris Rorden Status resolved => closed