public LogViewerViewModel(IDataSourceViewModel dataSource, IActionCenter actionCenter, IApplicationSettings applicationSettings, TimeSpan maximumWaitTime) { if (dataSource == null) { throw new ArgumentNullException(nameof(dataSource)); } if (actionCenter == null) { throw new ArgumentNullException(nameof(actionCenter)); } if (applicationSettings == null) { throw new ArgumentNullException(nameof(applicationSettings)); } _actionCenter = actionCenter; _applicationSettings = applicationSettings; _maximumWaitTime = maximumWaitTime; _dataSource = dataSource; _pendingSections = new List <KeyValuePair <ILogFile, LogFileSection> >(); LogFile = _dataSource.DataSource.FilteredLogFile; LogFile.AddListener(this, _maximumWaitTime, 1000); Search = _dataSource.DataSource.Search; UpdateCounts(); }
private IDataSourceViewModel Add(IDataSource dataSource) { IDataSourceViewModel viewModel = CreateViewModel(dataSource); _observable.Add(viewModel); return(viewModel); }
private static bool RequestBringIntoView(IDataSourceViewModel dataSourceViewModel, LogLineIndex index) { if (dataSourceViewModel == null) { return(false); } var logFile = dataSourceViewModel.DataSource.FilteredLogSource; if (logFile != null) { var actualIndex = logFile.GetLogLineIndexOfOriginalLineIndex(index); if (actualIndex == LogLineIndex.Invalid) { Log.WarnFormat("Unable to find index '{0}' of {1}", index, dataSourceViewModel); return(false); } index = actualIndex; } dataSourceViewModel.SelectedLogLines = new HashSet <LogLineIndex> { index }; dataSourceViewModel.RequestBringIntoView(index); return(true); }
public bool CanBeDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType, out IDataSourceViewModel finalDest) { return(_dataSources.CanBeDropped(source, dest, dropType, out finalDest)); }
private void UpdateWindowTitle(IDataSourceViewModel value) { if (value != null) { WindowTitle = string.Format("{0} - {1}", Constants.MainWindowTitle, value.DisplayName); var child = value as ISingleDataSourceViewModel; var parentId = value.DataSource.ParentId; var parent = _dataSources.TryGet(parentId); if (child != null && parent != null) { WindowTitleSuffix = string.Format("{0} -> [{1}] {2}", parent.DisplayName, child.CharacterCode, child.DataSourceOrigin); } else { WindowTitleSuffix = value.DataSourceOrigin; } } else { WindowTitle = Constants.MainWindowTitle; WindowTitleSuffix = null; } }
public DataSourcesViewModel(IApplicationSettings settings, IDataSources dataSources, IActionCenter actionCenter) { if (settings == null) throw new ArgumentNullException(nameof(settings)); if (dataSources == null) throw new ArgumentNullException(nameof(dataSources)); if (actionCenter == null) throw new ArgumentNullException(nameof(actionCenter)); _actionCenter = actionCenter; _settings = settings; _observable = new ObservableCollection<IDataSourceViewModel>(); _allDataSourceViewModels = new List<IDataSourceViewModel>(); _addDataSourceCommand = new DelegateCommand(AddDataSource); _dataSources = dataSources; foreach (IDataSource dataSource in dataSources.Sources) { if (dataSource.ParentId == DataSourceId.Empty) { Add(dataSource); } } foreach (IDataSource dataSource in dataSources.Sources) { DataSourceId parentId = dataSource.ParentId; if (parentId != DataSourceId.Empty) { IDataSourceViewModel parent = _observable.First(x => x.DataSource.Id == parentId); var group = (MergedDataSourceViewModel) parent; IDataSourceViewModel viewModel = CreateViewModel(dataSource); group.AddChild(viewModel); } } UpdateTooltip(); PropertyChanged += OnPropertyChanged; }
private void OnRemove(IDataSourceViewModel viewModel) { int index = _observable.IndexOf(viewModel); if (index != -1) { _observable.RemoveAt(index); var merged = viewModel as MergedDataSourceViewModel; if (merged != null) { IEnumerable <IDataSourceViewModel> items = merged.Observable; foreach (IDataSourceViewModel item in items) { _observable.Insert(index++, item); item.Parent = null; } } } else if (viewModel.Parent != null) { ((MergedDataSourceViewModel)viewModel.Parent).RemoveChild(viewModel); _dataSources.Remove(viewModel.DataSource); } _allDataSourceViewModels.Remove(viewModel); _dataSources.Remove(viewModel.DataSource); UpdateRemoveCommands(); _settings.SaveAsync(); if (_selectedItem == null || _selectedItem == viewModel) { SelectedItem = _observable.FirstOrDefault(); } }
public void OnDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType) { if (!CanBeDragged(source)) { throw new ArgumentException("source"); } IDataSourceViewModel unused; if (!CanBeDropped(source, dest, dropType, out unused)) { throw new ArgumentException("source or dest"); } if (dropType == DataSourceDropType.Group) { DropToGroup(source, dest); } else { DropToArrange(source, dest, dropType); } }
private IDataSourceViewModel CreateViewModel(IDataSource dataSource) { if (dataSource == null) throw new ArgumentNullException(nameof(dataSource)); IDataSourceViewModel viewModel; var single = dataSource as ISingleDataSource; if (single != null) { viewModel = new SingleDataSourceViewModel(single, _actionCenter); } else { var merged = dataSource as MergedDataSource; if (merged != null) { viewModel = new MergedDataSourceViewModel(merged, _actionCenter); } else { throw new ArgumentException(string.Format("Unknown data source: {0} ({1})", dataSource, dataSource.GetType())); } } viewModel.Remove += OnRemove; _allDataSourceViewModels.Add(viewModel); if (_settings.DataSources.SelectedItem == viewModel.DataSource.Id) { SelectedItem = viewModel; } return viewModel; }
private void DragFromGroup(IDataSourceViewModel source, IDataSourceViewModel dest, MergedDataSourceViewModel parent) { parent.RemoveChild(source); DissolveGroupIfNecessary(parent); Drag(source, dest); }
public IDataSourceViewModel OpenFile(string file) { IDataSourceViewModel dataSource = _dataSources.GetOrAdd(file); OpenFile(dataSource); return(dataSource); }
public void OnDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType) { var panel = _selectedMainPanel as LogViewMainPanelViewModel; panel?.OnDropped(source, dest, dropType); }
private bool Represents(IDataSourceViewModel dataSourceViewModel, string fullName) { var file = dataSourceViewModel as SingleDataSourceViewModel; if (file == null) return false; return string.Equals(file.FullName, fullName, StringComparison.InvariantCultureIgnoreCase); }
private IDataSourceViewModel Add(IDataSource dataSource) { IDataSourceViewModel viewModel = CreateViewModel(dataSource); _observable.Add(viewModel); UpdateRemoveCommands(); return(viewModel); }
private DataSourceDropType GetDropType(DragEventArgs e, TreeItem destination, IDataSourceViewModel source) { if (destination == null) { return(DataSourceDropType.None); } Point pos = e.GetPosition(destination.TreeViewItem); var dropType = DataSourceDropType.None; double height = destination.TreeViewItem.ActualHeight; if (source is SingleDataSourceViewModel) { // Let's distribute it as follows: // 20% top => arrange // 60% middle => group // 20% bottom => arrange // // This way 60% of the height is used for grouping and 40% is used for arranging. if (pos.Y < height * 0.2) { dropType |= DataSourceDropType.ArrangeTop; } else if (pos.Y < height * 0.8) { dropType |= DataSourceDropType.Group; } else { dropType |= DataSourceDropType.ArrangeBottom; } if (destination.ViewModel.Parent != null) { dropType |= DataSourceDropType.Group; } } else { // Groups can't be grouped any further, thus we // simply arrange it above or beneath the drop source // at a 50/50 split. if (pos.Y < height * 0.5) { dropType |= DataSourceDropType.ArrangeTop; } else { dropType |= DataSourceDropType.ArrangeBottom; } } return(dropType); }
public void TestGetOrAdd1() { IDataSourceViewModel viewModel = null; new Action(() => viewModel = _model.GetOrAdd("foobar")).ShouldNotThrow(); viewModel.Should().NotBeNull(); viewModel.DataSource.Should().NotBeNull(); viewModel.DataSource.Settings.Should().NotBeNull(); viewModel.DataSource.Id.Should().NotBe(Guid.Empty); }
public bool CanBeDragged(IDataSourceViewModel source) { var panel = _selectedMainPanel as LogViewMainPanelViewModel; if (panel != null) { return(panel.CanBeDragged(source)); } return(false); }
private void ChangeDataSource(IDataSourceViewModel value) { if (value != null) { value.QuickFilterChain = _quickFilters.CreateFilterChain(); } _dataSources.SelectedItem = value; _quickFilters.CurrentDataSource = value; _bookmarks.CurrentDataSource = value?.DataSource; OpenFile(value); }
private void PartDataSourcesOnMouseMove(object sender, MouseEventArgs e) { if (DragLayer.ShouldStartDrag(e)) { IDataSourceViewModel source = SelectedItem; TreeViewItem treeViewItem = SelectedTreeViewItem; if (treeViewItem.IsMouseOver && ((DataSourcesViewModel)DataContext).CanBeDragged(source)) { DragLayer.DoDragDrop(source, treeViewItem, DragDropEffects.Move); } } }
private void DissolveGroupIfNecessary(MergedDataSourceViewModel group) { if (group.ChildCount == 1) { int groupIndex = _observable.IndexOf(group); _observable.RemoveAt(groupIndex); _dataSources.Remove(group.DataSource); IDataSourceViewModel child = group.Observable.First(); group.RemoveChild(child); _observable.Insert(groupIndex, child); } }
private void UpdateWindowTitle(IDataSourceViewModel value) { if (value != null) { WindowTitle = string.Format("{0} - {1}", Constants.MainWindowTitle, value.DisplayName); WindowTitleSuffix = value.DataSourceOrigin; } else { WindowTitle = Constants.MainWindowTitle; WindowTitleSuffix = null; } }
public bool CanBeDragged(IDataSourceViewModel source) { if (source is FolderDataSourceViewModel) { return(false); //< see https://github.com/Kittyfisto/Tailviewer/issues/125 } var sourceParent = source?.Parent; if (sourceParent is FolderDataSourceViewModel) { return(false); //< see https://github.com/Kittyfisto/Tailviewer/issues/125 } return(true); }
public void RemoveChild(IDataSourceViewModel dataSource) { if (dataSource.Parent != this) { throw new ArgumentException("dataSource.Parent"); } _observable.Remove(dataSource); _dataSource.Remove(dataSource.DataSource); dataSource.Parent = null; Update(); DistributeCharacterCodes(); }
public void Insert(int index, IDataSourceViewModel dataSource) { if (dataSource.Parent != null) { throw new ArgumentException("dataSource.Parent"); } _observable.Insert(index, dataSource); _dataSource.Add(dataSource.DataSource); dataSource.Parent = this; Update(); DistributeCharacterCodes(); }
/// <summary> /// Yes, please don't make dealing with a tree complicated or anything... /// </summary> /// <param name="item"></param> /// <returns></returns> private TreeViewItem GetTreeViewItem(IDataSourceViewModel item) { var partDataSources = _partDataSources; if (partDataSources == null) { Log.Warn("Unable to get the selected tree view item: _partDataSources is not set!"); return(null); } ItemContainerGenerator containerGenerator = partDataSources.ItemContainerGenerator; return(GetTreeViewItem(containerGenerator, item)); }
public bool CanBeDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType, out IDataSourceViewModel finalDest) { var panel = _selectedMainPanel as LogViewMainPanelViewModel; if (panel != null) { return(panel.CanBeDropped(source, dest, dropType, out finalDest)); } finalDest = null; return(false); }
private void OpenFile(IDataSourceViewModel dataSource) { if (dataSource != null) { CurrentDataSource = dataSource; CurrentDataSourceLogView = new LogViewerViewModel( dataSource, _actionCenter, _applicationSettings); } else { CurrentDataSource = null; CurrentDataSourceLogView = null; } }
private bool PassesFilter(IDataSourceViewModel model, string filter) { if (filter == null) { return(true); } int idx = model.DisplayName.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase); if (idx != -1) { return(true); } return(false); }
private void DropToGroup(IDataSourceViewModel source, IDataSourceViewModel dest) { int sourceIndex = _observable.IndexOf(source); if (sourceIndex != -1) { DragFromUngrouped(source, dest, sourceIndex); } else { var parent = source.Parent as MergedDataSourceViewModel; if (parent != null) { DragFromGroup(source, dest, parent); } } }
public DataSourcesViewModel(IApplicationSettings settings, IDataSources dataSources, IActionCenter actionCenter) { _actionCenter = actionCenter ?? throw new ArgumentNullException(nameof(actionCenter)); _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _observable = new ObservableCollection <IDataSourceViewModel>(); _allDataSourceViewModels = new List <IDataSourceViewModel>(); _dataSources = dataSources ?? throw new ArgumentNullException(nameof(dataSources)); _removeCurrentDataSourceCommand = new DelegateCommand2(CloseSelectedDataSource); _removeAllDataSourcesCommand = new DelegateCommand2(CloseAllDataSources); foreach (IDataSource dataSource in dataSources.Sources) { if (dataSource.ParentId == DataSourceId.Empty) { Add(dataSource); } } foreach (IDataSource dataSource in dataSources.Sources) { DataSourceId parentId = dataSource.ParentId; if (parentId != DataSourceId.Empty) { IDataSourceViewModel parent = _observable.First(x => x.DataSource.Id == parentId); var group = (MergedDataSourceViewModel)parent; IDataSourceViewModel viewModel = CreateViewModel(dataSource); group.AddChild(viewModel); } } //_customDataSources = // _dataSources.CustomDataSources.Select(x => new AddCustomDataSourceViewModel(x.DisplayName, () => AddCustomDataSource(x.Id))).ToList(); // We need to make sure that if we construct this view model *and* the data sources panel is supposed // to be pinned, then we also need to make sure the toggle button is checked as otherwise nothing // is showing up. IsPinned = _settings.DataSources.IsPinned; if (IsPinned) { IsChecked = true; } UpdateTooltip(); UpdateRemoveCommands(); PropertyChanged += OnPropertyChanged; }
public LogViewerViewModel(IDataSourceViewModel dataSource, IDispatcher dispatcher, TimeSpan maximumWaitTime) { if (dataSource == null) throw new ArgumentNullException("dataSource"); if (dispatcher == null) throw new ArgumentNullException("dispatcher"); _maximumWaitTime = maximumWaitTime; _dataSource = dataSource; _dispatcher = dispatcher; _pendingSections = new List<KeyValuePair<ILogFile, LogFileSection>>(); LogFile = _dataSource.DataSource.FilteredLogFile; LogFile.AddListener(this, _maximumWaitTime, 1000); Search = _dataSource.DataSource.Search; UpdateCounts(); }
private void DropToArrange(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType) { IDataSourceViewModel sourceParent = source.Parent; if (sourceParent != null) { // // When the source is part of a group, then any arrange is going to remove it // from said group. // var group = ((MergedDataSourceViewModel) sourceParent); group.RemoveChild(source); if (sourceParent != dest.Parent) { // // If both source and dest are part of different groups, then // we need to check if source's group needs to be dissolved due to // having only 1 child left. // DissolveGroupIfNecessary(group); } } else { _observable.Remove(source); } if (dest.Parent != null) { // // If the destination has a parent then we need to insert // the source into it's collection. // var merged = ((MergedDataSourceViewModel) dest.Parent); int index = merged.Observable.IndexOf(dest); if (dropType.HasFlag(DataSourceDropType.ArrangeBottom)) ++index; merged.Insert(index, source); } else { // // Otherwise we insert the source into the flat, or root // collection. // int index = _observable.IndexOf(dest); if (dropType.HasFlag(DataSourceDropType.ArrangeBottom)) ++index; if (index < 0) index = 0; _observable.Insert(index, source); } SelectedItem = source; }
private void DragFromUngrouped(IDataSourceViewModel source, IDataSourceViewModel dest, int sourceIndex) { _observable.RemoveAt(sourceIndex); Drag(source, dest); }
private DataSourceDropType GetDropType(DragEventArgs e, TreeItem destination, IDataSourceViewModel source) { if (destination == null) return DataSourceDropType.None; Point pos = e.GetPosition(destination.TreeViewItem); var dropType = DataSourceDropType.None; double height = destination.TreeViewItem.ActualHeight; if (source is SingleDataSourceViewModel) { // Let's distribute it as follows: // 20% top => arrange // 60% middle => group // 20% bottom => arrange // // This way 60% of the height is used for grouping and 40% is used for arranging. if (pos.Y < height*0.2) dropType |= DataSourceDropType.ArrangeTop; else if (pos.Y < height*0.8) dropType |= DataSourceDropType.Group; else dropType |= DataSourceDropType.ArrangeBottom; if (destination.ViewModel.Parent != null) dropType |= DataSourceDropType.Group; } else { // Groups can't be grouped any further, thus we // simply arrange it above or beneath the drop source // at a 50/50 split. if (pos.Y < height*0.5) dropType |= DataSourceDropType.ArrangeTop; else dropType |= DataSourceDropType.ArrangeBottom; } return dropType; }
public void RemoveChild(IDataSourceViewModel dataSource) { if (dataSource.Parent != this) throw new ArgumentException("dataSource.Parent"); _observable.Remove(dataSource); _dataSource.Remove(dataSource.DataSource); dataSource.Parent = null; Update(); }
public void AddChild(IDataSourceViewModel dataSource) { if (dataSource.Parent != null) throw new ArgumentException("dataSource.Parent"); _observable.Add(dataSource); _dataSource.Add(dataSource.DataSource); dataSource.Parent = this; }
/// <summary> /// Yes, please don't make dealing with a tree complicated or anything... /// </summary> /// <param name="item"></param> /// <returns></returns> private TreeViewItem GetTreeViewItem(IDataSourceViewModel item) { var partDataSources = _partDataSources; if (partDataSources == null) { Log.Warn("Unable to get the selected tree view item: _partDataSources is not set!"); return null; } ItemContainerGenerator containerGenerator = partDataSources.ItemContainerGenerator; return GetTreeViewItem(containerGenerator, item); }
private void OpenFile(IDataSourceViewModel dataSource) { if (dataSource != null) { CurrentDataSource = dataSource; CurrentDataSourceLogView = new LogViewerViewModel( dataSource, _dispatcher); WindowTitle = string.Format("{0} - {1}", Constants.MainWindowTitle, dataSource.DisplayName); } else { CurrentDataSource = null; CurrentDataSourceLogView = null; WindowTitle = Constants.MainWindowTitle; } }
public bool CanBeDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType, out IDataSourceViewModel finalDest) { finalDest = null; if (dropType == DataSourceDropType.None) return false; if (dest == null) return false; if (source is MergedDataSourceViewModel) { if (dropType == DataSourceDropType.ArrangeBottom || dropType == DataSourceDropType.ArrangeTop) { // We cannot "rearrange" a group between parented data sources as that // would result in grouped groups - which is not supported (yet?). if (dest.Parent != null) return false; return true; } return false; } if (source == dest) return false; var single = dest as SingleDataSourceViewModel; if (single != null) finalDest = single.Parent ?? dest; else finalDest = dest; return true; }
public bool CanBeDragged(IDataSourceViewModel source) { return true; }
public void Insert(int index, IDataSourceViewModel dataSource) { if (dataSource.Parent != null) throw new ArgumentException("dataSource.Parent"); _observable.Insert(index, dataSource); _dataSource.Add(dataSource.DataSource); dataSource.Parent = this; Update(); }
private void OnDataSourceChanged(IDataSourceViewModel oldValue, IDataSourceViewModel newValue) { if (oldValue != null) { oldValue.PropertyChanged -= DataSourceOnPropertyChanged; } if (newValue != null) { newValue.PropertyChanged += DataSourceOnPropertyChanged; PART_ListView.FollowTail = newValue.FollowTail; PART_ListView.SelectedSearchResultIndex = newValue.CurrentSearchResultIndex; ShowLineNumbers = newValue.ShowLineNumbers; } OnLevelsChanged(); }
private void OnRemove(IDataSourceViewModel viewModel) { int index = _observable.IndexOf(viewModel); if (index != -1) { _observable.RemoveAt(index); var merged = viewModel as MergedDataSourceViewModel; if (merged != null) { IEnumerable<IDataSourceViewModel> items = merged.Observable; foreach (IDataSourceViewModel item in items) { _observable.Insert(index++, item); item.Parent = null; } } } else if (viewModel.Parent != null) { ((MergedDataSourceViewModel) viewModel.Parent).RemoveChild(viewModel); _dataSources.Remove(viewModel.DataSource); } _allDataSourceViewModels.Remove(viewModel); _dataSources.Remove(viewModel.DataSource); _settings.Save(); }
public bool CanBeDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType, out IDataSourceViewModel finalDest) { return _dataSourcesViewModel.CanBeDropped(source, dest, dropType, out finalDest); }
private bool PassesFilter(IDataSourceViewModel model, string filter) { if (filter == null) return true; int idx = model.DisplayName.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase); if (idx != -1) return true; return false; }
private bool PassesFilter(IDataSourceViewModel model) { return PassesFilter(model, StringFilter); }
private void OnSelectedItemChanged(IDataSourceViewModel selectedViewModel) { TreeViewItem treeViewItem = GetTreeViewItem(selectedViewModel); if (treeViewItem != null) { treeViewItem.IsSelected = true; } else { Dispatcher.BeginInvoke(new Action(() => { TreeViewItem item = GetTreeViewItem(selectedViewModel); if (item != null) { item.IsSelected = true; } })); } }
public IDataSourceViewModel GetOrAdd(string fileName) { string fullName = Path.GetFullPath(fileName); IDataSourceViewModel viewModel = _observable.FirstOrDefault(x => Represents(x, fullName)); if (viewModel == null) { IDataSource dataSource = _dataSources.AddDataSource(fileName); viewModel = Add(dataSource); _settings.Save(); if (_observable.Count == 1) { SelectedItem = viewModel; } } return viewModel; }
public LogViewerViewModel(IDataSourceViewModel dataSource, IDispatcher dispatcher) : this(dataSource, dispatcher, TimeSpan.FromMilliseconds(10)) { }
private void ChangeDataSource(IDataSourceViewModel value) { _dataSourcesViewModel.SelectedItem = value; _quickFilters.CurrentDataSource = value; OpenFile(value); }
public void OnDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType) { if (!CanBeDragged(source)) throw new ArgumentException("source"); IDataSourceViewModel unused; if (!CanBeDropped(source, dest, dropType, out unused)) throw new ArgumentException("source or dest"); if (dropType == DataSourceDropType.Group) { DropToGroup(source, dest); } else { DropToArrange(source, dest, dropType); } }
public void OnDropped(IDataSourceViewModel source, IDataSourceViewModel dest, DataSourceDropType dropType) { _dataSourcesViewModel.OnDropped(source, dest, dropType); }
private static void AddFileToGroup(IDataSourceViewModel source, MergedDataSourceViewModel viewModel) { viewModel.AddChild(source); }
public bool CanBeDragged(IDataSourceViewModel source) { return _dataSourcesViewModel.CanBeDragged(source); }
private IDataSourceViewModel CreateViewModel(IDataSource dataSource) { if (dataSource == null) throw new ArgumentNullException("dataSource"); IDataSourceViewModel viewModel; var single = dataSource as SingleDataSource; if (single != null) { viewModel = new SingleDataSourceViewModel(single); } else { var merged = dataSource as MergedDataSource; if (merged != null) { viewModel = new MergedDataSourceViewModel(merged); } else { throw new ArgumentException(string.Format("Unknown data source: {0} ({1})", dataSource, dataSource.GetType())); } } viewModel.Remove += OnRemove; _allDataSourceViewModels.Add(viewModel); if (_settings.DataSources.SelectedItem == viewModel.DataSource.Id) { SelectedItem = viewModel; } return viewModel; }
private void Drag(IDataSourceViewModel source, IDataSourceViewModel dest) { var merged = dest as MergedDataSourceViewModel; if (merged != null) { // Drag from ungrouped onto an existing group // => add to existing group AddFileToGroup(source, merged); } else { // Drag from ungrouped onto a dest within a group // => find group of dest and addd to it merged = dest.Parent as MergedDataSourceViewModel; if (merged != null) { AddFileToGroup(source, merged); } else { // Drag from ungrouped onto another ungrouped source // => remove dest as well and create new group int destIndex = _observable.IndexOf(dest); if (destIndex != -1) { _observable.Remove(dest); MergedDataSource mergedDataSource = _dataSources.AddGroup(); merged = new MergedDataSourceViewModel(mergedDataSource); merged.Remove += OnRemove; merged.AddChild(source); merged.AddChild(dest); _observable.Insert(destIndex, merged); SelectedItem = merged; } } } }
private TreeViewItem GetTreeViewItem(ItemContainerGenerator containerGenerator, IDataSourceViewModel item) { var container = (TreeViewItem) containerGenerator.ContainerFromItem(item); if (container != null) return container; foreach (object childItem in containerGenerator.Items) { var parent = containerGenerator.ContainerFromItem(childItem) as TreeViewItem; if (parent == null) continue; container = parent.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; if (container != null) return container; container = GetTreeViewItem(parent.ItemContainerGenerator, item); if (container != null) return container; } return null; }