Example #1
0
        public void CreateMenu()
        {
            using (NSAutoreleasePool a = new NSAutoreleasePool())
            {
                this.menu = new NSMenu();
                this.menu.AutoEnablesItems = false;

                this.state_item = new NSMenuItem()
                {
                    Title   = Controller.StateText,
                    Enabled = false
                };

                this.folder_item = new NSMenuItem()
                {
                    Title = "CmisSync"
                };

                this.folder_item.Activated += delegate {
                    Controller.CmisSyncClicked();
                };

                this.folder_item.Image      = this.cmissync_image;
                this.folder_item.Image.Size = new SizeF(16, 16);
                this.folder_item.Enabled    = true;

                this.add_item = new NSMenuItem()
                {
                    Title   = "Add Hosted Project…",
                    Enabled = true
                };

                this.add_item.Activated += delegate {
                    Controller.AddHostedProjectClicked();
                };

                this.recent_events_item = new NSMenuItem()
                {
                    Title   = "Recent Changes…",
                    Enabled = Controller.OpenRecentEventsItemEnabled
                };

                if (Controller.Folders.Length > 0)
                {
                    this.recent_events_item.Activated += delegate {
                        Controller.OpenRecentEventsClicked();
                    };
                }

                this.notify_item = new NSMenuItem()
                {
                    Enabled = (Controller.Folders.Length > 0)
                };

                if (Program.Controller.NotificationsEnabled)
                {
                    this.notify_item.Title = "Turn Notifications Off";
                }
                else
                {
                    this.notify_item.Title = "Turn Notifications On";
                }

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

                    InvokeOnMainThread(delegate {
                        if (Program.Controller.NotificationsEnabled)
                        {
                            this.notify_item.Title = "Turn Notifications Off";
                        }
                        else
                        {
                            this.notify_item.Title = "Turn Notifications On";
                        }
                    });
                };

                this.about_item = new NSMenuItem()
                {
                    Title   = "About CmisSync",
                    Enabled = true
                };

                this.about_item.Activated += delegate {
                    Controller.AboutClicked();
                };

                this.quit_item = new NSMenuItem()
                {
                    Title   = "Quit",
                    Enabled = Controller.QuitItemEnabled
                };

                this.quit_item.Activated += delegate {
                    Controller.QuitClicked();
                };


                this.menu.AddItem(this.state_item);
                this.menu.AddItem(NSMenuItem.SeparatorItem);
                this.menu.AddItem(this.folder_item);

                this.folder_menu_items = new NSMenuItem [Controller.Folders.Length];
                this.submenu_items     = new NSMenuItem [Controller.OverflowFolders.Length];

                if (Controller.Folders.Length > 0)
                {
                    this.folder_tasks   = new EventHandler [Controller.Folders.Length];
                    this.overflow_tasks = new EventHandler [Controller.OverflowFolders.Length];

                    int i = 0;
                    foreach (string folder_name in Controller.Folders)
                    {
                        NSMenuItem item = new NSMenuItem();
                        item.Title = folder_name;

                        if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                        {
                            item.Image = this.caution_image;
                        }
                        else
                        {
                            item.Image = this.folder_image;
                        }

                        item.Image.Size       = new SizeF(16, 16);
                        this.folder_tasks [i] = OpenFolderDelegate(folder_name);

                        this.folder_menu_items [i]            = item;
                        this.folder_menu_items [i].Activated += this.folder_tasks [i];

                        i++;
                    }
                    ;

                    i = 0;
                    foreach (string folder_name in Controller.OverflowFolders)
                    {
                        NSMenuItem item = new NSMenuItem();
                        item.Title = folder_name;

                        if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                        {
                            item.Image = this.caution_image;
                        }
                        else
                        {
                            item.Image = this.folder_image;
                        }

                        item.Image.Size         = new SizeF(16, 16);
                        this.overflow_tasks [i] = OpenFolderDelegate(folder_name);

                        this.submenu_items [i]            = item;
                        this.submenu_items [i].Activated += this.overflow_tasks [i];

                        i++;
                    }
                    ;
                }


                foreach (NSMenuItem item in this.folder_menu_items)
                {
                    this.menu.AddItem(item);
                }

                if (this.submenu_items.Length > 0)
                {
                    this.submenu = new NSMenu();

                    foreach (NSMenuItem item in this.submenu_items)
                    {
                        this.submenu.AddItem(item);
                    }

                    this.more_item = new NSMenuItem()
                    {
                        Title   = "More Projects",
                        Submenu = this.submenu
                    };

                    this.menu.AddItem(NSMenuItem.SeparatorItem);
                    this.menu.AddItem(this.more_item);
                }

                this.menu.AddItem(NSMenuItem.SeparatorItem);
                this.menu.AddItem(this.add_item);
                this.menu.AddItem(this.recent_events_item);
                this.menu.AddItem(NSMenuItem.SeparatorItem);
                this.menu.AddItem(this.notify_item);
                this.menu.AddItem(NSMenuItem.SeparatorItem);
                this.menu.AddItem(this.about_item);
                this.menu.AddItem(NSMenuItem.SeparatorItem);
                this.menu.AddItem(this.quit_item);

                this.menu.Delegate    = new StatusIconMenuDelegate();
                this.status_item.Menu = this.menu;
            }
        }