Exemple #1
0
        private void editCardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //make sure card is selected and get it
            ListViewItem selectedItem;

            if (listMain.SelectedItems.Count > 0)
            {
                selectedItem = listMain.SelectedItems[0];
            }
            else
            {
                return;
            }
            Card card = (Card)selectedItem.Tag;
            //editing form loaded with card in it
            //get edited card and save its data
            Card newCard = EditingView.GetCard(card, false);

            if (string.IsNullOrWhiteSpace(Helper.RtfToString(newCard.Front)) || string.IsNullOrWhiteSpace(Helper.RtfToString(newCard.Back)))
            {
                return; //don't edit
            }
            ((Subject)lastSelectedNode.Tag).Cards[((Subject)lastSelectedNode.Tag).Cards.IndexOf(card)] = newCard;
            ListViewItem item = new ListViewItem(Helper.RtfToString(newCard.Front));

            item.SubItems.Add(Helper.RtfToString(newCard.Back));
            item.SubItems.Add(newCard.SubjectTitle);
            item.Tag = newCard;
            listMain.Items.Insert(selectedItem.Index, item);
            selectedItem.Remove();
            //edited flag
            doEdited();
        }
Exemple #2
0
        private void newCardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //make sure subject is selected and get it
            if (lastSelectedNode == null)
            {
                Helper.ShowError("You must select a subject to work on cards with.");
                return;
            }
            //add card to list view and tag of selected node
            Card newCard = EditingView.GetCard();

            if (string.IsNullOrWhiteSpace(Helper.RtfToString(newCard.Front)) || string.IsNullOrWhiteSpace(Helper.RtfToString(newCard.Back)))
            {
                return; //don't edit
            }
            newCard.SubjectTitle = ((Subject)lastSelectedNode.Tag).Title;
            ListViewItem item = new ListViewItem(Helper.RtfToString(newCard.Front));

            item.SubItems.Add(Helper.RtfToString(newCard.Back));
            item.SubItems.Add(newCard.SubjectTitle);
            item.Tag = newCard;
            listMain.Items.Add(item);
            ((Subject)lastSelectedNode.Tag).Cards.Add(newCard);
            //edited flag
            doEdited();
        }
Exemple #3
0
        public static Card GetCard(Card oldCard = null, bool newCard = true)
        {
            EditingView editor = new EditingView();

            editor.isNewCard = newCard;
            string initialFrontText = newCard ? "" : oldCard.Front;
            string initialBackText  = newCard ? "" : oldCard.Back;

            editor.cardFrontRichTextBox.Rtf = initialFrontText;
            editor.cardBackRichTextBox.Rtf  = initialBackText;
            editor.ShowDialog();
            Card returnNewCard = new Card(editor.cardFrontRichTextBox.Rtf, editor.cardBackRichTextBox.Rtf);

            if (!newCard)
            {
                returnNewCard.SubjectTitle    = oldCard.SubjectTitle;
                returnNewCard.CorrectAttempts = oldCard.CorrectAttempts;
                returnNewCard.TotalAttempts   = oldCard.TotalAttempts;
            }
            return(returnNewCard);
        }