コード例 #1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(textBoxFilezillaLocation.Text) || File.Exists(textBoxFilezillaLocation.Text))
            {
                SuperPuTTY.Settings.FileZillaExe = textBoxFilezillaLocation.Text;
            }

            if (string.IsNullOrEmpty(textBoxWinSCPLocation.Text) || File.Exists(textBoxWinSCPLocation.Text))
            {
                SuperPuTTY.Settings.WinSCPExe = textBoxWinSCPLocation.Text;
            }

            if (string.IsNullOrEmpty(textBoxPscpLocation.Text) || File.Exists(textBoxPscpLocation.Text))
            {
                SuperPuTTY.Settings.PscpExe = textBoxPscpLocation.Text;
            }

            if (string.IsNullOrEmpty(textBoxVNCLocation.Text) || File.Exists(textBoxVNCLocation.Text))
            {
                SuperPuTTY.Settings.VNCExe = textBoxVNCLocation.Text;
            }

            string settingsDir = textBoxSettingsFolder.Text;

            if (string.IsNullOrEmpty(settingsDir) || !Directory.Exists(settingsDir))
            {
                errors.Add("Settings Folder must be set to valid directory");
            }
            else
            {
                SuperPuTTY.Settings.SettingsFolder = settingsDir;
            }

            if (comboBoxLayouts.SelectedValue != null)
            {
                SuperPuTTY.Settings.DefaultLayoutName = (string)comboBoxLayouts.SelectedValue;
            }

            if (!string.IsNullOrEmpty(textBoxPuttyLocation.Text) && File.Exists(textBoxPuttyLocation.Text))
            {
                SuperPuTTY.Settings.PuttyExe = textBoxPuttyLocation.Text;
            }
            else
            {
                errors.Insert(0, "PuTTY is required to properly use this application.");
            }

            string mintty = textBoxMinttyLocation.Text;

            if (!string.IsNullOrEmpty(mintty) && File.Exists(mintty))
            {
                SuperPuTTY.Settings.MinttyExe = mintty;
            }

            if (errors.Count == 0)
            {
                SuperPuTTY.Settings.SingleInstanceMode            = checkSingleInstanceMode.Checked;
                SuperPuTTY.Settings.RestrictContentToDocumentTabs = checkConstrainPuttyDocking.Checked;
                SuperPuTTY.Settings.MultipleTabCloseConfirmation  = checkConfirmTabClose.Checked;
                SuperPuTTY.Settings.RestoreWindowLocation         = checkRestoreWindow.Checked;
                SuperPuTTY.Settings.ExitConfirmation            = checkExitConfirmation.Checked;
                SuperPuTTY.Settings.ExpandSessionsTreeOnStartup = checkExpandTree.Checked;
                SuperPuTTY.Settings.EnableControlTabSwitching   = checkEnableControlTabSwitching.Checked;
                SuperPuTTY.Settings.EnableKeyboadShortcuts      = checkEnableKeyboardShortcuts.Checked;
                SuperPuTTY.Settings.MinimizeToTray        = checkMinimizeToTray.Checked;
                SuperPuTTY.Settings.TabTextBehavior       = (string)comboBoxTabText.SelectedItem;
                SuperPuTTY.Settings.TabSwitcher           = comboBoxTabSwitching.SelectedItem.GetType().FullName;
                SuperPuTTY.Settings.SessionsTreeShowLines = checkSessionsTreeShowLines.Checked;
                SuperPuTTY.Settings.SessionsTreeFont      = btnFont.Font;
                SuperPuTTY.Settings.WindowActivator       = (string)comboBoxActivatorType.SelectedItem;
                SuperPuTTY.Settings.Opacity            = (double)numericUpDownOpacity.Value / 100.0;
                SuperPuTTY.Settings.SessionsSearchMode = (string)comboSearchMode.SelectedItem;
                SuperPuTTY.Settings.QuickSelectorCaseSensitiveSearch = checkQuickSelectorCaseSensitiveSearch.Checked;
                SuperPuTTY.Settings.ShowDocumentIcons = checkShowDocumentIcons.Checked;
                SuperPuTTY.Settings.DockingRestrictFloatingWindows = checkRestrictFloatingWindows.Checked;
                SuperPuTTY.Settings.SessionsShowSearch             = checkSessionsShowSearch.Checked;
                SuperPuTTY.Settings.PuttyPanelShowNewSessionMenu   = checkPuttyEnableNewSessionMenu.Checked;
                SuperPuTTY.Settings.AutoUpdateCheck                = checkBoxCheckForUpdates.Checked;
                SuperPuTTY.Settings.PscpHomePrefix                 = textBoxHomeDirPrefix.Text;
                SuperPuTTY.Settings.PscpRootHomePrefix             = textBoxRootDirPrefix.Text;
                SuperPuTTY.Settings.SessiontreeShowFoldersFirst    = checkSessionTreeFoldersFirst.Checked;
                SuperPuTTY.Settings.PersistCommandBarHistory       = checkBoxPersistTsHistory.Checked;
                SuperPuTTY.Settings.SaveCommandHistoryDays         = (int)numericUpDown1.Value;
                SuperPuTTY.Settings.AllowPlainTextPuttyPasswordArg = checkBoxAllowPuttyPWArg.Checked;
                SuperPuTTY.Settings.PuttyDefaultParameters         = textBoxPuttyDefaultParameters.Text;

                // save shortcuts
                KeyboardShortcut[] shortcuts = new KeyboardShortcut[Shortcuts.Count];
                Shortcuts.CopyTo(shortcuts, 0);
                SuperPuTTY.Settings.UpdateFromShortcuts(shortcuts);

                SuperPuTTY.Settings.Save();

                // @TODO - move this to a better place...maybe event handler after opening
                if (OrigSettingsFolder != SuperPuTTY.Settings.SettingsFolder)
                {
                    SuperPuTTY.LoadLayouts();
                    SuperPuTTY.LoadSessions();
                }
                else if (OrigDefaultLayoutName != SuperPuTTY.Settings.DefaultLayoutName)
                {
                    SuperPuTTY.LoadLayouts();
                }

                DialogResult = DialogResult.OK;
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (string s in errors)
                {
                    sb.Append(s).AppendLine().AppendLine();
                }
                if (MessageBox.Show(sb.ToString(), LocalizedText.dlgFindPutty_buttonOk_Click_MessageBox_Errors, MessageBoxButtons.RetryCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                {
                    DialogResult = DialogResult.Cancel;
                }
            }
        }