Пример #1
0
        private void PostView_SelectedItemChanged(object sender, EventArgs e)
        {
            if (PostView.SelectedNodes.Count == 0)
            {
                ShowTips();
                return;
            }

            PostViewNode node = PostView.SelectedNodes[0] as PostViewNode;

            if (node == null)
            {
                return;
            }

            PostViewNode parent = node.ParentNode() as PostViewNode;

            OpPost parentPost = null;

            if (parent != null)
            {
                parentPost = parent.Post;
            }

            ShowMessage(node.Post, parentPost);
        }
Пример #2
0
        private void PostView_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            PostViewNode node = PostView.GetNodeAt(e.Location) as PostViewNode;

            if (node == null)
            {
                return;
            }

            PostViewNode parent = node.ParentNode() as PostViewNode;

            OpPost replyTo = node.Post;

            if (parent != null)
            {
                replyTo = parent.Post;
            }

            ContextMenuStripEx menu = new ContextMenuStripEx();

            if (!replyTo.Header.Archived)
            {
                menu.Items.Add(new PostMenuItem("Reply", replyTo, (s, a) => ReplyPost(replyTo)));
            }

            if (node.Post.Header.SourceID == Core.UserID)
            {
                if (!replyTo.Header.Archived)
                {
                    menu.Items.Add(new PostMenuItem("Edit", node.Post, (s, a) => EditPost(node.Post)));
                    menu.Items.Add("-");
                }

                if (parent == null)
                {
                    if (node.Post.Header.Archived)
                    {
                        menu.Items.Add(new PostMenuItem("Restore", node.Post, (s, a) => Boards.Archive(node.Post, false)));
                    }
                    else
                    {
                        menu.Items.Add(new PostMenuItem("Archive", node.Post, (s, a) => Boards.Archive(node.Post, true)));
                    }
                }
            }

            menu.Show(PostView, e.Location);
        }
Пример #3
0
        private void BoardView_Load(object sender, EventArgs e)
        {
            if (PostView.Nodes.Count > 0)
            {
                PostViewNode node = PostView.Nodes[0] as PostViewNode;

                PostView.Select(node);
                ShowMessage(node.Post, null);
            }
            else
            {
                ShowTips();
            }
        }
Пример #4
0
        void OnNodeCollapsed(object sender, EventArgs e)
        {
            PostViewNode node = sender as PostViewNode;

            if (node == null)
            {
                return;
            }

            // remove nodes except for place holder
            node.Nodes.Clear();
            node.Nodes.Add(new TreeListNode());

            ActiveThreads.Remove(node.Post.Ident);
        }
Пример #5
0
        void OnNodeExpanding(object sender, EventArgs e)
        {
            PostViewNode node = sender as PostViewNode;

            if (node == null)
            {
                return;
            }

            node.Nodes.Clear(); // remove place holder

            ActiveThreads[node.Post.Ident] = new Dictionary <int, PostViewNode>();

            Boards.LoadThread(node.Post);
        }
Пример #6
0
        private void AddPostNode(TreeListNodeCollection list, PostViewNode add, bool lowToHigh)
        {
            int i = 0;

            foreach (PostViewNode node in list)
            {
                if (lowToHigh && add.Post.Header.Time < node.Post.Header.Time)
                {
                    list.Insert(i, add);
                    return;
                }

                if (!lowToHigh && add.Post.Header.Time > node.Post.Header.Time)
                {
                    list.Insert(i, add);
                    return;
                }

                i++;
            }

            list.Insert(i, add);
        }
Пример #7
0
        private void PostHeader_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            string url = e.Url.OriginalString;

            if (GuiUtils.IsRunningOnMono() && url.StartsWith("wyciwyg"))
            {
                return;
            }

            url = url.Replace("http://", "");
            url = url.TrimEnd('/');

            string[] parts = url.Split('/');

            if (parts.Length < 1)
            {
                return;
            }

            if (parts[0] == "about")
            {
                return;
            }

            if (PostView.SelectedNodes.Count == 0)
            {
                return;
            }

            PostViewNode node = PostView.SelectedNodes[0] as PostViewNode;

            if (node == null || node.Post == null)
            {
                return;
            }

            OpPost post = node.Post;

            if (parts[0] == "reply")
            {
                // replies are directed at parent
                PostViewNode parent = node.ParentNode() as PostViewNode;

                if (parent != null)
                {
                    post = parent.Post;
                }

                ReplyPost(post);
            }
            if (parts[0] == "edit")
            {
                EditPost(post);
            }

            if (parts[0] == "archive")
            {
                Boards.Archive(post, true);
            }

            if (parts[0] == "restore")
            {
                Boards.Archive(post, false);
            }

            if (parts[0] == "attach" && parts.Length > 1)
            {
                int index = int.Parse(parts[1]);

                if (index < post.Attached.Count)
                {
                    string path = Core.User.RootPath + Path.DirectorySeparatorChar +
                                  "Downloads" + Path.DirectorySeparatorChar + post.Attached[index].Name;

                    try
                    {
                        if (!File.Exists(path))
                        {
                            Utilities.ExtractAttachedFile(Boards.GetPostPath(post.Header),
                                                          post.Header.FileKey,
                                                          post.Header.FileStart,
                                                          post.Attached.Select(a => a.Size).ToArray(),
                                                          index,
                                                          path);
                        }

                        Process.Start(path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, "Error Opening Attachment: " + ex.Message);
                    }
                }
            }

            e.Cancel = true;
        }
