/// <summary> /// Main constructor for creating the window for studying flashcards. /// </summary> public StudyFlashcardSetWindow(MainWindow mainWindow) { InitializeComponent(); UpdateFlashcardUI(); this.mainWindow = mainWindow; currentFlashcardState = FlashcardState.Term; // Make the term be the first thing the user sees for the first flashcard loaded }
/// <summary> /// Event handler for when the item selection changes in the flashcard set list box. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the selection is changed.</param> private void FlashcardSetListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Update the current flashcard to the one selected currentFlashcardSet = (FlashcardSet)flashcardSetListBox.SelectedItem; currentFlashcardState = FlashcardState.Term; flashcardsListCurrentIndex = 0; UpdateFlashcardUI(); }
/// <summary> /// Toggles the current flashcard face between the term and definition. /// </summary> private void ToggleFlashcardFace() { if (currentFlashcardSet == null) { return; } currentFlashcardState = (currentFlashcardState == FlashcardState.Definition) ? FlashcardState.Term : FlashcardState.Definition; UpdateFlashcardUI(); }
/// <summary> /// Goes to the next flashcard in the current set (if there is one). /// </summary> private void NextFlashcard() { flashcardsListCurrentIndex++; if (flashcardsListCurrentIndex >= currentFlashcardSet.FlashcardsList.Count) { flashcardsListCurrentIndex = currentFlashcardSet.FlashcardsList.Count - 1; return; } currentFlashcardState = FlashcardState.Term; UpdateFlashcardUI(); }
/// <summary> /// Goes to the previous flashcard in the current set (if there is one). /// </summary> private void PreviousFlashcard() { flashcardsListCurrentIndex--; if (flashcardsListCurrentIndex < 0) { flashcardsListCurrentIndex = 0; return; } currentFlashcardState = FlashcardState.Term; UpdateFlashcardUI(); }
/// <summary> /// Event handler for when the "Unload Current Set" button is clicked. /// </summary> /// <param name="sender">The object that raised the event.</param> /// <param name="e">The event arguments for when the button is clicked.</param> private void UnloadCurrentSetButton_Click(object sender, RoutedEventArgs e) { if (flashcardSetListBox.Items.Count > 0) { int selectedIndex = flashcardSetListBox.Items.IndexOf(currentFlashcardSet); flashcardSetListBox.Items.RemoveAt(selectedIndex); if (flashcardSetListBox.Items.Count > 0) { flashcardSetListBox.SelectedIndex = 0; } else { currentFlashcardSet = null; } currentFlashcardState = FlashcardState.Term; flashcardsListCurrentIndex = 0; UpdateFlashcardUI(); } }