void TemplatesTreeViewButtonPressed(object o, ButtonPressEventArgs args)
        {
            SolutionTemplate template = GetSelectedTemplate();

            if ((template == null) || (template.AvailableLanguages.Count <= 1))
            {
                return;
            }

            if (templateTextRenderer.IsLanguageButtonPressed(args.Event))
            {
                if (popupMenu == null)
                {
                    popupMenu = new Menu();
                    popupMenu.AttachToWidget(this, null);
                }
                ClearPopupMenuItems();
                AddLanguageMenuItems(popupMenu, template);
                popupMenu.ModifyBg(StateType.Normal, GtkTemplateCellRenderer.LanguageButtonBackgroundColor);
                popupMenu.ShowAll();

                MenuPositionFunc posFunc = (Menu m, out int x, out int y, out bool pushIn) => {
                    Gdk.Rectangle rect       = templateTextRenderer.GetLanguageRect();
                    Gdk.Rectangle screenRect = GtkUtil.ToScreenCoordinates(templatesTreeView, templatesTreeView.GdkWindow, rect);
                    x      = screenRect.X;
                    y      = screenRect.Bottom;
                    pushIn = false;
                };
                popupMenu.Popup(null, null, posFunc, 0, args.Event.Time);
            }
        }
        void HandlePopup(SolutionTemplate template, uint eventTime)
        {
            if (popupMenu == null)
            {
                popupMenu = new Menu();
                popupMenu.AttachToWidget(this, null);
            }
            ClearPopupMenuItems();
            AddLanguageMenuItems(popupMenu, template);
            popupMenu.ModifyBg(StateType.Normal, Styles.NewProjectDialog.TemplateLanguageButtonBackground.ToGdkColor());
            popupMenu.ShowAll();

            MenuPositionFunc posFunc = (Menu m, out int x, out int y, out bool pushIn) => {
                Gdk.Rectangle rect       = languageCellRenderer.GetLanguageRect();
                Gdk.Rectangle screenRect = GtkUtil.ToScreenCoordinates(templatesTreeView, templatesTreeView.GdkWindow, rect);
                x      = screenRect.X;
                y      = screenRect.Bottom;
                pushIn = false;
            };

            popupMenu.Popup(null, null, posFunc, 0, eventTime);
        }
Example #3
0
        /// <summary>Shows a context menu.</summary>
        /// <param name='menu'>The menu.</param>
        /// <param name='parent'>The parent widget.</param>
        /// <param name='evt'>The mouse event. May be null if triggered by keyboard.</param>
        /// <param name='caret'>The caret/selection position within the parent, if the EventButton is null.</param>
        public static void ShowContextMenu(Menu menu, Widget parent, Gdk.EventButton evt, Gdk.Rectangle caret)
        {
            MenuPositionFunc posFunc = null;

            if (parent != null)
            {
                menu.AttachToWidget(parent, null);
                menu.Hidden += (sender, e) => {
                    if (menu.AttachWidget != null)
                    {
                        menu.Detach();
                    }
                };
                posFunc = delegate(Menu m, out int x, out int y, out bool pushIn) {
                    Gdk.Window window = evt != null? evt.Window : parent.GdkWindow;
                    window.GetOrigin(out x, out y);
                    var alloc = parent.Allocation;
                    if (evt != null)
                    {
                        x += (int)evt.X;
                        y += (int)evt.Y;
                    }
                    else if (caret.X >= alloc.X && caret.Y >= alloc.Y)
                    {
                        x += caret.X;
                        y += caret.Y + caret.Height;
                    }
                    else
                    {
                        x += alloc.X;
                        y += alloc.Y;
                    }
                    Requisition   request  = m.SizeRequest();
                    var           screen   = parent.Screen;
                    Gdk.Rectangle geometry = screen.GetMonitorGeometry(screen.GetMonitorAtPoint(x, y));

                    //whether to push or flip menus that would extend offscreen
                    //FIXME: this is the correct behaviour for mac, check other platforms
                    bool flip_left = true;
                    bool flip_up   = false;

                    if (x + request.Width > geometry.X + geometry.Width)
                    {
                        if (flip_left)
                        {
                            x -= request.Width;
                        }
                        else
                        {
                            x = geometry.X + geometry.Width - request.Width;
                        }

                        if (x < geometry.Left)
                        {
                            x = geometry.Left;
                        }
                    }

                    if (y + request.Height > geometry.Y + geometry.Height)
                    {
                        if (flip_up)
                        {
                            y -= request.Height;
                        }
                        else
                        {
                            y = geometry.Y + geometry.Height - request.Height;
                        }

                        if (y < geometry.Top)
                        {
                            y = geometry.Top;
                        }
                    }

                    pushIn = false;
                };
            }

            uint time;
            uint button;

            if (evt == null)
            {
                time   = Global.CurrentEventTime;
                button = 0;
            }
            else
            {
                time   = evt.Time;
                button = evt.Button;
            }

            //HACK: work around GTK menu issues on mac when passing button to menu.Popup
            //some menus appear and immediately hide, and submenus don't activate
//            if (Platform.IsMac) {
//                button = 0;
//            }

            menu.Popup(null, null, posFunc, button, time);
        }
Example #4
0
        public void Popup(Widget widget)
        {
            // Enable none
            m_ConnectMenuItem.Sensitive    = false;
            m_MessageMenuItem.Sensitive    = false;
            m_GetInfoMenuItem.Sensitive    = false;
            m_InviteChatMenuRoom.Sensitive = false;
            m_BrowseMenuItem.Sensitive     = false;
            m_SendFileMenuItem.Sensitive   = false;

            m_TrustMenuItem.Visible = false;

            if (selectedNode != null)
            {
                if (Runtime.Core.IsLocalNode(selectedNode))
                {
                    m_GetInfoMenuItem.Sensitive = true;
                    m_BrowseMenuItem.Sensitive  = true;
                }
                else
                {
                    if (!network.TrustedNodes.ContainsKey(selectedNode.NodeID))
                    {
                        // Request Public Key
                        m_TrustMenuItem.Visible = true;
                    }
                    else
                    {
                        if (selectedNode.FinishedKeyExchange == true)
                        {
                            // Enable all
                            m_ConnectMenuItem.Sensitive    = true;
                            m_MessageMenuItem.Sensitive    = true;
                            m_GetInfoMenuItem.Sensitive    = true;
                            m_InviteChatMenuRoom.Sensitive = true;
                            m_BrowseMenuItem.Sensitive     = true;
                            m_SendFileMenuItem.Sensitive   = true;
                        }
                        else
                        {
                            // This just means we are waiting to finish the key exchange
                        }
                    }
                }
            }

            m_Menu.Show();

            if (widget != null)
            {
                m_GetInfoMenuItem.Hide();

                int windowX, windowY;
                widget.ParentWindow.GetOrigin(out windowX, out windowY);
                MenuPositionFunc positionFunc = delegate(Menu menu, out int x, out int y, out bool push_in) {
                    var widgetX = windowX + widget.Allocation.X;
                    var widgetY = windowY + widget.Allocation.Y;
                    widgetY += widget.Allocation.Height;

                    x = widgetX;
                    y = widgetY;

                    push_in = true;
                };
                m_Menu.Popup(null, null, positionFunc, 1, 0);
            }
            else
            {
                m_Menu.Popup();
            }
        }