Beispiel #1
0
            NSMenuItem CreateMenuItem(NSMenu menu, IRuntimeModel runtime)
            {
                NSMenuItem menuItem;
                string     runtimeFullDisplayString;

                using (var mutableModel = runtime.GetMutableModel()) {
                    runtimeFullDisplayString = mutableModel.FullDisplayString;

                    menuItem = new NSMenuItem {
                        IndentationLevel = runtime.IsIndented ? 2 : 1,
                        AttributedTitle  = new NSAttributedString(mutableModel.DisplayString, new NSStringAttributes {
                            Font = runtime.Notable ? NSFontManager.SharedFontManager.ConvertFont(menu.Font, NSFontTraitMask.Bold) : menu.Font,
                        }),
                        Enabled = mutableModel.Enabled,
                        Hidden  = !mutableModel.Visible,
                    };
                }

                var subMenu = CreateSubMenuForRuntime(runtime);

                if (subMenu != null)
                {
                    menuItem.Submenu = subMenu;
                    menuItem.Enabled = true;
                }
                else
                {
                    menuItem.Activated += (o2, e2) => {
                        string old;
                        using (var activeMutableModel = ActiveRuntime.GetMutableModel())
                            old = activeMutableModel.FullDisplayString;

                        IRuntimeModel newRuntime = runtimeModel.FirstOrDefault(r => {
                            using (var newRuntimeMutableModel = r.GetMutableModel())
                                return(newRuntimeMutableModel.FullDisplayString == runtimeFullDisplayString);
                        });
                        if (newRuntime == null)
                        {
                            return;
                        }

                        ActiveRuntime = newRuntime;
                        var ea = new HandledEventArgs();
                        if (RuntimeChanged != null)
                        {
                            RuntimeChanged(o2, ea);
                        }

                        if (ea.Handled)
                        {
                            ActiveRuntime = runtimeModel.First(r => {
                                using (var newRuntimeMutableModel = r.GetMutableModel())
                                    return(newRuntimeMutableModel.FullDisplayString == old);
                            });
                        }
                    };
                }
                menu.AddItem(menuItem);
                return(menuItem);
            }
Beispiel #2
0
            nfloat UpdatePathCellForSize(int idx, nfloat remaining, CellState newStateIfEnoughSize)
            {
                var    cell = PathComponentCells [idx];
                string text;

                if (idx == ConfigurationIdx)
                {
                    if (ActiveConfiguration != null)
                    {
                        text = ActiveConfiguration.DisplayString;
                    }
                    else
                    {
                        text = ConfigurationPlaceholder;
                    }
                }
                else
                {
                    if (ActiveRuntime != null)
                    {
                        using (var mutableModel = ActiveRuntime.GetMutableModel())
                            text = mutableModel.FullDisplayString;
                    }
                    else
                    {
                        text = RuntimePlaceholder;
                    }
                }
                var size = new NSAttributedString(text, new NSStringAttributes {
                    Font = cell.Font
                }).Size.Width + 20;

                if (size < remaining)
                {
                    state |= newStateIfEnoughSize;
                    UpdatePathText(idx, text);
                }
                return(remaining - size);
            }
