Ejemplo n.º 1
0
        protected override void SetRootBoxObj()
        {
            if (m_rootObj != null && m_rootObj.IsValidObject)
            {
                int hvo = m_fdoCache.DomainDataByFlid.get_ObjectProp(m_rootObj.Hvo, m_rootFlid);
                if (hvo != 0)
                {
                    var         obj   = m_fdoCache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvo);
                    ObjectLabel label = ObjectLabel.CreateObjectLabel(m_fdoCache, obj, m_displayNameProperty, m_displayWs);
                    m_sda.Tss = label.AsTss;
                }
                else
                {
                    var list = (ICmPossibilityList)m_rootObj.ReferenceTargetOwner(m_rootFlid);
                    int ws   = list.IsVernacular ? m_fdoCache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle
                                                : m_fdoCache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle;
                    if (list.PossibilitiesOS.Count > 0)
                    {
                        ObjectLabel label = ObjectLabel.CreateObjectLabel(m_fdoCache, list.PossibilitiesOS[0], m_displayNameProperty, m_displayWs);
                        ws = label.AsTss.get_WritingSystem(0);
                    }
                    m_sda.Tss = m_fdoCache.TsStrFactory.EmptyString(ws);
                }
            }

            base.SetRootBoxObj();
        }
Ejemplo n.º 2
0
        //methods

        public override ObjectLabel Execute()
        {
            IMoInflAffixSlot slot = new MoInflAffixSlot();
            IPartOfSpeech    pos  = PartOfSpeech.CreateFromDBObject(m_cache, m_posHvo);

            pos.AffixSlotsOC.Add(slot);
            string sNewSlotName = m_mediator.StringTbl.GetString("NewSlotName", "Linguistics/Morphology/TemplateTable");

            slot.Name.AnalysisDefaultWritingSystem = sNewSlotName;
            slot.Optional = m_fOptional;
            return(ObjectLabel.CreateObjectLabel(m_cache, slot.Hvo, ""));
        }
Ejemplo n.º 3
0
        protected virtual string GetTreeNodeLabel(ICmObject obj, out Font font)
        {
            string      displayPropertyName = GetDisplayPropertyName;
            ObjectLabel label = ObjectLabel.CreateObjectLabel(obj.Cache, obj, displayPropertyName, m_bestWS);
            int         ws    = TsStringUtils.GetWsAtOffset(label.AsTss, 0);

            if (!m_dictFonts.TryGetValue(ws, out font))
            {
                string sFont = m_cache.ServiceLocator.WritingSystemManager.Get(ws).DefaultFontName;
                font = new Font(sFont, m_typeSize);
                m_dictFonts.Add(ws, font);
            }
            return(TsStringUtils.NormalizeToNFC(label.DisplayName));
        }
Ejemplo n.º 4
0
        protected virtual string GetTreeNodeLabel(ICmObject obj, out Font font)
        {
            string      displayPropertyName = GetDisplayPropertyName;
            ObjectLabel label = ObjectLabel.CreateObjectLabel(obj.Cache, obj.Hvo, displayPropertyName, m_bestWS);
            int         ws    = StringUtils.GetWsAtOffset(label.AsTss, 0);

            if (!m_dictFonts.TryGetValue(ws, out font))
            {
                string sFont = obj.Cache.GetUnicodeProperty(ws, (int)LgWritingSystem.LgWritingSystemTags.kflidDefaultSerif);
                font = new Font(sFont, m_typeSize);
                m_dictFonts.Add(ws, font);
            }
            return(StringUtils.NormalizeToNFC(label.DisplayName));
        }
