private void OnSelectedPathChanged(string newPath) { // check if changed from outside if (!string.IsNullOrEmpty(newPath) && newPath != this.selectedItem?.FullName) { IEnumerable <ExplorerItem> items = this.InternalItemsSource; ExplorerItem item = null; char[] separators = this.DirectorySeparatorChars.ToArray(); string[] folders = newPath.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (var folder in folders) { item = items.Where(i => string.Equals(i.Name.Trim(separators), folder, this.IsCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (item != null) { item.IsExpanded = true; items = item.Children; } else { Window main = Application.Current.MainWindow; MessageBox.Show(main, $"Can't find '{newPath}'. Check the spelling and try again.", main.Title, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.None); return; } } SelectItem(item); item.IsSelectedInTree = true; } }
private void SelectItem(ExplorerItem item) { this.SelectedItem = item; this.selectedItem = item; // to use from working thread this.SelectedValue = item?.Content; this.ListItems = item?.Files; this.SelectedPath = item.FullName; }
private void OnClick(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 2) { FrameworkElement sp = sender as FrameworkElement; ExplorerItem item = sp.DataContext as ExplorerItem; item.IsSelectedInTree = true; } }
private void OnSelectedFolderChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { ExplorerItem item = e.NewValue as ExplorerItem; this.SelectedItem = item; this.selectedItem = item; // to use from working thread this.SelectedValue = item?.Content; this.ListItems = item?.Files; }
private static void OnIsSelectedInTreeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ExplorerItem explorerItem = (ExplorerItem)d; bool newValue = (bool)e.NewValue; if (newValue) { explorerItem.Refresh(false); } }
private void OnMouseDoubleClick(object sender, MouseEventArgs e) { FrameworkElement fe = e.OriginalSource as FrameworkElement; if (fe != null) { ExplorerItem ei = fe.DataContext as ExplorerItem; if (ei != null) { if (ei.Parent != null) { ei.Parent.IsExpanded = true; } ei.IsSelectedInTree = true; } } }
internal ExplorerItem(IExplorerItem content, ExplorerItem parent) { this.Parent = parent; content.Refresh += OnRefresh; SetValue(NameProperty, content.Name); SetValue(FullNameProperty, content.FullName); SetValue(LinkProperty, content.Link); SetValue(SizeProperty, content.Size); SetValue(DateProperty, content.Date); SetValue(TypeProperty, content.Type); SetValue(IconProperty, content.Icon); SetValue(IsDirectoryProperty, content.IsDirectory); this.Content = content; this.children = new ObservableCollection <ExplorerItem>(); if (content.HasChildren) { this.children.Add(new ExplorerItem(new Dummy(), this)); } this.folders = new CollectionViewSource() { Source = this.children }; this.folders.View.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); this.folders.View.Filter = i => ((ExplorerItem)i).IsDirectory; this.files = new CollectionViewSource() { Source = this.children }; this.files.View.SortDescriptions.Add(new SortDescription("IsDirectory", ListSortDirection.Descending)); this.files.View.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); this.Children = this.children; this.Folders = this.folders.View; this.Files = this.files.View; }
private void OnSelectedFolderChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { ExplorerItem item = e.NewValue as ExplorerItem; SelectItem(item); }