public async Task Search() { if (!String.IsNullOrWhiteSpace(SearchText)) { HighlightedText = SearchText.RemoveSearchWildcards(); Show(); if (IsRecursive) { try { IsLoading = true; DisplayItems = new FileModelCollection(); if (SearchText.OrdinalEquals(HighlightedText)) { SearchText = String.Format("*{0}*", SearchText); } await Search(CurrentFolder.FullPath, DisplayItems, this.GetAsyncCommand(x => x.Search()).CancellationTokenSource); } finally { IsLoading = false; } } } }
private static async void UpdateSubFolders(FileModelCollection collection) { Dictionary <FileModel, FileModelCollection> folders = new Dictionary <FileModel, FileModelCollection>(); foreach (FileModel fileModel in collection) { if (fileModel.Folders == null) { folders.Add(fileModel, await FileSystemHelper.GetFolders(fileModel)); } } try { BeginDataUpdate(); foreach (FileModel fileModel in folders.Keys) { fileModel.Folders = folders[fileModel]; } } finally { EndDataUpdate(); } }
/// <summary> /// Obtiene los archivos seleccionados /// </summary> public FileModelCollection GetisCheckedFiles() { FileModelCollection files = new FileModelCollection(); // Añade los nodos seleccionados files.AddRange(GetFilesIsChecked(Nodes)); // Devuelve la colección de archivos return(files); }
public async Task Refresh() { try { IsLoading = true; CurrentFolder.Files = await FileSystemHelper.GetFiles(CurrentFolder); CurrentFolder.Folders = await FileSystemHelper.GetFolders(CurrentFolder); DisplayItems = new FileModelCollection(CurrentFolder.Folders.Concat(CurrentFolder.Files)); } finally { IsLoading = false; } }
protected async Task Search(string path, FileModelCollection searchResults, CancellationTokenSource cancellationToken) { FileModelCollection results = await FileSystemHelper.SearchFolder(path, SearchText); searchResults.AddRange(results); string[] childFolders = await FileSystemHelper.GetFolderPaths(path); foreach (string childFolder in childFolders) { if (cancellationToken.IsCancellationRequested) { break; } await Search(childFolder, searchResults, cancellationToken); } }
public async void Show() { try { IsLoading = true; if (CurrentFolder.Files == null) { CurrentFolder.Files = await FileSystemHelper.GetFiles(CurrentFolder); } if (CurrentFolder.Folders == null) { CurrentFolder.Folders = await FileSystemHelper.GetFolders(CurrentFolder); } DisplayItems = new FileModelCollection(CurrentFolder.Folders.Concat(CurrentFolder.Files)); } finally { IsLoading = false; } }
/// <summary> /// Obtiene los archivos seleccionados /// </summary> private FileModelCollection GetFilesIsChecked(TreeViewItemsViewModelCollection nodes) { FileModelCollection files = new FileModelCollection(); // Busca los nodos seleccionados if (nodes != null) { foreach (TreeViewItemViewModel node in nodes) { // Añade el archivo si está seleccionado if (node.IsChecked && (node.Tag is FileModel)) { files.Add(node.Tag as FileModel); } // Añade los archivos hijo files.AddRange(GetFilesIsChecked(node.Children)); } } // Devuelve los archivos return(files); }
/// <summary> /// Carga los nodos hijos de un árbol /// </summary> private void LoadNodes(TreeViewItemsViewModelCollection nodes, TreeViewItemViewModel nodeParent, FileModelCollection files) { foreach (FileModel file in files) { TreeViewItemViewModel node; // Crea un nuevo nodo node = new TreeViewItemViewModel(file.FullFileName, file.Name, nodeParent, false, file); node.IsExpanded = true; // Selecciona el nodo if (files != null) { node.IsChecked = FilesSelected.ExistsByFileName(file.FullFileName); } // Lo añade al árbol if (nodeParent == null) { nodes.Add(node); } else { nodeParent.Children.Add(node); } // Añade el manejador de eventos if (node != null) { node.PropertyChanged += (sender, evntArgs) => { if (evntArgs.PropertyName.EqualsIgnoreCase("IsChecked") || evntArgs.PropertyName.EqualsIgnoreCase("IsSelected")) { IsTreeeUpdated = true; } } } ; // Añade los nodos hijo if (file.IsFolder) { LoadNodes(nodes, node, file.Files); } } }
public TreeDocumentsViewModel(FileModel file, FileModelCollection files) { File = file; FilesSelected = files; }