/// <summary> /// Cleans up all infobars on the selected control. /// </summary> /// <param name="parent">The parent.</param> /// <remarks>Documented by Dev02, 2008-05-21</remarks> public static void CleanUpInfobars(Control parent) { if (parent != null) { foreach (Control control in parent.Controls) { if (control is InfoBar) { InfoBar bar = (InfoBar)control; bar.ParentControlsLayoutSuspended = false; bar.Visible = false; bar.Dispose(); } } } }
/// <summary> /// Handles the UserDialog event of the learnlogic control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MLifter.BusinessLayer.UserDialogEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-05-21</remarks> void learnlogic_UserDialog(object sender, UserDialogEventArgs e) { if (e is UserNotifyDialogEventArgs) { UserNotifyDialogEventArgs args = (UserNotifyDialogEventArgs)e; string message = string.Empty; bool dontShowAgainMessage = false; switch (args.dialogkind) { case UserNotifyDialogEventArgs.NotifyDialogKind.PoolEmpty: message = Properties.Resources.POOL_EMPTY_TEXT; break; case UserNotifyDialogEventArgs.NotifyDialogKind.NotEnoughMultipleChoices: message = string.Format(Properties.Resources.MULTIPLE_CHOICE_TEXT, e.dictionary.Settings.MultipleChoiceOptions.NumberOfChoices.Value); break; case UserNotifyDialogEventArgs.NotifyDialogKind.SelectedLearnModeNotAllowed: if (Settings.Default.DontShowSelectedLearnModeNotAllowedMessage) break; dontShowAgainMessage = true; //[ML-2115] LearnModes for Infobar not localized message = string.Format(Properties.Resources.SELECTED_LEARNMODE_NOT_ALLOWED, (e.OptionalParamter is MLifter.BusinessLayer.LearnModes) ? Resources.ResourceManager.GetString("LEARNING_MODE_" + e.OptionalParamter.ToString().ToUpper()) : e.OptionalParamter); break; case UserNotifyDialogEventArgs.NotifyDialogKind.NoWords: //gets displayed in UserDialogComponent break; default: break; } if (!string.IsNullOrEmpty(message)) { InfoBar infobar; infobar = new InfoBar(message, answerPanel.InfoBarControl, DockStyle.Top, true, dontShowAgainMessage, answerPanel.AdditionalInfoBarSuspendControl); infobar.DontShowAgainChanged += new EventHandler(infobar_DontShowAgainChanged); } } }
/// <summary> /// Handles the CardStateChanged event of the learnlogic control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MLifter.BusinessLayer.CardStateChangedEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-04-23</remarks> void learnlogic_CardStateChanged(object sender, CardStateChangedEventArgs e) { Card card = e.dictionary.Cards.GetCardByID(e.cardid); //prepare title labels for either a new card, or the result in slideshow mode if (e is CardStateChangedNewCardEventArgs || (e is CardStateChangedShowResultEventArgs && ((CardStateChangedShowResultEventArgs)e).slideshow)) { string title = card != null ? card.CurrentAnswerCaption : string.Empty; if ((this.learnlogic == null) || (this.learnlogic.SlideShow == false)) { switch (e.dictionary.LearnMode) { case BusinessLayer.LearnModes.MultipleChoice: title = String.Format(Resources.MAINFORM_LBLANSWER_MULTI_TEXT, title); break; case BusinessLayer.LearnModes.Sentence: title = String.Format(Resources.MAINFORM_LBLANSWER_SENTENCES_TEXT, title); break; default: if (card.CurrentAnswer.Words.Count > 1) //in case of synonyms { title = String.Format(Resources.MAINFORM_LBLANSWER_DEFAULT_TEXT2, title, card.CurrentAnswer.Words.Count); } else { title = String.Format(Resources.MAINFORM_LBLANSWER_DEFAULT_TEXT1, title); } break; } } this.Title = title; } if (e is CardStateChangedNewCardEventArgs) { ComponentsHelper.IsResizing = true; //reset controls mLifterTextBox.Text = string.Empty; webBrowserAnswer.Stop(); MLifter.Components.InfoBar.CleanUpInfobars(InfoBarControl); if (generateAnswerThread != null && generateAnswerThread.IsAlive) { generateAnswerThread.Abort(); } //fix for [ML-1335] Problems with bidirectional Text (RTL languages) RightToLeft controlTextDirection = (e.dictionary.CurrentQueryDirection == EQueryDirection.Answer2Question ? card.BaseCard.Question.Culture : card.BaseCard.Answer.Culture).TextInfo.IsRightToLeft ? RightToLeft.Yes : RightToLeft.No; mLifterTextBox.RightToLeft = multipleChoice.RightToLeft = controlTextDirection; //switch main multipane according to current learn mode if (e.dictionary.LearnMode == BusinessLayer.LearnModes.MultipleChoice) { multiPaneControlMain.SelectedPage = multiPanePageMainMultipleChoice; BusinessLayer.MultipleChoice multipleChoiceQuery = e.dictionary.GetChoices(card.BaseCard); if (multipleChoiceQuery.Count > 0) { multipleChoice.Options = e.dictionary.CurrentMultipleChoiceOptions; multipleChoice.Show(multipleChoiceQuery); multipleChoice.Focus(); } } else { multiPaneControlMain.SelectedPage = multiPanePageMainTextbox; mLifterTextBox.IgnoreChars = e.dictionary.Settings.StripChars; mLifterTextBox.CaseSensitive = e.dictionary.Settings.CaseSensitive.Value; mLifterTextBox.CorrectOnTheFly = e.dictionary.Settings.CorrectOnTheFly.Value; mLifterTextBox.Synonyms = (e.dictionary.LearnMode == BusinessLayer.LearnModes.Sentence ? card.CurrentAnswerExample : card.CurrentAnswer).ToStringList(); //show synonym notification infobar if (mLifterTextBox.Synonyms.Count > 1 && learnlogic.SynonymInfoMessage) { string notificationText; if (e.dictionary.Settings.CorrectOnTheFly.Value) { notificationText = Resources.SYNONYM_PROMPT_FLY_TEXT; } else { notificationText = Resources.SYNONYM_PROMPT_TEXT; } MLifter.Components.InfoBar infobar = new MLifter.Components.InfoBar(notificationText, this.InfoBarControl, DockStyle.Top, true, true, gradientPanelAnswer); infobar.DontShowAgainChanged += new EventHandler(infobar_DontShowAgainChanged); } PositionTextBox(); mLifterTextBox.Focus(); } ComponentsHelper.IsResizing = false; Invalidate(); } else if (e is CardStateChangedShowResultEventArgs) { CardStateChangedShowResultEventArgs args = (CardStateChangedShowResultEventArgs)e; if (generateAnswerThread != null && generateAnswerThread.IsAlive) { generateAnswerThread.Abort(); } generateAnswerThread = new Thread(delegate() { this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserUrl = new Uri("about:blank"); //[ML-1621] Flicker in the answer result })); // WORKAROUND for Windows Media Player 6.4 [ML-2122] if (MLifter.Generics.Methods.IsWMP7OrGreater()) { Uri answer = MLifter.DAL.DB.DbMediaServer.DbMediaServer.PrepareAnswer(args.dictionary.DictionaryDAL.Parent, args.cardid, args.dictionary.GenerateAnswer(args.cardid, args.answer, args.promoted)); this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserUrl = answer; multiPaneControlMain.SelectedPage = multiPanePageMainViewer; if (!args.slideshow && e.dictionary.Settings.SelfAssessment.Value) { cardEventArgs = args;//this tag is needed for the submit of the answer } OnSetButtonFocus(e); })); } else { string content = args.dictionary.GenerateAnswer(args.cardid, args.answer, args.promoted); this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserContent = content; multiPaneControlMain.SelectedPage = multiPanePageMainViewer; if (!args.slideshow && e.dictionary.Settings.SelfAssessment.Value) { cardEventArgs = args;//this tag is needed for the submit of the answer } OnSetButtonFocus(e); })); } }); generateAnswerThread.IsBackground = true; generateAnswerThread.Name = "Generate Answer Thread"; generateAnswerThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; generateAnswerThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; generateAnswerThread.Start(); } else if (e is CardStateChangedCountdownTimerEventArgs) { //submit answers in case the timer is finished CardStateChangedCountdownTimerEventArgs args = (CardStateChangedCountdownTimerEventArgs)e; if (args.TimerFinished) { if (multiPaneControlMain.SelectedPage == multiPanePageMainTextbox) { mLifterTextBox.AllowAnswerSubmit = false; mLifterTextBox.ManualOnKeyPress(new KeyPressEventArgs((char)Keys.Enter)); mLifterTextBox.AllowAnswerSubmit = true; SubmitUserInput(); } else if (multiPaneControlMain.SelectedPage == multiPanePageMainMultipleChoice) { SubmitMultipleChoice(); } else if (learnlogic.SlideShow) { SubmitSlideShow(false); } } } }
/// <summary> /// Handles the CardStateChanged event of the learnlogic control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MLifter.BusinessLayer.CardStateChangedEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev02, 2008-04-23</remarks> void learnlogic_CardStateChanged(object sender, CardStateChangedEventArgs e) { Card card = e.dictionary.Cards.GetCardByID(e.cardid); //prepare title labels for either a new card, or the result in slideshow mode if (e is CardStateChangedNewCardEventArgs || (e is CardStateChangedShowResultEventArgs && ((CardStateChangedShowResultEventArgs)e).slideshow)) { string title = card != null ? card.CurrentAnswerCaption : string.Empty; if ((this.learnlogic == null) || (this.learnlogic.SlideShow == false)) { switch (e.dictionary.LearnMode) { case BusinessLayer.LearnModes.MultipleChoice: title = String.Format(Resources.MAINFORM_LBLANSWER_MULTI_TEXT, title); break; case BusinessLayer.LearnModes.Sentence: title = String.Format(Resources.MAINFORM_LBLANSWER_SENTENCES_TEXT, title); break; default: if (card.CurrentAnswer.Words.Count > 1) //in case of synonyms title = String.Format(Resources.MAINFORM_LBLANSWER_DEFAULT_TEXT2, title, card.CurrentAnswer.Words.Count); else title = String.Format(Resources.MAINFORM_LBLANSWER_DEFAULT_TEXT1, title); break; } } this.Title = title; } if (e is CardStateChangedNewCardEventArgs) { ComponentsHelper.IsResizing = true; //reset controls mLifterTextBox.Text = string.Empty; webBrowserAnswer.Stop(); MLifter.Components.InfoBar.CleanUpInfobars(InfoBarControl); if (generateAnswerThread != null && generateAnswerThread.IsAlive) generateAnswerThread.Abort(); //fix for [ML-1335] Problems with bidirectional Text (RTL languages) RightToLeft controlTextDirection = (e.dictionary.CurrentQueryDirection == EQueryDirection.Answer2Question ? card.BaseCard.Question.Culture : card.BaseCard.Answer.Culture).TextInfo.IsRightToLeft ? RightToLeft.Yes : RightToLeft.No; mLifterTextBox.RightToLeft = multipleChoice.RightToLeft = controlTextDirection; //switch main multipane according to current learn mode if (e.dictionary.LearnMode == BusinessLayer.LearnModes.MultipleChoice) { multiPaneControlMain.SelectedPage = multiPanePageMainMultipleChoice; BusinessLayer.MultipleChoice multipleChoiceQuery = e.dictionary.GetChoices(card.BaseCard); if (multipleChoiceQuery.Count > 0) { multipleChoice.Options = e.dictionary.CurrentMultipleChoiceOptions; multipleChoice.Show(multipleChoiceQuery); multipleChoice.Focus(); } } else { multiPaneControlMain.SelectedPage = multiPanePageMainTextbox; mLifterTextBox.IgnoreChars = e.dictionary.Settings.StripChars; mLifterTextBox.CaseSensitive = e.dictionary.Settings.CaseSensitive.Value; mLifterTextBox.IgnoreAccentChars = e.dictionary.Settings.IgnoreAccentChars.Value; mLifterTextBox.CorrectOnTheFly = e.dictionary.Settings.CorrectOnTheFly.Value; mLifterTextBox.Synonyms = (e.dictionary.LearnMode == BusinessLayer.LearnModes.Sentence ? card.CurrentAnswerExample : card.CurrentAnswer).ToStringList(); //show synonym notification infobar if (mLifterTextBox.Synonyms.Count > 1 && learnlogic.SynonymInfoMessage) { string notificationText; if (e.dictionary.Settings.CorrectOnTheFly.Value) notificationText = Resources.SYNONYM_PROMPT_FLY_TEXT; else notificationText = Resources.SYNONYM_PROMPT_TEXT; MLifter.Components.InfoBar infobar = new MLifter.Components.InfoBar(notificationText, this.InfoBarControl, DockStyle.Top, true, true, gradientPanelAnswer); infobar.DontShowAgainChanged += new EventHandler(infobar_DontShowAgainChanged); } PositionTextBox(); mLifterTextBox.Focus(); } ComponentsHelper.IsResizing = false; Invalidate(); } else if (e is CardStateChangedShowResultEventArgs) { CardStateChangedShowResultEventArgs args = (CardStateChangedShowResultEventArgs)e; if (generateAnswerThread != null && generateAnswerThread.IsAlive) generateAnswerThread.Abort(); generateAnswerThread = new Thread(delegate() { this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserUrl = new Uri("about:blank"); //[ML-1621] Flicker in the answer result })); // WORKAROUND for Windows Media Player 6.4 [ML-2122] if (MLifter.Generics.Methods.IsWMP7OrGreater()) { Uri answer = MLifter.DAL.DB.DbMediaServer.DbMediaServer.PrepareAnswer(args.dictionary.DictionaryDAL.Parent, args.cardid, args.dictionary.GenerateAnswer(args.cardid, args.answer, args.promoted)); this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserUrl = answer; multiPaneControlMain.SelectedPage = multiPanePageMainViewer; if (!args.slideshow && e.dictionary.Settings.SelfAssessment.Value) cardEventArgs = args;//this tag is needed for the submit of the answer OnSetButtonFocus(e); })); } else { string content = args.dictionary.GenerateAnswer(args.cardid, args.answer, args.promoted); this.Invoke(new MethodInvoker(delegate() { this.AnswerBrowserContent = content; multiPaneControlMain.SelectedPage = multiPanePageMainViewer; if (!args.slideshow && e.dictionary.Settings.SelfAssessment.Value) cardEventArgs = args;//this tag is needed for the submit of the answer OnSetButtonFocus(e); })); } }); generateAnswerThread.IsBackground = true; generateAnswerThread.Name = "Generate Answer Thread"; generateAnswerThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; generateAnswerThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; generateAnswerThread.Start(); } else if (e is CardStateChangedCountdownTimerEventArgs) { //submit answers in case the timer is finished CardStateChangedCountdownTimerEventArgs args = (CardStateChangedCountdownTimerEventArgs)e; if (args.TimerFinished) { if (multiPaneControlMain.SelectedPage == multiPanePageMainTextbox) { mLifterTextBox.AllowAnswerSubmit = false; mLifterTextBox.ManualOnKeyPress(new KeyPressEventArgs((char)Keys.Enter)); mLifterTextBox.AllowAnswerSubmit = true; SubmitUserInput(); } else if (multiPaneControlMain.SelectedPage == multiPanePageMainMultipleChoice) SubmitMultipleChoice(); else if (learnlogic.SlideShow) SubmitSlideShow(false); } } }