コード例 #1
0
        NSView CreateRow(string label, string [] items, int selectedItem, Action <int> handler)
        {
            var stackView = new NSStackView {
                Orientation  = NSUserInterfaceLayoutOrientation.Horizontal,
                Distribution = NSStackViewDistribution.Fill,
                Spacing      = 8
            };

            var labelView = new Views.XILabel {
                StringValue = label
            };

            labelView.SizeToFit();
            stackView.AddView(labelView, NSStackViewGravity.Leading);

            var menuView = new NSPopUpButton();

            menuView.AddItems(items);
            menuView.SelectItem(selectedItem);
            stackView.AddView(menuView, NSStackViewGravity.Trailing);

            menuView.Activated += (sender, e) => handler((int)menuView.IndexOfSelectedItem);

            return(stackView);
        }
コード例 #2
0
ファイル: FileDialogs.cs プロジェクト: yongaru/fuse-studio
        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;
            }
        }
コード例 #3
0
        /// <summary>
        /// Adds the elements associated with a command to a NSPopUpButton.
        /// </summary>
        /// <param name="command">The command to associate with the elements in the popup button.</param>
        /// <param name="button">The button to which the command is to be added.</param>
        /// <param name="itemTitles">The user-visible names of the items to add to the popup button.</param>
        /// <param name="itemTags">The identifying information for the choices added to the popup button.</param>
        /// <param name="itemToolTips">Tool tips for the choices in the popup button.</param>
        /// <remarks>The NSPopUpButton presents a choice for the user to select. The same command is associated with each choice in the
        /// button. When the command is invoked, the Tag associated with the item in the popup button is part of the data used in executing the command.</remarks>
        public static void PopulatePopUpButton(this ICommand command, NSPopUpButton button, string[] itemTitles, int[] itemTags, string[] itemToolTips)
        {
            button.RemoveAllItems();
            button.AddItems(itemTitles);
            var menuItems = button.Items();

            for (int i = 0; i < menuItems.Length; ++i)
            {
                var menuItem = menuItems[i];
                menuItem.RepresentedObject = new NSObjectWrapper <ICommand>(command);
                menuItem.Tag     = itemTags[i];
                menuItem.ToolTip = itemToolTips[i];
            }
        }