示例#1
0
 private StickyNoteColors GetStickyNoteColor(StickyNoteControl forThis)
 {
     if (!Core.App.Workspace.UserStickyNoteColors.ContainsKey(forThis.StickyNote.UserName))
     {
         // New user = new color. We need to get a new color and then add this user to
         // the dictionary
         StickyNoteColors clr = StickyNoteControl.GetNextUserStickyColor();
         Core.App.Workspace.UserStickyNoteColors.Add(forThis.StickyNote.UserName, clr);
         return(clr);
     }
     else
     {
         return(Core.App.Workspace.UserStickyNoteColors[forThis.StickyNote.UserName]);
     }
 }
        /// <summary>
        /// Invoked when the comment collection in m_pu changes. This method updates the set of
        /// sticky note controls on the drawing canvas that are used to represent comments for
        /// the process unit.
        /// </summary>
        private void CommentCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // Start by deleting any sticky note controls that represent comments that are no longer
            // in the comment collection. While we do this, build a list of all comments that we
            // have a sticky note control for (used in next step).
            List <Logic.StickyNote> existing = new List <Logic.StickyNote>();

            for (int i = 0; i < m_stickyNotes.Count; i++)
            {
                if (!m_pu.Comments.Contains(m_stickyNotes[i].StickyNote))
                {
                    // Tell the sticky note to remove itself from the drawing canvas
                    m_stickyNotes[i].RemoveSelfFromCanvas(m_canvas);

                    // Remove it from our collection as well and then back up the index
                    m_stickyNotes.RemoveAt(i);
                    i--;
                }
                else
                {
                    existing.Add(m_stickyNotes[i].StickyNote);
                }
            }

            // Now add new sticky note controls for comments that don't have them
            for (int i = 0; i < m_pu.Comments.Count; i++)
            {
                if (!existing.Contains(m_pu.Comments[i]))
                {
                    StickyNoteControl snc = StickyNoteControl.CreateOnCanvas(
                        m_canvas, m_pu.Comments[i], this);
                    m_stickyNotes.Add(snc);
                    snc.UpdateLineToParent();
                }
            }

            // If we have 1 or more comments then we show the comment icon over the process unit,
            // otherwise we hide it
            if (m_pu.Comments.Count >= 1)
            {
                CommentIcon.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                CommentIcon.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
示例#3
0
        public static StickyNoteControl CreateOnCanvas(DrawingCanvas canvas,
                                                       StickyNote memNote, object commentParentControl)
        {
            // I'm using a static constructor because this way I can at least choose
            // wording that implies that this control will be created AND added to
            // the drawing canvas.

            // Quick parameter check
            if (null == canvas || null == memNote)
            {
                throw new ArgumentNullException();
            }

            StickyNoteControl snc = new StickyNoteControl(canvas, memNote);

            snc.m_commentParent = commentParentControl;
            canvas.AddNewChild(snc);

            // Give it a high z-index since we want comments above everything else
            snc.SetValue(Canvas.ZIndexProperty, (int)4);

            // Setup extra stuff if we have a parent control
            if (null != commentParentControl)
            {
                if (!(commentParentControl is ChemProV.PFD.Streams.StreamControl) &&
                    !(commentParentControl is ProcessUnitControl))
                {
                    throw new InvalidOperationException(
                              "The parent element for a comment-sticky-note must be a stream or process unit");
                }

                // Create the line and add it to the drawing canvas
                snc.m_lineToParent = new Line();
                canvas.AddNewChild(snc.m_lineToParent);
                snc.m_lineToParent.SetValue(Canvas.ZIndexProperty, -3);
                snc.m_lineToParent.Stroke          = new SolidColorBrush(Color.FromArgb(255, 245, 222, 179));
                snc.m_lineToParent.StrokeThickness = 1.0;

                // Make sure that when the parent moves we update the line
                if (commentParentControl is ProcessUnitControl)
                {
                    (commentParentControl as ProcessUnitControl).ProcessUnit.PropertyChanged +=
                        snc.ProcessUnitParentPropertyChanged;
                }
                else
                {
                    (commentParentControl as PFD.Streams.StreamControl).Stream.PropertyChanged +=
                        snc.StreamParentPropertyChanged;
                }

                // Position the line to the parent
                snc.UpdateLineToParent();
            }

            // Hide if need be
            if (!memNote.IsVisible)
            {
                snc.Hide();
            }

            return(snc);
        }