private void BtnRename_Click(System.Object sender, System.EventArgs e)
        {
            TFrmSettingsRename frmRename;
            String             NewName;
            String             OldName;

            if (FStoredSettings.IsSystemSettings(LB_ExistingSettings.SelectedItem.ToString()))
            {
                MessageBox.Show(
                    "'" + LB_ExistingSettings.SelectedItem.ToString() + "'" + Environment.NewLine +
                    "is a predefined set of settings, and therefore cannot be renamed. " + Environment.NewLine +
                    "You should load it and then save it with a different name!", "Cannot rename System Settings");
                return;
            }

            frmRename         = new TFrmSettingsRename();
            frmRename.NewName = LB_ExistingSettings.SelectedItem.ToString();
            frmRename.OldName = frmRename.NewName;

            if (frmRename.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                NewName = frmRename.NewName;
                OldName = frmRename.OldName;

                if (NewName != OldName)
                {
                    // don't allow empty name
                    if (NewName.Length == 0)
                    {
                        return;
                    }

                    // check if the name already exists in the list
                    if (this.LB_ExistingSettings.FindStringExact(NewName) != ListBox.NoMatches)
                    {
                        if (FStoredSettings.IsSystemSettings(NewName))
                        {
                            MessageBox.Show(
                                "\"" + NewName + "\"" + Environment.NewLine +
                                "is a predefined set of settings, and therefore cannot be overwritten. " +
                                Environment.NewLine + "Please choose another name!",
                                "Cannot overwrite System Settings");
                            return;
                        }

                        // ask if it should be overwritten
                        if (MessageBox.Show("This name already exists. Do you still want to use this name and overwrite the existing settings?",
                                            "Overwrite existing Settings?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                        {
                            return;
                        }
                    }

                    // do the renaming
                    FStoredSettings.RenameSettings(OldName, NewName);
                    LoadSettingsList();
                }
            }
        }
Example #2
0
        private void Btn_SaveFile_Click(System.Object sender, System.EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.None;

            // don't allow empty name
            if (this.TBx_NewName.Text.Length == 0)
            {
                return;
            }

            // check if the name already exists in the list
            if (this.LB_ExistingSettings.FindStringExact(this.TBx_NewName.Text) == ListBox.NoMatches)
            {
                FSettingsName     = this.TBx_NewName.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                if (FStoredSettings.IsSystemSettings(this.TBx_NewName.Text))
                {
                    MessageBox.Show(
                        "'" + this.TBx_NewName.Text + "'" + Environment.NewLine +
                        "is a predefined set of settings, and therefore cannot be overwritten. " + Environment.NewLine +
                        "Please choose another name!",
                        "Cannot overwrite System Settings");
                    FSettingsName = "";
                }
                else
                {
                    // ask if it should be overwritten
                    if (MessageBox.Show("This name already exists. Do you still want to use this name and overwrite the existing settings?",
                                        "Overwrite existing Settings?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    {
                        FSettingsName = this.TBx_NewName.Text;
                        DialogResult  = System.Windows.Forms.DialogResult.OK;
                    }
                    else
                    {
                        // cancel overwriting
                        FSettingsName = "";
                    }
                }
            }
        }