Пример #1
0
        private void listView_ItemDrag(object sender, ItemDragEventArgs e)
        {
            if (listView.SelectedItems.Count > 0 && e.Button == MouseButtons.Left)
            {
                DrapDropItem dragDropItem = new DrapDropItem();

                TreeNode selectedNode = treeView.SelectedNode;

                if (selectedNode != null)
                {
                    Bookmarks.Folder folder = selectedNode.Tag as Bookmarks.Folder;
                    if (folder != null)
                    {
                        foreach (ListViewItem item in listView.SelectedItems)
                        {
                            Bookmarks.BookmarkBase bb = item.Tag as Bookmarks.BookmarkBase;

                            if (bb != null)
                            {
                                dragDropItem.Items.Add(bb);
                            }
                        }

                        dragDropItem.Folder = folder;
                        treeView.DoDragDrop(dragDropItem, DragDropEffects.Move);
                    }
                }
            }
        }
Пример #2
0
        private void treeView_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DrapDropItem)))
            {
                TreeNode node = GetTreeNode(e.X, e.Y);
                if (node != null)
                {
                    DrapDropItem data = (DrapDropItem)e.Data.GetData(typeof(DrapDropItem));

                    Bookmarks.Folder folder = node.Tag as Bookmarks.Folder;
                    if (folder != null && data.Folder != folder)
                    {
                        foreach (Bookmarks.BookmarkBase bb in data.Items)
                        {
                            Bookmarks.Bookmark b = bb as Bookmarks.Bookmark;

                            if (b != null)
                            {
                                data.Folder.Items.Remove(b);
                                folder.Items.Add(b);
                            }
                            else
                            {
                                MessageBox.Show("フォルダはフォルダにドロップできません:" + bb.Name);
                            }
                        }

                        UpdateTreeView();
                        SelectNode(folder);
                    }
                }
            }
        }
Пример #3
0
        private void SelectNode(Bookmarks.Folder folder)
        {
            TreeNode node = FindNode(folder);

            if (node != null)
            {
                treeView.SelectedNode = node;
            }
        }
Пример #4
0
        private void listView_DoubleClick(object sender, EventArgs e)
        {
            if (listView.SelectedItems.Count > 0)
            {
                ListViewItem selectedItem = listView.SelectedItems[0];

                Bookmarks.Folder folder = selectedItem.Tag as Bookmarks.Folder;

                if (folder != null)
                {
                    SelectNode(folder);
                }
            }
        }
Пример #5
0
        private void AddTreeNodes(TreeNode node, Bookmarks.Folder folder)
        {
            foreach (Bookmarks.BookmarkBase bb in folder.Items)
            {
                Bookmarks.Folder childFolder = bb as Bookmarks.Folder;

                if (childFolder != null)
                {
                    TreeNode childNode = node.Nodes.Add(childFolder.Name);

                    childNode.Tag = childFolder;
                    AddTreeNodes(childNode, childFolder);
                }
            }
        }
Пример #6
0
        private TreeNode FindNode(TreeNode node, Bookmarks.Folder folder)
        {
            if (node.Tag == folder)
            {
                return(node);
            }

            foreach (TreeNode childNode in node.Nodes)
            {
                TreeNode n = FindNode(childNode, folder);
                if (n != null)
                {
                    return(n);
                }
            }
            return(null);
        }
Пример #7
0
        public void UpdateUI()
        {
            isUpdatingUI = true;

            try
            {
                bool nameEnabled = false;
                bool urlEnabled  = false;

                if (listView.SelectedItems.Count > 0)
                {
                    ListViewItem selectedItem = listView.SelectedItems[0];

                    Bookmarks.Folder childFolder = selectedItem.Tag as Bookmarks.Folder;

                    if (childFolder != null)
                    {
                        nameEnabled      = true;
                        textBoxName.Text = childFolder.Name;
                        textBoxURL.Text  = "";
                    }

                    Bookmarks.Bookmark bookmark = selectedItem.Tag as Bookmarks.Bookmark;

                    if (bookmark != null)
                    {
                        nameEnabled      = true;
                        textBoxName.Text = bookmark.Name;

                        urlEnabled      = true;
                        textBoxURL.Text = bookmark.URL;
                    }
                }

                labelName.Enabled   = nameEnabled;
                labelURL.Enabled    = urlEnabled;
                textBoxName.Enabled = nameEnabled;
                textBoxURL.Enabled  = urlEnabled;
            }
            finally
            {
                isUpdatingUI = false;
            }
        }
