コード例 #1
0
        public PreferencesDialog()
        {
            window = new Window(new WindowOptions {
                ClientSize           = new Vector2(800, 600),
                FixedSize            = false,
                Title                = "Preferences",
                MinimumDecoratedSize = new Vector2(400, 300),
                Visible              = false
            });
            Frame = new ThemedFrame {
                Padding    = new Thickness(8),
                LayoutCell = new LayoutCell {
                    StretchY = float.MaxValue
                },
                Layout = new StackLayout(),
            };
            Content = new ThemedTabbedWidget();
            Content.AddTab("General", CreateGeneralPane(), true);
            Content.AddTab("Appearance", CreateColorsPane());
            Content.AddTab("Theme", CreateThemePane());
            Content.AddTab("Keyboard shortcuts", CreateKeyboardPane());
            Content.AddTab("Toolbar", toolbarModelEditor = new ToolbarModelEditor());

            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    Content,
                    new Widget {
                        Layout = new HBoxLayout {
                            Spacing = 8
                        },
                        LayoutCell = new LayoutCell(Alignment.LeftCenter),
                        Padding    = new Thickness {
                            Top = 5
                        },
                        Nodes =
                        {
                            (resetButton     = new ThemedButton {
                                Text         = "Reset To Defaults", MinMaxWidth    = 150f
                            }),
                            new Widget {
                                MinMaxHeight =        0
                            },
                            (okButton        = new ThemedButton {
                                Text         = "Ok"
                            }),
                            (cancelButton    = new ThemedButton {
                                Text         = "Cancel"
                            }),
                        }
                    }
                }
            };
            HotkeyRegistry.CurrentProfile.Save();
            okButton.Clicked += () => {
                saved = true;
                SaveAfterEdit();
                window.Close();
                VisualHintsPanel.Refresh();
                Core.UserPreferences.Instance.Save();
                if (themeEdited)
                {
                    AppUserPreferences.Instance.ColorThemeKind = ColorTheme.ColorThemeKind.Custom;
                }
                if (themeChanged)
                {
                    AlertDialog.Show("Color theme changes will be applied after Tangerine restart.");
                }
            };
            resetButton.Clicked += () => {
                if (new AlertDialog($"Are you sure you want to reset to defaults?", "Yes", "Cancel").Show() == 0)
                {
                    ResetToDefaults();
                }
            };
            cancelButton.Clicked += () => {
                window.Close();
                Core.UserPreferences.Instance.Load();
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                    Core.UserPreferences.Instance.Load();
                }
            });
            okButton.SetFocus();

            window.Closed += () => {
                if (saved)
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Save();
                    }
                    HotkeyRegistry.CurrentProfile = currentProfile;
                }
                else
                {
                    foreach (var profile in HotkeyRegistry.Profiles)
                    {
                        profile.Load();
                    }
                    HotkeyRegistry.CurrentProfile = HotkeyRegistry.CurrentProfile;
                }
            };

            foreach (var command in HotkeyRegistry.CurrentProfile.Commands)
            {
                command.Command.Shortcut = new Shortcut(Key.Unknown);
            }
            window.ShowModal();
        }