Form2.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Resources;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace EdgeVoyager
  15. {
  16. public partial class Form2 : Form
  17. {
  18. public Form2()
  19. {
  20. InitializeComponent();
  21. string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  22. string resxFilePath = Path.Combine(docPath, @"EdgeVoyager\favoritesMenuItem.resx");
  23. ResXResourceReader rsxr = new ResXResourceReader(resxFilePath);
  24. foreach (DictionaryEntry d in rsxr)
  25. {
  26. ListViewItem item = new ListViewItem(d.Key.ToString());
  27. item.SubItems.Add(d.Value.ToString());
  28. listView1.Items.Add(item);
  29. }
  30. rsxr.Close();
  31. }
  32. private void copyMenuItem_Click(object sender, EventArgs e)
  33. {
  34. if (listView1.SelectedItems.Count > 0)
  35. {
  36. ListViewItem selectedItem = listView1.SelectedItems[0];
  37. string value = selectedItem.SubItems[1].Text;
  38. Clipboard.SetText(value);
  39. }
  40. }
  41. private void deleteMenuItem_Click(object sender, EventArgs e)
  42. {
  43. if (listView1.SelectedItems.Count > 0)
  44. {
  45. ListViewItem selectedItem = listView1.SelectedItems[0];
  46. string key = selectedItem.SubItems[0].Text;
  47. string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  48. string resxFilePath = Path.Combine(docPath, @"EdgeVoyager\favoritesMenuItem.resx");
  49. ResXResourceReader rsxr = new ResXResourceReader(resxFilePath);
  50. Dictionary<string, object> resources = new Dictionary<string, object>();
  51. foreach (DictionaryEntry d in rsxr)
  52. {
  53. if (d.Key.ToString() != key)
  54. resources.Add(d.Key.ToString(), d.Value);
  55. }
  56. rsxr.Close();
  57. ResXResourceWriter rsxw = new ResXResourceWriter(resxFilePath);
  58. foreach (var kvp in resources)
  59. {
  60. rsxw.AddResource(kvp.Key, kvp.Value);
  61. }
  62. rsxw.Generate();
  63. rsxw.Close();
  64. listView1.Items.Clear();
  65. ResXResourceReader rsxr2 = new ResXResourceReader(resxFilePath);
  66. foreach (DictionaryEntry d in rsxr2)
  67. {
  68. ListViewItem item = new ListViewItem(d.Key.ToString());
  69. item.SubItems.Add(d.Value.ToString());
  70. listView1.Items.Add(item);
  71. }
  72. rsxr.Close();
  73. }
  74. }
  75. }
  76. }