Пример #1
0
        public bool ContainsComment(BasicComment comment, bool compareReferences = false)
        {
            if (compareReferences)
            {
                for (int i = 0; i < m_comments.Count; i++)
                {
                    if (object.ReferenceEquals(m_comments[i], comment))
                    {
                        return(true);
                    }
                }

                // Didn't find a matching reference
                return(false);
            }

            // Coming here means that we want to do a value comparison (not reference)
            foreach (BasicComment bc in m_comments)
            {
                if (bc.Equals(comment))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public IUndoRedoAction Execute(Workspace sender)
        {
            // Get the comment that we're about to remove
            BasicComment bc = m_comments[m_index];

            // Remove it
            m_comments.RemoveAt(m_index);

            // Return an action that will insert it back into the collection
            return(new InsertBasicComment(bc, m_comments, m_index));
        }
Пример #3
0
        /// <summary>
        /// Sets the comment object for this control to the specified BasicComment object. This control
        /// may subscribe to events for the object, so it is best practice to set this to null when the
        /// control is no longer being used.
        /// </summary>
        public void SetCommentObject(BasicComment comment)
        {
            if (null != m_sticky)
            {
                // Remove event handler before changing this value
                m_sticky.PropertyChanged -= this.StickyNote_PropertyChanged;
            }
            if (null != m_basic)
            {
                m_basic.OnTextChanged -= this.BasicComment_OnTextChanged;
            }

            // IMPORTANT: Unsubscribe from parent control property changes (if applicable)
            if (null != m_parentObject)
            {
                if (m_parentObject is AbstractProcessUnit)
                {
                    (m_parentObject as AbstractProcessUnit).PropertyChanged -= this.ParentPU_PropertyChanged;
                }
                else if (m_parentObject is AbstractStream)
                {
                    (m_parentObject as AbstractStream).PropertyChanged -= this.ParentStream_PropertyChanged;
                }
            }

            m_basic        = comment;
            m_sticky       = null;
            m_parentObject = null;

            // It is valid to call this method with a null comment, so only update the UI if we
            // have a non-null comment.
            if (null != m_basic)
            {
                // Update the text in the UI elements
                CommentTextBox.Text   = m_basic.CommentText;
                UserNameLabel.Content = m_basic.CommentUserName;

                // Allow deletion and editing
                XLabel.Visibility         = System.Windows.Visibility.Visible;
                CommentTextBox.IsReadOnly = false;

                // Make sure the icon is hidden
                IconImage.Visibility = System.Windows.Visibility.Collapsed;
                TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(0.0);

                // Subscribe to property changes
                m_basic.OnTextChanged += new EventHandler(BasicComment_OnTextChanged);
            }
        }
Пример #4
0
        private void UpdateComments()
        {
            // Clear first
            CommentsStack.Children.Clear();

            // Start with equation comments
            for (int i = 0; i < m_workspace.Equations.Count; i++)
            {
                EquationModel model = m_workspace.Equations[i];

                if (!model.CommentsVisible)
                {
                    continue;
                }

                Border brdr = new Border();
                brdr.Margin          = new Thickness(3.0, 3.0, 3.0, 0.0);
                brdr.CornerRadius    = new CornerRadius(3.0);
                brdr.BorderThickness = new Thickness(2.0);
                brdr.BorderBrush     = s_eqBorderBrush;
                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Vertical;
                brdr.Child     = sp;

                // Add an equation number label at the top
                Label numLabel = new Label();
                numLabel.Content             = "Equation " + (i + 1).ToString();
                numLabel.Foreground          = s_eqBorderBrush;
                numLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                sp.Children.Add(numLabel);

                // Add each comment
                foreach (BasicComment bc in model.Comments)
                {
                    PaneCommentControl cc = new PaneCommentControl();
                    cc.SetCommentObject(bc);
                    cc.Margin = new Thickness(3.0);
                    cc.XLabel.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                    {
                        // Create and undo that adds the comment back
                        BasicComment toRemove = cc.CommentObject as BasicComment;
                        m_workspace.AddUndo(new UndoRedoCollection(
                                                "Undo deletion of equation comment",
                                                new Logic.Undos.InsertBasicComment(toRemove, model.Comments, model.Comments.IndexOf(toRemove))));

                        model.Comments.Remove(cc.CommentObject as BasicComment);
                        sp.Children.Remove(cc);
                    };
                    sp.Children.Add(cc);
                }

                // Add a button to allow addition of more comments
                Button btn = new Button();
                btn.Margin = new Thickness(3.0);
                Image btnIcon = Core.App.CreateImageFromSource("plus_16x16.png");
                btnIcon.Width = btnIcon.Height = 16;
                btn.Content   = btnIcon;
                btn.Tag       = model;
                btn.Click    += new RoutedEventHandler(AddEqCommentButtonClick);
                sp.Children.Add(btn);

                CommentsStack.Children.Add(brdr);
            }

            // Next do comments for the degrees of freedom analysis
            if (m_workspace.DegreesOfFreedomAnalysis.CommentsVisible)
            {
                Border brdr = new Border();
                brdr.Margin          = new Thickness(3.0, 3.0, 3.0, 0.0);
                brdr.CornerRadius    = new CornerRadius(3.0);
                brdr.BorderThickness = new Thickness(2.0);
                brdr.BorderBrush     = s_dfBorderBrush;
                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Vertical;
                brdr.Child     = sp;

                // Add a label at the top
                Label numLabel = new Label();
                numLabel.Content             = "DF Analysis";
                numLabel.Foreground          = s_dfBorderBrush;
                numLabel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                sp.Children.Add(numLabel);

                DegreesOfFreedomAnalysis dfa = m_workspace.DegreesOfFreedomAnalysis;
                foreach (BasicComment bc in dfa.Comments)
                {
                    PaneCommentControl pcc = new PaneCommentControl();
                    pcc.SetCommentObject(bc);
                    pcc.Margin = new Thickness(3.0);
                    pcc.XLabel.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
                    {
                        BasicComment toRemove = pcc.CommentObject as BasicComment;
                        int          index    = dfa.Comments.IndexOf(toRemove);

                        // Add an undo that will re-insert the comment that we're about to delete
                        m_workspace.AddUndo(new UndoRedoCollection(
                                                "Undo deletion of comment for degrees of freedom analysis",
                                                new Logic.Undos.InsertBasicComment(toRemove, dfa.Comments, index)));

                        // Now delete the comment
                        m_workspace.DegreesOfFreedomAnalysis.Comments.Remove(pcc.CommentObject as BasicComment);
                    };
                    sp.Children.Add(pcc);
                }

                // Add a button to allow addition of more comments
                Button btn = new Button();
                btn.Margin = new Thickness(3.0);
                Image btnIcon = Core.App.CreateImageFromSource("plus_16x16.png");
                btnIcon.Width = btnIcon.Height = 16;
                btn.Content   = btnIcon;
                btn.Click    += new RoutedEventHandler(AddDFCommentButtonClick);
                sp.Children.Add(btn);

                CommentsStack.Children.Add(brdr);
            }
        }
Пример #5
0
 public InsertBasicComment(BasicComment comment, IList <BasicComment> collection, int index)
 {
     m_comment  = comment;
     m_comments = collection;
     m_index    = index;
 }
Пример #6
0
        public void SetCommentObject(StickyNote comment, object parent)
        {
            if (null != m_sticky)
            {
                // Remove event handler before changing this value
                m_sticky.PropertyChanged -= this.StickyNote_PropertyChanged;
            }
            if (null != m_basic)
            {
                m_basic.OnTextChanged -= this.BasicComment_OnTextChanged;
            }

            // IMPORTANT: Unsubscribe from parent control property changes (if applicable)
            if (null != m_parentObject)
            {
                if (m_parentObject is AbstractProcessUnit)
                {
                    (m_parentObject as AbstractProcessUnit).PropertyChanged -= this.ParentPU_PropertyChanged;
                }
                else if (m_parentObject is AbstractStream)
                {
                    (m_parentObject as AbstractStream).PropertyChanged -= this.ParentStream_PropertyChanged;
                }
            }

            // Store references
            m_basic        = null;
            m_sticky       = comment;
            m_parentObject = parent;

            AbstractStream      parentStream = parent as AbstractStream;
            AbstractProcessUnit parentAPU    = parent as AbstractProcessUnit;

            // Update the UI elements if the comment is not null
            if (null != m_sticky)
            {
                CommentTextBox.Text   = m_sticky.Text;
                UserNameLabel.Content = m_sticky.UserName;

                // Subsribe to property changes
                m_sticky.PropertyChanged += this.StickyNote_PropertyChanged;

                // Allow editing but not deletion
                CommentTextBox.IsReadOnly = false;
                XLabel.Visibility         = System.Windows.Visibility.Collapsed;

                // Show or hide the icon based on the parent
                if (null != parentStream)
                {
                    // Get the right icon for this type of stream
                    string      iconSource = PFD.Streams.StreamControl.GetIconSource(parent.GetType());
                    BitmapImage bmp        = new BitmapImage();
                    bmp.UriSource = new Uri(iconSource, UriKind.Relative);
                    IconImage.SetValue(Image.SourceProperty, bmp);

                    // Make sure the icon is visible
                    IconImage.Visibility = System.Windows.Visibility.Visible;
                    TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0);

                    // Give the icon a tooltip that tells what this is a comment for
                    ToolTipService.SetToolTip(IconImage, "Comment for stream #" +
                                              parentStream.Id);

                    // Subscribe to property changes for the stream
                    parentStream.PropertyChanged += new PropertyChangedEventHandler(ParentStream_PropertyChanged);
                }
                else if (null != parentAPU)
                {
                    // Get the right icon for this type of process unit
                    string      iconSource = ProcessUnitControl.GetIconSource(parent.GetType());
                    BitmapImage bmp        = new BitmapImage();
                    bmp.UriSource = new Uri(iconSource, UriKind.Relative);
                    IconImage.SetValue(Image.SourceProperty, bmp);

                    // Make sure the icon is visible
                    IconImage.Visibility = System.Windows.Visibility.Visible;
                    TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(20.0);

                    // Give the icon a tooltip that tells what this is a comment for
                    ToolTipService.SetToolTip(IconImage, "Comment for " +
                                              (m_parentObject as AbstractProcessUnit).Label);

                    // Subscribe to property changes for the process unit
                    parentAPU.PropertyChanged += new PropertyChangedEventHandler(ParentPU_PropertyChanged);
                }
                else
                {
                    // Make sure the icon is hidden
                    IconImage.Visibility = System.Windows.Visibility.Collapsed;
                    TitleBarGrid.ColumnDefinitions[0].Width = new GridLength(0.0);
                }
            }
        }