Beispiel #1
0
 /// <summary>
 /// Handle launching of the MSA editor.
 /// </summary>
 protected override void HandleChooser()
 {
     using (MsaCreatorDlg dlg = new MsaCreatorDlg())
     {
         MoMorphSynAnalysis originalMsa = m_obj as MoMorphSynAnalysis;
         ILexEntry          entry       = LexEntry.CreateFromDBObject(m_cache, originalMsa.OwnerHVO);
         dlg.SetDlgInfo(m_cache,
                        m_persistProvider,
                        m_mediator,
                        entry,
                        DummyGenericMSA.Create(originalMsa),
                        originalMsa.Hvo,
                        true,
                        String.Format(LexEdStrings.ksEditX, Slice.Label));
         if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
         {
             DummyGenericMSA dummyMsa = dlg.DummyMSA;
             if (!originalMsa.EqualsMsa(dummyMsa))
             {
                 m_cache.BeginUndoTask(LexEdStrings.ksUndoEditFunction,
                                       LexEdStrings.ksRedoEditFunction);
                 // The UpdateOrReplace call may end up disposing this. So any variables we
                 // need after it must be copied to the stack.
                 FdoCache            cache  = m_cache;
                 Slice               parent = Slice;
                 IMoMorphSynAnalysis newMsa = originalMsa.UpdateOrReplace(dummyMsa);
                 cache.EndUndoTask();
             }
         }
     }
 }
        public override ObjectLabel Execute()
        {
            ObjectLabel result = null;

            if (m_ler != null)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    // assume the owner is the entry (e.g. owner of LexEntryRef)
                    int hvoEntry = m_cache.GetOwnerOfObjectOfClass(m_ler.Hvo, LexEntry.kclsidLexEntry);
                    if (hvoEntry != 0)
                    {
                        le = LexEntry.CreateFromDBObject(m_cache, hvoEntry);
                    }
                    dlg.SetDlgInfo(m_cache, m_mediator, le);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense");
                    if (dlg.ShowDialog(m_form) == DialogResult.OK)
                    {
                        int hvo = dlg.SelectedID;
                        if (hvo != 0 && !m_ler.ComponentLexemesRS.Contains(hvo))
                        {
                            m_ler.ComponentLexemesRS.Append(hvo);
                        }
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Given a (potentially) owning object, and the flid in which is does/will own
        /// the feature structure, find the relevant POS.
        /// </summary>
        /// <param name="cobj"></param>
        /// <param name="owningFlid"></param>
        /// <returns></returns>
        private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid)
        {
            IPartOfSpeech pos = null;

            switch (cobj.ClassID)
            {
            case MoInflAffMsa.kclsidMoInflAffMsa:
                IMoInflAffMsa infl = cobj as IMoInflAffMsa;
                if (infl != null)
                {
                    pos = infl.PartOfSpeechRA;
                }
                break;

            case MoDerivAffMsa.kclsidMoDerivAffMsa:
                IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa;
                if (deriv != null)
                {
                    if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures)
                    {
                        pos = deriv.FromPartOfSpeechRA;
                    }
                    else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures)
                    {
                        pos = deriv.ToPartOfSpeechRA;
                    }
                }
                break;

            case MoStemMsa.kclsidMoStemMsa:
                IMoStemMsa stem = cobj as IMoStemMsa;
                if (stem != null)
                {
                    pos = stem.PartOfSpeechRA;
                }
                break;

            case MoStemName.kclsidMoStemName:
                IMoStemName sn = cobj as IMoStemName;
                pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO);
                break;

            case MoAffixAllomorph.kclsidMoAffixAllomorph:
                // get entry of the allomorph and then get the msa of first sense and return its (from) POS
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO);
                if (entry == null)
                {
                    return(pos);
                }
                ILexSense sense = entry.SensesOS.FirstItem;
                if (sense == null)
                {
                    return(pos);
                }
                IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA;
                pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures);
                break;
            }
            return(pos);
        }
