コード例 #1
0
        /// <summary>
        /// Initalize Gtk stuff
        /// </summary>
        private void GtkDBusInit()
        {
            launcher = LauncherEntry.GetForDesktopId("keepass2.desktop");
            var rootMenuItem    = new Dbusmenu.Menuitem();
            var trayContextMenu = pluginHost.MainWindow.TrayContextMenu;
            // make copy of item list to prevent list changed exception when iterating
            var menuItems =
                new System.Windows.Forms.ToolStripItem[trayContextMenu.Items.Count];

            trayContextMenu.Items.CopyTo(menuItems, 0);
            trayContextMenu.ItemAdded += (sender, e) =>
                                         DBusBackgroundWorker.InvokeGtkThread(() =>
                                                                              ConvertAndAddMenuItem(e.Item, rootMenuItem));
            foreach (System.Windows.Forms.ToolStripItem item in menuItems)
            {
                if (item.Name == "m_ctxTrayTray" || item.Name == "m_ctxTrayFileExit")
                {
                    continue;
                }
                ConvertAndAddMenuItem(item, rootMenuItem);
            }
            // the launcher may not be listening yet, so we delay setting the properties
            // to give it extra time
            finishInitDelaytimer.Tick += (sender, e) =>
            {
                finishInitDelaytimer.Stop();
                DBusBackgroundWorker.InvokeGtkThread(() =>
                                                     launcher.Quicklist = rootMenuItem);
            };
            finishInitDelaytimer.Interval = 1000;
            finishInitDelaytimer.Start();
        }
コード例 #2
0
        private void ConvertAndAddMenuItem(System.Windows.Forms.ToolStripItem item,
                                           Dbusmenu.Menuitem parent)
        {
            if (item is System.Windows.Forms.ToolStripMenuItem)
            {
                var winformMenuItem = item as System.Windows.Forms.ToolStripMenuItem;

                var dbusMenuItem = new Dbusmenu.Menuitem();
                dbusMenuItem.PropertySet("label", winformMenuItem.Text.Replace("&", ""));
                // VisibleChanged does not seem to be firing, so make everything visible for now
                //dbusMenuItem.PropertySetBool("visible", winformMenuItem.Visible);
                dbusMenuItem.PropertySetBool("enabled", winformMenuItem.Enabled);

                dbusMenuItem.ItemActivated += (sender, e) =>
                                              DBusBackgroundWorker.InvokeWinformsThread((Action)winformMenuItem.PerformClick);

                winformMenuItem.TextChanged +=
                    (sender, e) => DBusBackgroundWorker.InvokeGtkThread(() =>
                                                                        dbusMenuItem.PropertySet("label", winformMenuItem.Text.Replace("&", "")));
                winformMenuItem.EnabledChanged += (sender, e) =>
                                                  DBusBackgroundWorker.InvokeGtkThread(() =>
                                                                                       dbusMenuItem.PropertySetBool("enabled", winformMenuItem.Enabled));
                winformMenuItem.VisibleChanged += (sender, e) =>
                                                  DBusBackgroundWorker.InvokeGtkThread(() =>
                                                                                       dbusMenuItem.PropertySetBool("visible", winformMenuItem.Visible));

                parent.ChildAppend(dbusMenuItem);
            }
            else if (item is System.Windows.Forms.ToolStripSeparator)
            {
                // Ignore separator for now because there are too many of them
//        var dbusMenuItem = new DbusmenuMenuitem();
//        dbusMenuItem.PropertySet("type", "separator");
//        parent.ChildAppend(dbusMenuItem);
            }
            else
            {
                Debug.Fail("Unexpected menu item");
            }
        }