HostsEditorForm.cs 1.8 KB

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