public NotesBarModel(IAnnotationRepository repository, NotesToRecordMapping mapping) { _repository = repository; _mapping = mapping; repository.AddObserver(this, new NullProgress()); }
public override void FinishInit() { m_chorusSystem = new ChorusSystem(Cache.ProjectId.ProjectFolder); m_chorusSystem.InitWithoutHg(SendReceiveUser); // This is a required object for CreateNotesBar. It specifies delegates for getting the information // the bar requires about the current object. var notesToRecordMapping = new NotesToRecordMapping() { FunctionToGetCurrentUrlForNewNotes = GetCurrentUrlForNewNotes, FunctionToGoFromObjectToItsId = GetIdForObject, FunctionToGoFromObjectToAdditionalIds = GetAdditionalIdsForObject }; var dataFilePath = GetDataFilePath(Cache); var additionalPaths = GetAdditionalLexiconFilePaths(Cache); const string idAttrForOtherFiles = "guid"; // .lexdb chorus notes files identify FLEx object with a url attr of "guid". m_notesBar = m_chorusSystem.WinForms.CreateNotesBar(dataFilePath, additionalPaths, idAttrForOtherFiles, notesToRecordMapping, new NullProgress()); m_notesBar.SetTargetObject(m_obj); // Set the writing systems for the NoteDetailDialog. (See FWNX-1239.) var vernWs = Cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem; var labelWs = new ChorusWritingSystem(vernWs.LanguageName, vernWs.RFC5646, vernWs.DefaultFontName, 12); m_notesBar.LabelWritingSystem = labelWs; var analWs = Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem; var msgWs = new ChorusWritingSystem(analWs.LanguageName, analWs.RFC5646, analWs.DefaultFontName, 12); m_notesBar.MessageWritingSystem = msgWs; this.Control = m_notesBar; }
public void CanMakeNotesBarWithOtherFiles() { using (var otherFile = new TempFileFromFolder(_folder, "two.txt", "just a pretend file")) using (var otherNotesFile = new TempFileFromFolder(_folder, "two.txt." + AnnotationRepository.FileExtension, @"<notes version='0'> <annotation ref='somwhere://foo?guid=x' class='mergeConflict'> <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'> some description of the conflict </message> </annotation> </notes>" )) { var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = obj => "x"; // means it looks for "x" as the id in the one.txt urls and the guid in the two.txt urls. using (var view = _system.WinForms.CreateNotesBar(_targetFile1.Path, (new List <String> { otherFile.Path }), "guid", mapping, _progress)) { view._model.SetTargetObject("myobj"); var annotations = view._model.GetAnnotationsToShow().ToList(); Assert.That(annotations, Has.Count.EqualTo(2), "should have obtained annotations from both files"); ShowWindowWithControlThenClose(view); } } }
public NotesBarModel(AnnotationRepository repository, NotesToRecordMapping mapping) { _repository = repository; _mapping = mapping; repository.AddObserver(this, new NullProgress()); }
public DataEditor(ChorusSystem chorusSystem, string dataFilePath) { _chorusSystem = chorusSystem; _dataFilePath = dataFilePath; InitializeComponent(); var notesToRecordMapping = new NotesToRecordMapping() { FunctionToGetCurrentUrlForNewNotes = GetCurrentUrlForNewNotes, FunctionToGoFromObjectToItsId = GetIdForObject }; _notesBar = _chorusSystem.WinForms.CreateNotesBar(dataFilePath, notesToRecordMapping, new NullProgress()); _notesBar.Location = new Point(10, 6); this.Controls.Add(_notesBar); XmlDocument doc = new XmlDocument(); doc.Load(dataFilePath); var areas = doc.SelectNodes("//area"); _area1Text.Tag = _area1Label.Text = areas[0].Attributes["id"].Value; _area1Text.Text = areas[0].InnerText.Trim(); _area2Text.Tag = _area2Label.Text = areas[1].Attributes["id"].Value; _area2Text.Text = areas[1].InnerText.Trim(); }
public void CreateAnnotation_HaveCustomUrlGenerator_UseIt() { var repo = AnnotationRepository.FromString("id", "<notes version='0'/>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = (target) => "x" + target.ToString() + "x"; mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => "foobar:" + escapedId; var model = new NotesBarModel(repo, mapping); model.SetTargetObject("foo3"); model.CreateAnnotation(); Assert.AreEqual(1, repo.GetAllAnnotations().Count()); Assert.AreEqual("foobar:xfoo3x", repo.GetAllAnnotations().First().RefStillEscaped); }
public void CreateAnnotation_KeyHasDangerousCharacters_ResultingUrlHasThemEscaped() { var repo = AnnotationRepository.FromString("id", "<notes version='0'/>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => string.Format("lift://object?type=entry&id={0}&type=test", escapedId); mapping.FunctionToGoFromObjectToItsId = NotesToRecordMapping.DefaultIdGeneratorUsingObjectToStringAsId; //mapping.UrlGenerator = (target,key)=> string.Format("lift://object?type=entry&id={0}&type=test", key); var model = new NotesBarModel(repo, mapping); model.SetTargetObject("two'<three&four"); model.CreateAnnotation(); Assert.IsTrue(repo.GetAllAnnotations().First().RefUnEscaped.Contains("two'<three&four")); }
public void CreateAnnotation_HaveCustomUrlGenerator_UseIt() { var repo = AnnotationRepository.FromString("id", "<notes version='0'/>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = (target) => "x" + target.ToString() + "x"; mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => "foobar:" + escapedId; var model = new NotesBarModel(repo, mapping); model.SetTargetObject("foo3"); model.AddAnnotation(model.CreateAnnotation()); Assert.AreEqual(1, repo.GetAllAnnotations().Count()); Assert.AreEqual("foobar:xfoo3x", repo.GetAllAnnotations().First().RefStillEscaped); }
public void CreateAnnotation_KeyHasDangerousCharacters_ResultingUrlHasThemEscaped() { var repo = AnnotationRepository.FromString("id", "<notes version='0'/>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, escapedId) => string.Format("lift://object?type=entry&id={0}&type=test", escapedId); mapping.FunctionToGoFromObjectToItsId = NotesToRecordMapping.DefaultIdGeneratorUsingObjectToStringAsId; //mapping.UrlGenerator = (target,key)=> string.Format("lift://object?type=entry&id={0}&type=test", key); var model = new NotesBarModel(repo, mapping); model.SetTargetObject("two'<three&four"); model.AddAnnotation(model.CreateAnnotation()); Assert.IsTrue(repo.GetAllAnnotations().First().RefUnEscaped.Contains("two'<three&four")); }
[Platform(Exclude = "Mono")] //running CreateNotesBrowser twice in a mono test session causes a crash public void GetNotesBarAndBrowser_MakeNewAnnotationWithBar_BrowserSeesIt() { NotesToRecordMapping mapping = NotesToRecordMapping.SimpleForTest(); var bar = _system.WinForms.CreateNotesBar(_targetFile1.Path, mapping, _progress); var browser = _system.WinForms.CreateNotesBrowser(); Assert.AreEqual(1, browser._notesInProjectModel.GetMessages().Count()); bar.SetTargetObject(this); var a = bar._model.CreateAnnotation(); bar._model.AddAnnotation(a); a.AddMessage("test", "open", "hello"); Assert.AreEqual(2, browser._notesInProjectModel.GetMessages().Count()); }
/// <summary> /// Determine if the object really has data to be shown in the slice. This method is called by reflection /// from DataTree.AddSimpleNode, to determine whether to create the slice when visibility is "ifdata". /// </summary> /// <param name="obj">object to check; should be an ILexEntry</param> /// <returns>true if there are chorus notes for this object; false otherwise</returns> public static bool ShowSliceForVisibleIfData(XmlNode node, ICmObject obj) { using (var chorusSystem = new ChorusSystem(obj.Cache.ProjectId.ProjectFolder)) { chorusSystem.InitWithoutHg(SendReceiveUser); // This is a required object for CreateNotesBar. It specifies delegates for getting the information // the bar requires about the current object. For this model the FunctionToGetCurrentUrlForNewNotes will not be used. var notesToRecordMapping = new NotesToRecordMapping() { FunctionToGetCurrentUrlForNewNotes = DummyGetCurrentUrlForNewNotes, FunctionToGoFromObjectToItsId = GetIdForObject }; var dataFilePath = GetDataFilePath(obj.Cache); var notesmodel = chorusSystem.WinForms.CreateNotesBarModel(dataFilePath, notesToRecordMapping, new NullProgress()); notesmodel.SetTargetObject(obj); return(notesmodel.GetAnnotationsToShow().Any()); } }
public void GetAnnotationsToShow_ShowsAnnotationsFromFunctionToGoFromObjectToItsId() { var repo = AnnotationRepository.FromString("guid", @"<notes version='0'> <annotation guid='123' ref='lift://FTeam.lift?type=entry&guid=abc'><message guid='234'>hello</message></annotation> <annotation guid='345' ref='lift://FTeam.lift?type=entry&guid=def'><message guid='234'>hello</message></annotation> </notes>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = (x) => "def"; var model = new NotesBarModel(repo, mapping); model.SetTargetObject("xyz"); var annotationsToShow = model.GetAnnotationsToShow().ToList(); Assert.That(annotationsToShow, Has.Count.EqualTo(1)); Assert.That(annotationsToShow[0].Guid, Is.EqualTo("345")); }
public void CreateNotesBar() { //Tell Chorus how to map between our records and the url system we want to use in notes var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = who => ((Character)who).Guid; mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, unusedId) => string.Format("comics://character?id={0}?label={1}", _currentCharacter.Guid, _currentCharacter.Name); //or mapping.FunctionToGetCurrentUrlForNewNotes = (unusedTarget, unusedId) => _currentCharacter.GetUrl(); var barControl = _chorusSystem.WinForms.CreateNotesBar(_someDataFilePath, mapping, _progress); //Next, we'd add it to a parent control, for example, at the top of the screen showing the current record //myView.Controls.Add(barControl); //Then each time we change record, we let it know, and it will look up an display any notes targeted at this record: barControl.SetTargetObject(_currentCharacter); barControl.Dispose(); //normally, your parent control will do this for you }
public void GetAnnotationsToShow_ShowsAnnotationsFromFunctionToGoFromObjectToAdditionalIds() { var repo = AnnotationRepository.FromString("guid", @"<notes version='0'> <annotation guid='123' ref='lift://FTeam.lift?type=entry&guid=abc'><message guid='234'>hello</message></annotation> <annotation guid='345' ref='lift://FTeam.lift?type=entry&guid=def'><message guid='234'>hello</message></annotation> <annotation guid='567' ref='lift://FTeam.lift?type=entry&guid=ghi'><message guid='234'>hello</message></annotation> <annotation guid='678' ref='lift://FTeam.lift?type=entry&guid=klm'><message guid='234'>hello</message></annotation> </notes>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = (x) => "def"; mapping.FunctionToGoFromObjectToAdditionalIds = (x) => new [] {"ghi", "abc"}; var model = new NotesBarModel(repo, mapping); model.SetTargetObject("xyz"); var annotationsToShow = model.GetAnnotationsToShow().ToList(); Assert.That(annotationsToShow, Has.Count.EqualTo(3)); Assert.That(annotationsToShow[0].Guid, Is.EqualTo("345")); Assert.That(annotationsToShow[1].Guid, Is.EqualTo("567")); Assert.That(annotationsToShow[2].Guid, Is.EqualTo("123")); }
public void CanMakeNotesBarWithOtherFiles() { var otherFile = new TempFileFromFolder(_folder, "two.txt", "just a pretend file"); var otherNotesFile = new TempFileFromFolder(_folder, "two.txt." + AnnotationRepository.FileExtension, @"<notes version='0'> <annotation ref='somwhere://foo?guid=x' class='mergeConflict'> <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'> some description of the conflict </message> </annotation> </notes>"); var mapping = new NotesToRecordMapping(); mapping.FunctionToGoFromObjectToItsId = obj => "x"; // means it looks for "x" as the id in the one.txt urls and the guid in the two.txt urls. var view = _system.WinForms.CreateNotesBar(_targetFile1.Path, (new List<String> {otherFile.Path}), "guid", mapping, _progress); view._model.SetTargetObject("myobj"); var annotations = view._model.GetAnnotationsToShow().ToList(); Assert.That(annotations, Has.Count.EqualTo(2), "should have obtained annotations from both files"); ShowWindowWithControlThenClose(view); otherFile.Dispose(); otherNotesFile.Dispose(); }
public void ShowNotesBar() { using (var folder = new TemporaryFolder("NotesModelTests")) using (var dataFile = new TempFileFromFolder(folder, "one.txt", "just a pretend file")) using (new TempFileFromFolder(folder, "one.txt." + AnnotationRepository.FileExtension, @"<notes version='0'> <annotation ref='somwhere://foo?id=x' class='question'> <message guid='123' author='john' status='open' date='2009-07-18T23:53:04Z'> Suzie, is this ok? </message> <message guid='222' author='suzie' status='closed' date='2009-09-19T23:53:04Z'> It's fine. </message> </annotation> <annotation ref='lift://name%20with%20space.lift?id=x' class='mergeConflict'> <message guid='123' author='merger' status='open' date='2009-07-18T23:53:04Z'> some description of the conflict </message> </annotation> <annotation ref='somwhere://foo2?id=y' class='note'/> </notes>" )) { var chorus = new ChorusSystem(folder.Path); var view = chorus.WinForms.CreateNotesBar(dataFile.Path, NotesToRecordMapping.SimpleForTest(), _progress); view.Height = 32; view.SetTargetObject("x"); TextBox b = new TextBox(); b.Location = new Point(0, 50); b.Text = "x"; b.TextChanged += new EventHandler((s, e) => view.SetTargetObject(b.Text)); var form = new Form(); form.Size = new Size(700, 600); form.Controls.Add(view); form.Controls.Add(b); Application.EnableVisualStyles(); Application.Run(form); } }
internal NotesBarModel(IAnnotationRepository repository) : this(repository, NotesToRecordMapping.SimpleForTest()) { }