HostsEditorForm.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. namespace Optimizer {
  6. public sealed partial class HostsEditorForm : Form {
  7. string[] _toSave = null;
  8. public HostsEditorForm() {
  9. InitializeComponent();
  10. OptionsHelper.ApplyTheme(this);
  11. if (HostsHelper.GetReadOnly()) {
  12. savebtn.Enabled = false;
  13. }
  14. // translate UI elements
  15. if (OptionsHelper.CurrentOptions.LanguageCode != LanguageCode.EN) Translate();
  16. }
  17. private void HostsEditor_Load(object sender, EventArgs e) {
  18. //foreach (string line in HostsHelper.ReadHosts())
  19. //{
  20. // textBox1.Text += line + HostsHelper.NewLine;
  21. //}
  22. textBox1.Text = HostsHelper.ReadHostsFast();
  23. textBox1.Focus();
  24. }
  25. private void Translate() {
  26. this.Text = OptionsHelper.TranslationList["HostsEditorForm"];
  27. Dictionary<string, string> translationList = OptionsHelper.TranslationList.ToObject<Dictionary<string, string>>();
  28. Control element;
  29. foreach (var x in translationList) {
  30. if (x.Key == null || x.Key == string.Empty) continue;
  31. element = this.Controls.Find(x.Key, true).FirstOrDefault();
  32. if (element == null) continue;
  33. element.Text = x.Value;
  34. }
  35. }
  36. private void button1_Click(object sender, EventArgs e) {
  37. this.Close();
  38. }
  39. private void button7_Click(object sender, EventArgs e) {
  40. _toSave = textBox1.Lines;
  41. HostsHelper.SaveHosts(_toSave);
  42. this.Close();
  43. }
  44. }
  45. }