Пример #8
0
        void Board_PostUpdate(OpPost post)
        {
            if (post == null)
            {
                RefreshBoard();

                return;
            }

            if (post.Header.ProjectID != ProjectID)
            {
                return;
            }

            if (post.Header.Archived != ArchiveButton.Checked)
            {
                return;
            }

            ScopeType level = ScopeType.All;
            bool      pass  = false;

            // check if belongs in list
            if (post.Header.TargetID == UserID)
            {
                if ((post.Header.Scope == ScopeType.High && CurrentScope == ScopeType.Low) ||
                    (post.Header.Scope == ScopeType.Low && CurrentScope == ScopeType.High))
                {
                    return; // pass fail
                }
                pass = true;
            }

            else if (CurrentScope != ScopeType.None)          // use else because local id is in highIDs
            {
                if (HighIDs.Contains(post.Header.TargetID) && // high user
                    CurrentScope != ScopeType.Low &&          // view filter
                    post.Header.Scope != ScopeType.High)      // post meant for high user's highers, not us
                {
                    pass  = true;
                    level = ScopeType.High;
                }

                else if (LowIDs.Contains(post.Header.TargetID) && // low user
                         CurrentScope != ScopeType.High &&        // view filter
                         post.Header.Scope != ScopeType.Low)      // post meant for low user's lowers, not us
                {
                    pass  = true;
                    level = ScopeType.Low;
                }
            }

            if (!pass)
            {
                return;
            }


            // parent thread
            if (post.Header.ParentID == 0)
            {
                PostViewNode node = null;

                if (!ThreadMap.ContainsKey(post.Ident))
                {
                    node = new PostViewNode(Boards, post, level, post.Header.Scope);
                    ThreadMap[post.Ident] = node;

                    AddPostNode(PostView.Nodes, node, false);
                }
                else
                {
                    node = ThreadMap[post.Ident];
                    node.Update(Boards, post);
                }

                if (node.Selected)
                {
                    ShowMessage(post, null);
                }
            }

            // reply - must be on active threads list to show
            else
            {
                OpBoard board = Boards.GetBoard(post.Header.TargetID);

                if (board == null)
                {
                    return;
                }

                PostUID parentUid = new PostUID(post.Header.TargetID, post.Header.ProjectID, post.Header.ParentID);

                OpPost parentPost = Boards.GetPost(post.Header.TargetID, parentUid);

                if (parentPost == null)
                {
                    return;
                }

                int parentIdent = parentPost.Ident;

                if (!ThreadMap.ContainsKey(parentIdent))
                {
                    return;
                }

                PostViewNode parent = ThreadMap[parentIdent];
                parent.Update(Boards, parentPost);


                // if post has replies, add an empty item below so it has an expand option
                if (!ActiveThreads.ContainsKey(parentIdent))
                {
                    if (parent.Nodes.Count == 0)
                    {
                        parent.Nodes.Add(new TreeListNode());
                    }

                    PostView.Invalidate();
                    return;
                }

                // else post is active
                PostViewNode replyNode = null;

                if (!ActiveThreads[parentIdent].ContainsKey(post.Ident))
                {
                    replyNode = new PostViewNode(Boards, post, ScopeType.All, ScopeType.All);

                    ActiveThreads[parentIdent][post.Ident] = replyNode;

                    AddPostNode(parent.Nodes, replyNode, true);
                }
                else
                {
                    replyNode = ActiveThreads[parentIdent][post.Ident];
                    replyNode.Update(Boards, post);
                }

                if (replyNode.Selected)
                {
                    ShowMessage(replyNode.Post, parent.Post);
                }

                PostView.Invalidate();
            }
        }