Beispiel #3
0
            public override void MouseDown(NSEvent theEvent)
            {
                if (!Enabled)
                {
                    return;
                }

                var locationInView = ConvertPointFromView(theEvent.LocationInWindow, null);

                var cellIdx = IndexOfCellAtX(locationInView.X);

                if (cellIdx == -1)
                {
                    return;
                }

                var item = PathComponentCells [cellIdx];

                if (item == null || !item.Enabled)
                {
                    return;
                }

                var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this);
                int i             = 0;

                NSMenuItem selectedItem = null;
                var        menu         = new NSMenu {
                    AutoEnablesItems = false,
                    ShowsStateColumn = false,
                    Font             = NSFont.MenuFontOfSize(12),
                };

                if (cellIdx == ConfigurationIdx)
                {
                    if (ActiveConfiguration == null)
                    {
                        return;
                    }

                    foreach (var configuration in ConfigurationModel)
                    {
                        var _configuration = configuration;
                        var menuitem       = new NSMenuItem(configuration.DisplayString, (o2, e2) => {
                            ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId);
                        })
                        {
                            Enabled          = true,
                            IndentationLevel = 1,
                        };

                        menu.AddItem(menuitem);

                        if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId)
                        {
                            selectedItem = menuitem;
                        }
                    }
                }
                else if (cellIdx == RuntimeIdx)
                {
                    if (ActiveRuntime == null)
                    {
                        return;
                    }

                    using (var activeMutableModel = ActiveRuntime.GetMutableModel()) {
                        foreach (var runtime in RuntimeModel)
                        {
                            if (runtime.HasParent)
                            {
                                continue;
                            }

                            NSMenuItem menuitem = null;
                            if (runtime.IsSeparator)
                            {
                                menu.AddItem(NSMenuItem.SeparatorItem);
                            }
                            else
                            {
                                menuitem = CreateMenuItem(menu, runtime);
                            }

                            using (var mutableModel = runtime.GetMutableModel()) {
                                if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString)
                                {
                                    selectedItem = menuitem;
                                }
                            }

                            ++i;
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }

                if (menu.Count > 1)
                {
                    var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3);

                    if (Window?.Screen?.BackingScaleFactor == 2)
                    {
                        offs.Y += 0.5f;                         // fine tune menu position on retinas
                    }
                    menu.PopUpMenu(selectedItem, offs, this);
                }
            }
            void PopupMenuForCell(NSPathComponentCell item)
            {
                var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this);
                int i             = 0;

                NSMenuItem selectedItem = null;
                var        menu         = new NSMenu {
                    AutoEnablesItems = false,
                    ShowsStateColumn = true,
                    Font             = NSFont.MenuFontOfSize(12),
                };

                if (item.Identifier == RunConfigurationIdentifier)
                {
                    if (ActiveRunConfiguration == null)
                    {
                        return;
                    }

                    foreach (var configuration in RunConfigurationModel)
                    {
                        var _configuration = configuration;
                        var menuitem       = new NSMenuItem(configuration.DisplayString, (o2, e2) => {
                            ActiveRunConfiguration = runConfigurationModel.First(c => c.OriginalId == _configuration.OriginalId);
                        })
                        {
                            Enabled          = true,
                            IndentationLevel = 1,
                        };

                        menu.AddItem(menuitem);

                        if (selectedItem == null && configuration.OriginalId == ActiveRunConfiguration.OriginalId)
                        {
                            selectedItem = menuitem;
                        }
                    }
                }
                else if (item.Identifier == ConfigurationIdentifier)
                {
                    if (ActiveConfiguration == null)
                    {
                        return;
                    }

                    foreach (var configuration in ConfigurationModel)
                    {
                        var _configuration = configuration;
                        var menuitem       = new NSMenuItem(configuration.DisplayString, (o2, e2) => {
                            ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId);
                        })
                        {
                            Enabled          = true,
                            IndentationLevel = 1,
                        };

                        menu.AddItem(menuitem);

                        if (selectedItem == null && configuration.OriginalId == ActiveConfiguration.OriginalId)
                        {
                            selectedItem = menuitem;
                        }
                    }
                }
                else if (item.Identifier == RuntimeIdentifier)
                {
                    if (ActiveRuntime == null)
                    {
                        return;
                    }

                    using (var activeMutableModel = ActiveRuntime.GetMutableModel()) {
                        foreach (var runtime in RuntimeModel)
                        {
                            NSMenuItem menuitem = null;
                            if (runtime.IsSeparator)
                            {
                                menu.AddItem(NSMenuItem.SeparatorItem);
                            }
                            else
                            {
                                menuitem = CreateMenuItem(menu, runtime);
                            }

                            using (var mutableModel = runtime.GetMutableModel()) {
                                if (selectedItem == null && menuitem != null && mutableModel.DisplayString == activeMutableModel.DisplayString)
                                {
                                    selectedItem = menuitem;
                                }
                            }

                            ++i;
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }

                LastSelectedCell = IndexFromIdentifier(item.Identifier);
                if (menu.Count > 1)
                {
                    var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3);

                    if (Window?.Screen?.BackingScaleFactor == 2)
                    {
                        offs.Y += 0.5f;                         // fine tune menu position on retinas
                    }
                    menu.PopUpMenu(selectedItem, offs, this);
                }
            }
            public PathSelectorView(CGRect frameRect) : base(frameRect)
            {
                PathComponentCells = new [] {
                    new NSPathComponentCell {
                        Image   = MultiResImage.CreateMultiResImage("project", "disabled"),
                        Title   = TextForActiveConfiguration,
                        Enabled = false,
                    },
                    new NSPathComponentCell {
                        Image   = MultiResImage.CreateMultiResImage("device", "disabled"),
                        Title   = TextForRuntimeConfiguration,
                        Enabled = false,
                    }
                };
                UpdateStyle();

                BackgroundColor = NSColor.Clear;
                FocusRingType   = NSFocusRingType.None;
                Activated      += (sender, e) => {
                    var item = ClickedPathComponentCell;
                    if (item == null)
                    {
                        return;
                    }

                    var componentRect = ((NSPathCell)Cell).GetRect(item, Frame, this);
                    int idx           = -1;
                    int i             = 0;

                    var menu = new NSMenu {
                        AutoEnablesItems = false,
                        ShowsStateColumn = false,
                        Font             = NSFont.MenuFontOfSize(12),
                    };
                    if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [ConfigurationIdx]))
                    {
                        if (ActiveConfiguration == null)
                        {
                            return;
                        }

                        foreach (var configuration in ConfigurationModel)
                        {
                            if (idx == -1 && configuration.OriginalId == ActiveConfiguration.OriginalId)
                            {
                                idx = i;
                            }

                            var _configuration = configuration;
                            menu.AddItem(new NSMenuItem(configuration.DisplayString, (o2, e2) => {
                                ActiveConfiguration = configurationModel.First(c => c.OriginalId == _configuration.OriginalId);
                            })
                            {
                                Enabled          = true,
                                IndentationLevel = 1,
                            });
                            ++i;
                        }
                    }
                    else if (object.ReferenceEquals(ClickedPathComponentCell, PathComponentCells [RuntimeIdx]))
                    {
                        if (ActiveRuntime == null)
                        {
                            return;
                        }

                        using (var activeMutableModel = ActiveRuntime.GetMutableModel()) {
                            foreach (var runtime in RuntimeModel)
                            {
                                using (var mutableModel = runtime.GetMutableModel()) {
                                    if (idx == -1 && mutableModel.DisplayString == activeMutableModel.DisplayString)
                                    {
                                        idx = i;
                                    }
                                }

                                if (runtime.HasParent)
                                {
                                    continue;
                                }

                                if (runtime.IsSeparator)
                                {
                                    menu.AddItem(NSMenuItem.SeparatorItem);
                                }
                                else
                                {
                                    CreateMenuItem(menu, runtime);
                                }
                                ++i;
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }

                    if (menu.Count > 1)
                    {
                        var offs = new CGPoint(componentRect.Left + 3, componentRect.Top + 3);

                        if (Window.Screen.BackingScaleFactor == 2)
                        {
                            offs.Y += 0.5f;                             // fine tune menu position on retinas
                        }
                        menu.PopUpMenu(null, offs, this);
                    }
                };

                Ide.Gui.Styles.Changed += UpdateStyle;
            }