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

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

            this.notify_icon.HeaderText = "SparkleShare\n" + Controller.StateText;

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

            SparkleMenuItem folder_item = new SparkleMenuItem()
            {
                Header = "SparkleShare",
                Icon   = folder_image
            };

            folder_item.Click += delegate {
                Controller.SparkleShareClicked();
            };

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

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

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

            this.log_item.Click += delegate {
                Controller.OpenRecentEventsClicked();
            };

            SparkleMenuItem notify_item = new SparkleMenuItem()
            {
                Header = "Notifications"
            };

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

            notify_item.Icon = notify_check_box;

            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;
            };

            SparkleMenuItem about_item = new SparkleMenuItem()
            {
                Header = "About SparkleShare"
            };

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

            this.exit_item = new SparkleMenuItem()
            {
                Header = "Exit"
            };

            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)
            {
                foreach (string folder_name in Controller.Folders)
                {
                    SparkleMenuItem subfolder_item = new SparkleMenuItem()
                    {
                        Header = folder_name
                    };

                    subfolder_item.Click += OpenFolderDelegate(folder_name);

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

                    if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                    {
                        subfolder_item.Icon = new Image()
                        {
                            Source = (BitmapSource)Imaging.CreateBitmapSourceFromHIcon(
                                System.Drawing.SystemIcons.Exclamation.Handle,
                                Int32Rect.Empty,
                                BitmapSizeOptions.FromWidthAndHeight(16, 16)
                                )
                        };
                    }
                    else
                    {
                        subfolder_item.Icon = subfolder_image;
                    }

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

                SparkleMenuItem more_item = new SparkleMenuItem()
                {
                    Header = "More projects"
                };

                foreach (string folder_name in Controller.OverflowFolders)
                {
                    SparkleMenuItem subfolder_item = new SparkleMenuItem()
                    {
                        Header = folder_name
                    };

                    subfolder_item.Click += OpenFolderDelegate(folder_name);

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

                    if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                    {
                        subfolder_item.Icon = new Image()
                        {
                            Source = (BitmapSource)Imaging.CreateBitmapSourceFromHIcon(
                                System.Drawing.SystemIcons.Exclamation.Handle,
                                Int32Rect.Empty,
                                BitmapSizeOptions.FromWidthAndHeight(16, 16)
                                )
                        };
                    }
                    else
                    {
                        subfolder_item.Icon = subfolder_image;
                    }

                    more_item.Items.Add(subfolder_item);
                }

                if (more_item.Items.Count > 0)
                {
                    this.context_menu.Items.Add(new Separator());
                    this.context_menu.Items.Add(more_item);
                }
            }

            this.context_menu.Items.Add(new Separator());
            this.context_menu.Items.Add(add_item);
            this.context_menu.Items.Add(this.log_item);
            this.context_menu.Items.Add(new Separator());
            this.context_menu.Items.Add(notify_item);
            this.context_menu.Items.Add(new Separator());
            this.context_menu.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;
        }
Beispiel #2
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 = "SparkleShare"
                };

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

                this.folder_item.Image      = this.sparkleshare_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   = "View 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 SparkleShare",
                    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 SparkleStatusIconMenuDelegate();
                this.status_item.Menu = this.menu;
            }
        }
Beispiel #3
0
        public void CreateMenu()
        {
            this.menu = new Menu();

            this.state_item = new MenuItem(Controller.StateText)
            {
                Sensitive = false
            };

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

            ImageMenuItem folder_item = new SparkleMenuItem("SparkleShare")
            {
                Image = new Image(SparkleUIHelpers.GetIcon("folder-sparkleshare", 16))
            };

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

            this.menu.Add(folder_item);

            if (Program.Controller.Folders.Count > 0)
            {
                foreach (string folder_name in Controller.Folders)
                {
                    Gdk.Pixbuf folder_icon;

                    if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                    {
                        folder_icon = IconTheme.Default.LoadIcon("dialog-error", 16,
                                                                 IconLookupFlags.GenericFallback);
                    }
                    else
                    {
                        folder_icon = IconTheme.Default.LoadIcon("folder", 16,
                                                                 IconLookupFlags.GenericFallback);
                    }

                    ImageMenuItem subfolder_item = new SparkleMenuItem(folder_name)
                    {
                        Image = new Image(folder_icon)
                    };

                    subfolder_item.Activated += OpenFolderDelegate(folder_name);
                    this.menu.Add(subfolder_item);
                }

                Menu submenu = new Menu();

                foreach (string folder_name in Controller.OverflowFolders)
                {
                    Gdk.Pixbuf folder_icon;

                    if (Program.Controller.UnsyncedFolders.Contains(folder_name))
                    {
                        folder_icon = IconTheme.Default.LoadIcon("dialog-error", 16,
                                                                 IconLookupFlags.GenericFallback);
                    }
                    else
                    {
                        folder_icon = IconTheme.Default.LoadIcon("folder", 16,
                                                                 IconLookupFlags.GenericFallback);
                    }

                    ImageMenuItem subfolder_item = new SparkleMenuItem(folder_name)
                    {
                        Image = new Image(folder_icon)
                    };

                    subfolder_item.Activated += OpenFolderDelegate(folder_name);
                    submenu.Add(subfolder_item);
                }

                if (submenu.Children.Length > 0)
                {
                    SparkleMenuItem more_item = new SparkleMenuItem("More Projects")
                    {
                        Submenu = submenu
                    };

                    this.menu.Add(new SeparatorMenuItem());
                    this.menu.Add(more_item);
                }
            }

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

            MenuItem sync_item = new MenuItem(_("Add Hosted Project…"));

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

            this.menu.Add(sync_item);

            this.recent_events_item = new MenuItem(_("View Recent Changes…"));

            this.recent_events_item.Sensitive = Controller.OpenRecentEventsItemEnabled;

            this.recent_events_item.Activated += delegate {
                Controller.OpenRecentEventsClicked();
            };

            this.menu.Add(this.recent_events_item);
            this.menu.Add(new SeparatorMenuItem());


            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 {
                Application.Invoke(delegate {
                    Program.Controller.ToggleNotifications();

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

            this.menu.Add(notify_item);
            this.menu.Add(new SeparatorMenuItem());


            MenuItem about_item = new MenuItem(_("About SparkleShare"));

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

            this.menu.Add(about_item);
            this.menu.Add(new SeparatorMenuItem());


            this.quit_item = new MenuItem(_("Quit"))
            {
                Sensitive = Controller.QuitItemEnabled
            };

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

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

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