public void Update()
        {
            var directoryItems = DirectoryStructure.GetDirectoryContents(this.FullPath);
            var children       = new ObservableCollection <DirectoryItemViewModel>();

            if (this.searchToLevel == DirectoryItemType.File && !string.IsNullOrEmpty(this.fileExtention))
            {
                directoryItems = directoryItems.Where(x => x.Type == DirectoryItemType.File ? IsCorectFileExtantion(x) : true).ToList();
            }

            foreach (DirectoryItem directoryItem in directoryItems)
            {
                if (directoryItem.Type != DirectoryItemType.Folder && this.searchToLevel == DirectoryItemType.Folder)
                {
                    continue;
                }

                var childViewModel = new DirectoryItemViewModel(directoryItem.FullPath, directoryItem.Type, searchToLevel, this.fileExtention);
                childViewModel.Parent = this;
                childViewModel.SelectDirectoryItem += SelectDirectoryItem;
                children.Add(childViewModel);
            }

            this.Children = children;
        }
        public SelectPathViewModel(DirectoryItemType searchToLevel, string startPath = "", string fileExtantion = "")
        {
            this.searchToLevel       = searchToLevel;
            this.selectedPath        = startPath;
            this.newFolderCommand    = new RelayCommand <object>(OnNewFolderClick);
            this.renameFolderCommand = new RelayCommand <object>(OnRenameFolderClick);
            this.deleteFolderCommand = new RelayCommand <object>(OnDeleteFolderClick);
            this.okCommand           = new RelayCommand <object>(OkCommandClick);
            this.closeCommand        = new RelayCommand <object>(OnCloseCliked);
            this.pathChangeCommand   = new RelayCommand <object>(OnPathChange);

            this.SelectionChanged += OnFolderPathChange;
            this.DirectoryItems    = new ObservableCollection <DirectoryItemViewModel>();
            var children = DirectoryStructure.GetLogicalDrives();


            foreach (DirectoryItem drive in children)
            {
                var childViewModel = new DirectoryItemViewModel(drive.FullPath, drive.Type, searchToLevel, fileExtantion);
                childViewModel.SelectDirectoryItem += OnSelectDirectoryItem;
                this.DirectoryItems.Add(childViewModel);
            }

            if (!string.IsNullOrEmpty(startPath) && (System.IO.Directory.Exists(startPath) || File.Exists(startPath)))
            {
                var pathList = startPath.Split(Path.DirectorySeparatorChar).ToList();
                Navigate(this.DirectoryItems, pathList);
            }
            //TODO: navigate to path
        }
