Beispiel #1
0
        /// <summary>
        /// Event handler that is called when the document node has disposed or name changed. Because the path to the node can have changed too,
        /// the path is renewed in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="source">Source of the tunneled event.</param>
        /// <param name="e"></param>
        private void EhDocNode_TunneledEvent(object sender, object source, Main.TunnelingEventArgs e)
        {
            if (IsDisposeInProgress)
            {
                return;
            }

#if DEBUG_DOCNODEPROXYLOGGING
            Current.Console.WriteLine("DocNodeProxy.EhDocNode_TunneledEvent: sender={0}, source={1} e={2}", sender, source, e);
#endif

            bool shouldFireChangedEvent = false;

            var senderAsNode = source as IDocumentLeafNode;
            if (!(senderAsNode != null))
            {
                throw new InvalidProgramException();
            }

            if (e is DisposeEventArgs)
            {
                // when our DocNode was disposed, it is probable that the parent of this node (and further parents) are disposed too
                // thus we need to watch the first node that is not disposed
                var docNode = InternalDocumentNode;
                ClearDocNode();

                if (!(sender is IProject)) // if the whole project is disposed, there is no point in trying to watch something
                {
                    // note Dispose is designed to let the hierarchy from child to parent (root) valid, but not from root to child!
                    // thus trying to get an actual document path here is in must cases unsuccessfull. We have to rely on our stored path, and that it was always updated!
                    // the only case were it is successfull if a new node immediately replaces an old document node
                    var node = AbsoluteDocumentPath.GetNodeOrLeastResolveableNode(_docNodePath, senderAsNode, out var wasResolvedCompletely);
                    if (wasResolvedCompletely)
                    {
                        SetDocNode(node);
                    }
                    else
                    {
                        SetWatchOnNode(node);
                    }

                    shouldFireChangedEvent = true;
                }
            }
            else if (e is DocumentPathChangedEventArgs)
            {
                if (null != InternalDocumentNode)
                {
                    InternalDocumentPath = Main.AbsoluteDocumentPath.GetAbsolutePath(InternalDocumentNode);
                    InternalCheckAbsolutePath();
                }

                shouldFireChangedEvent = true;
            }

            if (shouldFireChangedEvent)
            {
                EhSelfChanged(EventArgs.Empty);
            }
        }
Beispiel #2
0
 private void EhDataTableTunneledEvent(object sender, object source, Main.TunnelingEventArgs args)
 {
     if (args is Main.DisposeEventArgs)
     {
         Dispose();
     }
 }
 private void EhChildNodeTunneledEvent(object sender, object source, Main.TunnelingEventArgs e)
 {
     if (e is Main.DisposeEventArgs && source is WorksheetLayout)
     {
         var src = (WorksheetLayout)source;
         Remove(src);
     }
 }
Beispiel #4
0
 private void EhKey_TunneledEvent(object sender, object source, Main.TunnelingEventArgs e)
 {
     if (e is Main.DisposeEventArgs)
     {
         var c = source as DataColumn;
         if (c != null)
         {
             Remove(c); // do not use direct remove, as the event handler has to be detached also
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Event handler that is called when the watched node or a parent node below has disposed or its name changed. We then try to resolve the path again.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="source">Source of the tunneled event.</param>
        /// <param name="e"></param>
        private void EhWatchedNode_TunneledEvent(object sender, object source, Main.TunnelingEventArgs e)
        {
            if (IsDisposeInProgress)
            {
                return;
            }

            if (!(_docNodeRef == null))
            {
                throw new InvalidProgramException();
            }
            var senderAsDocNode = sender as IDocumentLeafNode;
            var sourceAsDocNode = source as IDocumentLeafNode;

            if (!(senderAsDocNode != null))
            {
                throw new InvalidProgramException();
            }
            if (!(sourceAsDocNode != null))
            {
                throw new InvalidProgramException();
            }

            // then we try to resolve the path again
            if ((e is DisposeEventArgs) || (e is DocumentPathChangedEventArgs))
            {
#if DEBUG_DOCNODEPROXYLOGGING
                Current.Console.WriteLine("DocNodeProxy.EhWatchedNode_TunneledEvent");
#endif

                var node = RelativeDocumentPath.GetNodeOrLeastResolveableNode(_docNodePath, sourceAsDocNode, out var wasResolvedCompletely);
                if (null == node)
                {
                    throw new InvalidProgramException(nameof(node) + " should always be != null, since we use absolute paths, and at least an AltaxoDocument should be resolved here.");
                }

                if (wasResolvedCompletely)
                {
                    ClearWatch();
                    InternalSetDocNode(node, _parent);
                }
                else // not completely resolved
                {
                    if (!object.ReferenceEquals(sender, node))
                    {
                        ClearWatch();
                        SetWatchOnNode(node);
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Event handler that is called when the watched node or a parent node below has disposed or its name changed. We then try to resolve the path again.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="source">Source of the tunneled event.</param>
        /// <param name="e"></param>
        private void EhWatchedNode_TunneledEvent(object sender, object source, Main.TunnelingEventArgs e)
        {
            if (IsDisposeInProgress)
            {
                return;
            }

            if (!(InternalDocumentNode == null))
            {
                throw new InvalidProgramException();
            }
            var senderAsDocNode = sender as IDocumentLeafNode;
            var sourceAsDocNode = source as IDocumentLeafNode;

            if (!(senderAsDocNode != null))
            {
                throw new InvalidProgramException();
            }
            if (!(sourceAsDocNode != null))
            {
                throw new InvalidProgramException();
            }

            if (e is DocumentPathChangedEventArgs) // here, we activly change our stored path, if the watched node or a parent has changed its name
            {
                var watchedPath = AbsoluteDocumentPath.GetAbsolutePath(senderAsDocNode);
                watchedPath = watchedPath.Append(_docNodePath.SubPath(watchedPath.Count, _docNodePath.Count - watchedPath.Count));
                var oldPath = _docNodePath;
                _docNodePath = watchedPath;

#if DEBUG_DOCNODEPROXYLOGGING
                Current.Console.WriteLine("DocNodeProxy.EhWatchedNode_TunneledEvent: Modified path, oldpath={0}, newpath={1}", oldPath, _docNodePath);
#endif
            }

            // then we try to resolve the path again
            if ((e is DisposeEventArgs) || (e is DocumentPathChangedEventArgs))
            {
#if DEBUG_DOCNODEPROXYLOGGING
                Current.Console.WriteLine("DocNodeProxy.EhWatchedNode_TunneledEvent");
#endif

                var node = AbsoluteDocumentPath.GetNodeOrLeastResolveableNode(_docNodePath, sourceAsDocNode, out var wasResolvedCompletely);
                if (null == node)
                {
                    throw new InvalidProgramException(nameof(node) + " should always be != null, since we use absolute paths, and at least an AltaxoDocument should be resolved here.");
                }

                if (wasResolvedCompletely)
                {
                    ClearWatch();
                    SetDocNode(node);
                }
                else // not completely resolved
                {
                    if (!object.ReferenceEquals(sender, node))
                    {
                        ClearWatch();
                        SetWatchOnNode(node);
                    }
                }
            }
        }