/// <summary> /// Append views for comments from a Graph /// </summary> private void AddCommentViews(IEnumerable <Comment> comments) { foreach (var comment in comments) { var commentView = new CommentView(comment); commentViews.Add(commentView); AddElement(commentView); Dirty(commentView); } }
/// <summary> /// Remove a comment from both the canvas view and the graph model /// </summary> public void RemoveComment(CommentView comment) { Undo.RegisterCompleteObjectUndo(Graph, "Delete Comment"); // Remove the model Graph.Comments.Remove(comment.Target); serializedGraph.Update(); EditorUtility.SetDirty(Graph); // Remove the view RemoveElement(comment); commentViews.Remove(comment); }
/// <summary> /// Remove a comment from both the canvas view and the graph model /// </summary> /// <param name="comment"></param> public void RemoveComment(CommentView comment) { Undo.RegisterCompleteObjectUndo(m_Graph, "Delete Comment"); Debug.Log($"-comment {comment.target.title}"); // Remove from the model m_Graph.comments.Remove(comment.target); m_SerializedGraph.Update(); EditorUtility.SetDirty(m_Graph); RemoveElement(comment); m_CommentViews.Remove(comment); }
/// <summary> /// Add a new comment to the canvas and the associated Graph /// /// If there are selected nodes, this'll encapsulate the selection with /// the comment box. Otherwise, it'll add at defaultPosition. /// </summary> private void AddComment() { Undo.RegisterCompleteObjectUndo(Graph, "Add Comment"); // Pad out the bounding box a bit more on the selection var padding = 30f; // TODO: Remove hardcoding var bounds = GetBounds(selection); if (bounds.width < 1 || bounds.height < 1) { Vector2 worldPosition = contentViewContainer.WorldToLocal(lastMousePosition); bounds.x = worldPosition.x; bounds.y = worldPosition.y; // TODO: For some reason CSS minWidth/minHeight isn't being respected. // Maybe I need to wait for CSS to load before setting bounds? bounds.width = 150 - (padding * 2); bounds.height = 100 - (padding * 3); } bounds.x -= padding; bounds.y -= padding * 2; bounds.width += padding * 2; bounds.height += padding * 3; // Add the model var comment = new Comment(); comment.Text = "New Comment"; comment.Region = bounds; Graph.Comments.Add(comment); serializedGraph.Update(); EditorUtility.SetDirty(Graph); // Add the view var commentView = new CommentView(comment); commentViews.Add(commentView); AddElement(commentView); Dirty(commentView); // Focus the title editor on first load commentView.EditTitle(); }
/// <summary> /// Add a new comment to the canvas and the associated Graph /// /// If there are selected nodes, this'll encapsulate the selection with /// the comment box. Otherwise, it'll add at defaultPosition. /// </summary> void AddComment() { Undo.RegisterCompleteObjectUndo(m_Graph, "Add Comment"); Debug.Log("+comment"); // Pad out the bounding box a bit more on the selection float padding = 30; // TODO: Remove hardcoding Rect bounds = GetBounds(selection); if (bounds.width < 1 || bounds.height < 1) { Vector2 worldPosition = contentViewContainer.WorldToLocal(m_LastMousePosition); bounds.x = worldPosition.x; bounds.y = worldPosition.y; // TODO: For some reason CSS minWidth/minHeight isn't being respected. // Maybe I need to wait for CSS to load before setting bounds? bounds.width = 150 - padding * 2; bounds.height = 100 - padding * 3; } bounds.x -= padding; bounds.y -= padding * 2; bounds.width += padding * 2; bounds.height += padding * 3; var comment = new Comment(); comment.title = "New Comment"; comment.graphRect = bounds; var commentView = new CommentView(comment); commentView.onResize += Dirty; // Add to the model m_Graph.comments.Add(comment); m_SerializedGraph.Update(); EditorUtility.SetDirty(m_Graph); m_CommentViews.Add(commentView); AddElement(commentView); Dirty(commentView); }