Beispiel #4
0
        /// <summary>
        /// when calling the dialog from an "Insert Variant" context this
        /// constructor is used to indicate that m_startingEntry is a componentLexeme
        /// rather than the variant
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="mediator"></param>
        /// <param name="componentLexeme">the entry we wish to find or create a variant for.</param>
        protected void SetDlgInfoForComponentLexeme(FdoCache cache, Mediator mediator, IVariantComponentLexeme componentLexeme)
        {
            m_fBackRefToVariant = true;
            ILexEntry startingEntry = null;

            if (componentLexeme.ClassID == LexEntry.kclsidLexEntry)
            {
                startingEntry = componentLexeme as LexEntry;
            }
            else
            {
                int hvoEntry = cache.GetOwnerOfObjectOfClass(componentLexeme.Hvo, LexEntry.kclsidLexEntry);
                if (hvoEntry != 0)
                {
                    startingEntry = LexEntry.CreateFromDBObject(cache, hvoEntry);
                }
            }
            base.SetDlgInfo(cache, mediator, startingEntry);
            // we are looking for an existing variant form
            // so hide the Entry/Sense radio group box.
            grplbl.Visible = false;
            // also hide variant type.
            tcVariantTypes.Visible = false;
            lblVariantType.Visible = false;
            m_fGetVariantEntryTypeFromTreeCombo = false;
            lblCreateEntry.Visible = false;

            // The dialog title and other labels need to reflect "Insert Variant" context.
            m_formLabel.Text = LexTextControls.ks_Variant;
            this.Text        = LexTextControls.ksFindVariant;
            btnInsert.Text   = LexTextControls.ks_Create;
            // We disable the "Create" button when we don't have text in the Find textbox.
            UpdateButtonCreateNew();
        }
Beispiel #5
0
 /// <summary>
 /// extracts the variant and component from the dialog, depending upon whether we're
 /// called from an "Insert Variant" or "Variant Of..." context.
 /// </summary>
 /// <param name="variant"></param>
 /// <param name="componentLexeme"></param>
 private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
 {
     variant         = null;
     componentLexeme = null;
     if (m_fBackRefToVariant)
     {
         // in "Insert Variant" contexts,
         // we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
         componentLexeme = m_startingEntry;
         variant         = LexEntry.CreateFromDBObject(m_cache, SelectedID);
     }
     else
     {
         // in "Variant of..." contexts,
         // we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
         variant         = m_startingEntry;
         componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme;
     }
     if (m_fGetVariantEntryTypeFromTreeCombo)
     {
         selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo);
     }
     else
     {
         selectedEntryType = null;
     }
 }
Beispiel #6
0
 protected override void HandleMatchingSelectionChanged()
 {
     if (m_selEntryID > 0)
     {
         // Make sure that none of the allomorphs of this entry match the original
         // form before we can enable btnOK.
         ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);
         // true if current list of MoForms contains one with matching form text.
         bool fMatchingForm = false;
         // true if current list of MoForms contains one of correct type
         bool fMatchingType = false;
         // If we don't know a morpheme type, don't restrict by type.
         IMoMorphType mtOrig = null;
         if (m_hvoType == 0)
         {
             fMatchingType = true;
         }
         else
         {
             mtOrig = MoMorphType.CreateFromDBObject(m_cache, m_hvoType);
         }
         foreach (IMoForm mf in le.AllAllomorphs)
         {
             if (mf.Form.VernacularDefaultWritingSystem == m_formOrig)
             {
                 fMatchingForm = true;
                 fMatchingType = false;
             }
             // To prevent confusion, allow any type that is ambiguous with the
             // current type (or, of course, if it is the SAME type, which for some
             // reason is NOT considered ambiguous).
             if (mtOrig != null && mf.MorphTypeRA != null &&
                 (m_hvoType == mf.MorphTypeRA.Hvo ||
                  mtOrig.IsAmbiguousWith(m_cache, m_types, mtOrig, mf.MorphTypeRA)))
             {
                 fMatchingType = true;
             }
             if (fMatchingForm)
             {
                 break;
             }
         }
         m_fInconsistentType = !fMatchingType;
         m_fMatchingForm     = fMatchingForm;
         if (fMatchingForm && fMatchingType)
         {
             btnOK.Text = SIL.FieldWorks.LexText.Controls.LexTextControls.ksUseAllomorph;
         }
         else
         {
             btnOK.Text = SIL.FieldWorks.LexText.Controls.LexTextControls.ksAddAllomorph_;
         }
         btnOK.Enabled = true;
     }
     else
     {
         base.HandleMatchingSelectionChanged();
     }
 }