Пример #8
0
        private void toolStripMenuItemAddBookmak_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeView.SelectedNode;

            if (selectedNode != null)
            {
                Bookmarks.Folder folder = selectedNode.Tag as Bookmarks.Folder;
                if (folder != null)
                {
                    folder.Items.Add(new Bookmarks.Bookmark());

                    UpdateListView();
                    int count = listView.Items.Count;
                    if (count > 0) //0なわけないけど
                    {
                        //今追加したところを選択状態に
                        listView.Items[count - 1].Selected = true;
                    }
                }
            }
        }
Пример #9
0
        public void UpdateListView()
        {
            listView.Items.Clear();
            TreeNode selectedNode = treeView.SelectedNode;

            if (selectedNode != null)
            {
                Bookmarks.Folder folder = selectedNode.Tag as Bookmarks.Folder;
                if (folder != null)
                {
                    foreach (Bookmarks.BookmarkBase bb in folder.Items)
                    {
                        Bookmarks.Folder childFolder = bb as Bookmarks.Folder;

                        if (childFolder != null)
                        {
                            ListViewItem item = listView.Items.Add("");

                            item.SubItems.Add("");
                            item.Tag = childFolder;
                            UpdateListViewItem(item);
                        }

                        Bookmarks.Bookmark bookmark = bb as Bookmarks.Bookmark;

                        if (bookmark != null)
                        {
                            ListViewItem item = listView.Items.Add("");

                            item.Tag = bookmark;
                            item.SubItems.Add("");
                            item.SubItems.Add("");
                            UpdateListViewItem(item);
                        }
                    }
                }
            }
            UpdateUI();
        }
Пример #10
0
        private void UpdateListViewItem(ListViewItem item)
        {
            Bookmarks.Folder childFolder = item.Tag as Bookmarks.Folder;

            if (childFolder != null)
            {
                item.SubItems[1].Text = childFolder.Name;
                item.ImageIndex       = 0;
                TreeNode node = FindNode(childFolder);
                if (node != null)
                {
                    node.Text = childFolder.Name;
                }
            }

            Bookmarks.Bookmark bookmark = item.Tag as Bookmarks.Bookmark;

            if (bookmark != null)
            {
                item.SubItems[1].Text = bookmark.Name;
                item.SubItems[2].Text = bookmark.URL;
            }
        }
Пример #11
0
        private void toolStripMenuItemAddFolder_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeView.SelectedNode;

            if (selectedNode != null)
            {
                Bookmarks.Folder folder = selectedNode.Tag as Bookmarks.Folder;
                if (folder != null)
                {
                    FormAddBookmarkFolder form = new FormAddBookmarkFolder();

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        Bookmarks.Folder newFolder = new Bookmarks.Folder();

                        newFolder.Name = form.FolderName;
                        folder.Items.Add(newFolder);

                        UpdateTreeView();
                        SelectNode(newFolder);
                    }
                }
            }
        }
Пример #12
0
        private void UpdateBookmark()
        {
            if (listView.SelectedItems.Count > 0)
            {
                ListViewItem selectedItem = listView.SelectedItems[0];

                Bookmarks.Folder childFolder = selectedItem.Tag as Bookmarks.Folder;

                if (childFolder != null)
                {
                    childFolder.Name = textBoxName.Text;
                }

                Bookmarks.Bookmark bookmark = selectedItem.Tag as Bookmarks.Bookmark;

                if (bookmark != null)
                {
                    bookmark.Name = textBoxName.Text;
                    bookmark.URL  = textBoxURL.Text;
                }

                UpdateListViewItem(selectedItem);
            }
        }
Пример #13
0
        private void toolStripMenuItemDelete_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeView.SelectedNode;

            if (selectedNode != null)
            {
                Bookmarks.Folder folder = selectedNode.Tag as Bookmarks.Folder;
                if (folder != null)
                {
                    foreach (ListViewItem item in listView.SelectedItems)
                    {
                        Bookmarks.BookmarkBase bb = item.Tag as Bookmarks.BookmarkBase;

                        if (bb != null)
                        {
                            folder.Items.Remove(bb);
                        }
                    }

                    UpdateTreeView();
                    SelectNode(folder);
                }
            }
        }
Пример #14
0
 private TreeNode FindNode(Bookmarks.Folder folder)
 {
     return(FindNode(treeView.Nodes[0], folder));
 }