예제 #1
0
        /// <summary>
        /// 指定したファイルに対応するファイルツリーのノードを選択状態にします。
        /// </summary>
        /// <param name="fileInfo">対象のファイル</param>
        /// <returns></returns>
        public bool SelectTreeNode(FileInfoViewModel fileInfo)
        {
            if (fileInfo.FileType != FileInfoViewModel.FileInfoType.Directory)
            {
                return(false);
            }

            var candidates = this.FileTreeRoot.AsEnumerable();

            fileInfo.GetAncestors().ForEach(f =>
            {
                var node = candidates?.FirstOrDefault(t => t.Name.ToLower() == f.Name.ToLower());
                if (node == null)
                {
                    return;
                }

                node.IsExpanded = true;
                candidates      = node.Children;
            });

            var targetNode = candidates?.FirstOrDefault(t => t.Name.ToLower() == fileInfo.Name.ToLower());

            if (targetNode != null)
            {
                targetNode.IsSelected = false;
                targetNode.IsSelected = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// ファイルリストの項目選択コマンド
        /// </summary>
        /// <param name="file"></param>
        public void SelectFileListItemCommand(FileInfoViewModel file)
        {
            var isSelected = this.SelectTreeNode(file);

            if (!isSelected)
            {
                this.Navigate(file);
            }
        }
예제 #3
0
        /// <summary>
        /// 指定したディレクトリへ移動します。
        /// </summary>
        /// <param name="dist">対象のディレクトリ</param>
        private void NavigateToDirectory(FileInfoViewModel dist)
        {
            if (dist.FileType != FileInfoViewModel.FileInfoType.Directory)
            {
                return;
            }

            this.SetCurrentDirectory(dist);
        }
예제 #4
0
        /// <summary>
        /// 指定したファイルの前のファイルを取得します。
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private FileInfoViewModel GetPrevFile(FileInfoViewModel file)
        {
            var index         = this.FileInfoList.IndexOf(file);
            var prevFileIndex = this.GetPrevPageFileIndex(index);

            return(prevFileIndex == -1
                ? null
                : this.FileInfoList[prevFileIndex]);
        }
예제 #5
0
        /// <summary>
        /// 指定したファイルの次の画像ファイルを取得します。
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private FileInfoViewModel GetNextFile(FileInfoViewModel file)
        {
            var index         = this.FileInfoList.IndexOf(file);
            var nextFileIndex = this.GetNextPageFileIndex(index);

            return(nextFileIndex == -1
                ? null
                : this.FileInfoList[nextFileIndex]);
        }
예제 #6
0
 /// <summary>
 /// 指定した要素を子要素として追加します。
 /// </summary>
 /// <param name="child"></param>
 public void Add(FileInfoViewModel child)
 {
     if (null == Children)
     {
         Children = new ObservableCollection <FileInfoViewModel>();
     }
     child.Parent = this;
     Children.Add(child);
 }
예제 #7
0
        /// <summary>
        /// 指定したアーカイブファイルへ移動します。
        /// </summary>
        /// <param name="dist">対象のアーカイブファイル</param>
        private void NavigateToArchiveFile(FileInfoViewModel dist)
        {
            if (dist.FileType != FileInfoViewModel.FileInfoType.Archive &&
                dist.FileType != FileInfoViewModel.FileInfoType.ArchivedDirectory)
            {
                return;
            }

            this.SetCurrentDirectory(dist);
        }
예제 #8
0
        private void SetCurrentDirectory(FileInfoViewModel dist)
        {
            this.autoPagerTimer.Stop();
            this.IsEnabledAutoPager = false;

            if (dist != null &&
                this.currentDirectory != null &&
                !dist.FullName.Contains(this.currentDirectory.FullName))
            {
                this.currentDirectory?.Cleanup();
            }
            this.currentDirectory = dist;

            var children = dist.GetChildrenForList();

            this.RefreshFileList(children);
        }
예제 #9
0
        /// <summary>
        /// 指定した左右の画像を画面に表示します。
        /// </summary>
        /// <param name="rightFile"></param>
        /// <param name="rightImage"></param>
        /// <param name="leftFile"></param>
        /// <param name="leftImage"></param>
        private void DisplayImages(FileInfoViewModel rightFile, BitmapImage rightImage, FileInfoViewModel leftFile, BitmapImage leftImage)
        {
            if (rightImage == null)
            {
                throw new ArgumentNullException(nameof(rightImage));
            }

            this.FileInfoList.ForEach(f => f.IsDisplayed = false);

            if (rightFile != null)
            {
                rightFile.IsDisplayed = true;
            }
            if (leftFile != null)
            {
                leftFile.IsDisplayed = true;
            }

            this.rightFile = rightFile;
            this.leftFile  = leftFile;

            var rectHeight = leftImage == null
                ? rightImage.Height
                : Math.Min(rightImage.Height, leftImage.Height);

            if (leftImage == null)
            {
                this.leftImageRect = default;
            }
            else
            {
                var leftRectWidth = leftImage.Width * rectHeight / leftImage.Height;
                this.LeftImageRect = new Rect(0, 0, leftRectWidth, rectHeight);
            }

            this.LeftImageSource = leftImage;

            var rightRectWidth = rightImage.Width * rectHeight / rightImage.Height;

            this.RightImageRect   = new Rect(this.leftImageRect.Width, 0, rightRectWidth, rectHeight);
            this.RightImageSource = rightImage;

            this.SelectedFileInfo = this.FileInfoList.FirstOrDefault(f => f.Name == rightFile.Name);
        }
예제 #10
0
        ///// <summary>
        ///// 指定した画像ファイルへ逆順で移動します。
        ///// </summary>
        ///// <param name="dist">対象の画像ファイル</param>
        private void NavigateToPhotoFileReverse(FileInfoViewModel dist)
        {
            if (dist.FileType != FileInfoViewModel.FileInfoType.File)
            {
                return;
            }

            this.autoPagerTimer.Reset();

            using (var stream1 = dist.GetFileStream())
            {
                var bitmapImage1 = new BitmapImage();
                bitmapImage1.BeginInit();
                bitmapImage1.StreamSource = stream1;
                bitmapImage1.EndInit();

                if (bitmapImage1.Width < bitmapImage1.Height)
                {
                    var dist2 = this.GetPrevFile(dist);

                    using var stream2 = dist2.GetFileStream();
                    var bitmapImage2 = new BitmapImage();
                    bitmapImage2.BeginInit();
                    bitmapImage2.StreamSource = stream2;
                    bitmapImage2.EndInit();

                    if (bitmapImage2.Width < bitmapImage2.Height)
                    {
                        this.DisplayImages(dist2, bitmapImage2, dist, bitmapImage1);
                    }
                    else
                    {
                        this.DisplayImages(dist, bitmapImage1, null, null);
                    }
                }
                else
                {
                    this.DisplayImages(dist, bitmapImage1, null, null);
                }
            }

            this.ScrollFileListToSelectedItem?.Invoke(this, EventArgs.Empty);
        }
예제 #11
0
        /// <summary>
        /// ディレクトリを指定した場合は、そこに移動します。
        /// ファイルを指定した場合は、そのファイルを表示します。
        /// </summary>
        /// <param name="nextFileInfo">移動先のディレクトリまたはファイル</param>
        public void Navigate(FileInfoViewModel nextFileInfo)
        {
            switch (nextFileInfo.FileType)
            {
            case FileInfoViewModel.FileInfoType.File:
                this.NavigateToPhotoFile(nextFileInfo);
                break;

            case FileInfoViewModel.FileInfoType.Archive:
            case FileInfoViewModel.FileInfoType.ArchivedDirectory:
                this.NavigateToArchiveFile(nextFileInfo);
                break;

            case FileInfoViewModel.FileInfoType.Directory:
                this.NavigateToDirectory(nextFileInfo);
                break;

            default:
                // なにもしない
                break;
            }
        }
예제 #12
0
        public void DeleteFileListItemCommand(FileInfoViewModel file, Func <bool> confirm)
        {
            var deleteIndex     = this.FileInfoList.IndexOf(file);
            var nextSelectIndex = deleteIndex == this.FileInfoList.Count - 1
                ? deleteIndex - 1
                : deleteIndex;

            if (Directory.Exists(file.FullName))
            {
                // ディレクトリの場合
                if (!confirm())
                {
                    return;
                }

                Directory.Delete(file.FullName, true);
                this.FileInfoList.Remove(file);
            }

            if (File.Exists(file.FullName))
            {
                // ファイルの場合
                if (!confirm())
                {
                    return;
                }

                File.Delete(file.FullName);
                this.FileInfoList.Remove(file);
            }

            if (this.FileInfoList.IsEmpty())
            {
                return;
            }

            this.SelectedFileInfo = this.FileInfoList[nextSelectIndex];
        }
예제 #13
0
 /// <summary>
 /// ファイルツリーの項目選択コマンド
 /// </summary>
 /// <param name="file"></param>
 public void SelectFileTreeItemCommand(FileInfoViewModel file)
 {
     this.Navigate(file);
     this.historyService.Visit(file);
 }
예제 #14
0
        /// <summary>
        /// アーカイブファイルを表すFileInfoViewModel のインスタンスを初期化します。
        /// </summary>
        /// <param name="source">アーカイブファイル</param>
        /// <param name="mainWindowViewModel">メインウィンドウのインスタンス</param>
        /// <param name="parent">親要素</param>
        public FileInfoViewModel(ArchiveItem source, MainWindowViewModel mainWindowViewModel, FileInfoViewModel parent)
        {
            this.mainWindowViewModel = mainWindowViewModel;
            this.IsExpanded          = false;
            this.Add(Dummy);

            this.ArchiveItem    = source;
            this.FullName       = Path.Combine(parent.FullName, this.ArchiveItem.FileName);
            this.Name           = this.ArchiveItem.FileName;
            this.LastUpdateDate = this.ArchiveItem.TimeStamp.ToString();
            this.Type           = "";
            this.Size           = this.ArchiveItem.FileSize.ToString();
            this.Parent         = parent;

            switch (source.Type)
            {
            case ArchiveItem.ArchiveItemType.Directory:
                this.FileType = FileInfoType.ArchivedDirectory;
                break;

            case ArchiveItem.ArchiveItemType.File:
                var extension = Path.GetExtension(this.ArchiveItem.FileName).ToLower();

                this.FileType = ApplicationSettings.Instance.ArchiveExtensions.Contains(extension)
                        ? FileInfoType.ArchivedDirectory
                        : ApplicationSettings.Instance.FileExtensions.Contains(extension)
                            ? FileInfoType.File
                            : FileInfoType.Unknown;
                break;
            }

            this.archiveChildren = source.Children
                                   .Select(c => new FileInfoViewModel(c, mainWindowViewModel, this))
                                   .ToArray();
        }