Beispiel #7
0
        private void btnTouchLexicon_Click(object sender, System.EventArgs e)
        {
            int       hvo = m_selectedFdoCache.LangProject.LexDbOA.Entries.ToHvoArray()[0];
            ILexEntry le  = LexEntry.CreateFromDBObject(m_selectedFdoCache, hvo);

            le.HomographNumber++;
            m_selectedFdoCache.Save();
        }
Beispiel #8
0
        private bool RunMergeEntryDialog(object argument, bool fLoseNoTextData)
        {
            ICmObject obj = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ICmObject;

            Debug.Assert(obj != null);
            if (obj == null)
            {
                return(false);                          // should never happen, but nothing we can do if it does!
            }
            FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");

            Debug.Assert(cache != null);
            Debug.Assert(cache == obj.Cache);
            ILexEntry currentEntry = obj as ILexEntry;

            if (currentEntry == null)
            {
                int hvoEntry = cache.GetOwnerOfObjectOfClass(obj.Hvo, LexEntry.kclsidLexEntry);
                if (hvoEntry != 0)
                {
                    currentEntry = LexEntry.CreateFromDBObject(cache, hvoEntry);
                }
            }
            Debug.Assert(currentEntry != null);
            if (currentEntry == null)
            {
                return(false);
            }

            using (MergeEntryDlg dlg = new MergeEntryDlg())
            {
                Debug.Assert(argument != null && argument is XCore.Command);
                dlg.SetDlgInfo(cache, m_mediator, currentEntry);
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    int       entryID  = dlg.SelectedID;
                    ILexEntry survivor = LexEntry.CreateFromDBObject(cache, entryID);
                    Debug.Assert(survivor != currentEntry);
                    cache.BeginUndoTask(SIL.FieldWorks.LexText.Controls.LexTextControls.ksUndoMergeEntry,
                                        SIL.FieldWorks.LexText.Controls.LexTextControls.ksRedoMergeEntry);
                    // If lexeme forms differ, make the source lexeme form an allomorph of the target entry.
                    if (survivor.LexemeFormOA.Form.VernacularDefaultWritingSystem !=
                        currentEntry.LexemeFormOA.Form.VernacularDefaultWritingSystem)
                    {
                        survivor.AlternateFormsOS.Append(currentEntry.LexemeFormOA.Hvo);
                    }
                    survivor.MergeObject(currentEntry, fLoseNoTextData);
                    cache.EndUndoTask();
                    survivor.DateModified = DateTime.Now;
                    MessageBox.Show(null,
                                    SIL.FieldWorks.LexText.Controls.LexTextControls.ksEntriesHaveBeenMerged,
                                    SIL.FieldWorks.LexText.Controls.LexTextControls.ksMergeReport,
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    m_mediator.SendMessage("JumpToRecord", entryID);
                }
            }
            return(true);
        }
