/// <summary>
        /// Adds the services menu.
        /// </summary>
        /// <param name="menuItems">The menu item collection to add this menu item to.</param>
        /// <param name="label">The label for the menu item.</param>
        /// <returns>The created menu item.</returns>
        public static MenuItem AddServicesMenu(this MenuItemCollection menuItems, string label = "Services")
        {
            var nativeMenu = new CocoaLabelMenuItem(label);
            var submenu    = nativeMenu.SetSubMenu("services");
            var menu       = new LabelMenuItem(nativeMenu);

            menuItems.Add(menu);

            ObjC.Call(MacApplication.Handle, "setServicesMenu:", submenu.Handle);

            return(menu);
        }
Пример #2
0
        private static LabelMenuItem AddDefaultHandlerMenuItem(MenuItemCollection menuItems, string label, string command, long tag = 0)
        {
            if (menuItems == null)
            {
                throw new ArgumentNullException(nameof(menuItems));
            }
            if (label == null)
            {
                throw new ArgumentNullException(nameof(label));
            }

            // when setting target to null, cocoa will look for the first responder that can handle the action
            var nativeItem = new CocoaLabelMenuItem(label, command, null, 0);
            var item       = new LabelMenuItem(nativeItem);

            menuItems.Add(item);

            return(item);
        }
Пример #3
0
        public static void StartInterface()
        {
            Application.Init();

            Catalog.Init("monovs", "./locale");

            logger = new LoggerListener();
            Debug.Listeners.Add(logger);

            RunInTerminal = MonoToolsConfigurationManager.PauseTerminal;

            // Creation of the status icon
            string icon_resource = "monotools.png";

            if (Platform.GetPlatform() == OS.Mac)
            {
                icon_resource = "mactools.png";
            }

            status_icon            = new StatusIcon(new Pixbuf(Assembly.GetExecutingAssembly(), icon_resource));
            status_icon.PopupMenu += OnStatusIconPopup;
            status_icon.Visible    = true;

            // Creation of status menu
            status_menu = new Menu();

            // IP Address / Port label
            StringBuilder sb = new StringBuilder();

            sb.Append("Listening on:");

            int port = MonoToolsConfigurationManager.ServerPort;

            foreach (IPAddress ip in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    sb.AppendFormat("\n{0}:{1}", ip, port);
                }
            }

            LabelMenuItem ip_label = new LabelMenuItem(sb.ToString());

            ip_label.Activated += HandleIPLabelActivated;
            status_menu.Add(ip_label);

            // Separator
            status_menu.Add(new SeparatorMenuItem());

            // Run in Terminal
            CheckMenuItem terminal = new CheckMenuItem("Pause Terminal");

            terminal.Active     = RunInTerminal;
            terminal.Activated += HandleTerminalActivated;
            status_menu.Add(terminal);

            // Log viewer
            ImageMenuItem menu_log_viewer = new ImageMenuItem(Catalog.GetString("Log _Viewer"));

            menu_log_viewer.Image      = new Gtk.Image(Stock.Info, IconSize.Menu);
            menu_log_viewer.Activated += OnLogViewerMenuActivated;
            status_menu.Add(menu_log_viewer);

            // About
            ImageMenuItem menu_about = new ImageMenuItem(Catalog.GetString("_About"));

            menu_about.Image      = new Gtk.Image(Stock.About, IconSize.Menu);
            menu_about.Activated += OnAboutMenuActivated;
            status_menu.Add(menu_about);

            // Separator
            status_menu.Add(new SeparatorMenuItem());

            // Quit
            ImageMenuItem menu_quit = new ImageMenuItem(Catalog.GetString("_Quit"));

            menu_quit.Image      = new Gtk.Image(Stock.Quit, IconSize.Menu);
            menu_quit.Activated += OnQuitMenuActivated;
            status_menu.Add(menu_quit);

            status_menu.ShowAll();

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                Thread signal_thread = new Thread(delegate() {
                    UnixSignal[] signals = new UnixSignal[] {
                        new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                        new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                    };

                    while (!exit_application && (UnixSignal.WaitAny(signals, 1000) == 1000))
                    {
                    }

                    Application.Quit();
                });

                signal_thread.Start();
            }

            Application.Run();
            //StopServer ();
        }