Пример #1
0
        public void CreateMenu()
        {
            this.context_menu = new ContextMenu ();

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

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

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

            OrangeMenuItem folder_item = new OrangeMenuItem () {
                Header = "OrangeShare",
                Icon   = folder_image
            };

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

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

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

            this.log_item = new OrangeMenuItem () {
                Header    = "View recent changes…",
                IsEnabled = Controller.OpenRecentEventsItemEnabled
            };

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

            OrangeMenuItem notify_item = new OrangeMenuItem () {
                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_item.Click += delegate {
                    Program.Controller.ToggleNotifications ();
                    notify_check_box.IsChecked = Program.Controller.NotificationsEnabled;
                };

            OrangeMenuItem about_item = new OrangeMenuItem () {
                Header = "About OrangeShare"
            };

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

            this.exit_item = new OrangeMenuItem () {
                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) {
                    OrangeMenuItem subfolder_item = new OrangeMenuItem () {
                        Header = folder_name
                    };

                    subfolder_item.Click += OpenFolderDelegate (folder_name);

                    Image subfolder_image = new Image () {
                        Source = OrangeUIHelpers.GetImageSource ("folder-windows-16"),
                        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);
                }

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

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

                    subfolder_item.Click += OpenFolderDelegate (folder_name);

                    Image subfolder_image = new Image () {
                        Source = OrangeUIHelpers.GetImageSource ("folder-windows-16"),
                        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;
        }
Пример #2
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 OrangeMenuItem ("OrangeShare"){
                    Image = new Image (OrangeUIHelpers.GetIcon ("folder-sparkleshare", 16))
                };

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

            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 OrangeMenuItem (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 OrangeMenuItem (folder_name) {
                            Image = new Image (folder_icon)
                        };

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

                    if (submenu.Children.Length > 0) {
                        OrangeMenuItem more_item = new OrangeMenuItem ("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 ());

            CheckMenuItem notify_item = new CheckMenuItem (_("Notifications")) {
                Active = (Controller.Folders.Length > 0 && Program.Controller.NotificationsEnabled)
            };

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

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

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

                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
        }