Beispiel #9
0
        protected override void HandleMatchingSelectionChanged()
        {
            // Clear out senses combo box, no matter how the dlg is being used.
            m_fwcbSenses.Items.Clear();
            m_fwcbSenses.Text = String.Empty;
            m_senseIds.Clear();

            bool okBtnEnabled         = false;
            bool senseControlsEnabled = false;

            if (m_selEntryID > 0)
            {
                if (m_rbSense.Checked)
                {
                    // Add new stuff to sense combo box.
                    m_fwcbSenses.SuspendLayout();
                    ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);
                    foreach (ILexSense sense in le.AllSenses)
                    {
                        m_fwcbSenses.AddItem(sense.ChooserNameTS);
                        m_senseIds.Add(sense.Hvo);
                    }
                    m_fwcbSenses.ResumeLayout();
                    if (m_fwcbSenses.Items.Count > 0)
                    {
                        // Select first sense, and enable various controls.
                        m_fwcbSenses.SelectedItem = m_fwcbSenses.Items[0];
                        okBtnEnabled         = true;
                        senseControlsEnabled = true;
                    }
                    else
                    {
                        // Entry has no senses, so disable controls, and notify user.
                        okBtnEnabled         = false;
                        senseControlsEnabled = false;
                        m_fwcbSenses.Text    = LexText.Controls.LexTextControls.ksNoSensesInEntry;
                    }
                }
                else
                {
                    // User is selecting an entry, so enable OK button,
                    // but not the sense controls.
                    Debug.Assert(m_rbEntry.Checked);
                    okBtnEnabled         = true;
                    senseControlsEnabled = false;
                }
            }
            else
            {
                // No entry is selected.
                // Nothing new need happen here, since the relevant controls will already be disabled.
                // Indeed, the OK button will have been disabled in the m_tbForm_TextChanged event handler,
                // and this 'code' will never even be called.
            }
            btnOK.Enabled        = okBtnEnabled;
            m_fwcbSenses.Enabled = senseControlsEnabled;
        }
        private void PopulateTreeFromPosInEntry(ICmObject cobj)
        {
            ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO);

            if (entry == null)
            {
                return;
            }
            foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC)
            {
                IPartOfSpeech pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures);
                PopulateTreeFromPos(pos);
            }
        }
Beispiel #11
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);
        }
Beispiel #12
0
        private ILexEntry TryToFindMatchingEntry(Guid guid, IdentifyingInfo idInfo, out bool canPrune)
        {
            ILexEntry entry = null;

            if (guid != Guid.Empty)
            {
                int hvo = _cache.GetIdFromGuid(guid);
                if (hvo > 0)
                {
                    entry = LexEntry.CreateFromDBObject(_cache, hvo);
                }

                canPrune = CanSafelyPruneMerge(idInfo, entry);
                return(entry);
            }
            canPrune = false;
            return(null);
        }
Beispiel #13
0
        protected override void HandleMatchingSelectionChanged()
        {
            m_fwcbAllomorphs.Items.Clear();
            m_fwcbAllomorphs.Text = String.Empty;
            if (m_selEntryID == 0)
            {
                return;
            }
            m_fwcbAllomorphs.SuspendLayout();
            ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);

            /* NB: We remove abstract MoForms, because the adhoc allo coprohibiton object wants them removed.
             * If any other client of this dlg comes along that wants them,
             * we will need to feed in a parameter that tells us whether to exclude them or not.
             */
            // Add the lexeme form, if it exists.
            IMoForm lf = le.LexemeFormOA;

            if (lf != null && !lf.IsAbstract)
            {
                m_fwcbAllomorphs.Items.Add(new LAllomorph(le.LexemeFormOA));
            }
            foreach (IMoForm allo in le.AlternateFormsOS)
            {
                if (!allo.IsAbstract)
                {
                    m_fwcbAllomorphs.Items.Add(new LAllomorph(allo));
                }
            }
            if (m_fwcbAllomorphs.Items.Count > 0)
            {
                m_fwcbAllomorphs.SelectedItem = m_fwcbAllomorphs.Items[0];
            }
            btnOK.Enabled = m_fwcbAllomorphs.Items.Count > 0;
            m_fwcbAllomorphs.ResumeLayout();
            // For a resizeable dialog, we don't want AdjustForStylesheet to really change its size,
            // because then it ends up growing every time it launches!
            int oldHeight = this.Height;

            m_fwcbAllomorphs.AdjustForStyleSheet(this, grplbl, m_mediator);
            this.Height = oldHeight;
        }
Beispiel #14
0
        protected override void HandleMatchingSelectionChanged()
        {
            m_fwcbFunctions.Items.Clear();
            if (m_selEntryID == 0)
            {
                return;
            }
            m_fwcbFunctions.SuspendLayout();
            ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);

            foreach (IMoMorphSynAnalysis msa in le.MorphoSyntaxAnalysesOC)
            {
                m_fwcbFunctions.Items.Add(new LMsa(msa));
            }
            if (m_fwcbFunctions.Items.Count > 0)
            {
                m_fwcbFunctions.SelectedItem = m_fwcbFunctions.Items[0];
            }
            btnOK.Enabled = m_fwcbFunctions.Items.Count > 0;
            m_fwcbFunctions.ResumeLayout();
        }
