Exemplo n.º 1
0
        public FontChooserPanelWidget()
        {
            this.Build();

            foreach (var desc in FontService.FontDescriptions)
            {
                selectedFonts [desc.Name] = FontService.GetUnderlyingFontName(desc.Name);
                var fontNameLabel = new Label(GettextCatalog.GetString(desc.DisplayName));
                fontNameLabel.Justify = Justification.Left;
                fontNameLabel.Xalign  = 0;
                mainBox.PackStart(fontNameLabel, false, false, 0);
                var hBox          = new HBox();
                var setFontButton = new Button();
                setFontButton.Label = FontService.FilterFontName(GetFont(desc.Name));

                var descStr = GettextCatalog.GetString("Set the font options for {0}", GettextCatalog.GetString(desc.DisplayName));
                setFontButton.Accessible.Description = descStr;
                setFontButton.Clicked += delegate {
                    var selectionDialog = new FontSelectionDialog(GettextCatalog.GetString("Select Font"))
                    {
                        Modal             = true,
                        DestroyWithParent = true,
                        TransientFor      = this.Toplevel as Gtk.Window
                    };
                    MonoDevelop.Components.IdeTheme.ApplyTheme(selectionDialog);
                    try {
                        string fontValue = FontService.FilterFontName(GetFont(desc.Name));
                        selectionDialog.SetFontName(fontValue);
                        if (MessageService.RunCustomDialog(selectionDialog) != (int)Gtk.ResponseType.Ok)
                        {
                            return;
                        }
                        fontValue = selectionDialog.FontName;
                        if (fontValue == FontService.FilterFontName(FontService.GetFont(desc.Name).FontDescription))
                        {
                            fontValue = FontService.GetFont(desc.Name).FontDescription;
                        }
                        SetFont(desc.Name, fontValue);
                        setFontButton.Label = selectionDialog.FontName;
                    } finally {
                        selectionDialog.Destroy();
                        selectionDialog.Dispose();
                    }
                };
                hBox.PackStart(setFontButton, true, true, 0);

                var setDefaultFontButton = new Button();
                setDefaultFontButton.Label    = GettextCatalog.GetString("Set To Default");
                setDefaultFontButton.Clicked += delegate {
                    SetFont(desc.Name, FontService.GetFont(desc.Name).FontDescription);
                    setFontButton.Label = FontService.FilterFontName(GetFont(desc.Name));
                };
                hBox.PackStart(setDefaultFontButton, false, false, 0);
                mainBox.PackStart(hBox, false, false, 0);
            }
            mainBox.ShowAll();
        }