InputFileNameDialogViewModel.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net.Sockets;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using Aitex.Common.Util;
  9. using MECF.Framework.UI.Client.CenterViews.Editors.Sequence;
  10. using OpenSEMI.ClientBase;
  11. namespace MECF.Framework.UI.Client.CenterViews.Editors
  12. {
  13. public class InputFileNameDialogViewModel : DialogViewModel<string>
  14. {
  15. public InputFileNameDialogViewModel(string dialogName = "", ObservableCollection<FileNode> filepath = null, string comment = "", Visibility commentvisible = Visibility.Visible, Visibility folderVisibility = Visibility.Visible)
  16. {
  17. this.DisplayName = dialogName;
  18. this.fileNodes = filepath;
  19. this.Comment = comment;
  20. CommentVisiblility = commentvisible;
  21. FolderVisibility = folderVisibility;
  22. }
  23. public ObservableCollection<FileNode> fileNodes;
  24. public Dictionary<string, FileNode> FilePaths { get; set; } = new Dictionary<string, FileNode>();
  25. public string FilePath { get; set; }
  26. public string FileName { get; set; }
  27. public FileNode SelectNode { get; set; }
  28. public string Comment { get; set; }
  29. public int SelectIndex { get; set; } = -1;
  30. private Visibility _commentVisibility;
  31. public Visibility CommentVisiblility
  32. {
  33. get
  34. {
  35. return _commentVisibility;
  36. }
  37. set
  38. {
  39. _commentVisibility = value;
  40. NotifyOfPropertyChange(nameof(CommentVisiblility));
  41. }
  42. }
  43. #region
  44. #region 选择框 是否可见
  45. /// <summary>
  46. /// 是否可见
  47. /// </summary>
  48. public Visibility FolderVisibility
  49. {
  50. get { return __folderVisibility; }
  51. set
  52. {
  53. __folderVisibility = value;
  54. NotifyOfPropertyChange(nameof(FolderVisibility));
  55. }
  56. }
  57. private Visibility __folderVisibility= Visibility.Visible;
  58. #endregion
  59. #endregion
  60. public void Cancel()
  61. {
  62. IsCancel = true;
  63. TryClose(false);
  64. }
  65. protected override void OnViewLoaded(object view)
  66. {
  67. base.OnViewLoaded(view);
  68. InputFileNameDialogView v = (InputFileNameDialogView)view;
  69. FocusManager.SetFocusedElement(v, v.tbName);
  70. FilePaths.Clear();
  71. foreach (var item in fileNodes)
  72. {
  73. GetFilePathByNode(item);
  74. }
  75. }
  76. void GetFilePathByNode(FileNode node)
  77. {
  78. if (!node.IsFile)
  79. {
  80. if (FilePaths.ContainsKey(node.FullPath))
  81. {
  82. FilePaths[node.FullPath] = node;
  83. }
  84. else
  85. {
  86. FilePaths.Add(node.FullPath, node);
  87. }
  88. }
  89. foreach (var item in node.Files)
  90. {
  91. GetFilePathByNode(item);
  92. }
  93. }
  94. public void OK()
  95. {
  96. this.DialogResult = FileName;
  97. InputFileNameDialogView v = ((Window)GetView()).Content as InputFileNameDialogView;
  98. FilePath = v.cbFolder.Text;
  99. if (!string.IsNullOrEmpty(v.cbFolder.Text))
  100. {
  101. SelectNode = FilePaths[v.cbFolder.Text];
  102. }
  103. IsCancel = false;
  104. TryClose(true);
  105. }
  106. }
  107. }