/// <summary> /// Shows the form as a dialog and the specified comment. /// </summary> /// <param name="owner">The owner window.</param> /// <param name="comment">The comment.</param> /// <returns>The dialog result.</returns> public DialogResult ShowDialog(IWin32Window owner, CrawlerComment comment) { // If the comment is null, do nothing. if (null == comment) return DialogResult.Abort; // Set the comment. this.control.Comment = comment; // Set the title. switch (comment.Type) { case CrawlerComment.CommentType.Video: this.Text = "Comment for Video {0} Properties".FormatWith(comment.Item); break; case CrawlerComment.CommentType.User: this.Text = "Comment for User {0} Properties".FormatWith(comment.Item); break; case CrawlerComment.CommentType.Playlist: this.Text = "Comment for Playlist {0} Properties".FormatWith(comment.Item); break; default: this.Text = "Comment for Item {0} Properties".FormatWith(comment.Item); break; } // Open the dialog. return base.ShowDialog(owner); }
/// <summary> /// Initializes the control. /// </summary> /// <param name="comments">A crawler object.</param> public void Initialize(CrawlerCommentsList comments, CrawlerComment.CommentType commentType) { this.comments = comments; this.formAdd.CommentType = commentType; this.Enabled = true; if ((int)commentType < commentTypeHeader.Length) { this.columnHeaderItem.Text = ControlComments.commentTypeHeader[(int)commentType]; this.panelComments.Title = ControlComments.commentTypeTitle[(int)commentType]; } // Populate the comments list. foreach (CrawlerComment comment in this.comments) { // Add a new list view item. ListViewItem item = new ListViewItem(new string[] { comment.Time.ToString(), comment.Item, comment.User, comment.Text }, 0); item.Tag = comment; this.listView.Items.Add(item); } this.buttonExport.Enabled = this.listView.Items.Count > 0; }
/// <summary> /// An event handler called when a new comment has been added. /// </summary> /// <param name="comment">The comment.</param> private void OnAddComment(CrawlerComment comment) { try { // Add the comment to the comments list. this.comments.AddComment(comment); // Add a new list view item. ListViewItem item = new ListViewItem(new string[] { comment.Time.ToString(), comment.Item, comment.User, comment.Text }, 0); item.Tag = comment; this.listView.Items.Add(item); this.buttonExport.Enabled = true; } catch (Exception exception) { MessageBox.Show( "Cannot add the comment. {0}".FormatWith(exception.Message), "Cannot Add Comment", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// Protected methods. /// <summary> /// An event handler called when a new comment has been set. /// </summary> /// <param name="oldComment">The old comment.</param> /// <param name="newComment">The new comment.</param> protected virtual void OnCommentSet(CrawlerComment oldComment, CrawlerComment newComment) { // If the comment has not changed, do nothing. if (oldComment == newComment) return; if (null == newComment) { this.labelTitle.Text = "No comment selected"; this.pictureBox.Image = Resources.Comment_32; this.tabControl.Visible = false; } else { this.textBoxTime.Text = newComment.Time.ToString(); this.textBoxUser.Text = newComment.User; this.textBoxGuid.Text = newComment.Guid.ToString(); this.textBoxText.Text = newComment.Text; this.textBoxObject.Text = newComment.Item; this.tabControl.Visible = true; switch (newComment.Type) { case CrawlerComment.CommentType.Video: this.labelTitle.Text = "Comment for video {0}".FormatWith(newComment.Item); this.labelObject.Text = "&Video:"; this.pictureBox.Image = Resources.CommentVideo_32; break; case CrawlerComment.CommentType.User: this.labelTitle.Text = "Comment for user {0}".FormatWith(newComment.Item); this.labelObject.Text = "&User:"******"Comment for playlist {0}".FormatWith(newComment.Item); this.labelObject.Text = "&Playlist:"; this.pictureBox.Image = Resources.CommentPlay_32; break; default: this.labelTitle.Text = "Comment for item {0}".FormatWith(newComment.Item); this.labelObject.Text = "&Item:"; this.pictureBox.Image = Resources.Comment_32; break; } } this.tabControl.SelectedTab = this.tabPageGeneral; if (this.Focused) { this.textBoxTime.Select(); this.textBoxTime.SelectionStart = 0; this.textBoxTime.SelectionLength = 0; } }
/// <summary> /// Creates a new event instance. /// </summary> /// <param name="comment">The comment.</param> public CommentEventArgs(CrawlerComment comment) { this.Comment = comment; }