Ejemplo n.º 5
0
        //methods

        public override ObjectLabel Execute()
        {
            // Make create lex entry dialog and invoke it.
            ObjectLabel result = null;

            using (InsertEntryDlg dlg = new InsertEntryDlg())
            {
                var morphType = GetMorphType();
                dlg.SetDlgInfo(m_cache, morphType, MsaType.kInfl, m_slot, m_mediator,
                               m_fPrefix ? InsertEntryDlg.MorphTypeFilterType.Prefix : InsertEntryDlg.MorphTypeFilterType.Suffix);
                dlg.DisableAffixTypeMainPosAndSlot();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    bool      fCreated;
                    ILexEntry entry;
                    dlg.GetDialogInfo(out entry, out fCreated);
                    if (entry == null)
                    {
                        throw new ArgumentNullException("Expected entry cannot be null", "entry");
                    }
                    // TODO: what do to make sure it has an infl affix msa?
                    // this just assumes it will
                    bool fInflAffix = false;
                    foreach (var msa in entry.MorphoSyntaxAnalysesOC)
                    {
                        if (msa is IMoInflAffMsa)
                        {
                            fInflAffix = true;
                            break;
                        }
                    }
                    if (!fInflAffix)
                    {
                        UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(DetailControlsStrings.ksUndoCreatingInflectionalAffixCategoryItem,
                                                                        DetailControlsStrings.ksRedoCreatingInflectionalAffixCategoryItem,
                                                                        m_cache.ActionHandlerAccessor,
                                                                        () => {
                            var newby = m_cache.ServiceLocator.GetInstance <IMoInflAffMsaFactory>().Create();
                            entry.MorphoSyntaxAnalysesOC.Add(newby);
                        });
                    }
                    if (entry.MorphoSyntaxAnalysesOC.Count > 0)
                    {
                        result = ObjectLabel.CreateObjectLabel(m_cache, entry.MorphoSyntaxAnalysesOC.First(), "");
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        private bool PerformUpdate(object param)
        {
            CreateSearcher();
            try
            {
                m_changingSelection = true;
                try
                {
                    m_listBox.BeginUpdate();
                    m_listBox.Items.Clear();
                    // TODO: sort the results
                    foreach (ICmPossibility poss in m_searcher.Search(0, (ITsString)param))
                    {
                        // Every so often see whether the user has typed something that makes our search irrelevant.
                        if (ShouldAbort())
                        {
                            return(false);
                        }

                        var autoCompleteItem = ObjectLabel.CreateObjectLabel(m_cache, poss, m_displayNameProperty, m_displayWs);
                        if (m_listBox.Items.OfType <ObjectLabel>().All(item => !ReferenceEquals(item.Object, autoCompleteItem.Object)))
                        {
                            m_listBox.Items.Add(autoCompleteItem);
                        }
                    }
                }
                finally
                {
                    m_listBox.EndUpdate();
                }

                if (m_listBox.Items.Count > 0)
                {
                    m_listBox.AdjustSize(500, 400);
                    m_listBox.SelectedIndex = 0;
                    m_listBox.Launch(m_control.RectangleToScreen(m_control.Bounds), Screen.GetWorkingArea(m_control));
                }
                else
                {
                    m_listBox.HideForm();
                }
            }
            finally
            {
                m_changingSelection = false;
            }
            return(true);
        }
Ejemplo n.º 7
0
        //methods

        public override ObjectLabel Execute()
        {
            // Make create lex entry dialog and invoke it.
            ObjectLabel result = null;

            using (InsertEntryDlg dlg = new InsertEntryDlg())
            {
                IMoMorphType morphType = GetMorphType();
                dlg.SetDlgInfo(m_cache, morphType, MsaType.kInfl, m_slot, m_mediator,
                               m_fPrefix ? InsertEntryDlg.MorphTypeFilterType.prefix : InsertEntryDlg.MorphTypeFilterType.suffix);
                dlg.DisableAffixTypeMainPosAndSlot();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    bool fCreated;
                    int  entryID;
                    dlg.GetDialogInfo(out entryID, out fCreated);
                    if (entryID <= 0)
                    {
                        throw new ArgumentException("Expected entry ID to be greater than 0", "entryID");
                    }
                    ILexEntry lex = LexEntry.CreateFromDBObject(m_cache, entryID);
                    // TODO: what do to make sure it has an infl affix msa?
                    // this just assumes it will
                    bool fInflAffix = false;
                    foreach (IMoMorphSynAnalysis msa in lex.MorphoSyntaxAnalysesOC)
                    {
                        if (msa is IMoInflAffMsa)
                        {
                            fInflAffix = true;
                            break;
                        }
                    }
                    if (!fInflAffix)
                    {
                        int hvoNew = m_cache.CreateObject((int)MoInflAffMsa.kClassId,
                                                          lex.Hvo, (int)LexEntry.LexEntryTags.kflidMorphoSyntaxAnalyses, 0);
                    }
                    int[] hvos = lex.MorphoSyntaxAnalysesOC.HvoArray;
                    if (hvos.Length > 0)
                    {
                        result = ObjectLabel.CreateObjectLabel(m_cache, hvos[0], "");
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 8
0
        //methods

        public override ObjectLabel Execute()
        {
            var slot = m_cache.ServiceLocator.GetInstance <IMoInflAffixSlotFactory>().Create();
            var pos  = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(m_posHvo);

            UndoableUnitOfWorkHelper.Do(DetailControlsStrings.ksUndoCreateSlot, DetailControlsStrings.ksRedoCreateSlot,
                                        Cache.ActionHandlerAccessor,
                                        () =>
            {
                pos.AffixSlotsOC.Add(slot);
                string sNewSlotName = StringTable.Table.GetString("NewSlotName", "Linguistics/Morphology/TemplateTable");
                int defAnalWs       = m_cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle;
                slot.Name.set_String(defAnalWs, TsStringUtils.MakeString(sNewSlotName, defAnalWs));
                slot.Optional = m_fOptional;
            });
            // Enhance JohnT: usually the newly created slot will also get inserted into a template.
            // Ideally we would make both part of the same UOW. However the code is in two distinct DLLs (see MorphologyEditor.dll).
            return(ObjectLabel.CreateObjectLabel(m_cache, slot, ""));
        }
Ejemplo n.º 9
0
        protected virtual string GetTreeNodeLabel(ICmObject obj, out Font font)
        {
            string      displayPropertyName = GetDisplayPropertyName;
            ObjectLabel label = ObjectLabel.CreateObjectLabel(obj.Cache, obj, displayPropertyName, m_bestWS);
            // Get the ws of the name, not the abbreviation, if we can.  See FWNX-1059.
            // The string " - " is inserted by ObjectLabel.AsTss after the abbreviation
            // and before the name for semantic domains and anthropology codes.  When
            // localized, these lists are likely not to have localized the abbreviation.
            var tss = label.AsTss;
            int ws  = tss.get_WritingSystem(tss.RunCount - 1);

            if (!m_dictFonts.TryGetValue(ws, out font))
            {
                string sFont = m_cache.ServiceLocator.WritingSystemManager.Get(ws).DefaultFontName;
                font = new Font(sFont, m_typeSize);
                m_dictFonts.Add(ws, font);
            }
            return(TsStringUtils.NormalizeToNFC(label.DisplayName));
        }
        /// <summary>
        /// Reload the vector in the root box, presumably after it's been modified by a chooser.
        /// </summary>
        public override void ReloadVector()
        {
            CheckDisposed();
            ITsStrFactory tsf = m_fdoCache.TsStrFactory;
            int           ws  = 0;

            if (m_rootObj != null && m_rootObj.IsValidObject)
            {
                ILgWritingSystemFactory wsf = m_fdoCache.WritingSystemFactory;
                int count = m_sda.get_VecSize(m_rootObj.Hvo, m_rootFlid);
                // This loop is mostly redundant now that the decorator will generate labels itself as needed.
                // It still serves the purpose of figuring out the WS that should be used for the 'fake' item where the user
                // is typing to select.
                for (int i = 0; i < count; ++i)
                {
                    int hvo = m_sda.get_VecItem(m_rootObj.Hvo, m_rootFlid, i);
                    Debug.Assert(hvo != 0);
                    ws = m_sda.GetLabelFor(hvo).get_WritingSystem(0);
                }

                if (ws == 0)
                {
                    var list = (ICmPossibilityList)m_rootObj.ReferenceTargetOwner(m_rootFlid);
                    ws = list.IsVernacular ? m_fdoCache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle
                                                 : m_fdoCache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle;
                    if (list.PossibilitiesOS.Count > 0)
                    {
                        ObjectLabel label = ObjectLabel.CreateObjectLabel(m_fdoCache, list.PossibilitiesOS[0], m_displayNameProperty, m_displayWs);
                        ws = label.AsTss.get_WritingSystem(0);
                    }
                }
            }

            if (ws == 0)
            {
                ws = m_fdoCache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle;
            }
            m_sda.Strings[khvoFake] = tsf.EmptyString(ws);
            base.ReloadVector();
        }
            public ITsString GetLabelFor(int hvo)
            {
                ITsString value;

                if (m_strings.TryGetValue(hvo, out value))
                {
                    return(value);
                }
                Debug.Assert(Cache != null);
                var obj = Cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvo);

                Debug.Assert(obj != null);

                ObjectLabel label = ObjectLabel.CreateObjectLabel(Cache, obj, DisplayNameProperty, DisplayWs);
                ITsString   tss   = label.AsTss;

                if (tss == null)
                {
                    tss = Cache.TsStrFactory.EmptyString(Cache.DefaultUserWs);
                }
                Strings[hvo] = tss;
                return(tss);                // never return null!
            }