Exemple #1
0
        void CreateFilters(FileFilter [] filters)
        {
            if (filters.Any())
            {
                var label     = new NSTextField();
                var fileTypes = new NSPopUpButton();
                fileTypes.AddItems(filters.Select(f => f.Label).ToArray());

                var fileTypeView = new NSView();
                fileTypeView.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
                const int padding = 15;

                label.StringValue     = "Show Files";
                label.DrawsBackground = false;
                label.Bordered        = false;
                label.Bezeled         = false;
                label.Editable        = false;
                label.Selectable      = false;
                label.SizeToFit();
                fileTypeView.AddSubview(label);

                fileTypes.SizeToFit();
                fileTypes.Activated += (sender, e) =>
                {
                    var currentFilter = filters.FirstOrDefault(f => f.Label == fileTypes.TitleOfSelectedItem);
                    SetCurrentItem(currentFilter);

                    // THIS DOES NOT WORK ON MAC OS FROM MAVERICS TO YOSEMITE
                    // There exists hacks, however they are dependent on OS X version
                    // I have filed bug as many others, but I guess this will never be fixed
                    _panel.ValidateVisibleColumns();
                    _panel.Update();
                };
                fileTypeView.AddSubview(fileTypes);
                fileTypes.SetFrameOrigin(new CGPoint(label.Frame.Width + 10, padding));

                label.SetFrameOrigin(new CGPoint(0, padding + (fileTypes.Frame.Height - label.Frame.Height) / 2));

                fileTypeView.Frame = new CGRect(0, 0, fileTypes.Frame.Width + label.Frame.Width + 10, fileTypes.Frame.Height + padding * 2);

                _panel.AccessoryView = fileTypeView;
                if (filters.Any())
                {
                    SetCurrentItem(filters.First());
                }
            }
            else
            {
                _panel.AccessoryView = null;
            }
        }