public void CreateMenu()
        {
            this.context_menu = new ContextMenu ();

            this.state_item = new PryanetMenuItem () {
                Header    = Controller.StateText,
                IsEnabled = false
            };

            Image folder_image = new Image () {
                Source = PryanetUIHelpers.GetImageSource ("pryanetshare-folder"),
                Width  = 16,
                Height = 16
            };

            PryanetMenuItem folder_item = new PryanetMenuItem () {
                Header = "PryanetShare",
                Icon   = folder_image
            };

            PryanetMenuItem add_item = new PryanetMenuItem () { Header = "Add hosted project…" };

            this.log_item = new PryanetMenuItem () {
                Header    = "Recent changes…",
                IsEnabled = Controller.RecentEventsItemEnabled
            };

            PryanetMenuItem link_code_item = new PryanetMenuItem () { Header = "Client ID" };

            if (Controller.LinkCodeItemEnabled) {
                PryanetMenuItem code_item = new PryanetMenuItem ();
                code_item.Header = Program.Controller.CurrentUser.PublicKey.Substring (0, 20) + "...";

                PryanetMenuItem copy_item = new PryanetMenuItem () { Header = "Copy to Clipboard" };
                copy_item.Click += delegate { Controller.CopyToClipboardClicked (); };

                link_code_item.Items.Add (code_item);
                link_code_item.Items.Add (new Separator());
                link_code_item.Items.Add (copy_item);
            }

            CheckBox notify_check_box = new CheckBox () {
                Margin    = new Thickness (6, 0, 0, 0),
                IsChecked = Program.Controller.NotificationsEnabled
            };

            PryanetMenuItem notify_item = new PryanetMenuItem () { Header = "Notifications" };
            notify_item.Icon = notify_check_box;

            PryanetMenuItem about_item = new PryanetMenuItem () { Header = "About PryanetShare" };
            this.exit_item = new PryanetMenuItem () { Header = "Exit" };

            add_item.Click      += delegate { Controller.AddHostedProjectClicked (); };
            this.log_item.Click += delegate { Controller.RecentEventsClicked (); };
            about_item.Click    += delegate { Controller.AboutClicked (); };

            notify_check_box.Click += delegate {
                this.context_menu.IsOpen = false;
                Program.Controller.ToggleNotifications ();
                notify_check_box.IsChecked = Program.Controller.NotificationsEnabled;
            };

            notify_item.Click += delegate {
                Program.Controller.ToggleNotifications ();
                notify_check_box.IsChecked = Program.Controller.NotificationsEnabled;
            };

            this.exit_item.Click += delegate {
                this.notify_icon.Dispose ();
                Controller.QuitClicked ();
            };

            this.context_menu.Items.Add (this.state_item);
            this.context_menu.Items.Add (new Separator ());
            this.context_menu.Items.Add (folder_item);

            if (Controller.Folders.Length > 0) {
                int i = 0;
                foreach (string folder_name in Controller.Folders) {
                    PryanetMenuItem subfolder_item = new PryanetMenuItem () {
                        Header = folder_name.Replace ("_", "__")
                    };

                    Image subfolder_image = new Image () {
                        Source = PryanetUIHelpers.GetImageSource ("folder"),
                        Width  = 16,
                        Height = 16
                    };

                    if (!string.IsNullOrEmpty (Controller.FolderErrors [i])) {
                        subfolder_item.Icon = new Image () {
                            Source = (BitmapSource) Imaging.CreateBitmapSourceFromHIcon (
                                System.Drawing.SystemIcons.Exclamation.Handle, Int32Rect.Empty,
                                BitmapSizeOptions.FromWidthAndHeight (16,16))
                        };

                        PryanetMenuItem error_item = new PryanetMenuItem () {
                            Header    = Controller.FolderErrors [i],
                            IsEnabled = false
                        };

                        PryanetMenuItem try_again_item = new PryanetMenuItem () {
                            Header = "Try again"
                        };

                        try_again_item.Click += delegate { Controller.TryAgainDelegate (folder_name); };

                        subfolder_item.Items.Add (error_item);
                        subfolder_item.Items.Add (new Separator ());
                        subfolder_item.Items.Add (try_again_item);

                    } else {
                        subfolder_item.Icon = subfolder_image;
                        subfolder_item.Click += new RoutedEventHandler (Controller.OpenFolderDelegate (folder_name));
                    }

                    this.context_menu.Items.Add (subfolder_item);
                    i++;
                }
            }

            folder_item.Items.Add (this.log_item);
            folder_item.Items.Add (add_item);
            folder_item.Items.Add (new Separator ());
            folder_item.Items.Add (notify_item);
            folder_item.Items.Add (new Separator ());
            folder_item.Items.Add (link_code_item);
            folder_item.Items.Add (new Separator ());
            folder_item.Items.Add (about_item);

            this.context_menu.Items.Add (new Separator ());
            this.context_menu.Items.Add (this.exit_item);

            this.notify_icon.ContextMenu = this.context_menu;
        }
        public void CreateMenu()
        {
            this.menu       = new Menu ();
            this.state_item = new MenuItem (Controller.StateText) { Sensitive = false };

            ImageMenuItem folder_item = new PryanetMenuItem ("PryanetShare");
            folder_item.Image = new Image (PryanetUIHelpers.GetIcon ("pryanetshare", 16));

            this.menu.Add (this.state_item);
            this.menu.Add (new SeparatorMenuItem ());
            this.menu.Add (folder_item);

            if (Program.Controller.Folders.Count > 0) {
                int i = 0;
                foreach (string folder_name in Controller.Folders) {
                    ImageMenuItem item = new PryanetMenuItem (folder_name);
                    Gdk.Pixbuf folder_icon;

                    if (!string.IsNullOrEmpty (Controller.FolderErrors [i])) {
                        folder_icon = IconTheme.Default.LoadIcon ("dialog-warning", 16, IconLookupFlags.GenericFallback);
                        item.Submenu = new Menu ();

                        MenuItem error_item = new MenuItem (Controller.FolderErrors [i]) { Sensitive = false };
                        MenuItem try_again_item = new MenuItem ("Try Again");
                        try_again_item.Activated += Controller.TryAgainDelegate (folder_name);

                        (item.Submenu as Menu).Add (error_item);
                        (item.Submenu as Menu).Add (new SeparatorMenuItem ());
                        (item.Submenu as Menu).Add (try_again_item);

                    } else {
                        folder_icon = IconTheme.Default.LoadIcon ("folder", 16, IconLookupFlags.GenericFallback);
                        item.Activated += Controller.OpenFolderDelegate (folder_name);
                    }

                    (item.Child as Label).UseUnderline = false;
                    item.Image = new Image (folder_icon);
                    this.menu.Add (item);

                    i++;
                }
            }

            this.recent_events_item = new MenuItem ("Recent Changes…");
            this.recent_events_item.Sensitive = Controller.RecentEventsItemEnabled;
            this.quit_item    = new MenuItem ("Quit") { Sensitive = Controller.QuitItemEnabled };
            MenuItem add_item = new MenuItem ("Add Hosted Project…");
            MenuItem notify_item;

            if (Program.Controller.NotificationsEnabled)
                notify_item = new MenuItem ("Turn Notifications Off");
            else
                notify_item = new MenuItem ("Turn Notifications On");

            notify_item.Activated += delegate {
                Program.Controller.ToggleNotifications ();

                Application.Invoke (delegate {
                    if (Program.Controller.NotificationsEnabled)
                        (notify_item.Child as Label).Text = "Turn Notifications Off";
                    else
                        (notify_item.Child as Label).Text = "Turn Notifications On";
                });
            };

            MenuItem link_code_item = new MenuItem ("Client ID");

            if (Controller.LinkCodeItemEnabled) {
                link_code_item.Submenu = new Menu ();

                string link_code = Program.Controller.CurrentUser.PublicKey.Substring (0, 20) + "...";
                MenuItem code_item = new MenuItem (link_code) { Sensitive = false };

                MenuItem copy_item = new MenuItem ("Copy to Clipboard");
                copy_item.Activated += delegate { Controller.CopyToClipboardClicked (); };

                (link_code_item.Submenu as Menu).Add (code_item);
                (link_code_item.Submenu as Menu).Add (new SeparatorMenuItem ());
                (link_code_item.Submenu as Menu).Add (copy_item);
            }

            MenuItem about_item = new MenuItem ("About PryanetShare");

            about_item.Activated              += delegate { Controller.AboutClicked (); };
            add_item.Activated                += delegate { Controller.AddHostedProjectClicked (); };
            this.recent_events_item.Activated += delegate { Controller.RecentEventsClicked (); };
            this.quit_item.Activated          += delegate { Controller.QuitClicked (); };

            folder_item.Submenu = new Menu ();
            (folder_item.Submenu as Menu).Add (this.recent_events_item);
            (folder_item.Submenu as Menu).Add (add_item);
            (folder_item.Submenu as Menu).Add (new SeparatorMenuItem ());
            (folder_item.Submenu as Menu).Add (notify_item);
            (folder_item.Submenu as Menu).Add (new SeparatorMenuItem ());
            (folder_item.Submenu as Menu).Add (link_code_item);
            (folder_item.Submenu as Menu).Add (new SeparatorMenuItem ());
            (folder_item.Submenu as Menu).Add (about_item);

            this.menu.Add (new SeparatorMenuItem ());
            this.menu.Add (this.quit_item);
            this.menu.ShowAll ();

            #if HAVE_APP_INDICATOR
            this.indicator.Menu = this.menu;
            #endif
        }