public void SelectDirectory(DirectoryEntryViewModel directoryEntry, TreeView treeView, Action beforeSelectItem, Action afterSelectItem) { if (ReferenceEquals(CurrentRootNodesViewModel, _fileSystemEntryRootNodes)) { return; } var chromiumRoot = GetChromiumRoot(directoryEntry); var entryViewModel = _fileSystemEntryRootNodes.OfType <DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, chromiumRoot.Name)); if (entryViewModel == null) { return; } foreach (var childName in directoryEntry.Name.Split(Path.DirectorySeparatorChar)) { var childViewModel = entryViewModel .Children .OfType <DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, childName)); if (childViewModel == null) { entryViewModel.EnsureAllChildrenLoaded(); childViewModel = entryViewModel .Children .OfType <DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, childName)); if (childViewModel == null) { return; } } entryViewModel = childViewModel; } SwitchToFileSystemTree(); entryViewModel.IsExpanded = true; entryViewModel.IsSelected = true; WpfUtilities.Invoke(treeView, DispatcherPriority.ApplicationIdle, () => { try { beforeSelectItem(); try { WpfUtilities.SelectItem(treeView, entryViewModel); } finally { afterSelectItem(); } } catch (Exception e) { Logger.LogException(e, "Error updating TreeView UI to show selected item."); } }); }
public void NavigateToDirectory(DirectoryEntryViewModel directoryEntry) { // The use of "Post" is significant, as it prevents the message from // bubbling up thus preventing the newly opened document to receive // the focus. SynchronizationContextProvider.UIContext.Post(() => _control.ViewModel.SelectDirectory(directoryEntry, _control.FileTreeView, () => _control.SwallowsRequestBringIntoView(false), () => _control.SwallowsRequestBringIntoView(true))); }
private DirectoryEntryViewModel GetChromiumRoot(DirectoryEntryViewModel directoryEntry) { for (TreeViewItemViewModel parent = directoryEntry; parent != null; parent = parent.ParentViewModel) { if (parent.ParentViewModel == null) { var model = parent as DirectoryEntryViewModel; if (model != null) { return(model); } break; } } return(null); }
private DirectoryEntryViewModel GetChromiumRoot(DirectoryEntryViewModel directoryEntry) { for (TreeViewItemViewModel parent = directoryEntry; parent != null; parent = parent.ParentViewModel) { if (parent.ParentViewModel == null) { var model = parent as DirectoryEntryViewModel; if (model != null) return model; break; } } return null; }
public void SelectDirectory(DirectoryEntryViewModel directoryEntry, TreeView treeView, Action beforeSelectItem, Action afterSelectItem) { if (ReferenceEquals(CurrentRootNodesViewModel, _fileSystemEntryRootNodes)) return; var chromiumRoot = GetChromiumRoot(directoryEntry); var entryViewModel = _fileSystemEntryRootNodes.OfType<DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, chromiumRoot.Name)); if (entryViewModel == null) return; foreach (var childName in directoryEntry.Name.Split(Path.DirectorySeparatorChar)) { var childViewModel = entryViewModel .Children .OfType<DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, childName)); if (childViewModel == null) { entryViewModel.EnsureAllChildrenLoaded(); childViewModel = entryViewModel .Children .OfType<DirectoryEntryViewModel>() .FirstOrDefault(x => SystemPathComparer.Instance.Comparer.Equals(x.Name, childName)); if (childViewModel == null) return; } entryViewModel = childViewModel; } SwitchToFileSystemTree(); entryViewModel.IsExpanded = true; entryViewModel.IsSelected = true; WpfUtilities.Invoke(treeView, DispatcherPriority.ApplicationIdle, () => { try { beforeSelectItem(); try { WpfUtilities.SelectItem(treeView, entryViewModel); } finally { afterSelectItem(); } } catch (Exception e) { Logger.LogException(e, "Error updating TreeView UI to show selected item."); } }); }