2 using System.Collections.Generic;
3 using System.ComponentModel;
8 using System.Windows.Forms;
9 using DirectOutput.GlobalConfiguration;
12 namespace GlobalConfigEditor
19 string ConfigFilename =
"";
23 InitializeComponent();
26 private void GlobalConfigEdit_Load(
object sender, EventArgs e)
33 private void SaveConfig(
string Filename)
45 this.Text =
"Global Configuration Editor - {0}".Build(Filename);
49 MessageBox.Show(
"Could not save global configuration to file: {0}.\n{1}".Build(Filename, E.Message),
"Save error", MessageBoxButtons.OK, MessageBoxIcon.Error);
55 private void LoadConfig(
string Filename =
"")
58 this.Text =
"Global Configuration Editor - <New global configuration>".Build(Filename);
59 if (!Filename.IsNullOrWhiteSpace())
64 ConfigFilename = Filename;
66 this.Text =
"Global Configuration Editor - {0}".Build(Filename);
70 MessageBox.Show(
"A exception occured when loading the global config file {0}.\nWill use empty global config instead.".Build(Filename),
"Global config loading error", MessageBoxButtons.OK, MessageBoxIcon.Error);
91 private void SelectIniFilePathButton_Click(
object sender, EventArgs e)
93 DirectoryInfo DI = null;
94 if (!IniFilesPath.Text.IsNullOrWhiteSpace())
98 DI =
new DirectoryInfo(IniFilesPath.Text);
101 SelectIniFileDirectoryDialog.SelectedPath = DI.FullName;
107 if (SelectIniFileDirectoryDialog.ShowDialog(Owner) == DialogResult.OK)
110 IniFilesPath.Text = SelectIniFileDirectoryDialog.SelectedPath;
119 private void SelectCabinetConfigFileButton_Click(
object sender, EventArgs e)
122 if (!CabinetFilename.Text.IsNullOrWhiteSpace())
126 FI =
new FileInfo(CabinetFilename.Text);
129 SelectCabinetConfigFileDialog.FileName = FI.FullName;
135 if (SelectCabinetConfigFileDialog.ShowDialog(Owner) == DialogResult.OK)
138 CabinetFilename.Text = SelectCabinetConfigFileDialog.FileName;
149 private void SelectLogFileButton_Click(
object sender, EventArgs e)
152 if (!LogFilename.Text.IsNullOrWhiteSpace())
156 FI =
new FileInfo(LogFilename.Text);
159 SelectLogFileDialog.FileName = FI.FullName;
165 if (SelectLogFileDialog.ShowDialog(Owner) == DialogResult.OK)
168 LogFilename.Text = SelectLogFileDialog.FileName;
177 private void saveToolStripMenuItem_Click(
object sender, EventArgs e)
179 if (!ConfigFilename.IsNullOrWhiteSpace())
181 SaveConfig(ConfigFilename);
185 saveAsToolStripMenuItem_Click(sender, e);
189 private void saveAsToolStripMenuItem_Click(
object sender, EventArgs e)
191 SaveGlobalConfigDialog.FileName = ConfigFilename;
193 if (SaveGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
195 SaveConfig(SaveGlobalConfigDialog.FileName);
200 private void newToolStripMenuItem_Click(
object sender, EventArgs e)
202 if (ContinueDialog())
208 private void loadToolStripMenuItem_Click(
object sender, EventArgs e)
210 if (ContinueDialog())
212 OpenGlobalConfigDialog.InitialDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
214 if (OpenGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
216 LoadConfig(OpenGlobalConfigDialog.FileName);
222 private bool ContinueDialog()
224 if (ConfigHasChanged)
226 switch (MessageBox.Show(Owner,
"The current configuration has changed. Do you want to save the changes?\nPress Yes to save your changes.\nPress No to discard your changes.\nPress Cancel to abort this operation.",
"Save changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
228 case System.Windows.Forms.DialogResult.Yes:
229 SaveGlobalConfigDialog.FileName = ConfigFilename;
231 if (SaveGlobalConfigDialog.ShowDialog(Owner) == DialogResult.OK)
233 SaveConfig(SaveGlobalConfigDialog.FileName);
238 if (MessageBox.Show(Owner,
"You config has not been saved.\nDo you want to continue and discard your changes?",
"Discard changes", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
245 case System.Windows.Forms.DialogResult.No:
261 private void quitToolStripMenuItem_Click(
object sender, EventArgs e)
268 private void GlobalConfigEdit_FormClosing(
object sender, FormClosingEventArgs e)
270 e.Cancel = !ContinueDialog();
274 private bool ConfigHasChanged