/// ------------------------------------------------------------------------------------ /// <summary> /// Determines if a dialog box asking for user settings is necessary and, if so, /// shows the dialog box. /// </summary> /// ------------------------------------------------------------------------------------ private bool GetFilterValuesFromUser(CmFilter userFilter) { if (userFilter == null) return true; // Don't try create an undo task for this. The user won't expect to undo/redo this // action. (TE-8575) using (new SuppressSubTasks(Cache)) { Cache.SetIntProperty(userFilter.Hvo, (int)SIL.FieldWorks.FDO.Cellar.CmFilter.CmFilterTags.kflidShowPrompt, 0); if (userFilter.ShortName == "kstidNoteMultiFilter") { using (MultipleFilterDlg dlg = new MultipleFilterDlg(Cache, userFilter)) { if (dlg.ShowDialog() != DialogResult.OK) return false; } } else if (userFilter.ShortName == "kstidCategoryNoteFilter") { using (CategoryFilterDlg dlg = new CategoryFilterDlg(Cache, userFilter)) { if (dlg.ShowDialog() != DialogResult.OK) return false; } } } return true; }
public void TestLoad_AtomicObjectFilter() { CheckDisposed(); // Set up a filter CmFilter filter = new CmFilter(); Cache.LangProject.FiltersOC.Add(filter); filter.ClassId = ScrScriptureNote.kClassId; // We will filter ScrScriptureNotes on the AnnotationType field (which is actually a // field of the base class CmAnnotation). filter.ColumnInfo = ScrScriptureNote.kclsidScrScriptureNoteString + "," + ((int)CmAnnotation.CmAnnotationTags.kflidAnnotationType).ToString(); filter.ShowPrompt = 0; CmRow row = new CmRow(); filter.RowsOS.Append(row); CmCell cell = new CmCell(); row.CellsOS.Append(cell); // Now specify the matching criteria for this filter cell ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Matches ", SIL.FieldWorks.Common.FwUtils.StyleUtils.CharStyleTextProps(null, Cache.DefaultUserWs)); StringUtils.InsertOrcIntoPara(m_inMemoryCache.m_translatorNoteDefn.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, bldr.Length, bldr.Length, Cache.DefaultUserWs); cell.Contents.UnderlyingTsString = bldr.GetString(); // Construct a handler to apply the above filter. filter.UserView = m_userView; FilteredSequenceHandler handler = new FilteredSequenceHandler(Cache, ScrBookAnnotations.kClassId, -42, filter, null, m_userView); // CacheVecProp() should be called with an array of HVOs representing only the translator notes. m_mockedDataAccess.Expect("CacheVecProp", new object[] {m_annotationsGen.Hvo, -94, new int[] {m_note2b.Hvo, m_note3.Hvo}, 2}); // Now test the Load method handler.Load(m_annotationsGen.Hvo, -94, -1, (IVwCacheDa)m_mockedDataAccess.MockInstance); m_mockedDataAccess.Verify(); }
public void TestLoad_ObjectSequenceFilterWithSubItems() { CheckDisposed(); // Set up a filter CmFilter filter = new CmFilter(); Cache.LangProject.FiltersOC.Add(filter); filter.ClassId = ScrScriptureNote.kClassId; // We will filter ScrScriptureNotes on the Categories field. filter.ColumnInfo = ScrScriptureNote.kclsidScrScriptureNoteString + "," + ((int)ScrScriptureNote.ScrScriptureNoteTags.kflidCategories).ToString(); filter.ShowPrompt = 1; CmRow row = new CmRow(); filter.RowsOS.Append(row); CmCell cell = new CmCell(); row.CellsOS.Append(cell); // Now specify the matching criteria for this filter cell ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.Replace(0, 0, "Matches +subitems", SIL.FieldWorks.Common.FwUtils.StyleUtils.CharStyleTextProps(null, Cache.DefaultUserWs)); StringUtils.InsertOrcIntoPara(m_inMemoryCache.m_categoryDiscourse.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 8, 8, Cache.DefaultUserWs); cell.Contents.UnderlyingTsString = bldr.GetString(); // Set up mocked ChooserDlg to expect to be called with the default category of Discourse (from // filter cell criteria defined above) but return Grammar category. m_mockedChooserDlg.ExpectAndReturn("GetPossibility", m_inMemoryCache.m_categoryGrammar.Hvo, new object[] {m_scr.NoteCategoriesOA, m_inMemoryCache.m_categoryDiscourse.Hvo}); // Construct a handler to apply the above filter. filter.UserView = m_userView; filter.PossibilitySupplier = (ICmPossibilitySupplier)m_mockedChooserDlg.MockInstance; FilteredSequenceHandler handler = new FilteredSequenceHandler(Cache, ScrBookAnnotations.kClassId, -42, filter, null, m_userView); // Now test the Load method // CacheVecProp() should be called with an array of HVOs representing all the Grammar notes, // including those that refer to sub-items of the main Grammar category. m_mockedDataAccess.Expect("CacheVecProp", new object[] {m_annotationsGen.Hvo, -94, new int[] {m_note2a.Hvo, m_note2b.Hvo, m_note3.Hvo}, 3}); handler.Load(m_annotationsGen.Hvo, -94, -1, (IVwCacheDa)m_mockedDataAccess.MockInstance); m_mockedDataAccess.Verify(); m_mockedChooserDlg.Verify(); // Make sure the newly-selected object (i.e., the Grammar category) has been stored as the // filter criteria (for next time). StringUtils.InsertOrcIntoPara(m_inMemoryCache.m_categoryGrammar.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 8, 9, Cache.DefaultUserWs); AssertEx.AreTsStringsEqual(bldr.GetString(), cell.Contents.UnderlyingTsString); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="NotesViewFilter"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="userFilter">The user filter.</param> /// ------------------------------------------------------------------------------------ internal NotesViewFilter(FdoCache cache, CmFilter userFilter) : base(new ExcludeCheckingErrorsFilter(cache), userFilter) { }
public void TestLoad_IntFilter() { CheckDisposed(); // Set up a filter CmFilter filter = new CmFilter(); Cache.LangProject.FiltersOC.Add(filter); filter.ClassId = ScrScriptureNote.kClassId; // We will filter ScrScriptureNotes on the ResolutionStatus field. filter.ColumnInfo = ScrScriptureNote.kclsidScrScriptureNoteString + "," + ((int)ScrScriptureNote.ScrScriptureNoteTags.kflidResolutionStatus).ToString(); filter.ShowPrompt = 0; CmRow row = new CmRow(); filter.RowsOS.Append(row); CmCell cell = new CmCell(); row.CellsOS.Append(cell); // Now specify the matching criteria for this filter cell ITsStrFactory factory = TsStrFactoryClass.Create(); cell.Contents.UnderlyingTsString = factory.MakeString("= 0", Cache.DefaultUserWs); // Construct a handler to apply the above filter. filter.UserView = m_userView; FilteredSequenceHandler handler = new FilteredSequenceHandler(Cache, ScrBookAnnotations.kClassId, -42, filter, null, m_userView); // CacheVecProp() should be called with an array of HVOs representing only the open notes. m_mockedDataAccess.Expect("CacheVecProp", new object[] { m_annotationsGen.Hvo, -94, new int[] { m_note1.Hvo, m_note2b.Hvo }, 2 }); // Now test the Load method handler.Load(m_annotationsGen.Hvo, -94, -1, (IVwCacheDa)m_mockedDataAccess.MockInstance); m_mockedDataAccess.Verify(); }
public void TestClearInfoAbout() { // Create two test objects and add them to the language project. // It doesn't really matter what type of object they are as long // as the object contains at least one guid property. CmFilter testObj1 = new CmFilter(); CmFilter testObj2 = new CmFilter(); m_fdoCache.LangProject.FiltersOC.Add(testObj1); m_fdoCache.LangProject.FiltersOC.Add(testObj2); // Set a guid property for the 2nd test object // that is equal to the first test object's guid. m_sda.SetGuid(testObj2.Hvo, (int)CmFilter.CmFilterTags.kflidApp, testObj1.Guid); // This should not delete the first test object's guid // from the cache's internal cache of object guids. ((IVwCacheDa)m_da).ClearInfoAbout(testObj2.Hvo, VwClearInfoAction.kciaRemoveObjectAndOwnedInfo); // This will make sure that get_ObjFromGuid()j doesn't defer to // the database when it cannot find the object in the cache. m_da.AutoloadPolicy = AutoloadPolicies.kalpNoAutoload; // Make sure we still can create the first test object from it's guid. Assert.AreEqual(testObj1.Hvo, m_sda.get_ObjFromGuid(testObj1.Guid)); }
public void TestUpdatePropIfCached() { // Create two test objects and add them to the language project. // It doesn't really matter what type of object they are as long // as the object contains at least one guid property. CmFilter testObj1 = new CmFilter(); CmFilter testObj2 = new CmFilter(); m_fdoCache.LangProject.FiltersOC.Add(testObj1); m_fdoCache.LangProject.FiltersOC.Add(testObj2); // Set a guid property for the 2nd test object // that is equal to the first test object's guid. m_sda.SetGuid(testObj2.Hvo, (int)CmFilter.CmFilterTags.kflidApp, testObj1.Guid); // This should not delete guid from the cache's internal object guid cache. m_da.UpdatePropIfCached(testObj2.Hvo, testObj2.FieldId, (int)CellarModuleDefns.kcptGuid, 0); // Make sure we still can create the first test object from it's guid. Assert.AreEqual(testObj1.Hvo, m_sda.get_ObjFromGuid(testObj1.Guid)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the filter panel in the status bar. /// </summary> /// ------------------------------------------------------------------------------------ private void NoteFilterChanged(object sender, CmFilter filter) { bool fFiltered = (filter != null); ShowFilterStatusBarMessage(fFiltered); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Implement CreateTestData, called by InMemoryFdoTestBase set up. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { // Set up a filter, with a CmCell we can test on. m_inMemoryCache.InitializeAnnotationDefs(); m_inMemoryCache.InitializeAnnotationCategories(); CmFilter filter = new CmFilter(); Cache.LangProject.FiltersOC.Add(filter); CmRow row = new CmRow(); filter.RowsOS.Append(row); m_cell = new DummyCmCell(); row.CellsOS.Append(m_cell); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create the "book" filter if it doesn't already exist. /// </summary> /// ------------------------------------------------------------------------------------ private void CreateBookFilterIfMissing() { foreach (ICmFilter filter in m_cache.LangProject.FiltersOC) { if (filter.App == TeApp.AppGuid && filter.ClassId == ScrBook.kClassId) return; } ICmFilter bookFilter = new CmFilter(); m_cache.LangProject.FiltersOC.Add(bookFilter); bookFilter.App = TeApp.AppGuid; bookFilter.ClassId = ScrBook.kClassId; bookFilter.Name = TeResourceHelper.GetResourceString("kstidFilterBook"); bookFilter.ColumnInfo = "3002,3002003"; // Theoretically, we should probably be creating a CmRow and a CmCell for this filter, // but since we aren't making use of the FW approach for filtering by book, we don't // need those things. m_cache.Save(); }