コード例 #1
0
        /// <summary>
        /// Opens the load keyboard form.
        /// </summary>
        private void mnuLoadKeyboard_Click(object sender, EventArgs e)
        {
            this.menuOpen = false;

            using (var manageForm = new LoadKeyboardForm())
            {
                manageForm.DefinitionChanged += (kbDef, kbStyle, globalStyle) =>
                {
                    var backupDef   = GlobalSettings.CurrentDefinition;
                    var backupStyle = GlobalSettings.CurrentStyle;

                    var backupCat           = GlobalSettings.Settings.LoadedCategory;
                    var backupKb            = GlobalSettings.Settings.LoadedKeyboard;
                    var backupKbStyle       = GlobalSettings.Settings.LoadedStyle;
                    var backupkbGlobalStyle = GlobalSettings.Settings.LoadedGlobalStyle;

                    GlobalSettings.CurrentDefinition = kbDef;
                    GlobalSettings.CurrentStyle      = kbStyle ?? new KeyboardStyle();

                    GlobalSettings.Settings.LoadedCategory    = kbDef.Category;
                    GlobalSettings.Settings.LoadedKeyboard    = kbDef.Name;
                    GlobalSettings.Settings.LoadedStyle       = kbStyle?.Name;
                    GlobalSettings.Settings.LoadedGlobalStyle = globalStyle;

                    try
                    {
                        var missingKeyboards = this.LoadKeyboard();
                        manageForm.ToggleFontsPanel(missingKeyboards);
                    }
                    catch (Exception ex)
                    {
                        GlobalSettings.CurrentDefinition = backupDef;
                        GlobalSettings.CurrentStyle      = backupStyle;

                        GlobalSettings.Settings.LoadedCategory    = backupCat;
                        GlobalSettings.Settings.LoadedKeyboard    = backupKb;
                        GlobalSettings.Settings.LoadedStyle       = backupKbStyle;
                        GlobalSettings.Settings.LoadedGlobalStyle = backupkbGlobalStyle;

                        this.LoadKeyboard();

                        MessageBox.Show(ex.Message + Environment.NewLine + "Reverted keyboard change.");
                    }
                };

                manageForm.ShowDialog(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Opens the load keyboard form.
        /// </summary>
        private void mnuLoadKeyboard_Click(object sender, EventArgs e)
        {
            if (GlobalSettings.UnsavedDefinitionChanges || GlobalSettings.UnsavedStyleChanges)
            {
                var result = MessageBox.Show(
                    "You have unsaved changes. Loading a new keyboard will undo them. Are you sure you want to load a new keyboard?",
                    "Discard changes",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    return;
                }
            }

            this.menuOpen = false;

            using (var manageForm = new LoadKeyboardForm())
            {
                manageForm.DefinitionChanged += (kbDef, kbStyle, globalStyle) =>
                {
                    var backupDef   = GlobalSettings.CurrentDefinition;
                    var backupStyle = GlobalSettings.CurrentStyle;

                    var backupCat           = GlobalSettings.Settings.LoadedCategory;
                    var backupKb            = GlobalSettings.Settings.LoadedKeyboard;
                    var backupKbStyle       = GlobalSettings.Settings.LoadedStyle;
                    var backupkbGlobalStyle = GlobalSettings.Settings.LoadedGlobalStyle;

                    // Don't worry about undo history, it will be initialized alter in LoadKeyboard.
                    GlobalSettings.Settings.UpdateDefinition(kbDef, false);
                    GlobalSettings.Settings.UpdateStyle(kbStyle ?? new KeyboardStyle(), false);

                    GlobalSettings.Settings.LoadedCategory    = kbDef.Category;
                    GlobalSettings.Settings.LoadedKeyboard    = kbDef.Name;
                    GlobalSettings.Settings.LoadedStyle       = kbStyle?.Name;
                    GlobalSettings.Settings.LoadedGlobalStyle = globalStyle;

                    try
                    {
                        var missingFonts = this.LoadKeyboard();
                        manageForm.ToggleFontsPanel(missingFonts);
                    }
                    catch (Exception ex)
                    {
                        GlobalSettings.Settings.UpdateDefinition(backupDef, false);
                        GlobalSettings.Settings.UpdateStyle(backupStyle, false);

                        GlobalSettings.Settings.LoadedCategory    = backupCat;
                        GlobalSettings.Settings.LoadedKeyboard    = backupKb;
                        GlobalSettings.Settings.LoadedStyle       = backupKbStyle;
                        GlobalSettings.Settings.LoadedGlobalStyle = backupkbGlobalStyle;

                        this.LoadKeyboard();

                        MessageBox.Show(ex.Message + Environment.NewLine + "Reverted keyboard change.");
                    }
                };

                manageForm.ShowDialog(this);
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: ThoNohT/NohBoard
        /// <summary>
        /// Opens the load keyboard form.
        /// </summary>
        private void mnuLoadKeyboard_Click(object sender, EventArgs e)
        {
            using (var manageForm = new LoadKeyboardForm())
            {
                manageForm.DefinitionChanged += (kbDef, kbStyle, globalStyle) =>
                {
                    var backupDef = GlobalSettings.CurrentDefinition;
                    var backupStyle = GlobalSettings.CurrentStyle;

                    var backupCat = GlobalSettings.Settings.LoadedCategory;
                    var backupKb = GlobalSettings.Settings.LoadedKeyboard;
                    var backupKbStyle = GlobalSettings.Settings.LoadedStyle;
                    var backupkbGlobalStyle = GlobalSettings.Settings.LoadedGlobalStyle;

                    GlobalSettings.CurrentDefinition = kbDef;
                    GlobalSettings.CurrentStyle = kbStyle ?? new KeyboardStyle();

                    GlobalSettings.Settings.LoadedCategory = kbDef.Category;
                    GlobalSettings.Settings.LoadedKeyboard = kbDef.Name;
                    GlobalSettings.Settings.LoadedStyle = kbStyle?.Name;
                    GlobalSettings.Settings.LoadedGlobalStyle = globalStyle;

                    try
                    {
                        this.LoadKeyboard();
                    }
                    catch (Exception ex)
                    {
                        GlobalSettings.CurrentDefinition = backupDef;
                        GlobalSettings.CurrentStyle = backupStyle;

                        GlobalSettings.Settings.LoadedCategory = backupCat;
                        GlobalSettings.Settings.LoadedKeyboard = backupKb;
                        GlobalSettings.Settings.LoadedStyle = backupKbStyle;
                        GlobalSettings.Settings.LoadedGlobalStyle = backupkbGlobalStyle;

                        this.LoadKeyboard();

                        MessageBox.Show(ex.Message + Environment.NewLine + "Reverted keyboard change.");
                    }
                };

                manageForm.ShowDialog(this);
            }
        }