public override void Add(LexEntry entry) { IWritingSystemDefinition headWordWritingSystem = _viewTemplate.HeadwordWritingSystems[0]; int h = _lexEntryRepository.GetHomographNumber(entry, headWordWritingSystem); Add(entry, h); }
public void TestAddItem() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWritingSystemDefinition ws2 = WritingSystemDefinition.Parse("en"); var listBox = new GeckoListBox(); listBox.FormWritingSystem = ws; listBox.MeaningWritingSystem = ws2; listBox.Name = "ControlUnderTest"; Assert.IsNotNull(listBox); String volvo = "Volvo"; String saab = "Saab"; String toyota = "Toyota"; listBox.AddItem(volvo); listBox.AddItem(saab); listBox.AddItem(toyota); Assert.AreSame(saab, listBox.GetItem(1)); Assert.AreSame(toyota, listBox.GetItem(2)); Assert.AreEqual(3, listBox.Length); Assert.AreSame(ws2, listBox.MeaningWritingSystem); listBox.Clear(); Assert.AreEqual(0, listBox.Length); }
public void KeyboardInputAfterInitialValueTest() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWeSayTextBox textBox = new GeckoBox(ws, "ControlUnderTest"); Assert.IsNotNull(textBox); Assert.AreSame(ws, textBox.WritingSystem); _window.Controls.Add((GeckoBox)textBox); _window.Show(); ControlTester t = new ControlTester("ControlUnderTest", _window); textBox.Text = "Test"; KeyboardController keyboardController = new KeyboardController(t); Application.DoEvents(); keyboardController.Press(Key.HOME); Application.DoEvents(); keyboardController.Press("V"); keyboardController.Press("a"); keyboardController.Press("l"); keyboardController.Press("u"); keyboardController.Press("e"); keyboardController.Press(" "); Application.DoEvents(); Assert.AreEqual("Value Test", textBox.Text); keyboardController.Dispose(); }
/// <summary> /// Gets a ResultSet containing entries whose gloss match glossForm sorted by the lexical form /// in the given writingsystem. /// Use "Form" to access the lexical form and "Gloss/Form" to access the Gloss in a RecordToken. /// </summary> /// <param name="glossForm"></param> /// <param name="lexicalUnitWritingSystem"></param> /// <returns></returns> public ResultSet <LexEntry> GetEntriesWithMatchingGlossSortedByLexicalForm( LanguageForm glossForm, IWritingSystemDefinition lexicalUnitWritingSystem) { if (null == glossForm || string.IsNullOrEmpty(glossForm.Form)) { throw new ArgumentNullException("glossForm"); } if (lexicalUnitWritingSystem == null) { throw new ArgumentNullException("lexicalUnitWritingSystem"); } ResultSet <LexEntry> allGlossesResultSet = GetAllEntriesWithGlossesSortedByLexicalForm(lexicalUnitWritingSystem); List <RecordToken <LexEntry> > filteredResultSet = new List <RecordToken <LexEntry> >(); foreach (RecordToken <LexEntry> recordToken in allGlossesResultSet) { if (((string)recordToken["Gloss"] == glossForm.Form) && ((string)recordToken["GlossWritingSystem"] == glossForm.WritingSystemId)) { filteredResultSet.Add(recordToken); } } return(new ResultSet <LexEntry>(this, filteredResultSet)); }
public GatherWordListControl(GatherWordListTask task, IWritingSystemDefinition lexicalUnitWritingSystem) { _task = task; InitializeComponent(); InitializeDisplaySettings(); _vernacularBox.AutoSizeMode = AutoSizeMode.GrowAndShrink; _vernacularBox.WritingSystemsForThisField = new IWritingSystemDefinition[] { lexicalUnitWritingSystem }; _vernacularBox.TextChanged += _vernacularBox_TextChanged; _vernacularBox.KeyDown += _boxVernacularWord_KeyDown; _vernacularBox.MinimumSize = new Size(_boxForeignWord.Size.Width - 25, _boxForeignWord.Size.Height); _vernacularBox.ForeColor = System.Drawing.Color.Black; _listViewOfWordsMatchingCurrentItem.UserClick += new System.EventHandler(this.OnListViewOfWordsMatchingCurrentItem_Click); _listViewOfWordsMatchingCurrentItem.Clear(); _listViewOfWordsMatchingCurrentItem.FormWritingSystem = lexicalUnitWritingSystem; // _listViewOfWordsMatchingCurrentItem.ItemHeight = (int)Math.Ceiling(_task.FormWritingSystem.Font.GetHeight()); _verticalWordListView.WritingSystem = task.PromptingWritingSystem; _verticalWordListView.MaxLength = 18; _verticalWordListView.MinLength = 10; // Space fill to this length _verticalWordListView.BackColor = Color.White; _verticalWordListView.DataSource = task.Words; UpdateStuff(); _verticalWordListView.ItemSelectionChanged += OnWordsList_SelectedIndexChanged; _flyingLabel.Font = _vernacularBox.TextBoxes[0].Font; _flyingLabel.Finished += OnAnimator_Finished; }
private static bool StartNewSpan(StringBuilder html, String writingSystemId, bool boldText, bool underline, int fontSizeBoost) { if (!WritingSystems.Contains(writingSystemId)) { return(false); //that ws isn't actually part of our configuration, so can't get a special font for it } IWritingSystemDefinition ws = (IWritingSystemDefinition)WritingSystems.Get(writingSystemId); Font font = WritingSystemInfo.CreateFont(ws); float fontSize = font.Size + fontSizeBoost; String lang = ws.Bcp47Tag.IndexOf('-') == -1 ? ws.Bcp47Tag : ws.Bcp47Tag.Substring(0, ws.Bcp47Tag.IndexOf('-')); var formattedSpan = string.Format( "<span lang='{5}' style='font-family:{0}; font-size:{1}pt;font-weight:{2};font-style:{3};text-decoration:{4}'>", font.Name, fontSize.ToString(), boldText ? "bold": "normal", italicsOn ? "italic" : "normal", underline ? "underline" : "none", lang); html.Append(formattedSpan); AddFontFamily(font.Name); return(true); }
public IEnumerable <IWritingSystemDefinitionSuggestion> GetSuggestions(IWritingSystemDefinition primary, IEnumerable <IWritingSystemDefinition> existingWritingSystemsForLanguage) { if (string.IsNullOrEmpty(primary.Language) && !primary.Variant.StartsWith("x-", StringComparison.OrdinalIgnoreCase)) { yield break; } if (SuppressSuggestionsForMajorWorldLanguages && new[] { "en", "th", "es", "fr", "de", "hi", "id", "vi", "my", "pt", "fi", "ar", "it", "sv", "ja", "ko", "ch", "nl", "ru" }.Contains(primary.Language)) { yield break; } if (SuggestIpa && IpaSuggestion.ShouldSuggest(existingWritingSystemsForLanguage)) { yield return(new IpaSuggestion(primary)); } if (SuggestVoice && VoiceSuggestion.ShouldSuggest(existingWritingSystemsForLanguage)) { yield return(new VoiceSuggestion(primary)); } if (SuggestDialects) { yield return(new DialectSuggestion(primary)); } if (SuggestOther) { yield return(new OtherSuggestion(primary, existingWritingSystemsForLanguage)); } }
private ResultSet <LexEntry> GetAllEntriesWithMeaningsSortedByLexicalForm(IWritingSystemDefinition lexicalUnitWritingSystem, bool glossMeaningField) { if (lexicalUnitWritingSystem == null) { throw new ArgumentNullException("lexicalUnitWritingSystem"); } string cachename = String.Format("MeaningsSortedByLexicalForm_{0}", lexicalUnitWritingSystem); if (_caches[cachename] == null) { DelegateQuery <LexEntry> MatchingMeaningQuery = new DelegateQuery <LexEntry>( delegate(LexEntry entry) { List <IDictionary <string, object> > fieldsandValuesForRecordTokens = new List <IDictionary <string, object> >(); int senseNumber = 0; foreach (LexSense sense in entry.Senses) { foreach (LanguageForm form in glossMeaningField ? sense.Gloss.Forms : sense.Definition.Forms) { IDictionary <string, object> tokenFieldsAndValues = new Dictionary <string, object>(); string lexicalForm = entry.LexicalForm[lexicalUnitWritingSystem.Id]; if (String.IsNullOrEmpty(lexicalForm)) { lexicalForm = null; } tokenFieldsAndValues.Add("Form", lexicalForm); string meaning = form.Form; if (String.IsNullOrEmpty(meaning)) { meaning = null; } tokenFieldsAndValues.Add("Meaning", meaning); string meaningWritingSystem = form.WritingSystemId; if (String.IsNullOrEmpty(meaningWritingSystem)) { meaningWritingSystem = null; } tokenFieldsAndValues.Add("MeaningWritingSystem", meaningWritingSystem); tokenFieldsAndValues.Add("SenseNumber", senseNumber); fieldsandValuesForRecordTokens.Add(tokenFieldsAndValues); } senseNumber++; } return(fieldsandValuesForRecordTokens); } ); ResultSet <LexEntry> itemsMatchingQuery = GetItemsMatching(MatchingMeaningQuery); SortDefinition[] sortDefinition = new SortDefinition[4]; sortDefinition[0] = new SortDefinition("Form", lexicalUnitWritingSystem.Collator); sortDefinition[1] = new SortDefinition("Meaning", StringComparer.InvariantCulture); sortDefinition[2] = new SortDefinition("MeaningWritingSystem", StringComparer.InvariantCulture); sortDefinition[3] = new SortDefinition("SenseNumber", Comparer <int> .Default); ResultSetCache <LexEntry> cache = new ResultSetCache <LexEntry>(this, sortDefinition, itemsMatchingQuery, MatchingMeaningQuery); _caches.Add(cachename, cache); } return(_caches[cachename].GetResultSet()); }
/// <summary> /// Gets a ResultSet containing entries whose gloss match glossForm sorted by the lexical form /// in the given writingsystem. /// Use "Form" to access the lexical form and "Gloss/Form" to access the Gloss in a RecordToken. /// </summary> /// <param name="glossForm"></param> /// <param name="lexicalUnitWritingSystem"></param> /// <returns></returns> public ResultSet <LexEntry> GetEntriesWithMatchingMeaningSortedByLexicalForm( LanguageForm meaningForm, IWritingSystemDefinition lexicalUnitWritingSystem, bool glossMeaningField) { if (null == meaningForm || string.IsNullOrEmpty(meaningForm.Form)) { throw new ArgumentNullException("meaningForm"); } if (lexicalUnitWritingSystem == null) { throw new ArgumentNullException("lexicalUnitWritingSystem"); } ResultSet <LexEntry> allMeaningsResultSet = GetAllEntriesWithMeaningsSortedByLexicalForm(lexicalUnitWritingSystem, glossMeaningField); List <RecordToken <LexEntry> > filteredResultSet = new List <RecordToken <LexEntry> >(); foreach (RecordToken <LexEntry> recordToken in allMeaningsResultSet) { if (((string)recordToken["Meaning"] == meaningForm.Form) && ((string)recordToken["MeaningWritingSystem"] == meaningForm.WritingSystemId)) { filteredResultSet.Add(recordToken); } } return(new ResultSet <LexEntry>(this, filteredResultSet)); }
public GatherBySemanticDomainTask( GatherBySemanticDomainConfig config, LexEntryRepository lexEntryRepository, ViewTemplate viewTemplate, TaskMemoryRepository taskMemoryRepository, ILogger logger ) : base( config, lexEntryRepository, viewTemplate, taskMemoryRepository ) { ViewTemplate = viewTemplate; Guard.AgainstNull(config, "config"); Guard.AgainstNull(viewTemplate, "viewTemplate"); _config = config; _logger = logger; _taskMemory = taskMemoryRepository.FindOrCreateSettingsByTaskId(config.TaskName); _currentDomainIndex = -1; _currentQuestionIndex = 0; _words = null; _semanticDomainField = viewTemplate.GetField(LexSense.WellKnownProperties.SemanticDomainDdp4); var definitionWsId = viewTemplate.GetField(LexSense.WellKnownProperties.Definition).WritingSystemIds.First(); IWritingSystemDefinition writingSystemForDefinition = viewTemplate.WritingSystems.Get(definitionWsId); Guard.AgainstNull(writingSystemForDefinition, "Definition input System"); DefinitionWritingSystem = writingSystemForDefinition; }
/// <summary> /// Gets a ResultSet containing all entries sorted by lexical form for a given writing system. /// Use "Form" to access the lexical form in a RecordToken. /// </summary> /// <param name="writingSystem"></param> /// <returns></returns> private ResultSet <LexEntry> GetAllEntriesSortedByLexicalForm(IWritingSystemDefinition writingSystem) { if (writingSystem == null) { throw new ArgumentNullException("writingSystem"); } string cacheName = String.Format("sortedByLexicalForm_{0}", writingSystem.Id); if (_caches[cacheName] == null) { DelegateQuery <LexEntry> lexicalFormQuery = new DelegateQuery <LexEntry>( delegate(LexEntry entryToQuery) { IDictionary <string, object> tokenFieldsAndValues = new Dictionary <string, object>(); string headWord = entryToQuery.LexicalForm[writingSystem.Id]; if (String.IsNullOrEmpty(headWord)) { headWord = null; } tokenFieldsAndValues.Add("Form", headWord); return(new IDictionary <string, object>[] { tokenFieldsAndValues }); }); ResultSet <LexEntry> itemsMatching = _decoratedDataMapper.GetItemsMatching(lexicalFormQuery); SortDefinition[] sortOrder = new SortDefinition[1]; sortOrder[0] = new SortDefinition("Form", writingSystem.Collator); _caches.Add(cacheName, new ResultSetCache <LexEntry>(this, sortOrder, itemsMatching, lexicalFormQuery)); } ResultSet <LexEntry> resultsFromCache = _caches[cacheName].GetResultSet(); return(resultsFromCache); }
/// <summary> /// /// </summary> /// <param name="ws">The ws.</param> protected override void OnChangeNotifySharedStore(IWritingSystemDefinition ws) { base.OnChangeNotifySharedStore(ws); if (m_globalStore != null) { IWritingSystemDefinition globalWs; if (m_globalStore.TryGet(ws.Id, out globalWs)) { if (ws.DateModified > globalWs.DateModified) { WritingSystemDefinition newWs = ws.Clone(); newWs.Modified = true; // ensure any existing file for this WS is overwritten try { m_globalStore.Remove(ws.Id); m_globalStore.Set(newWs); } catch (UnauthorizedAccessException) { // Live with it if we can't update the global store. In a CS world we might // well not have permission. } } } else { m_globalStore.Set(ws.Clone()); } } }
public WeSayAudioFieldBox(IWritingSystemDefinition writingSystem, AudioPathProvider audioPathProvider, Palaso.Reporting.ILogger logger) { _audioPathProvider = audioPathProvider; _logger = logger; WritingSystem = writingSystem; InitializeComponent(); // may be changed in a moment when the actual field is read _shortSoundFieldControl1.Path = _audioPathProvider.GetNewPath(); _shortSoundFieldControl1.SoundRecorded += (sender, e) => { _fileName.Text = _audioPathProvider.GetPartialPathFromFull( _shortSoundFieldControl1.Path); _logger.WriteConciseHistoricalEvent("Recorded Sound"); } ; _shortSoundFieldControl1.SoundDeleted += (sender, e) => { _fileName.Text = string.Empty; _logger.WriteConciseHistoricalEvent("Deleted Sound"); }; _shortSoundFieldControl1.BeforeStartingToRecord += new EventHandler(shortSoundFieldControl1_BeforeStartingToRecord); this.Height = _shortSoundFieldControl1.Height + 10; }
public DeleteInputSystemDialog(IWritingSystemDefinition wsToDelete, IEnumerable <IWritingSystemDefinition> possibleWritingSystemsToConflateWith, bool showHelpButton) { InitializeComponent(); if (!showHelpButton) { _helpButton.Hide(); } _deleteRadioButton.Text = String.Format(_deleteRadioButton.Text, DisplayName(wsToDelete)); _mergeRadioButton.Text = String.Format(_mergeRadioButton.Text, DisplayName(wsToDelete)); _wsSelectionComboBox.Items.AddRange( possibleWritingSystemsToConflateWith.Where(ws => ws != wsToDelete).Select(ws => new WritingSystemDisplayAdaptor(ws)).ToArray()); Choice = Choices.Delete; if (_wsSelectionComboBox.Items.Count > 0) { _wsSelectionComboBox.SelectedIndex = 0; } _wsSelectionComboBox.DropDownStyle = ComboBoxStyle.DropDownList; _okButton.Click += OnOkClicked; _cancelButton.Click += OnCancelClicked; _deleteRadioButton.CheckedChanged += OnDeleteRadioButtonCheckedChanged; _mergeRadioButton.CheckedChanged += OnMergeRadioButtonCheckedChanged; _helpButton.Click += OnCustomHelpButtonClicked; _deleteRadioButton.Checked = true; }
public virtual IKeyboardDefinition DefaultForWritingSystem(IWritingSystemDefinition ws) { return(new DefaultKeyboardDefinition() { Layout = "English", Locale = "en-US" }); }
private static void SortLift(string outputPath, LexEntryRepository lexEntryRepository, ViewTemplate template) { using (var exporter = new LiftWriter(outputPath, LiftWriter.ByteOrderStyle.NoBOM)) { IWritingSystemDefinition firstWs = template.HeadwordWritingSystems[0]; ResultSet <LexEntry> recordTokens = lexEntryRepository.GetAllEntriesSortedByHeadword(firstWs); int index = 0; foreach (RecordToken <LexEntry> token in recordTokens) { int homographNumber = 0; if ((bool)token["HasHomograph"]) { homographNumber = (int)token["HomographNumber"]; } LexEntry lexEntry = token.RealObject; EmbeddedXmlCollection sortedAnnotation = new EmbeddedXmlCollection(); sortedAnnotation.Values.Add("<annotation name='sorted-index' value='" + (++index) + "'/>"); lexEntry.Properties.Add(new KeyValuePair <string, IPalasoDataObjectProperty>("SortedIndex", sortedAnnotation)); exporter.Add(lexEntry, homographNumber); } exporter.End(); } }
protected WordGatheringTaskBase(ITaskConfiguration config, LexEntryRepository lexEntryRepository, ViewTemplate viewTemplate, TaskMemoryRepository taskMemoryRepository) : base(config, lexEntryRepository, taskMemoryRepository) { if (viewTemplate == null) { throw new ArgumentNullException("viewTemplate"); } _viewTemplate = viewTemplate; _lexicalFormWritingSystem = viewTemplate.GetDefaultWritingSystemForField(Field.FieldNames.EntryLexicalForm.ToString()); var glossField = _viewTemplate.GetField(LexSense.WellKnownProperties.Gloss); if (glossField == null) { _glossMeaningField = false; } else { _glossMeaningField = glossField.IsMeaningField; } }
private WritingSystemTreeItem MakeExistingDefinitionItem(IWritingSystemDefinition definition) { var item = new WritingSystemDefinitionTreeItem(definition, OnClickExistingDefinition); item.Selected = item.Definition == _setupModel.CurrentDefinition; return((WritingSystemTreeItem)item); }
public void GeckoBox_KeyboardInputWhenReadOnlyTest() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWeSayTextBox textBox = new GeckoBox(ws, "ControlUnderTest"); textBox.ReadOnly = true; Assert.IsNotNull(textBox); Assert.AreSame(ws, textBox.WritingSystem); _window.Controls.Add((GeckoBox)textBox); _window.Show(); ControlTester t = new ControlTester("ControlUnderTest", _window); textBox.Text = "Value"; KeyboardController keyboardController = new KeyboardController(t); Application.DoEvents(); keyboardController.Press(Key.END); Application.DoEvents(); keyboardController.Press(" "); keyboardController.Press("T"); keyboardController.Press("e"); keyboardController.Press("s"); keyboardController.Press("t"); Application.DoEvents(); Assert.AreEqual("Value", textBox.Text); keyboardController.Dispose(); }
public void SetWritingSystem_DoesntThrow() { var textBox = new GeckoComboBox(); IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); Assert.DoesNotThrow(() => textBox.WritingSystem = ws); }
public DeleteInputSystemDialog(IWritingSystemDefinition wsToDelete, IEnumerable<IWritingSystemDefinition> possibleWritingSystemsToConflateWith, bool showHelpButton) { InitializeComponent(); if (!showHelpButton) { _helpButton.Hide(); } _deleteRadioButton.Text = String.Format(_deleteRadioButton.Text, DisplayName(wsToDelete)); _mergeRadioButton.Text = String.Format(_mergeRadioButton.Text, DisplayName(wsToDelete)); _wsSelectionComboBox.Items.AddRange( possibleWritingSystemsToConflateWith.Where(ws => ws != wsToDelete).Select(ws=>new WritingSystemDisplayAdaptor(ws)).ToArray()); Choice = Choices.Delete; if (_wsSelectionComboBox.Items.Count > 0) { _wsSelectionComboBox.SelectedIndex = 0; } _wsSelectionComboBox.DropDownStyle = ComboBoxStyle.DropDownList; _okButton.Click += OnOkClicked; _cancelButton.Click += OnCancelClicked; _deleteRadioButton.CheckedChanged += OnDeleteRadioButtonCheckedChanged; _mergeRadioButton.CheckedChanged += OnMergeRadioButtonCheckedChanged; _helpButton.Click += OnCustomHelpButtonClicked; _deleteRadioButton.Checked = true; }
public void Setup() { _ws = WritingSystemDefinition.Parse("qaa-x-qaa"); _ws.DefaultFontName = "Arial"; _ws.DefaultFontSize = (float)55.9; // _createNewClickedFired=false; // _valueChangedFired = false; _sourceChoices = new OptionsList(); _choiceKeys = new List <string>(); AddSourceChoice("one", "1", "Notice, this is not the number two."); //nb: key 'two' in there AddSourceChoice("two", "2", "A description of two which includes the word duo."); AddSourceChoice("three", "3", "A description of this which includes the word trio and is not two."); _displayAdaptor = new OptionDisplayAdaptor(_sourceChoices, _ws.Id); _control = new AutoCompleteWithCreationBox <Option, string>( CommonEnumerations.VisibilitySetting.Visible, null); _control.Name = "autobox"; _control.Box.Items = _sourceChoices.Options; _control.Box.ItemFilterer = _displayAdaptor.GetItemsToOffer; //leave for individual tests _control.CreateNewClicked += new EventHandler<CreateNewArgs>(_control_CreateNewClicked); _control.Box.ItemDisplayStringAdaptor = _displayAdaptor; _control.Box.WritingSystem = _ws; _control.GetKeyValueFromValue = _displayAdaptor.GetOptionFromKey; _control.GetValueFromKeyValue = _displayAdaptor.GetKeyFromOption; _control.ValueChanged += _control_ValueChanged; _dataBeingEditted = new OptionRef(); }
/// <summary> /// Get the writing system that is most probably intended by the user, when input language changes to the specified layout and cultureInfo, /// given the indicated candidates, and that wsCurrent is the preferred result if it is a possible WS for the specified culture. /// wsCurrent is also returned if none of the candidates is found to match the specified inputs. /// See interface comment for intended usage information. /// Enhance JohnT: it may be helpful, if no WS has an exact match, to look for one where the culture prefix (before hyphen) matches, /// thus finding a WS that has a keyboard for the same language as the one the user selected. /// Could similarly match against WS ID's language ID, for WS's with no RawLocalKeyboard. /// Could use LocalKeyboard instead of RawLocalKeyboard, thus allowing us to find keyboards for writing systems where the /// local keyboard has not yet been determined. However, this would potentially establish a particular local keyboard for /// a user who has never typed in that writing system or configured a keyboard for it, nor even selected any text in it. /// In the expected usage of this library, there will be a RawLocalKeyboard for every writing system in which the user has /// ever typed or selected text. That should have a high probability of catching anything actually useful. /// </summary> /// <param name="layoutName"></param> /// <param name="cultureInfo"></param> /// <param name="wsCurrent"></param> /// <param name="options"></param> /// <returns></returns> public IWritingSystemDefinition GetWsForInputLanguage(string layoutName, CultureInfo cultureInfo, IWritingSystemDefinition wsCurrent, IWritingSystemDefinition[] options) { // See if the default is suitable. if (WsMatchesLayout(layoutName, wsCurrent) && WsMatchesCulture(cultureInfo, wsCurrent)) { return(wsCurrent); } IWritingSystemDefinition layoutMatch = null; IWritingSystemDefinition cultureMatch = null; foreach (var ws in options) { bool matchesCulture = WsMatchesCulture(cultureInfo, ws); if (WsMatchesLayout(layoutName, ws)) { if (matchesCulture) { return(ws); } if (layoutMatch == null || ws.Equals(wsCurrent)) { layoutMatch = ws; } } if (matchesCulture && (cultureMatch == null || ws.Equals(wsCurrent))) { cultureMatch = ws; } } return(layoutMatch ?? cultureMatch ?? wsCurrent); }
public IEnumerable<IWritingSystemDefinitionSuggestion> GetSuggestions(IWritingSystemDefinition primary, IEnumerable<IWritingSystemDefinition> existingWritingSystemsForLanguage) { if(string.IsNullOrEmpty(primary.Language) && !primary.Variant.StartsWith("x-", StringComparison.OrdinalIgnoreCase)) yield break; if(SuppressSuggestionsForMajorWorldLanguages && new[]{"en", "th", "es", "fr", "de", "hi", "id", "vi","my","pt", "fi", "ar", "it","sv", "ja", "ko", "ch", "nl", "ru"}.Contains(primary.Language)) yield break; if (SuggestIpa && IpaSuggestion.ShouldSuggest(existingWritingSystemsForLanguage)) { yield return new IpaSuggestion(primary); } if (SuggestVoice && VoiceSuggestion.ShouldSuggest(existingWritingSystemsForLanguage)) { yield return new VoiceSuggestion(primary); } if (SuggestDialects) { yield return new DialectSuggestion(primary); } if (SuggestOther) { yield return new OtherSuggestion(primary, existingWritingSystemsForLanguage); } }
private void InitializeRelationControl(LexRelation relation) { //TODO: refactor this (sortHelper, pairStringLexEntryIdList, _keyIdMap, GetKeyIdPairFromLexEntry) // to use ApproximateFinder. Eventually refactor the automcompletetextbox to just take one IWritingSystemDefinition writingSystem = GetWritingSystemFromField(); ResultSet <LexEntry> recordTokenList = _lexEntryRepository.GetAllEntriesSortedByLexicalFormOrAlternative(writingSystem); _resultSet = recordTokenList; AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker = CreatePicker <RecordToken <LexEntry> >(relation); picker.GetKeyValueFromValue = GetRecordTokenFromTargetId; picker.GetValueFromKeyValue = GetTargetIdFromRecordToken; picker.Box.ItemDisplayStringAdaptor = new PairStringLexEntryIdDisplayProvider(); picker.Box.FormToObjectFinder = FindRecordTokenFromForm; picker.Box.ItemFilterer = FindClosestAndNextClosestAndPrefixedPairStringLexEntryForms; picker.Box.Items = recordTokenList; if (!String.IsNullOrEmpty(relation.TargetId)) { picker.Box.SelectedItem = GetRecordTokenFromLexEntry(_lexEntryRepository.GetLexEntryWithMatchingId(relation.TargetId)); } picker.CreateNewClicked += OnCreateNewPairStringLexEntryId; _control = picker; }
public void Setup() { BasilProjectTestHelper.InitializeForTests(); _writingSystemId = WritingSystemsIdsForTests.AnalysisIdForTest; IWritingSystemDefinition writingSystem = WritingSystemDefinition.Parse(_writingSystemId); _papaNameWidget = new WeSayTextBox(writingSystem, null); _papaNameWidget.Text = "John"; _ghostFirstNameWidget = new WeSayTextBox(writingSystem, null); _binding = new GhostBinding <Child>(null, _papa.Children, "First", writingSystem, _ghostFirstNameWidget); _didNotify = false; //Window w = new Window("test"); //VBox box = new VBox(); //w.Add(box); //box.PackStart(_papaNameWidget); //box.PackStart(_ghostFirstNameWidget); //box.ShowAll(); //w.ShowAll(); _papaNameWidget.Show(); // while (Gtk.Application.EventsPending()) // { Gtk.Application.RunIteration(); } //Application.Run(); _papaNameWidget.Focus(); _ghostFirstNameWidget.Focus(); }
public void SetListWritingSystem(IWritingSystemDefinition writingSystem) { Guard.AgainstNull(writingSystem, "writingSystem"); if (_listWritingSystem == writingSystem) { return; } _listWritingSystem = writingSystem; _recordsListBox.WritingSystem = _listWritingSystem; LoadRecords(); _recordsListBox.RetrieveVirtualItem -= OnRetrieveVirtualItemEvent; _recordsListBox.RetrieveVirtualItem += OnRetrieveVirtualItemEvent; //WHy was this here (I'm (JH) scared to remove it)? // it is costing us an extra second, as we set the record // to the first one, then later set it to the one we actually want. // SetRecordToBeEdited(CurrentEntry); ConfigureSearchBox(); }
public string GetAutoFontsCascadingStyleSheetLinesForWritingSystem(IWritingSystemDefinition ws) { var builder = new StringBuilder(); // var family = FontFamily.Families.FirstOrDefault(f => f.Name == ws.FontName); builder.AppendLine("font-family: '" + ws.DefaultFontName + "';"); var word = FindFieldWithFieldName(LexEntry.WellKnownProperties.LexicalUnit); //make the first vernacular field bold if (word.WritingSystemIds.Count > 0 && word.WritingSystemIds[0] == ws.Id) { builder.AppendLine("font-weight: bold"); } else { //if there are two definition writing systems, make the second one italic var defField = FindFieldWithFieldName(LexSense.WellKnownProperties.Definition); if (defField.WritingSystemIds.Count > 1 && defField.WritingSystemIds[1] == ws.Id) { // if(family != default(FontFamily)) // { // family.IsStyleAvailable(FontStyle.Italic) // } builder.AppendLine("font-style: italic"); } } return(builder.ToString()); }
public string GetNewStoreIDWhenSet(IWritingSystemDefinition ws) { if (ws == null) { throw new ArgumentNullException("ws"); } return(String.IsNullOrEmpty(ws.StoreID) ? ws.Id : ws.StoreID); }
public void GeckoBox_CreateWithWritingSystem() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWeSayTextBox textBox = new GeckoBox(ws, null); Assert.IsNotNull(textBox); Assert.AreSame(ws, textBox.WritingSystem); }
public IWritingSystemDefinition MakeDuplicate(IWritingSystemDefinition definition) { if (definition == null) { throw new ArgumentNullException("definition"); } return(definition.Clone()); }
public virtual void SetUp() { _writingSystem = new WritingSystemDefinition(); RepositoryUnderTest = CreateNewStore(); _writingSystemIdChangedEventArgs = null; _writingSystemDeletedEventArgs = null; _writingSystemConflatedEventArgs = null; }
public void CreateWithWritingSystem() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); var comboBox = new GeckoComboBox(ws, null); Assert.IsNotNull(comboBox); Assert.AreSame(ws, comboBox.WritingSystem); }
public void Init(IWritingSystemDefinition writingSystem, String name) { WritingSystem = writingSystem; _nameForLogging = name; if (_nameForLogging == null) { _nameForLogging = "??"; } Name = name; }
public GeckoBox(IWritingSystemDefinition ws, string nameForLogging) : this() { _nameForLogging = nameForLogging; if (_nameForLogging == null) { _nameForLogging = "??"; } Name = _nameForLogging; WritingSystem = ws; }
public IpaSuggestion(IWritingSystemDefinition primary) { _templateDefinition = new WritingSystemDefinition(primary.Language, "", primary.Region, primary.Variant, "ipa", false) { LanguageName = primary.LanguageName, DefaultFontSize = primary.DefaultFontSize, DefaultFontName = _fontsForIpa.FirstOrDefault(FontExists), IpaStatus = IpaStatusChoices.Ipa, }; var ipaKeyboard = Keyboard.Controller.AllAvailableKeyboards.FirstOrDefault(k => k.Id.ToLower().Contains("ipa")); if (ipaKeyboard != null) _templateDefinition.Keyboard = ipaKeyboard.Id; this.Label = string.Format("IPA input system for {0}", _templateDefinition.LanguageName); }
public IKeyboardDefinition LegacyForWritingSystem(IWritingSystemDefinition ws) { throw new NotImplementedException(); }
public IKeyboardDefinition DefaultForWritingSystem(IWritingSystemDefinition ws) { return null; }
public IKeyboardDefinition GetKeyboard(IWritingSystemDefinition writingSystem) { throw new NotImplementedException(); }
public void ClearSelection() { CurrentDefinition = null; }
public virtual IKeyboardDefinition DefaultForWritingSystem(IWritingSystemDefinition ws) { return new DefaultKeyboardDefinition() {Layout = "English", Locale = "en-US"}; }
public IKeyboardDefinition LegacyForWritingSystem(IWritingSystemDefinition ws) { return null; }
/// <summary> /// Creates the presentation model object based off of a single writing system definition. /// This is the easiest form to use if you only want part of the UI elements or only operate on /// one WritingSystemDefiniion /// </summary> public WritingSystemSetupModel(WritingSystemDefinition ws) { if (ws == null) { throw new ArgumentNullException("ws"); } WritingSystemSuggestor = new WritingSystemSuggestor(); _currentWritingSystem = ws; _currentIndex = 0; _writingSystemRepository = null; _writingSystemDefinitions = new List<IWritingSystemDefinition>(1); WritingSystemDefinitions.Add(ws); _deletedWritingSystemDefinitions = null; _usingRepository = false; }
public WhatToDoWithDataInWritingSystemToBeDeletedEventArgs(IWritingSystemDefinition writingSystemIdToDelete) { WritingSystemIdToDelete = writingSystemIdToDelete; WhatToDo = WhatToDos.Delete; }
internal void RenameIsoCode(IWritingSystemDefinition existingWs) { WritingSystemDefinition newWs = null; if (!_usingRepository) { throw new InvalidOperationException("Unable to add new writing system definition when there is no store."); } if (MethodToShowUiToBootstrapNewDefinition != null) { newWs = MethodToShowUiToBootstrapNewDefinition(); } if (newWs == null) //cancelled return; existingWs.Language = newWs.Language; existingWs.LanguageName = newWs.LanguageName; // Remove First Not WellKnownPrivateUseTag string rfcVariant = ""; string rfcPrivateUse = ""; WritingSystemDefinition.SplitVariantAndPrivateUse(existingWs.Variant, out rfcVariant, out rfcPrivateUse); List<string> privateUseTokens = new List<string>(rfcPrivateUse.Split('-')); string oldIsoCode = WritingSystemDefinition.FilterWellKnownPrivateUseTags(privateUseTokens).FirstOrDefault(); if (!String.IsNullOrEmpty(oldIsoCode)) { privateUseTokens.Remove(oldIsoCode); } string newPrivateUse = "x-" + String.Join("-", privateUseTokens.ToArray()); //would be nice if writingsystemdefintion.ConcatenateVariantAndPrivateUse would add the x for us existingWs.Variant = WritingSystemDefinition.ConcatenateVariantAndPrivateUse(rfcVariant, newPrivateUse); OnSelectionChanged(); OnCurrentItemUpdated(); }
public virtual string VerboseDescription(IWritingSystemDefinition writingSystem) { var summary = new StringBuilder(); summary.AppendFormat(" {0}", writingSystem.LanguageName); if (!String.IsNullOrEmpty(writingSystem.Region)) { summary.AppendFormat(" in {0}", writingSystem.Region); } if (!String.IsNullOrEmpty(writingSystem.Script)) { summary.AppendFormat(" written in {0} script", CurrentIso15924Script.ShortLabel()); } summary.AppendFormat(". ({0})", writingSystem.Bcp47Tag); return summary.ToString().Trim(); }
public virtual bool SetCurrentDefinition(IWritingSystemDefinition definition) { var index = WritingSystemDefinitions.FindIndex(d => d == definition); if (index < 0) { return false; } CurrentIndex = index; return true; }
/// <summary> /// Imports the given file into the writing system store. /// </summary> /// <param name="fileName">Full path of file to import</param> public void ImportFile(string fileName) { if (!_usingRepository) { throw new InvalidOperationException("Unable to import file when not using writing system store."); } if (fileName == null) { throw new ArgumentNullException("fileName"); } if (!System.IO.File.Exists(fileName)) { throw new ArgumentException("File does not exist.", "fileName"); } LdmlDataMapper _adaptor = new LdmlDataMapper(); var ws = _writingSystemRepository.CreateNew(); _adaptor.Read(fileName, (WritingSystemDefinition)ws); WritingSystemDefinitions.Add(ws); OnAddOrDelete(); CurrentDefinition = ws; }
/// <summary> /// Makes a copy of the currently selected writing system and selects the new copy. /// </summary> public void DuplicateCurrent() { if (!_usingRepository) { throw new InvalidOperationException("Unable to duplicate current selection when there is no writing system store."); } if (!HasCurrentSelection) { throw new InvalidOperationException("Unable to duplicate current selection when there is no current selection."); } var ws = _writingSystemRepository.MakeDuplicate(CurrentDefinition); WritingSystemDefinitions.Insert(CurrentIndex+1, ws); OnAddOrDelete(); CurrentDefinition = ws; }
public void GetWsForInputLanguage_CorrectlyPrioritizesLayoutAndCulture() { var wsEn = new WritingSystemDefinition("en"); RepositoryUnderTest.Set(wsEn); var wsEnIpa = new WritingSystemDefinition("en-fonipa"); RepositoryUnderTest.Set(wsEnIpa); var wsFr = new WritingSystemDefinition("fr"); RepositoryUnderTest.Set(wsFr); var wsDe = new WritingSystemDefinition("de"); RepositoryUnderTest.Set(wsDe); var kbdEn = new DefaultKeyboardDefinition() { Layout = "English", Locale = "en-US" }; wsEn.LocalKeyboard = kbdEn; var kbdEnIpa = new DefaultKeyboardDefinition() { Layout = "English-IPA", Locale = "en-US" }; wsEnIpa.LocalKeyboard = kbdEnIpa; var kbdFr = new DefaultKeyboardDefinition() { Layout = "French", Locale = "fr-FR" }; wsFr.LocalKeyboard = kbdFr; var kbdDe = new DefaultKeyboardDefinition() { Layout = "English", Locale = "de-DE" }; wsDe.LocalKeyboard = kbdDe; var wss = new IWritingSystemDefinition[] {wsEn, wsFr, wsDe, wsEnIpa}; // Exact match selects correct one, even though there are other matches for layout and/or culture Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsFr, wss), Is.EqualTo(wsEn)); Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English-IPA", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEnIpa)); Assert.That(RepositoryUnderTest.GetWsForInputLanguage("French", new CultureInfo("fr-FR"), wsDe, wss), Is.EqualTo(wsFr)); Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("de-DE"), wsEn, wss), Is.EqualTo(wsDe)); // If there is no exact match, but there are matches by both layout and culture, we prefer layout (even though there is a // culture match for the default WS) Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsFr, wss), Is.EqualTo(wsEn)); // first of two equally good matches }
public void GetWsForInputLanguage_PrefersWsCurrentIfEqualMatches() { var wsEn = new WritingSystemDefinition("en"); RepositoryUnderTest.Set(wsEn); var wsEnUS = new WritingSystemDefinition("en-US"); RepositoryUnderTest.Set(wsEnUS); var wsEnIpa = new WritingSystemDefinition("en-fonipa"); RepositoryUnderTest.Set(wsEnIpa); var wsFr = new WritingSystemDefinition("fr"); RepositoryUnderTest.Set(wsFr); var wsDe = new WritingSystemDefinition("de"); RepositoryUnderTest.Set(wsDe); var kbdEn = new DefaultKeyboardDefinition() { Layout = "English", Locale = "en-US" }; wsEn.LocalKeyboard = kbdEn; var kbdEnIpa = new DefaultKeyboardDefinition() { Layout = "English-IPA", Locale = "en-US" }; wsEnIpa.LocalKeyboard = kbdEnIpa; wsEnUS.LocalKeyboard = kbdEn; // exact same keyboard used! var kbdFr = new DefaultKeyboardDefinition() { Layout = "French", Locale = "fr-FR" }; wsFr.LocalKeyboard = kbdFr; var kbdDe = new DefaultKeyboardDefinition() { Layout = "English", Locale = "de-DE" }; wsDe.LocalKeyboard = kbdDe; var wss = new IWritingSystemDefinition[] { wsEn, wsFr, wsDe, wsEnIpa, wsEnUS }; // Exact matches Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsFr, wss), Is.EqualTo(wsEn)); // first of 2 Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEn)); // prefer default Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("en-US"), wsEnUS, wss), Is.EqualTo(wsEnUS)); // prefer default // Match on Layout only Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsFr, wss), Is.EqualTo(wsEn)); // first of 3 Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsEn, wss), Is.EqualTo(wsEn)); // prefer default Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsEnUS, wss), Is.EqualTo(wsEnUS)); // prefer default Assert.That(RepositoryUnderTest.GetWsForInputLanguage("English", new CultureInfo("fr-FR"), wsDe, wss), Is.EqualTo(wsDe)); // prefer default // Match on culture only Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsDe, wss), Is.EqualTo(wsEn)); // first of 3 Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEn, wss), Is.EqualTo(wsEn)); // prefer default Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEnUS, wss), Is.EqualTo(wsEnUS)); // prefer default Assert.That(RepositoryUnderTest.GetWsForInputLanguage("Nonsence", new CultureInfo("en-US"), wsEnIpa, wss), Is.EqualTo(wsEnIpa)); // prefer default }
/// <summary> /// Creates a new writing system and selects it. /// </summary> /// <returns></returns> public virtual void AddNew() { if (!_usingRepository) { throw new InvalidOperationException("Unable to add new input system definition when there is no store."); } IWritingSystemDefinition ws=null; if (MethodToShowUiToBootstrapNewDefinition == null) { ws = _writingSystemRepository.CreateNew(); ws.Abbreviation = "New"; } else { ws = MethodToShowUiToBootstrapNewDefinition(); } if(ws==null)//cancelled return; if (ws.Abbreviation == WellKnownSubTags.Unlisted.Language) // special case for Unlisted Language { ws.Abbreviation = "v"; // TODO magic string!!! UnlistedLanguageView.DefaultAbbreviation; } WritingSystemDefinitions.Add(ws); CurrentDefinition = ws; OnAddOrDelete(); }
public void CanSetSecondNew_False() { RepositoryUnderTest.Set(_writingSystem); _writingSystem = RepositoryUnderTest.CreateNew(); Assert.IsFalse(RepositoryUnderTest.CanSet(_writingSystem)); }
internal void SaveDefinition(IWritingSystemDefinition ws) { SaveDefinition((WritingSystemDefinition)ws); }
public void SetKeyboard(IWritingSystemDefinition writingSystem) { }
public override void Set(IWritingSystemDefinition ws) { if (ws == null) { throw new ArgumentNullException("ws"); } var oldStoreId = ws.StoreID; base.Set(ws); //Renaming the file here is a bit ugly as the content has not yet been updated. Thus there //may be a mismatch between the filename and the contained rfc5646 tag. Doing it here however //helps us avoid having to deal with situations where a writing system id is changed to be //identical with the old id of another writing sytsem. This could otherwise lead to dataloss. //The inconsistency is resolved on Save() if (oldStoreId != ws.StoreID && File.Exists(GetFilePathFromIdentifier(oldStoreId))) { File.Move(GetFilePathFromIdentifier(oldStoreId), GetFilePathFromIdentifier(ws.StoreID)); } }
/// <summary> /// Tries to get the keyboard for the specified <paramref name="writingSystem"/>. /// </summary> public IKeyboardDefinition GetKeyboard(IWritingSystemDefinition writingSystem) { return TrivialKeyboard; }
// /// <summary> // /// Cause the model to reload, if you've made changes // /// (e.g., using a dialog to edit another copy of the mode) // /// </summary> // public void Refresh() // { // // } public virtual void AddPredefinedDefinition(IWritingSystemDefinition definition) { if (!_usingRepository) { throw new InvalidOperationException("Unable to add new writing system definition when there is no store."); } WritingSystemDefinitions.Add(definition); CurrentDefinition = definition; OnAddOrDelete(); }
/// <summary> /// /// </summary> /// <param name="ws">The ws.</param> protected override void OnChangeNotifySharedStore(IWritingSystemDefinition ws) { base.OnChangeNotifySharedStore(ws); if (m_globalStore != null) { if (m_globalStore.Contains(ws.Id)) { if (ws.DateModified > m_globalStore.Get(ws.Id).DateModified) { WritingSystemDefinition newWs = ws.Clone(); newWs.Modified = true; m_globalStore.Remove(ws.Id); m_globalStore.Set(newWs); } } else { m_globalStore.Set(ws.Clone()); } } }
/// <summary> /// Gets the specified writing system if it exists. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="ws">The writing system.</param> /// <returns></returns> public bool TryGet(string identifier, out IWritingSystemDefinition ws) { if (Contains(identifier)) { ws = Get(identifier); return true; } ws = null; return false; }