public ClozeHintOptions(string Hint, ClozeLocation ClozeLocation) { this.Hint = Hint; this.ClozeLocation = ClozeLocation; }
/// <summary> /// Create the cloze hint. /// TODO: Add proper UI locking when methods are available /// </summary> private void CreateClozeHint() { /// It is not currently possible to modify an SM element without it being /// the currently displayed SM Element. Therefore to add the cloze hint /// this first generates the cloze, then navigates to /// the new cloze element to modify it, then returns to the original element // Cancel if there is no currently selected text if (ContentUtils.GetSelectedText().IsNullOrEmpty()) { return; } var wdw = OpenClozeHintWdw(); if (wdw.IsNull()) { return; } ClozeLocation Location = wdw.Location; string Hint = wdw.Hint; if (Hint.IsNullOrEmpty()) { return; } // The current element we are executing GenerateCloze on int restoreElementId = Svc.SM.UI.ElementWdw.CurrentElementId; // The newly created element int newClozeId = Svc.SM.UI.ElementWdw.GenerateCloze(); if (newClozeId < 0) { string msg = "Failed to create cloze: GenerateCloze method failed."; MessageBox.Show(msg); LogTo.Debug(msg); return; } // Move to the new cloze, add the cloze hint Svc.SM.UI.ElementWdw.GoToElement(newClozeId); // TODO: Loop over htmlCtrls for the first control with a cloze symbol var htmlCtrl = ContentUtils.GetClozeHtmlControl(); var text = htmlCtrl?.Text; var htmlDoc = htmlCtrl?.GetDocument(); var body = htmlDoc?.body as IHTMLBodyElement; if (text.IsNullOrEmpty() || htmlCtrl.IsNull() || body.IsNull()) { string msg = "Failed to create cloze: Failed to get text from the generated item"; MessageBox.Show(msg); LogTo.Error(msg); return; } string replacement = Location == ClozeLocation.Inside ? $"[{Hint}]" : $"[...]({Hint})"; htmlCtrl.Text = htmlCtrl.Text.Replace("[...]", replacement); // Return to the parent element Svc.SM.UI.ElementWdw.GoToElement(restoreElementId); }