예제 #1
0
        private void RemoveNode(object sender, RemoveNodeEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(e.IdToRemove))
            {
                return;
            }

            IModelType nodeToRemove          = GetModelTypeById(e.IdToRemove, _bookmarksTree);
            bool       isNodeToRemoveAFolder = nodeToRemove.GetType() == typeof(Folder);
            IModelType parentNode            = GetModelTypeById(nodeToRemove.ParentId, _bookmarksTree);
            bool       isParentAFolder       = parentNode == null ? true : parentNode.GetType() == typeof(Folder);

            if (!isParentAFolder)
            {
                return;
            }


            if (isNodeToRemoveAFolder)
            {
                bool isFolderEmpty = ((Folder)nodeToRemove).Children.Count() == 0;
                if (!isFolderEmpty)
                {
                    var diagResult = _dialogService.ShowMessageBox(
                        "Remove folder?", "Deleting this folder will delete all children. Continue?",
                        System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning
                        );

                    if (diagResult != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                }
            }
            else
            {
                var diagResult = _dialogService.ShowMessageBox(
                    "Delete node?", "There is no going back. Continue?",
                    System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning);
                if (diagResult != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
            }

            if (parentNode == null)
            {
                _bookmarksTree.Bookmarks.Remove(nodeToRemove);
            }
            else
            {
                Folder parentFolder = (Folder)GetModelTypeById(nodeToRemove.ParentId, _bookmarksTree);
                parentFolder.Children.Remove(nodeToRemove);
            }

            _view.RemoveNodeFromTree(e.IdToRemove);
            _bookmarksTree.WriteToFile("bookmarks.xml");
        }