using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Interactivity; using System.Windows.Markup.Localizer; using Aitex.Core.UI.Control; using Aitex.Core.UI.MVVM; using DocumentFormat.OpenXml.Drawing.Charts; using DocumentFormat.OpenXml.EMMA; using MECF.Framework.UI.Client.CenterViews.Editors.Sequence; using OpenSEMI.ClientBase; using SciChart.Charting.Common.Extensions; using SciChart.Core.Extensions; namespace MECF.Framework.UI.Client.CenterViews.Editors.Recipe { public class RecipeSelectDialogViewModel : DialogViewModel { public ObservableCollection ProcessTypeFileList { get; set; } public FileNode CurrentFileNode { get; set; } public int ProcessTypeIndexSelection { get; set; } public ObservableCollection Files { get; set; } private FileNode currentFileNode; private double viewportWidth = 276;//judge TreeviewItem display Region private double lastLocation = 0; public void LinePageUp(MouseEventArgs e) { IEnumerable source = ProcessTypeFileList.First()?.FileListByProcessType; if (source==null|| currentFileNode == null) return; if (!(e.Source is ScrollViewer)) return; var scrollViewer = e.Source as ScrollViewer; viewportWidth = scrollViewer.ViewportWidth; if (e.GetPosition(scrollViewer).X < viewportWidth) {return; } var originalSource = e.OriginalSource as FrameworkElement; var repeatButton = originalSource.FindVisualParent(); var scrollBar = repeatButton.FindVisualParent(); // Handle only the case when the horizontal scrollbar is clicked if (repeatButton != null && scrollBar != null && scrollBar.Name == "PART_VerticalScrollBar") { double count = Math.Ceiling(scrollViewer.VerticalOffset / 24.0); switch (repeatButton.Name) { case "PageUp": if (source.First().IsSelected == true) return; if (lastLocation == count) source.First().IsSelected = true; else PageUPDown((int)count); break; case "PageDown": if (source.Last().IsSelected == true) return; if (lastLocation == count) source.Last().IsSelected = true; else PageUPDown((int)count); break; case "LineUp": if (source.First().IsSelected == true) return; if (currentFileNode.IsFile) { FileNode parentNode = currentFileNode.Parent; for (int i = 0; i < parentNode.Files.Count; i++) { if (parentNode.Files[i] == currentFileNode) { if (i == 0) parentNode.IsSelected = true; else currentFileNode.Parent.Files[i - 1].IsSelected = true; break; } } } else { if (currentFileNode.Parent != null) { FileNode parentNode = currentFileNode.Parent; for (int i = 0; i < parentNode.Files.Count; i++) { if (parentNode.Files[i] == currentFileNode) { if (i !=0) { FileNode node = parentNode.Files[i - 1]; if (node.Files.Count > 0&& node.IsExpanded) { node.Files[node.Files.Count-1].IsSelected = true; } else node.IsSelected = true; } break; } } } } break; case "LineDown": if (source.Last().IsSelected == true) return; if (currentFileNode.IsFile) { FileNode parentNode = currentFileNode.Parent; for (int i = 0; i < parentNode.Files.Count; i++) { if (parentNode.Files[i] == currentFileNode) { if (i == parentNode.Files.Count - 1) { if (parentNode.Parent != null) { for (global::System.Int32 j = 0; j < parentNode.Parent.Files.Count; j++) { if (parentNode.Parent.Files[j] == parentNode) { if (j != parentNode.Parent.Files.Count - 1) parentNode.Parent.Files[j + 1].IsSelected = true; break; } } } } else { currentFileNode.Parent.Files[i + 1].IsSelected = true; break; } } } } else { if (currentFileNode.Files.Count > 0) { currentFileNode.IsExpanded = true; currentFileNode.Files[0].IsSelected = true; } else { if (currentFileNode.Parent != null) { FileNode parentNode = currentFileNode.Parent; for (int i = 0; i < parentNode.Files.Count; i++) { if (parentNode.Files[i] == currentFileNode) { if (i != parentNode.Files.Count - 1) { currentFileNode.Parent.Files[i + 1].IsSelected = true; } break; } } } } } break; default: break; } lastLocation = count; } } private void PageUPDown(int count) { int sum = 0; IEnumerable roots= ProcessTypeFileList.First()?.FileListByProcessType; if (roots.Any()) { foreach(FileNode fileNode in roots) { if (GetNode(fileNode, ref sum, count)) break; } } } private bool GetNode(FileNode node,ref int sum,int count) { if (++sum >= count) { node.IsSelected = true; return true; } if (node.IsExpanded&&node.Files.Count>0) { foreach (FileNode fileNode in node.Files) { if (GetNode(fileNode, ref sum, count)) return true; } } return false; } public void TreeSelectChanged(FileNode file) { this.currentFileNode = file; } public void TreeMouseDoubleClick(MouseButtonEventArgs item) { item.Handled = true; if (item.Source is TreeView tree) { Point t = item.GetPosition(tree); if (t.X < viewportWidth) OK(); } } public void OK() { if (this.currentFileNode != null) { if (this.currentFileNode.IsFile) { //this.DialogResult = currentFileNode.PrefixPath + "\\" + currentFileNode.FullPath; this.DialogResult = currentFileNode.FullPath; IsCancel = false; TryClose(true); } } else { Cancel(); } } public void Cancel() { IsCancel = true; TryClose(false); } } }