Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the Click event of the m_btnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// ------------------------------------------------------------------------------------
        private void btnOk_Click(object sender, EventArgs e)
        {
            CmCell        cell;
            string        fmtClassFlid = ScrScriptureNote.kClassId + ",{0}|";
            StringBuilder bldr         = new StringBuilder();

            m_filter.RowsOS[0].CellsOS.RemoveAll();

            if (chkStatus.Checked)
            {
                bldr.AppendFormat(fmtClassFlid,
                                  (int)ScrScriptureNote.ScrScriptureNoteTags.kflidResolutionStatus);

                cell = new CmCell();
                m_filter.RowsOS[0].CellsOS.Append(cell);
                int value = (rbResolved.Checked ? 1 : 0);
                cell.BuildIntegerMatchCriteria(CmCell.ComparisionTypes.kEquals, value, value);
            }

            if (chkType.Checked)
            {
                bldr.AppendFormat(fmtClassFlid,
                                  (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType);

                cell = new CmCell();
                m_filter.RowsOS[0].CellsOS.Append(cell);
                cell.BuildObjectMatchCriteria(rbConsultant.Checked ?
                                              LangProject.kguidAnnConsultantNote :
                                              LangProject.kguidAnnTranslatorNote, false, false);
            }

            if (chkScrRange.Checked)
            {
                bldr.AppendFormat(fmtClassFlid,
                                  (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginRef);
                bldr.AppendFormat(fmtClassFlid,
                                  (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginRef);

                ScrReference startRef = (scrBookFrom.ScReference.Chapter == 1 && scrBookFrom.ScReference.Verse == 1) ?
                                        new ScrReference(scrBookFrom.ScReference.Book, 0, 0, m_scr.Versification) :
                                        scrBookFrom.ScReference;

                cell = new CmCell();
                m_filter.RowsOS[0].CellsOS.Append(cell);
                cell.BuildIntegerMatchCriteria(CmCell.ComparisionTypes.kGreaterThanEqual,
                                               startRef, 0);
                cell = new CmCell();
                m_filter.RowsOS[0].CellsOS.Append(cell);
                cell.BuildIntegerMatchCriteria(CmCell.ComparisionTypes.kLessThanEqual,
                                               scrBookTo.ScReference, 0);
            }

            m_filter.ColumnInfo = bldr.ToString().TrimEnd('|');

            if (chkCategory.Checked)
            {
                tvCatagories.UpdateFilter(m_filter);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the specified filter with the selected category hvos.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void UpdateFilter(ICmFilter filter)
        {
            CmCell cell;
            string catColInfo = ScrScriptureNote.kClassId + "," +
                                (int)ScrScriptureNote.ScrScriptureNoteTags.kflidCategories + "|";

            StringBuilder bldr = new StringBuilder();

            if (SelectedHvos.Count == 0)
            {
                bldr.Append(catColInfo);
                cell = new CmCell();
                filter.RowsOS[0].CellsOS.Append(cell);
                cell.BuildObjectMatchCriteria();
            }
            else
            {
                foreach (int matchVal in SelectedHvos)
                {
                    bldr.Append(catColInfo);
                    cell = new CmCell();
                    filter.RowsOS[0].CellsOS.Append(cell);
                    cell.BuildObjectMatchCriteria(matchVal, true, false);
                }
            }

            if (bldr.Length > 0)
            {
                catColInfo = "|" + bldr.ToString().TrimEnd('|');
                if (filter.ColumnInfo == null)
                {
                    filter.ColumnInfo = catColInfo;
                }
                else
                {
                    filter.ColumnInfo += catColInfo;
                }
                filter.ColumnInfo = filter.ColumnInfo.TrimStart('|');
            }
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes the form's controls from the settings in the filter.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitializeFromFilter()
        {
            if (m_filter == null || m_filter.RowsOS.Count == 0 || m_filter.RowsOS[0].CellsOS.Count == 0)
            {
                return;
            }

            // Get the pairs of class ids and flids.
            string[] pairs = m_filter.ColumnInfo.Split('|');
            Debug.Assert(m_filter.RowsOS[0].CellsOS.Count == pairs.Length);

            for (int i = 0; i < pairs.Length; i++)
            {
                CmCell cell = (CmCell)m_filter.RowsOS[0].CellsOS[i];
                Guid   guid;

                // Get the flid for this cell.
                string[] pair = pairs[i].Split(',');
                int      flid = 0;
                int.TryParse(pair[1], out flid);

                switch (flid)
                {
                case (int)ScrScriptureNote.ScrScriptureNoteTags.kflidResolutionStatus:
                    chkStatus.Checked = true;
                    cell.ParseIntegerMatchCriteria();
                    rbResolved.Checked   = (cell.MatchValue == 1);
                    rbUnresolved.Checked = (cell.MatchValue == 0);
                    break;

                case (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType:
                    chkType.Checked = true;
                    cell.ParseObjectMatchCriteria();
                    guid = StringUtils.GetGuidFromRun(cell.Contents.UnderlyingTsString, 1);
                    rbConsultant.Checked = (guid == LangProject.kguidAnnConsultantNote);
                    rbTranslator.Checked = (guid == LangProject.kguidAnnTranslatorNote);
                    break;

                case (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginRef:
                    chkScrRange.Checked = true;
                    cell.ParseIntegerMatchCriteria();
                    ScrReference scrRef = new ScrReference(cell.MatchValue, m_scr.Versification);
                    // If the reference was adjusted to 0:0 to include notes in the title and
                    // introduction, adjust it back to 1:1 so we don't confuse the user.
                    if (scrRef.Chapter == 0)
                    {
                        scrRef.Chapter = 1;
                    }
                    if (scrRef.Verse == 0)
                    {
                        scrRef.Verse = 1;
                    }

                    if (cell.ComparisonType == CmCell.ComparisionTypes.kGreaterThanEqual)
                    {
                        scrBookFrom.ScReference = scrRef;
                    }
                    else
                    {
                        scrBookTo.ScReference = scrRef;
                    }
                    break;
                }
            }
        }