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 DataSourceArrangeAdorner(TreeViewItem dropTarget,
                                 DataSourceDropType dropType)
     : base(dropTarget)
 {
     _pen  = new Pen(Brushes.DodgerBlue, 2);
     _type = dropType;
 }
        public DataSourceArrangeAdorner(TreeViewItem dropTarget,
		                                DataSourceDropType dropType)
            : base(dropTarget)
        {
            _pen = new Pen(Brushes.DodgerBlue, 2);
            _type = dropType;
        }
 public bool CanBeDropped(IDataSourceViewModel source,
                          IDataSourceViewModel dest,
                          DataSourceDropType dropType,
                          out IDataSourceViewModel finalDest)
 {
     return(_dataSources.CanBeDropped(source, dest, dropType, out finalDest));
 }
        public void OnDropped(IDataSourceViewModel source,
                              IDataSourceViewModel dest,
                              DataSourceDropType dropType)
        {
            var panel = _selectedMainPanel as LogViewMainPanelViewModel;

            panel?.OnDropped(source, dest, dropType);
        }
        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);
        }
Beispiel #7
0
        private static void AddArrangeAdorner(TreeViewItem treeViewItem, DataSourceDropType dropType)
        {
            if (_arrangeAdorner == null)
            {
                _arrangeAdorner = new DataSourceArrangeAdorner(treeViewItem, dropType);
                _adornerLayer.Add(_arrangeAdorner);
            }
            else if (!Equals(_arrangeAdorner.AdornedElement, treeViewItem) ||
                     _arrangeAdorner.DropType != dropType)
            {
                RemoveArrangeAdorner();

                _arrangeAdorner = new DataSourceArrangeAdorner(treeViewItem, dropType);
                _adornerLayer.Add(_arrangeAdorner);
            }
        }
        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 IMergedDataSourceViewModel)
            {
                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 ISingleDataSourceViewModel;
            if (single != null)
                finalDest = single.Parent ?? dest;
            else
                finalDest = dest;

            var group = dest as IMergedDataSourceViewModel;
            if (group != null)
            {
                if (group.Observable.Count >= LogLineSourceId.MaxSources)
                    return false;
            }

            return true;
        }
        private bool IsValidDrop(DragEventArgs e, out DropInfo dropInfo)
        {
            dropInfo = null;
            IDataSourceViewModel viewModel = e.Data.GetData(typeof(SingleDataSourceViewModel)) as IDataSourceViewModel ??
                                             e.Data.GetData(typeof(MergedDataSourceViewModel)) as IDataSourceViewModel;
            var source = new TreeItem
            {
                ViewModel = viewModel
            };

            if (source.ViewModel == null)
            {
                return(false);
            }

            TreeItem dropTarget = GetDataSourceFromPosition(e.GetPosition(_partDataSources));

            if (dropTarget == null)
            {
                return(false);
            }

            DataSourceDropType dropType = GetDropType(e, dropTarget, viewModel);
            var model = (DataSourcesViewModel)DataContext;
            IDataSourceViewModel group;

            if (!model.CanBeDropped(source.ViewModel, dropTarget.ViewModel, dropType, out group))
            {
                return(false);
            }

            dropInfo = new DropInfo
            {
                Source      = source,
                Type        = dropType,
                Target      = dropTarget,
                TargetGroup = new TreeItem
                {
                    ViewModel    = group,
                    TreeViewItem = GetTreeViewItem(group)
                }
            };
            return(true);
        }
Beispiel #10
0
        private static void AddArrangeAdorner(TreeViewItem treeViewItem, DataSourceDropType dropType)
        {
            if (_arrangeAdorner == null)
            {
                _arrangeAdorner = new DataSourceArrangeAdorner(treeViewItem, dropType);
                _adornerLayer.Add(_arrangeAdorner);
            }
            else if (!Equals(_arrangeAdorner.AdornedElement, treeViewItem) ||
                     _arrangeAdorner.DropType != dropType)
            {
                RemoveArrangeAdorner();

                _arrangeAdorner = new DataSourceArrangeAdorner(treeViewItem, dropType);
                _adornerLayer.Add(_arrangeAdorner);
            }
        }
        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;
        }
        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 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 CanBeDropped(IDataSourceViewModel source,
		                         IDataSourceViewModel dest,
		                         DataSourceDropType dropType,
		                         out IDataSourceViewModel finalDest)
        {
            return _dataSourcesViewModel.CanBeDropped(source, dest, dropType, out finalDest);
        }
        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 IMergedDataSourceViewModel)
            {
                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 ISingleDataSourceViewModel;

            if (single != null)
            {
                finalDest = single.Parent ?? dest;
            }
            else
            {
                finalDest = dest;
            }

            if (finalDest is FolderDataSourceViewModel)
            {
                return(false);                //< https://github.com/Kittyfisto/Tailviewer/issues/125
            }
            var group = dest as IMergedDataSourceViewModel;

            if (group != null)
            {
                if (group.Observable.Count >= LogEntrySourceId.MaxSources)
                {
                    return(false);
                }
            }

            return(true);
        }
 public void OnDropped(IDataSourceViewModel source,
                       IDataSourceViewModel dest,
                       DataSourceDropType dropType)
 {
     _logViewPanel?.OnDropped(source, dest, dropType);
 }
        public void OnDropped(IDataSourceViewModel source,
		                      IDataSourceViewModel dest,
		                      DataSourceDropType dropType)
        {
            _dataSourcesViewModel.OnDropped(source, dest, dropType);
        }
 public void OnDropped(IDataSourceViewModel source,
                       IDataSourceViewModel dest,
                       DataSourceDropType dropType)
 {
     _dataSources.OnDropped(source, dest, dropType);
 }
        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);
                if (dropType.HasFlag(DataSourceDropType.ArrangeTop))
                {
                    if (index + 1 < _observable.Count)
                    {
                        var tmp    = source.DataSource.Settings;
                        var before = _observable[index + 1].DataSource.Settings;
                        _settings.DataSources.MoveBefore(tmp, before);
                    }
                }
            }

            SelectedItem = source;
            _settings.SaveAsync();
        }