Ejemplo n.º 1
0
            void UpdateImages()
            {
                string projectStyle = "";
                string deviceStyle  = "";

                if (!PathComponentCells [ConfigurationIdx].Enabled)
                {
                    projectStyle = "disabled";
                }

                if (!PathComponentCells [ConfigurationIdx].Enabled)
                {
                    deviceStyle = "disabled";
                }

                // HACK
                // For some reason NSPathControl does not like the images that ImageService provides. To use them it requires
                // ToBitmap() to be called first. But a second problem is that ImageService only seems to provide a single resolution
                // for its icons. It may be related to the images being initially loaded through the Gtk backend and then converted to NSImage
                // at a later date.
                // For whatever reason, we custom load the images here through NSImage, providing both 1x and 2x image reps.
                PathComponentCells [ConfigurationIdx].Image = MultiResImage.CreateMultiResImage("project", projectStyle);
                PathComponentCells [RuntimeIdx].Image       = MultiResImage.CreateMultiResImage("device", deviceStyle);
                RealignTexts();
            }
Ejemplo n.º 2
0
            public PathSelectorView(CGRect frameRect) : base(frameRect)
            {
                Cells = new [] {
                    new NSPathComponentCell {
                        Image   = MultiResImage.CreateMultiResImage("project", "disabled"),
                        Title   = TextForActiveRunConfiguration,
                        Enabled = false,
                    },
                    new NSPathComponentCell {
                        Image   = MultiResImage.CreateMultiResImage("project", "disabled"),
                        Title   = TextForActiveConfiguration,
                        Enabled = false,
                    },
                    new NSPathComponentCell {
                        Image   = MultiResImage.CreateMultiResImage("device", "disabled"),
                        Title   = TextForRuntimeConfiguration,
                        Enabled = false,
                    }
                };
                SetVisibleCells(RunConfigurationIdx, ConfigurationIdx, RuntimeIdx);

                UpdateStyle();

                BackgroundColor = NSColor.Clear;
                FocusRingType   = NSFocusRingType.None;

                Ide.Gui.Styles.Changed += UpdateStyle;
            }
Ejemplo n.º 3
0
        void UpdateIcons(object sender = null, EventArgs e = null)
        {
            stopIcon     = MultiResImage.CreateMultiResImage("stop", "");
            continueIcon = MultiResImage.CreateMultiResImage("continue", "");
            buildIcon    = MultiResImage.CreateMultiResImage("build", "");

            // We can use Template images supported by NSButton, thus no reloading
            // on theme/skin change is required.
            stopIcon.Template = continueIcon.Template = buildIcon.Template = true;
        }
            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;
            }