using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Net.Sockets; using System.Windows; using System.Windows.Input; using Aitex.Common.Util; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using OpenSEMI.ClientBase; namespace MECF.Framework.UI.Client.CenterViews.Editors { public class InputFileNameDialogViewModel : DialogViewModel { public InputFileNameDialogViewModel(string dialogName = "", ObservableCollection filepath = null, string comment = "", Visibility commentvisible = Visibility.Visible, Visibility folderVisibility = Visibility.Visible) { this.DisplayName = dialogName; this.fileNodes = filepath; this.Comment = comment; CommentVisiblility = commentvisible; FolderVisibility = folderVisibility; } public ObservableCollection fileNodes; public Dictionary FilePaths { get; set; } = new Dictionary(); public string FilePath { get; set; } public string FileName { get; set; } public FileNode SelectNode { get; set; } public string Comment { get; set; } public int SelectIndex { get; set; } = -1; private Visibility _commentVisibility; public Visibility CommentVisiblility { get { return _commentVisibility; } set { _commentVisibility = value; NotifyOfPropertyChange(nameof(CommentVisiblility)); } } #region #region 选择框 是否可见 /// /// 是否可见 /// public Visibility FolderVisibility { get { return __folderVisibility; } set { __folderVisibility = value; NotifyOfPropertyChange(nameof(FolderVisibility)); } } private Visibility __folderVisibility= Visibility.Visible; #endregion #endregion public void Cancel() { IsCancel = true; TryClose(false); } protected override void OnViewLoaded(object view) { base.OnViewLoaded(view); InputFileNameDialogView v = (InputFileNameDialogView)view; FocusManager.SetFocusedElement(v, v.tbName); FilePaths.Clear(); foreach (var item in fileNodes) { GetFilePathByNode(item); } } void GetFilePathByNode(FileNode node) { if (!node.IsFile) { if (FilePaths.ContainsKey(node.FullPath)) { FilePaths[node.FullPath] = node; } else { FilePaths.Add(node.FullPath, node); } } foreach (var item in node.Files) { GetFilePathByNode(item); } } public void OK() { this.DialogResult = FileName; InputFileNameDialogView v = ((Window)GetView()).Content as InputFileNameDialogView; FilePath = v.cbFolder.Text; if (!string.IsNullOrEmpty(v.cbFolder.Text)) { SelectNode = FilePaths[v.cbFolder.Text]; } IsCancel = false; TryClose(true); } } }