Esempio n. 3
0
        private void OnSelectDirectoryItem(DirectoryItemViewModel selectDirectoryItem)
        {
            this.selectDirectoryItem = selectDirectoryItem;
            var selectionChanged = SelectionChanged;

            if (selectionChanged != null)
            {
                selectionChanged(selectDirectoryItem.FullPath);
            }
        }
        public SelectPathViewModel(IDialogFactory dialogFactory, DirectoryItemType searchToLevel, IIOWrapper iOWrapper, string rootPath = "", string startPath = "", string fileExtantion = "")
        {
            if (dialogFactory == null)
            {
                throw new ArgumentNullException(nameof(dialogFactory));
            }
            if (iOWrapper == null)
            {
                throw new ArgumentNullException(nameof(iOWrapper));
            }

            this.dialogFactory       = dialogFactory;
            this.iOWrapper           = iOWrapper;
            this.searchToLevel       = searchToLevel;
            this.selectedPath        = startPath;
            this.newFolderCommand    = new RelayCommand <object>(OnNewFolderClick);
            this.renameFolderCommand = new RelayCommand <object>(OnRenameFolderClick);
            this.deleteFolderCommand = new RelayCommand <object>(OnDeleteFolderClick);
            this.okCommand           = new RelayCommand <object>(OkCommandClick);
            this.closeCommand        = new RelayCommand <object>(OnCloseCliked);
            this.pathChangeCommand   = new RelayCommand <object>(OnPathChange);

            this.SelectionChanged += OnFolderPathChange;
            this.DirectoryItems    = new ObservableCollection <DirectoryItemViewModel>();

            List <DirectoryItem> children;

            if (System.IO.Directory.Exists(rootPath))
            {
                children = new List <DirectoryItem> {
                    new DirectoryItem()
                    {
                        FullPath = rootPath, Type = DirectoryItemType.Folder
                    }
                };
            }
            else
            {
                children = DirectoryStructure.GetLogicalDrives();
            }

            foreach (DirectoryItem drive in children)
            {
                var childViewModel = new DirectoryItemViewModel(drive.FullPath, drive.Type, searchToLevel, fileExtantion);
                childViewModel.SelectDirectoryItem += OnSelectDirectoryItem;
                this.DirectoryItems.Add(childViewModel);
            }

            if (!string.IsNullOrEmpty(startPath) && (System.IO.Directory.Exists(startPath) || File.Exists(startPath)))
            {
                var pathList = startPath.Split(Path.DirectorySeparatorChar).ToList();
                Navigate(this.DirectoryItems, pathList);
            }
            //TODO: navigate to path
        }
        private void OnNewFolderClick(object window)
        {
            var viewModel = new FolderNameViewModel();
            var view      = new FolderNameDialog();

            view.DataContext = viewModel;
            view.Owner       = window as Window;

            if (view.ShowDialog() == true)
            {
                string folderName = viewModel.FolderName;

                string newFolderPath = Path.Combine(selectDirectoryItem.FullPath, folderName);
                int    index         = 1;

                while (System.IO.Directory.Exists(newFolderPath))
                {
                    newFolderPath = Path.Combine(selectDirectoryItem.FullPath, $"{folderName} {index}");
                    index++;
                }

                System.IO.Directory.CreateDirectory(newFolderPath);

                if (selectDirectoryItem.IsExpanded)
                {
                    var childViewModel = new DirectoryItemViewModel(newFolderPath, DirectoryItemType.Folder, searchToLevel);
                    childViewModel.Parent = selectDirectoryItem;
                    childViewModel.SelectDirectoryItem += OnSelectDirectoryItem;

                    selectDirectoryItem.Children.Add(childViewModel);
                    selectDirectoryItem.Children   = new ObservableCollection <DirectoryItemViewModel>(selectDirectoryItem.Children.OrderBy(x => x.Name));
                    selectDirectoryItem.IsSelected = false;
                    childViewModel.IsSelected      = true;
                }
                else
                {
                    selectDirectoryItem.IsExpanded = true;

                    var childViewModel = selectDirectoryItem.Children.FirstOrDefault(x => x.FullPath == newFolderPath);
                    if (childViewModel != null)
                    {
                        selectDirectoryItem.IsSelected = false;
                        childViewModel.IsSelected      = true;
                    }
                }
            }
        }
Esempio n. 6
0
        private void OnNewFolderClick(object window)
        {
            var folderNameDialogAdapter   = this.dialogFactory.GetFolderNameDialog();
            FolderNameDialogResult result = folderNameDialogAdapter.ShowDialog();

            if (result.DialogOperationResult == true)
            {
                string folderName = result.FolderName;

                string newFolderPath = Path.Combine(selectDirectoryItem.FullPath, folderName);
                int    index         = 1;

                while (this.iOWrapper.DirectoryExists(newFolderPath))
                {
                    newFolderPath = Path.Combine(selectDirectoryItem.FullPath, $"{folderName} {index}");
                    index++;
                }

                this.iOWrapper.DirectoryCreateDirectory(newFolderPath);

                if (selectDirectoryItem.IsExpanded)
                {
                    var childViewModel = new DirectoryItemViewModel(newFolderPath, DirectoryItemType.Folder, searchToLevel);
                    childViewModel.Parent = selectDirectoryItem;
                    childViewModel.SelectDirectoryItem += OnSelectDirectoryItem;

                    selectDirectoryItem.Children.Add(childViewModel);
                    selectDirectoryItem.Children   = new ObservableCollection <DirectoryItemViewModel>(selectDirectoryItem.Children.OrderBy(x => x.Name));
                    selectDirectoryItem.IsSelected = false;
                    childViewModel.IsSelected      = true;
                }
                else
                {
                    selectDirectoryItem.IsExpanded = true;

                    var childViewModel = selectDirectoryItem.Children.FirstOrDefault(x => x.FullPath == newFolderPath);
                    if (childViewModel != null)
                    {
                        selectDirectoryItem.IsSelected = false;
                        childViewModel.IsSelected      = true;
                    }
                }
            }
        }