Ejemplo n.º 1
0
        public InnerLabeledMultiStringControl(LcmCache cache, int wsMagic)
        {
            m_realCache = cache;
            m_sda       = new TextBoxDataAccess {
                WritingSystemFactory = cache.WritingSystemFactory
            };
            m_rgws = WritingSystemServices.GetWritingSystemList(cache, wsMagic, 0, false);

            AutoScroll = true;
            IsTextBox  = true;                  // range selection not shown when not in focus
        }
Ejemplo n.º 2
0
        /// <summary>
        /// returns a list of the writing systems available to display for this view
        /// </summary>
        /// <param name="fIncludeUncheckedActiveWss">if false, include only current wss,
        /// if true, includes unchecked active wss.</param>
        public List <CoreWritingSystemDefinition> GetWritingSystemOptions(bool fIncludeUncheckedActiveWss)
        {
            var result = WritingSystemServices.GetWritingSystemList(m_cache, m_wsMagic, m_hvoObj,
                                                                    m_forceIncludeEnglish, fIncludeUncheckedActiveWss);

            if (fIncludeUncheckedActiveWss && m_wsOptional != 0)
            {
                result = new List <CoreWritingSystemDefinition>(result);                // just in case caller does not want it modified
                var additionalWss = WritingSystemServices.GetWritingSystemList(m_cache, m_wsOptional, m_hvoObj,
                                                                               m_forceIncludeEnglish, fIncludeUncheckedActiveWss);
                foreach (var ws in additionalWss)
                {
                    if (!result.Contains(ws))
                    {
                        result.Add(ws);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public void InnerViewRefreshesWhenRefreshIsPending()
        {
            ILexEntry entry = null;
            int       flid  = 5035001;      // MoForm flid

            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
                IMoStemAllomorph morph = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create();
                entry.LexemeFormOA     = morph;
            });

            Form dummyForm = new Form();
            LabeledMultiStringView view = new LabeledMultiStringView(entry.LexemeFormOA.Hvo, flid, WritingSystemServices.kwsVern, false, true);

            dummyForm.Controls.Add(view);
            InnerLabeledMultiStringView innerView = view.InnerView;

            view.FinishInit();
            innerView.Cache = Cache;

            // Access the Handle of the innerView to construct the RootBox.
            var handle = innerView.Handle;

            Assert.IsFalse(innerView.Visible);
            Assert.IsFalse(innerView.RefreshPending);
            view.WritingSystemsToDisplay =
                WritingSystemServices.GetWritingSystemList(Cache, WritingSystemServices.kwsVern, false);
            view.RefreshDisplay();
            // The flag gets set because the view is not yet visible, so the display cannot refresh.
            Assert.IsTrue(innerView.RefreshPending);
            // Trigger the display to refresh by making the form visible.
            dummyForm.Visible = true;
            Assert.IsFalse(innerView.RefreshPending);
            view.Dispose();
            NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => entry.Delete());
        }
Ejemplo n.º 4
0
        public void WriteCustomFieldConfigForOneFieldSourceType(
            int classId,
            string fieldSourceType,              // Can be either "entry", "senses", or "examples"
            Dictionary <string, LfConfigFieldBase> lfCustomFieldConfig,
            Dictionary <string, string> lfCustomFieldTypes
            )
        {
            IEnumerable <int> customFieldIds =
                LcmMetaData.GetFields(classId, false, (int)CellarPropertyTypeFilter.All)
                .Where(flid => cache.GetIsCustomField(flid));

            foreach (int flid in customFieldIds)
            {
                string label = LcmMetaData.GetFieldNameOrNull(flid);
                if (label == null)
                {
                    continue;
                }
                string             lfCustomFieldName = ConvertUtilities.NormalizedFieldName(label, fieldSourceType);
                CellarPropertyType LcmFieldType      = (CellarPropertyType)LcmMetaData.GetFieldType(flid);
                lfCustomFieldTypes[lfCustomFieldName] = LcmFieldType.ToString();
                string lfCustomFieldType;
                if (CellarPropertyTypeToLfCustomFieldType.TryGetValue(LcmFieldType, out lfCustomFieldType))
                {
                    // Get custom field configuration info
                    LfConfigFieldBase fieldConfig = null;

                    if (lfCustomFieldType.EndsWith("ListRef"))
                    {
                        // List references, whether single or multi, need a list code
                        string listCode = GetParentListCode(flid);
                        fieldConfig = GetLfCustomFieldOptionListConfig(label, lfCustomFieldType, listCode);
                    }
                    else if (lfCustomFieldType == CellarPropertyTypeToLfCustomFieldType[CellarPropertyType.OwningAtomic])
                    {
                        // Multiparagraphs don't need writing systems
                        fieldConfig = GetLfCustomFieldMultiParagraphConfig(label, lfCustomFieldType);
                    }
                    else
                    {
                        // Single line or MultiText fields need writing systems
                        int fieldWs = LcmMetaData.GetFieldWs(flid);
                        // That's a "magic" ws, which we need to expand into a (list of) real writing system(s).
#if FW8_COMPAT
                        var wsesForThisField = new List <IWritingSystem>();
#else
                        var wsesForThisField = new List <CoreWritingSystemDefinition>();
#endif
                        // GetWritingSystemList() in FW 8.3 is buggy and doesn't properly handle the kwsAnal and kwsVern cases, so we handle them here instead.
                        switch (fieldWs)
                        {
                        case WritingSystemServices.kwsAnal:
                            wsesForThisField.Add(servLoc.LanguageProject.DefaultAnalysisWritingSystem);
                            break;

                        case WritingSystemServices.kwsVern:
                            wsesForThisField.Add(servLoc.LanguageProject.DefaultVernacularWritingSystem);
                            break;

                        default:
                            wsesForThisField = WritingSystemServices.GetWritingSystemList(cache, fieldWs, forceIncludeEnglish: false);
                            break;
                        }
#if FW8_COMPAT
                        IEnumerable <string> inputSystems = wsesForThisField.Select(LcmWs => LcmWs.Id);
#else
                        IEnumerable <string> inputSystems = wsesForThisField.Select(LcmWs => LcmWs.LanguageTag);
#endif
                        // GetWritingSystemList returns all analysis WSes even when asked for just one, so if this
                        // is a single-line custom field, trim the WSes down to just the first one
                        if (lfCustomFieldType.StartsWith("Single"))
                        {
                            inputSystems = inputSystems.Take(1);
                        }
                        fieldConfig = GetLfCustomFieldMultiTextConfig(label, lfCustomFieldType, inputSystems.ToList());
                    }

                    if (fieldConfig != null)
                    {
                        lfCustomFieldConfig[lfCustomFieldName] = fieldConfig;
                    }
                }
            }
        }