Beispiel #15
0
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries.
        /// </summary>
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";
            string postDialogMessageTrigger = null;

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }
            Set <int>             candidates = m_obj.ReferenceTargetCandidates(m_flid);
            ObjectLabelCollection labels     = new ObjectLabelCollection(m_cache, candidates,
                                                                         m_displayNameProperty, displayWs);

            using (MorphTypeChooser chooser = GetChooser(labels))
            {
                bool      fMadeMorphTypeChange = false;
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, m_obj.OwnerHVO);
                chooser.InitializeExtras(m_configurationNode, Mediator);
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                int hvoType = m_cache.GetObjProperty(m_obj.Hvo, m_flid);
                chooser.MakeSelection(hvoType);
                // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
                // when inserting.  Thus, we need the check box in that environment as well.
                //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
                //    chooser.ShowAllTypesCheckBoxVisible = false;
                if (chooser.ShowDialog() == DialogResult.OK)
                {
                    ObjectLabel selected    = chooser.ChosenOne;
                    int         hvoOriginal = TargetHvo;
                    string      sUndo       = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
                    string      sRedo       = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

                    bool fRemoveComponents = false;
                    if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphRoot)) ||
                        selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphBoundRoot)))
                    {
                        // changing to root...not allowed to have complex forms.
                        foreach (LexEntryRef ler in entry.EntryRefsOS)
                        {
                            if (ler.RefType == LexEntryRef.krtComplexForm)
                            {
                                fRemoveComponents = true;
                                // If there are no components we will delete without asking...but must then check for more
                                // complex forms that DO have components.
                                if (ler.ComponentLexemesRS.Count > 0)
                                {
                                    if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
                                                        DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
                                                        HelpNavigator.Topic, "khtRootCannotHaveComponents") != DialogResult.Yes)
                                    {
                                        return;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    using (new UndoRedoTaskHelper(entry.Cache, sUndo, sRedo))
                    {
                        if (fRemoveComponents)
                        {
                            Set <int> delObjs = new Set <int>();
                            foreach (LexEntryRef ler in entry.EntryRefsOS)
                            {
                                if (ler.RefType == LexEntryRef.krtComplexForm)
                                {
                                    delObjs.Add(ler.Hvo);
                                }
                            }
                            CmObject.DeleteObjects(delObjs, m_cache);
                        }

                        if (IsStemType(hvoOriginal) || m_obj is MoStemAllomorph)
                        {
                            if (IsStemType(selected.Hvo))
                            {
                                TargetHvo = selected.Hvo;
                            }
                            else
                            {
                                //have to switch from stem to affix
                                fMadeMorphTypeChange = ChangeStemToAffix(entry, selected.Hvo, sUndo, sRedo);
                            }
                        }
                        else
                        {
                            // original is affix variety
                            if (IsStemType(selected.Hvo))
                            {
                                //have to switch from affix to stem
                                fMadeMorphTypeChange = ChangeAffixToStem(entry, selected.Hvo, sUndo, sRedo);
                            }
                            else
                            {
                                TargetHvo = selected.Hvo;
                            }
                        }
                        if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphPhrase)))
                        {
                            ILexEntryRef ler = new LexEntryRef();
                            entry.EntryRefsOS.Append(ler);
                            ler.RefType        = LexEntryRef.krtComplexForm;
                            ler.HideMinorEntry = 1;
                            // No automatic propchanged for new objects, need to let the view see it.
                            // At that point our slice will be disposed, so don't do anything after this.
                            entry.Cache.PropChanged(entry.Hvo, (int)LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries or senses.
        /// </summary>
        protected override void HandleChooser()
        {
            Debug.Assert(m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes ||
                         m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes);
            if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    if (m_obj.ClassID == LexEntry.kclsidLexEntry)
                    {
                        // filter this entry from the list.
                        le = m_obj as ILexEntry;
                    }
                    else
                    {
                        // assume the owner is the entry (e.g. owner of LexEntryRef)
                        int hvoEntry = m_cache.GetOwnerOfObjectOfClass(m_obj.Hvo, LexEntry.kclsidLexEntry);
                        if (hvoEntry != 0)
                        {
                            le = LexEntry.CreateFromDBObject(m_cache, hvoEntry);
                        }
                    }
                    dlg.SetDlgInfo(m_cache, m_mediator, le);
                    String str = ShowHelp.RemoveSpaces(this.Slice.Label);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense-" + str);
                    if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
                    {
                        AddItem(dlg.SelectedID);
                    }
                }
            }
            else if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes)
            {
                string displayWs = "analysis vernacular";
                if (m_configurationNode != null)
                {
                    XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                    if (node != null)
                    {
                        displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    }
                }
                ILexEntryRef ler = m_obj as ILexEntryRef;
                Debug.Assert(ler != null);
                List <int> candidates = new List <int>();
                candidates.AddRange(ler.ComponentLexemesRS.HvoArray);
                ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates,
                                                                         m_displayNameProperty, displayWs);
                using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null,
                                                                                     labels, "PrimaryLexemes", m_cache, ler.PrimaryLexemesRS.HvoArray, false))

                {
                    chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);                        // may set TextParamHvo

                    chooser.Text = "Choose where to show subentry";

                    //chooser.ReplaceTreeView(Mediator, "WordformsBrowseView");

                    chooser.InitializeExtras(null, Mediator);
                    chooser.AddLink("Add a Component...", ReallySimpleListChooser.LinkType.kDialogLink,
                                    new AddComponentChooserCommand(m_cache, false, null, m_mediator, m_obj, FindForm()));
                    DialogResult res = chooser.ShowDialog();
                    if (DialogResult.Cancel == res)
                    {
                        return;
                    }
                    if (chooser.ChosenHvos != null)
                    {
                        SetItems(chooser.ChosenHvos);
                    }
                }
            }
        }
