/// <summary> /// Adds the newly created question to the currently loaded subject. /// </summary> private void addNewQuestion() { Debug.Assert(editingQuestion == null); //confirm that user wants to add a new question and not edit an existing one QuestionCard qCard = new QuestionCard(questionText.Rtf, answerText.Rtf, acknowledgmentsText.Rtf, questionImageFull, answerImageFull); SubjectControl.addQuestionCard(qCard); Debug.Assert(RuntimeData.CurrentlyLoadedSubject.checkForCard(qCard)); //confirm card has been added to the subject }
/// <summary> /// Remove a card in the subject, if present. /// </summary> /// <param name="card">Card to remove</param> public bool removeCard(QuestionCard card) { if (checkForCard(card)) //card is present in the subject { cards.Remove(card.FlavourText); return true; } return false; }
//Create a new AddQuestion box with text field equal to the question card passed as parameter, i.e. editing an existing card public AddQuestion(QuestionCard card) { InitializeComponent(); questionText.Rtf = card.QuestionText; answerText.Rtf = card.AnswerText; acknowledgmentsText.Rtf = card.AcknowledgementsText; questionImageFull = card.QuestionImage; answerImageFull = card.AnswerImage; editingQuestion = card; setPreviewImage(attachImageButtonQuestion); setPreviewImage(attachImageButtonAnswer); }
/// <summary> /// Adds a QuestionCard to the currently loaded subject. /// </summary> /// <param name="card">The QuestionCard object to add.</param> public static void addQuestionCard(QuestionCard card) { refreshMainWindow(); if (mainWindow.addToCardMap(card)) { if (RuntimeData.CurrentlyLoadedSubject.checkForCard(card)) { RuntimeData.CurrentlyLoadedSubject.removeCard(card); } RuntimeData.CurrentlyLoadedSubject.addCard(card); RuntimeData.UnsavedChanges = true; notify(); } }
/// <summary> /// Swaps one question card in the currently loaded subject for another. /// </summary> /// <param name="card">The QuestionCard object to add.</param> public static void changeQuestionCard(QuestionCard oldCard, QuestionCard newCard) { refreshMainWindow(); //NB: The methods addQuestionCard() and removeQuestionCard() are not called because this would result in notify() being called twice, slowing the operation down. //remove the old card from the list. RuntimeData.CurrentlyLoadedSubject.removeCard(oldCard); mainWindow.removeFromCardMap(oldCard); //adds the new card to the list. RuntimeData.CurrentlyLoadedSubject.addCard(newCard); mainWindow.addToCardMap(newCard); RuntimeData.UnsavedChanges = true; notify(); }
/// <summary> /// Add a question card to the card map. /// </summary> /// <param name="card">The question card to add.</param> public bool addToCardMap(QuestionCard card) { if (cardMap.ContainsKey(card.FlavourText)) { if (MessageBox.Show("The same question already exists. Overwrite?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) { cardMap.Remove(card.FlavourText); cardMap.Add(card.FlavourText, card); return true; } else { return false; } } else { cardMap.Add(card.FlavourText, card); return true; } }
public ViewQuestion(QuestionCard cardToView) { card = cardToView; Text = card.FlavourText; InitializeComponent(); questionText.Rtf = card.QuestionText; answerText.Rtf = card.AnswerText; acknowledgmentsText.Rtf = card.AcknowledgementsText; if (card.QuestionImage != null) { Image questionThumbnail = Imagery.resizeImageToSquareThumbnail(card.QuestionImage, pictureBoxQuestion.Width); pictureBoxQuestion.Size = questionThumbnail.Size; pictureBoxQuestion.Image = questionThumbnail; } if (card.AnswerImage != null) { Image answerThumbnail = Imagery.resizeImageToSquareThumbnail(card.AnswerImage, pictureBoxAnswer.Width); pictureBoxAnswer.Size = answerThumbnail.Size; pictureBoxAnswer.Image = answerThumbnail; } hasAcknowledgements = !String.IsNullOrEmpty(acknowledgmentsText.Text); if (!hasAcknowledgements) { //hide empty (and therefore useless acknowledgements box) acknowledgementsBox.Visible = false; //'pull up' show/hide button accordingly viewAnswerButton.Location = new Point(viewAnswerButton.Location.X, viewAnswerButton.Location.Y - acknowledgementsBox.Height); //resize window to remove resultant white space this.Height -= acknowledgementsBox.Height; } //wouldn't really make sense if the answer was shown immediately, now would it? hideAnswer(); }
/// <summary> /// Removes a QuestionCard from the currently loaded subject. /// </summary> /// <param name="card">The QuestionCard object to remove.</param> public static void removeQuestionCard(QuestionCard card) { refreshMainWindow(); RuntimeData.CurrentlyLoadedSubject.removeCard(card); mainWindow.removeFromCardMap(card); RuntimeData.UnsavedChanges = true; notify(); }
/// <summary> /// Construct a QuestionCard identical to the one passed as parameter. /// </summary> /// <param name="card"></param> public QuestionCard(QuestionCard card) : this(card.questionText, card.answerText, card.acknowledgementsText, card.QuestionImage, card.AnswerImage) { //deliberately left blank }
/// <summary> /// Check for the presence of a card in this subject. /// </summary> /// <param name="card">Card to check for</param> /// <returns>true if present in the subject, false if not</returns> public bool checkForCard(QuestionCard card) { return cards.ContainsKey(card.FlavourText); }
/// <summary> /// Add a QuestionCard to this subject. /// </summary> /// <param name="card">QuestionCard to add.</param> public void addCard(QuestionCard card) { cards.Add(card.FlavourText, card); }
/// <summary> /// Remove a question card from the card map. /// </summary> /// <param name="card">The question card to remove.</param> /// <returns>true if the card was present and is removed, false otherwise.</returns> public bool removeFromCardMap(QuestionCard card) { if (cardMap.ContainsKey(card.FlavourText)) { cardMap.Remove(card.FlavourText); return true; } else { return false; } }
private bool checkForPresence(Subject s, QuestionCard c) { return s.checkForCard(c); }
//Create a new AddQuestion box with blank text fields, i.e. creating a new question card. public AddQuestion() { InitializeComponent(); editingQuestion = null; }
/// <summary> /// Finalises the changes for the question being edited. /// </summary> private void editExistingQuestion() { Debug.Assert(editingQuestion != null); //confirm that user wants to edit an existing question and not add a new one QuestionCard outputQuestion = new QuestionCard(editingQuestion); outputQuestion.QuestionText = questionText.Rtf; outputQuestion.AnswerText = answerText.Rtf; outputQuestion.AcknowledgementsText = acknowledgmentsText.Rtf; outputQuestion.QuestionImage = questionImageFull; outputQuestion.AnswerImage = answerImageFull; SubjectControl.changeQuestionCard(editingQuestion, outputQuestion); Debug.Assert(!RuntimeData.CurrentlyLoadedSubject.checkForCard(editingQuestion)); //confirm old card has been removed from the subject Debug.Assert(RuntimeData.CurrentlyLoadedSubject.checkForCard(outputQuestion)); //confirm new card has been added to the subject }