public OptionCollectionControl(OptionRefCollection optionRefCollection, OptionsList list, string idOfPreferredWritingSystem) { _optionRefCollection = optionRefCollection; _list = list; _idOfPreferredWritingSystem = idOfPreferredWritingSystem; InitializeComponent(); LoadDisplay(); }
public void Setup() { _ws = new WritingSystem("xx", new Font("Arial", (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); _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(); }
public override void Activate() { base.Activate(); if (DomainKeys == null) { _domainKeys = new List<string>(); _domainQuestions = new Dictionary<string, List<string>>(); ParseSemanticDomainFile(); // always have at least one domain and one question // so default indexes of 0 are valid. if (_domainKeys.Count == 0) { _domainKeys.Add(string.Empty); } if (_domainQuestions.Count == 0) { List<string> emptyList = new List<string>(); emptyList.Add(string.Empty); _domainQuestions.Add(string.Empty, emptyList); } } if (_semanticDomainOptionsList == null) { _semanticDomainOptionsList = WeSayWordsProject.Project.GetOptionsList(_semanticDomainField, false); } UpdateCurrentWords(); if (CurrentDomainIndex == -1) { GotoLastDomainWithAnswers(); } _gatherControl = new GatherBySemanticDomainsControl(this); }
public void SaveToFile() { Option x = new Option(); x.Abbreviation.SetAlternative("a", "aabrev"); x.Abbreviation.SetAlternative("b", "babrev"); x.Key = "akey"; x.Name.SetAlternative("a", "aname"); x.Name.SetAlternative("b", "bname"); Option y = new Option(); y.Abbreviation.SetAlternative("a", "aabrev"); y.Abbreviation.SetAlternative("b", "babrev"); y.Key = "akey"; y.Name.SetAlternative("a", "aname"); y.Name.SetAlternative("b", "bname"); OptionsList list = new OptionsList(); list.Options.Add(x); list.Options.Add(y); string path = Path.GetTempFileName(); list.SaveToFile(path); // Debug.WriteLine(xml); OptionsList.LoadFromFile(path); Assert.AreEqual("aname", list.Options[1].Name.GetBestAlternative("a")); }
public OptionsList GetOptionsList(Field field, bool createIfFileMissing) { if (String.IsNullOrEmpty(field.OptionsListFile)) { throw new ConfigurationException( "The administrator needs to declare an options list file for the field {0}. This can be done under the Fields tab of the WeSay Configuration Tool.", field.FieldName); } OptionsList list; if (_optionLists.TryGetValue(field.OptionsListFile, out list)) { return list; } string pathInProject = Path.Combine(PathToWeSaySpecificFilesDirectoryInProject, field.OptionsListFile); if (File.Exists(pathInProject)) { LoadOptionsList(pathInProject); } else { string pathInProgramDir = Path.Combine(ApplicationCommonDirectory, field.OptionsListFile); if (!File.Exists(pathInProgramDir)) { if (createIfFileMissing) { list = new OptionsList(); _optionLists.Add(Path.GetFileName(pathInProject), list); return list; } else { throw new ConfigurationException( "Could not find the optionsList file {0}. Expected to find it at: {1} or {2}", field.OptionsListFile, pathInProject, pathInProgramDir); } } LoadOptionsList(pathInProgramDir); } return _optionLists[field.OptionsListFile]; }
private void LoadList(Field field) { try { SaveCurrentList(); _currentField = field; _currentList = WeSayWordsProject.Project.GetOptionsList(_currentField, true); _listBox.Items.Clear(); _currentListWasModified = false; foreach (Option option in _currentList.Options) { _listBox.Items.Add(option.GetDisplayProxy(PreferredWritingSystem)); } if (_listBox.Items.Count > 0) { _listBox.SelectedIndex = 0; } _fieldChooser.SelectedItem = field; UpdateDisplay(); } catch (ConfigurationException e) { ErrorReport.ReportNonFatalMessage(e.Message); } }
public void Setup() { _sourceChoices = new OptionsList(); AddSourceChoice("one", "1"); AddSourceChoice("two", "2"); AddSourceChoice("three", "3"); AddSourceChoice("four", "4"); AddSourceChoice("five", "5"); _chosenItems = new OptionRefCollection(this); List<WritingSystem> writingSystems = new List<WritingSystem>(); writingSystems.Add(_ws); _control = new ReferenceCollectionEditor<Option, string, OptionRef>( _chosenItems.Members, _sourceChoices.Options, writingSystems, CommonEnumerations.VisibilitySetting.Visible, new OptionDisplayAdaptor(_sourceChoices, _ws.Id)); _control.Name = "refcontrol"; _control.AlternateEmptinessHelper = _chosenItems; }