void UpdateIniItem(object sender) { var l = sender as ListView; if (l.SelectedIndex == -1) return; var c = l.Items[l.SelectedIndex] as IniElement; var items = l.ItemsSource; var w = new IniSettingsWindow(c.Field, c.Value); if (w.ShowDialog() != false) return; switch (w.RetChangeType) { case ChangeType.Amend: AmendOption(w, sender, ref c); break; case ChangeType.Cancel: break; case ChangeType.Comment: CommentEntry(w, sender, ref c); break; case ChangeType.Uncomment: UnCommentEntry(w, sender, ref c); break; default: break; } l.SelectedIndex = -1; }
void CommentEntry(IniSettingsWindow w, object sender, ref IniElement c) { var listView = sender as ListView; var current = listView.Items[listView.SelectedIndex] as IniElement; if (current.Field[0] == '#') return; var ini = new IniFile(Properties.Resources.machine_ini); ini.DeleteKey(current.Category, current.Field); current.Field = "#" + current.Field; listView.Items.Refresh(); GetMachineIni.WriteMachineIni(current.Category, current.Field); GetMachineIni.ChangesPending = true; }
void UnCommentEntry(IniSettingsWindow w, object sender, ref IniElement c) { var listView = sender as ListView; var current = listView.Items[listView.SelectedIndex] as IniElement; if (current != null && current.Field[0] != '#') return; listView.Items.Refresh(); GetMachineIni.WriteMachineIni(current.Category, current.Field); GetMachineIni.ChangesPending = true; current.Field = current.Field.Substring(1); listView.Items.Refresh(); GetMachineIni.WriteMachineIni(current.Category, current.Field); GetMachineIni.ChangesPending = true; }
void AmendOption(IniSettingsWindow w, object sender, ref IniElement c) { var newValue = w.OptionValue; Debug.WriteLine(newValue); var listView = sender as ListView; var current = listView.Items[listView.SelectedIndex] as IniElement; if (newValue == c.Value && (newValue != c.Value || current.Field[0] != '#')) return; current.Value = newValue; if (current.Field[0] == '#') { var ini = new IniFile(Properties.Resources.machine_ini); ini.DeleteKey(current.Category, current.Field); current.Field = current.Field.Substring(1); } current.Value = newValue; listView.Items.Refresh(); GetMachineIni.WriteMachineIni(current.Category, current.Field); GetMachineIni.ChangesPending = true; }