コード例 #1
0
        /// <summary>
        /// Helper for avoiding refresh if Window is ICancellable and Cancelled
        /// </summary>
        /// <param name="window"></param>
        private void SetFilter(Window window)
        {
            if (window is ICancellable &&
                ((ICancellable)window).Cancelled)
            {
                return;
            }

            SetFilter(SelectedNode == null? null : SelectedNode.GetData());
        }
コード例 #2
0
        private void DeleteSelected()
        {
            try
            {
                if (SelectedNode == null)
                {
                    MessageBoxFactory.ShowError("No item selected");
                    return;
                }

                INodeData parent = null;

                if (SelectedNode.IsBook)
                {
                    Book bk = (Book)SelectedNode.GetData();

                    if (!MessageBoxFactory.ShowConfirmAsBool("Delete book and all notes for '" + bk.Title + "'?", "Delete Book"))
                    {
                        return;
                    }

                    parent = bk.DefaultTopic;
                    Util.DB.Books.Remove(bk);
                }
                else if (SelectedNode.IsNote)
                {
                    Note n = (Note)SelectedNode.GetData();
                    if (!MessageBoxFactory.ShowConfirmAsBool("Delete " + n.OriginalText + "'?", "Delete Note"))
                    {
                        return;
                    }

                    parent = n.Book;
                    Util.DB.Notes.Remove(n);
                }
                else if (SelectedNode.IsTopic)
                {
                    Util.DB.Topics.Remove((Topic)SelectedNode.GetData());
                }
                else
                {
                    throw new Exception("Type not supported: " + SelectedNode.GetDataType());
                }

                Util.DB.SaveChanges();
                SetFilter(parent);
            }
            catch (Exception e)
            {
                Util.DB.RejectChanges();
                MessageBoxFactory.ShowError(e);
            }
        }