Beispiel #17
0
        protected override void SetBottomMessage()
        {
            int    userWs = m_cache.LangProject.DefaultUserWritingSystem;
            int    vernWs = m_cache.LangProject.DefaultVernacularWritingSystem;
            string sBase;

            if (m_selEntryID > 0)
            {
                sBase = LexText.Controls.LexTextControls.ksEntryXMergedIntoY;
            }
            else
            {
                sBase = LexText.Controls.LexTextControls.ksEntryXMergedIntoSel;
            }
            ITsStrBldr tsb = TsStrBldrClass.Create();

            tsb.ReplaceTsString(0, tsb.Length, m_tsf.MakeString(sBase, userWs));
            // Replace every "{0}" with the headword we'll be merging, and make it bold.
            ITsString tssFrom = m_startingEntry.HeadWord;
            string    sTmp    = tsb.Text;
            int       ich     = sTmp.IndexOf("{0}");
            int       cch     = tssFrom.Length;

            while (ich >= 0 && cch > 0)
            {
                tsb.ReplaceTsString(ich, ich + 3, tssFrom);
                tsb.SetIntPropValues(ich, ich + cch,
                                     (int)FwTextPropType.ktptBold,
                                     (int)FwTextPropVar.ktpvEnum,
                                     (int)FwTextToggleVal.kttvForceOn);
                sTmp = tsb.Text;
                ich  = sTmp.IndexOf("{0}");                     // in case localization needs more than one.
            }
            if (m_selEntryID > 0)
            {
                // Replace every "{1}" with the headword we'll be merging into.
                ILexEntry le    = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);
                ITsString tssTo = le.HeadWord;
                ich = sTmp.IndexOf("{1}");
                cch = tssTo.Length;
                while (ich >= 0 && cch > 0)
                {
                    tsb.ReplaceTsString(ich, ich + 3, tssTo);
                    tsb.SetIntPropValues(ich, ich + cch,
                                         (int)FwTextPropType.ktptBold,
                                         (int)FwTextPropVar.ktpvEnum,
                                         (int)FwTextToggleVal.kttvForceOn);
                    sTmp = tsb.Text;
                    ich  = sTmp.IndexOf("{0}");
                }
                // Replace every "{2}" with a newline character.
                ich = sTmp.IndexOf("{2}");
                while (ich >= 0)
                {
                    tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString("\x2028", userWs));
                    sTmp = tsb.Text;
                    ich  = sTmp.IndexOf("{2}");
                }
            }
            else
            {
                // Replace every "{1}" with a newline character.
                ich = sTmp.IndexOf("{1}");
                while (ich >= 0)
                {
                    tsb.ReplaceTsString(ich, ich + 3, m_tsf.MakeString("\x2028", userWs));
                    sTmp = tsb.Text;
                    ich  = sTmp.IndexOf("{1}");
                }
            }
            m_fwTextBoxBottomMsg.Tss = tsb.GetString();
        }
