private static string RenderField(MultiText text, CurrentItemEventArgs currentItem, int sizeBoost, Field field) { var rtfBuilder = new StringBuilder(); if (text != null) { if (text.Count == 0 && currentItem != null && text == currentItem.DataTarget) { rtfBuilder.Append(RenderBlankPosition()); } if (field == null) // show them all { foreach (string id in WritingSystems.FilterForTextIds(text.Forms.Select(f => f.WritingSystemId))) { var form = text.Forms.First(f => f.WritingSystemId == id); RenderForm(text, currentItem, rtfBuilder, form, sizeBoost); } } else // show all forms turned on in the field { foreach (string id in field.WritingSystemIds.Intersect(text.Forms.Select(f => f.WritingSystemId))) { var form = text.Forms.First(f => f.WritingSystemId == id); RenderForm(text, currentItem, rtfBuilder, form, sizeBoost); } } } return(rtfBuilder.ToString()); }
void LogFocusChanged(object sender, CurrentItemEventArgs<IGitLogItem> e) { if (ItemSource != null && ItemSource.FocusedItem != null) logMessageEditor.Text = logItemSource.FocusedItem.LogMessage; else logMessageEditor.Text = ""; }
public static string ToHtml(LexEntry entry, CurrentItemEventArgs currentItem, LexEntryRepository lexEntryRepository, System.Drawing.Color backColor) { _fontFamilies = new List <string>(); _fontFamiliesStyle = new StringBuilder(); italicsOn = false; if (lexEntryRepository == null) { throw new ArgumentNullException("lexEntryRepository"); } if (entry == null) { return(string.Empty); } var html = new StringBuilder(); // The {0} is filled in by the setHtml method that consumes the html generated here // The {1} is filled in by the font-face sections created by AddFontFamily which are required by some fonts on Windows html.Append("<html><header><meta charset=\"UTF-8\"><style>{1}</style></head><body style='background:{0}' id='mainbody'><div style='min-height:20px' id='main' name='textArea' contentEditable='false'>"); RenderHeadword(entry, html, lexEntryRepository); int senseNumber = 1; foreach (LexSense sense in entry.Senses) { RenderSense(entry, sense, senseNumber, currentItem, html); ++senseNumber; } Field glossField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Gloss); if (glossField.IsMeaningField) { html.Append(RenderGhostedField(null, LexSense.WellKnownProperties.Gloss, currentItem, entry.Senses.Count + 1)); } else { html.Append(RenderGhostedField(null, LexSense.WellKnownProperties.Definition, currentItem, entry.Senses.Count + 1)); } html.Append("</div></body></html>"); String strHtmlColor = System.Drawing.ColorTranslator.ToHtml(backColor); var finalHtml = string.Format(html.ToString(), strHtmlColor, _fontFamiliesStyle); return(finalHtml.ToString()); }
private static void RenderExampleSentences(CurrentItemEventArgs currentItem, StringBuilder html, LexSense sense) { foreach (LexExampleSentence exampleSentence in sense.ExampleSentences) { italicsOn = true; html.Append(RenderField(exampleSentence.Sentence, currentItem)); italicsOn = false; html.Append(RenderField(exampleSentence.Translation, currentItem)); } }
private static void RenderExampleSentences(CurrentItemEventArgs currentItem, StringBuilder rtf, LexSense sense) { foreach (LexExampleSentence exampleSentence in sense.ExampleSentences) { rtf.Append(@" \i "); rtf.Append(RenderField(exampleSentence.Sentence, currentItem)); rtf.Append(@"\i0 "); rtf.Append(RenderField(exampleSentence.Translation, currentItem)); } }
private static bool IsCurrentField(MultiText text, LanguageForm l, CurrentItemEventArgs currentItem) { if (currentItem == null) { return(false); } return(currentItem.DataTarget == text && currentItem.WritingSystemId == l.WritingSystemId); }
private void StateManager_ItemSelected(object sender, CurrentItemEventArgs e) { if (StateSaver.Default.Get(Strings.RUN_SCHEDULETIME, false)) { var runAt = StateSaver.Default.Get <TimeSpan>(Strings.SCHEDULETIME, TimeSpan.Zero); m_ScheduledWorker.Add(e.PrevItem, runAt, (i) => { i.Message = string.Concat("Scheduled upload for ", runAt); i.State = StateManager.eState.WAIT; }); } else { SendToServerAsync(e.PrevItem); } }
private static void RenderForm(MultiText text, CurrentItemEventArgs currentItem, StringBuilder htmlBuilder, LanguageForm form, int sizeBoost) { bool underLineOn = IsCurrentField(text, form, currentItem); if (StartNewSpan(htmlBuilder, form.WritingSystemId, false, underLineOn, sizeBoost)) { var str = MakeSafeForHtmlAndFormat(form.Form); htmlBuilder.Append(str); htmlBuilder.Append(" </span>"); } }
public static string ToRtf(LexEntry entry, CurrentItemEventArgs currentItem, LexEntryRepository lexEntryRepository) { if (lexEntryRepository == null) { throw new ArgumentNullException("lexEntryRepository"); } if (entry == null) { return(string.Empty); } var rtf = new StringBuilder(); rtf.Append(@"{\rtf1\ansi\uc1\fs28 "); rtf.Append(MakeFontTable()); RenderHeadword(entry, rtf, lexEntryRepository); int senseNumber = 1; foreach (LexSense sense in entry.Senses) { RenderSense(entry, sense, senseNumber, currentItem, rtf); ++senseNumber; } Field glossField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Gloss); if (glossField.IsMeaningField) { rtf.Append(RenderGhostedField(null, LexSense.WellKnownProperties.Gloss, currentItem, entry.Senses.Count + 1)); } else { rtf.Append(RenderGhostedField(null, LexSense.WellKnownProperties.Definition, currentItem, entry.Senses.Count + 1)); } rtf.Append(@"\par}"); return(Utf16ToRtfAnsi(rtf.ToString())); }
public void UpdateContents(LexEntry record, CurrentItemEventArgs currentItemInFocus, LexEntryRepository lexEntryRepository) { if (_geckoOption) { if (record != null) { _formattedTextOfEntry = HtmlRenderer.ToHtml(record, currentItemInFocus, lexEntryRepository, _entryPreview.BackColor); ((GeckoBox)_entryPreview).SetHtml(_formattedTextOfEntry); } } else { if (record == null) { ((RichTextBox)_entryPreview).Rtf = string.Empty; } else { _formattedTextOfEntry = RtfRenderer.ToRtf(record, currentItemInFocus, lexEntryRepository); ((RichTextBox)_entryPreview).Rtf = _formattedTextOfEntry; } } if (record != _currentRecord) { _currentRecord = record; if (_notesBar == null) { return; } if (record == null) { _notesBar.SetTargetObject(null); } else { _notesBar.SetTargetObject(record); } } //_notesBar.Visible = true; }
private static string RenderGhostedField(PalasoDataObject parent, string property, CurrentItemEventArgs currentItem, int?number) { string rtf = string.Empty; if (currentItem != null && property == currentItem.PropertyName && parent == currentItem.Parent) { //REVIEW: is a ws switch needed for a blank? rtf += SwitchToWritingSystem(WritingSystems.AnalysisWritingSystemDefault.Id); if (number != null) { rtf += number.ToString(); } rtf += RenderBlankPosition(); } return(rtf); }
private void SetupTestData() { Palaso.Reporting.ErrorReport.IsOkToInteractWithUser = false; _tempFolder = new TemporaryFolder(); _filePath = _tempFolder.GetTemporaryFile(); _currentItem = null; string lexicalForm = "test"; string definition = "definition"; string exampleSentence = "Test sentence"; string exampleTranslation = "Translated sentence"; _lexEntryRepository = (LexEntryRepository) WeSayWordsProject.Project.ServiceLocator.GetService(typeof(LexEntryRepository)); _viewTemplate = (ViewTemplate) WeSayWordsProject.Project.ServiceLocator.GetService(typeof(ViewTemplate)); List <String> headwordWritingSystemIds = new List <string>(_viewTemplate.GetHeadwordWritingSystemIds()); string wsA = headwordWritingSystemIds[0]; string wsB = _viewTemplate.GetDefaultWritingSystemForField(definition).Id; HtmlRenderer.HeadWordWritingSystemId = _viewTemplate.HeadwordWritingSystem.Id; _entry = _lexEntryRepository.CreateItem(); _entry.LexicalForm[wsA] = lexicalForm; LexSense sense = new LexSense(); sense.Definition[wsB] = definition; LexExampleSentence example = new LexExampleSentence(); example.Sentence[wsA] = exampleSentence; example.Translation[wsB] = exampleTranslation; sense.ExampleSentences.Add(example); _entry.Senses.Add(sense); empty = CreateTestEntry("", "", ""); apple = CreateTestEntry("apple", "red thing", "An apple a day keeps the doctor away."); anotherApple = CreateTestEntry("apple", "fruit", "An apple a day keeps the doctor away."); banana = CreateTestEntry("banana", "yellow food", "Monkeys like to eat bananas."); car = CreateTestEntry("car", "small motorized vehicle", "Watch out for cars when you cross the street."); bike = CreateTestEntry("bike", "vehicle with two wheels", "He rides his bike to school."); }
//public static IList<LanguageForm> GetActualTextForms(MultiText text, IWritingSystemRepository writingSytems) //{ // var x = text.Forms.Where(f => !writingSytems.Get(f.WritingSystemId).IsVoice); // return new List<LanguageForm>(x); //} private static void RenderForm(MultiText text, CurrentItemEventArgs currentItem, StringBuilder rtfBuilder, LanguageForm form, int sizeBoost) { if (IsCurrentField(text, form, currentItem)) { rtfBuilder.Append(@"\ul"); } rtfBuilder.Append(SwitchToWritingSystem(form.WritingSystemId, sizeBoost)); rtfBuilder.Append(form.Form); // + " "); if (IsCurrentField(text, form, currentItem)) { //rtfBuilder.Append(" "); //rtfBuilder.Append(Convert.ToChar(160)); rtfBuilder.Append(@"\ulnone "); //rtfBuilder.Append(Convert.ToChar(160)); } rtfBuilder.Append(" "); }
public static string ToRtf(LexEntry entry, CurrentItemEventArgs currentItem, LexEntryRepository lexEntryRepository) { if (lexEntryRepository == null) { throw new ArgumentNullException("lexEntryRepository"); } if (entry == null) { return(string.Empty); } var rtf = new StringBuilder(); rtf.Append(@"{\rtf1\ansi\uc1\fs28 "); rtf.Append(MakeFontTable()); RenderHeadword(entry, rtf, lexEntryRepository); int senseNumber = 1; foreach (LexSense sense in entry.Senses) { RenderSense(entry, sense, senseNumber, currentItem, rtf); ++senseNumber; } #if GlossMeaning rtf.Append(RenderGhostedField("Gloss", currentItem, entry.Senses.Count + 1)); #else rtf.Append(RenderGhostedField(null, LexSense.WellKnownProperties.Definition, currentItem, entry.Senses.Count + 1)); #endif rtf.Append(@"\par}"); return(Utf16ToRtfAnsi(rtf.ToString())); }
private static void RenderPartOfSpeech(LexSense sense, CurrentItemEventArgs currentItem, StringBuilder rtf) { OptionRef posRef = sense.GetProperty <OptionRef>( LexSense.WellKnownProperties.PartOfSpeech ); if (posRef == null) { return; } OptionsList list = WeSayWordsProject.Project.GetOptionsList( LexSense.WellKnownProperties.PartOfSpeech ); if (list == null) { return; } Option posOption = list.GetOptionFromKey(posRef.Value); if (posOption == null) { return; } Field posField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate( LexSense.WellKnownProperties.PartOfSpeech ); if (posField == null) { return; } rtf.Append(@" \i "); rtf.Append(RenderField(posOption.Name, currentItem, 0, posField)); rtf.Append(@"\i0 "); }
private void OnChangeOfWhichItemIsInFocus(object sender, CurrentItemEventArgs e) { VerifyNotDisposed(); _currentItemInFocus = e; RefreshLexicalEntryPreview(); }
void logToolControl1_SelectionChanged(object sender, CurrentItemEventArgs<ISvnLogItem> e) { OnSelectionChanged(EventArgs.Empty); }
private void StateManager_LastItemProcessing(object sender, CurrentItemEventArgs e) { lblWarningMessage.Start(); }
private static void RenderSense(LexEntry entry, LexSense sense, int senseNumber, CurrentItemEventArgs currentItem, StringBuilder rtf) { //rtf.Append(SwitchToWritingSystem(WritingSystems.AnalysisWritingSystemDefault.Id)); #if GlossMeaning if (entry.Senses.Count > 1 || (currentItem != null && currentItem.PropertyName == "Gloss")) #else if (entry.Senses.Count > 1 || (currentItem != null && currentItem.PropertyName == LexSense.WellKnownProperties.Definition)) #endif { rtf.Append(" " + senseNumber); } RenderPartOfSpeech(sense, currentItem, rtf); #if GlossMeaning rtf.Append(" " + RenderField(sense.Gloss, currentItem)); #else // Render the Definition (meaning) field Field dfnField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate( LexSense.WellKnownProperties.Definition); rtf.Append(" " + RenderField(sense.Definition, currentItem, 0, dfnField)); #endif // rtf.Append(@"\i0 "); RenderExampleSentences(currentItem, rtf, sense); rtf.Append(RenderGhostedField(sense, "Sentence", currentItem, null)); rtf.Append(RenderGhostedField(sense, "Translation", currentItem, null)); }
private static void RenderSense(LexEntry entry, LexSense sense, int senseNumber, CurrentItemEventArgs currentItem, StringBuilder html) { Field glossField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Gloss); if (entry.Senses.Count > 1 || (currentItem != null && ((glossField.IsMeaningField && currentItem.PropertyName == LexSense.WellKnownProperties.Gloss) || (!glossField.IsMeaningField && currentItem.PropertyName == LexSense.WellKnownProperties.Definition)) )) { html.Append(" " + senseNumber); } RenderPartOfSpeech(sense, currentItem, html); // Render the Gloss/Definition (meaning) field if (glossField.IsMeaningField) { html.Append(" " + RenderField(sense.Gloss, currentItem, 0, glossField)); } else { Field dfnField = WeSayWordsProject.Project.GetFieldFromDefaultViewTemplate(LexSense.WellKnownProperties.Definition); html.Append(" " + RenderField(sense.Definition, currentItem, 0, dfnField)); } RenderExampleSentences(currentItem, html, sense); html.Append(RenderGhostedField(sense, "Sentence", currentItem, null)); html.Append(RenderGhostedField(sense, "Translation", currentItem, null)); }
private static string RenderField(MultiText text, CurrentItemEventArgs currentItem) { return(RenderField(text, currentItem, 0, null)); }