| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 | 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<string>    {        public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }        public FileNode CurrentFileNode { get; set; }        public int ProcessTypeIndexSelection { get; set; }        public ObservableCollection<FileNode> Files { get; set; }        private FileNode currentFileNode;        private double viewportWidth = 276;//judge TreeviewItem display Region        private double lastLocation = 0;        public void LinePageUp(MouseEventArgs e)        {            IEnumerable<FileNode> 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<RepeatButton>();            var scrollBar = repeatButton.FindVisualParent<ScrollBar>();            // 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<FileNode> 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);        }           }  }
 |