Beispiel #18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Display a view of the LexEntry (or fragment thereof).
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// <param name="frag"></param>
        /// ------------------------------------------------------------------------------------
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            CheckDisposed();

            switch (frag)
            {
            case (int)VcFrags.kfragHeadWord:
                // This case should stay in sync with
                // LexEntry.LexemeFormMorphTypeAndHomographStatic
                vwenv.OpenParagraph();
                AddHeadwordWithHomograph(vwenv, hvo);
                vwenv.CloseParagraph();
                break;

            case (int)kfragEntryAndVariant:
                IWfiMorphBundle wfb         = WfiMorphBundle.CreateFromDBObject(m_cache, hvo);
                int             hvoMf       = wfb.MorphRAHvo;
                int             hvoLexEntry = m_cache.GetOwnerOfObject(hvoMf);
                // if morphbundle morph (entry) is in a variant relationship to the morph bundle sense
                // display its entry headword and variant type information (LT-4053)
                ILexEntryRef ler     = null;
                ILexEntry    variant = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry);
                if ((variant as LexEntry).IsVariantOfSenseOrOwnerEntry(wfb.SenseRA, out ler))
                {
                    // build Headword from sense's entry
                    vwenv.OpenParagraph();
                    vwenv.OpenInnerPile();
                    vwenv.AddObj(wfb.SenseRA.EntryID, this, (int)VcFrags.kfragHeadWord);
                    vwenv.CloseInnerPile();
                    vwenv.OpenInnerPile();
                    // now add variant type info
                    vwenv.AddObj(ler.Hvo, this, kfragVariantTypes);
                    vwenv.CloseInnerPile();
                    vwenv.CloseParagraph();
                    break;
                }
                else
                {
                    // build Headword even though we aren't in a variant relationship.
                    vwenv.AddObj(hvoLexEntry, this, (int)VcFrags.kfragHeadWord);
                }
                break;

            case kfragVariantTypes:
                ler = LexEntryRef.CreateFromDBObject(m_cache, hvo);
                bool fNeedInitialPlus = true;
                vwenv.OpenParagraph();
                foreach (ILexEntryType let in ler.VariantEntryTypesRS)
                {
                    // just concatenate them together separated by comma.
                    ITsString tssVariantTypeRevAbbr = let.ReverseAbbr.BestAnalysisAlternative;
                    if (tssVariantTypeRevAbbr != null && tssVariantTypeRevAbbr.Length > 0)
                    {
                        if (fNeedInitialPlus)
                        {
                            vwenv.AddString(StringUtils.MakeTss("+", m_cache.DefaultUserWs));
                        }
                        else
                        {
                            vwenv.AddString(StringUtils.MakeTss(",", m_cache.DefaultUserWs));
                        }
                        vwenv.AddString(tssVariantTypeRevAbbr);
                        fNeedInitialPlus = false;
                    }
                }
                vwenv.CloseParagraph();
                break;

            case kfragFormForm:                     // form of MoForm
                vwenv.AddStringAltMember((int)MoForm.MoFormTags.kflidForm, m_wsActual, this);
                break;

            default:
                base.Display(vwenv, hvo, frag);
                break;
            }
        }