Пример #1
0
        private TreeNode generateTreeNode(List <Bookmark> lbm)
        {
            TreeNode parent = new TreeNode();

            for (int i = 0; i < lbm.Count(); i++)
            {
                if (lbm[i].children == null && lbm[i].folder != true)
                {
                    // Bookmark
                    TreeNode child = new TreeNode();
                    child.Text = lbm[i].name;

                    BookmarkTag tag = new BookmarkTag();
                    tag.url   = lbm[i].url;
                    tag.id    = currid++;
                    child.Tag = tag;

                    parent.Nodes.Add(child);
                }
                else
                {
                    TreeNode child = generateTreeNode(lbm[i].children.ToList());
                    child.Text = lbm[i].name;

                    BookmarkTag tag = new BookmarkTag();
                    tag.url   = null;
                    tag.id    = currid++;
                    child.Tag = tag;

                    parent.Nodes.Add(child);
                }
            }
            return(parent);
        }
Пример #2
0
 private void btnmodify_Click(object sender, EventArgs e)
 {
     if (treeview.Nodes.Count > 0)
     {
         if (treeview.Enabled)
         {
             if (treeview.SelectedNode.Text != "root")
             {
                 chkfolder.Enabled = false;
                 treeview.Enabled  = false;
                 btnadd.Enabled    = false;
                 btnremove.Enabled = false;
                 txtname.Text      = treeview.SelectedNode.Text;
                 BookmarkTag tag = (BookmarkTag)treeview.SelectedNode.Tag;
                 Debug.WriteLine(tag.url);
                 if (tag.url == null)
                 {
                     txturl.Enabled    = false;
                     chkfolder.Checked = true;
                 }
                 else
                 {
                     txturl.Text = tag.url;
                 }
                 btnmodify.Text = "Confirm";
             }
             else
             {
                 MessageBox.Show("Cannot modify root", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
         }
         else
         {
             if (txtname.Text != "root" || txtname.Text != "<Empty>" || txtname.Text.Trim() != "")
             {
                 treeview.SelectedNode.Text = txtname.Text;
                 if (((BookmarkTag)treeview.SelectedNode.Tag).url != null)
                 {
                     ((BookmarkTag)treeview.SelectedNode.Tag).url = txturl.Text;
                 }
             }
             else
             {
                 MessageBox.Show("Name cannot be root", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             chkfolder.Enabled = true;
             chkfolder.Checked = false;
             treeview.Enabled  = true;
             txtname.Text      = "";
             txturl.Enabled    = true;
             txturl.Text       = "";
             btnadd.Enabled    = true;
             btnremove.Enabled = true;
             btnmodify.Text    = "Modify";
         }
         updateLiveOutput();
     }
 }
Пример #3
0
        private TreeNode convertJsonToTreenode(string data)
        {
            List <Bookmark> lbm  = JsonConvert.DeserializeObject <List <Bookmark> >(data);
            TreeNode        root = generateTreeNode(lbm);

            root.Text = "root";

            BookmarkTag tag = new BookmarkTag();

            tag.url  = null;
            tag.id   = currid++;
            root.Tag = tag;

            treeview.Nodes.Clear();
            treeview.Nodes.Add(root);
            treeview.ExpandAll();
            updateLiveOutput();
            return(root);
        }
Пример #4
0
        private List <Object> outputObject(List <TreeNode> lbm)
        {
            List <Object> output = new List <Object>();

            if (lbm != null)
            {
                for (int i = 0; i < lbm.Count(); i++)
                {
                    Debug.WriteLine(lbm[i].Tag);
                    BookmarkTag tag = (BookmarkTag)lbm[i].Tag;
                    if (tag.url != null)
                    {
                        // Bookmark
                        if (!lbm[i].Text.Equals("<Empty>"))
                        {
                            BookmarkOutput parent = new BookmarkOutput();
                            Debug.WriteLine(lbm[i].Text);
                            parent.name = lbm[i].Text;
                            parent.url  = tag.url;
                            output.Add(parent);
                        }
                    }
                    else
                    {
                        // Folder
                        BookmarkFolderOutput parent = new BookmarkFolderOutput();
                        parent.name = lbm[i].Text;
                        List <TreeNode> nodes = new List <TreeNode>();
                        foreach (TreeNode t in lbm[i].Nodes)
                        {
                            nodes.Add(t);
                        }
                        List <Object> children = outputObject(nodes);
                        parent.children = children.ToArray();
                        output.Add(parent);
                    }
                }
            }
            return(output);
        }
Пример #5
0
        private void btnadd_Click(object sender, EventArgs e)
        {
            if (treeview.Nodes.Count > 0)
            {
                TreeNode selected = treeview.SelectedNode;
                string   name     = txtname.Text;
                string   url      = txturl.Text;

                if (selected != null)
                {
                    if (name != "root" && name.Trim() != "" && name != "<Empty>")
                    {
                        if (chkfolder.Checked)
                        {
                            // Folder
                            if (((BookmarkTag)selected.Tag).url == null || selected.Text == "<Empty>")
                            {
                                if (selected.Text == "<Empty>")
                                {
                                    selected = selected.Parent;
                                }
                                TreeNode newNode = new TreeNode();
                                newNode.Text = name;

                                BookmarkTag tag = new BookmarkTag();
                                tag.id      = currid++;
                                tag.url     = null;
                                newNode.Tag = tag;

                                TreeNode emptyNode = new TreeNode();
                                emptyNode.Text = "<Empty>";
                                BookmarkTag emptytag = new BookmarkTag();
                                emptytag.url  = "";
                                emptytag.id   = currid++;
                                emptyNode.Tag = emptytag;
                                newNode.Nodes.Add(emptyNode);

                                if (selected.Nodes.Count == 1)
                                {
                                    if (selected.Nodes[0].Text == "<Empty>")
                                    {
                                        selected.Nodes.Clear();
                                    }
                                }
                                newNode.ExpandAll();
                                selected.Nodes.Add(newNode);
                                treeview.SelectedNode = newNode;
                            }
                            else
                            {
                                MessageBox.Show("Can't add a bookmark to a non-folder", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            // Bookmark
                            if (((BookmarkTag)selected.Tag).url == null || selected.Text == "<Empty>")
                            {
                                if (selected.Text == "<Empty>")
                                {
                                    selected = selected.Parent;
                                }
                                TreeNode newNode = new TreeNode();
                                newNode.Text = name;

                                BookmarkTag tag = new BookmarkTag();
                                tag.id      = currid++;
                                tag.url     = url;
                                newNode.Tag = tag;
                                if (selected.Nodes.Count == 1)
                                {
                                    if (selected.Nodes[0].Text == "<Empty>")
                                    {
                                        selected.Nodes.Clear();
                                    }
                                }
                                selected.Nodes.Add(newNode);
                            }
                            else
                            {
                                MessageBox.Show("Can't add a bookmark to a non-folder", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Name cannot be root or blank", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                updateLiveOutput();
            }
        }