DuplicateRemovalViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using TranslateTool.Model;
  8. namespace TranslateTool.ViewModel
  9. {
  10. class DuplicateRemovalViewModel
  11. {
  12. /// <summary>
  13. /// 所选内容
  14. /// </summary>
  15. public string _selectContent;
  16. /// <summary>
  17. /// 重复Key值
  18. /// </summary>
  19. private string _key;
  20. /// <summary>
  21. /// 重复Key列表
  22. /// </summary>
  23. private List<LanguageItem> _languageItems;
  24. /// <summary>
  25. /// 关闭当前窗口
  26. /// </summary>
  27. private Action _closeAction;
  28. /// <summary>
  29. /// 显示Key相关描述
  30. /// </summary>
  31. public string Key
  32. {
  33. get
  34. {
  35. return _key;
  36. }
  37. }
  38. /// <summary>
  39. /// 选择Content
  40. /// </summary>
  41. private ButtonCommand _submitCommand;
  42. /// <summary>
  43. /// 重复Key和Content
  44. /// </summary>
  45. public List<LanguageItem> RepeatList
  46. {
  47. get { return _languageItems; }
  48. }
  49. /// <summary>
  50. /// 选择Content
  51. /// </summary>
  52. public ButtonCommand SubmitCommand
  53. {
  54. get
  55. {
  56. return _submitCommand;
  57. }
  58. set
  59. {
  60. _submitCommand = value;
  61. }
  62. }
  63. /// <summary>
  64. /// 所选内容
  65. /// </summary>
  66. public LanguageItem SelectContent
  67. {
  68. set
  69. {
  70. if (_selectContent != value.Content)
  71. {
  72. _selectContent = value.Content;
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 删除重复Key值
  78. /// </summary>
  79. public event EventHandler RemoveRepeatKey;
  80. public DuplicateRemovalViewModel(List<LanguageItem> languageItems,Action closeAction)
  81. {
  82. this._closeAction = closeAction;
  83. _languageItems = languageItems;
  84. _key = $"存在重复值{ _languageItems[0].Key},请选择一个最佳Content";
  85. _submitCommand = new ButtonCommand(OnSubmit, "Submit");
  86. }
  87. /// <summary>
  88. /// 选择后关闭当前窗口
  89. /// </summary>
  90. /// <param name="obj"></param>
  91. private void OnSubmit(object obj)
  92. {
  93. if(!string.IsNullOrWhiteSpace(_selectContent))
  94. {
  95. _closeAction.Invoke();
  96. }
  97. }
  98. }
  99. }