Exemplo n.º 1
0
        private void m_tvMasterList_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            MasterCategory mc = e.Node.Tag as MasterCategory;

            mc.ResetDescription(m_rtbDescription);
            ResetOKBtnEnable();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                foreach (TreeNode tn in m_nodes)
                {
                    MasterCategory mc = tn.Tag as MasterCategory;
                    tn.Tag = null;
                    mc.Dispose();
                }
                if (components != null)
                {
                    components.Dispose();
                }
                if (m_nodes != null)
                {
                    m_nodes.Clear();
                }
            }
            m_posList  = null;
            m_mediator = null;
            m_cache    = null;
            m_selPOS   = null;
            m_nodes    = null;

            base.Dispose(disposing);
        }
Exemplo n.º 3
0
        private void AddNode(Set <IPartOfSpeech> posSet, XmlNode node, TreeNodeCollection treeNodes, FdoCache cache)
        {
            if (node.Attributes["id"].InnerText == "PartOfSpeechValue")
            {
                AddNodes(posSet, node.SelectNodes("item"), treeNodes, cache);
                return;                 // Skip the top level node.
            }
            MasterCategory mc = MasterCategory.Create(posSet, node, cache);
            TreeNode       tn = new TreeNode();

            tn.Tag  = mc;
            tn.Text = TsStringUtils.NormalizeToNFC(mc.ToString());
            if (mc.InDatabase)
            {
                try
                {
                    m_skipEvents = true;
                    tn.Checked   = true;
                    tn.ForeColor = Color.Gray;
                }
                finally
                {
                    m_skipEvents = false;
                }
            }

            treeNodes.Add(tn);
            m_nodes.Add(tn);
            XmlNodeList list = node.SelectNodes("item");

            if (list.Count > 0)
            {
                AddNodes(posSet, list, tn.Nodes, cache);
            }
        }
Exemplo n.º 4
0
        private void DeterminePOSLocationInfo(LcmCache cache, IPartOfSpeech subItemOwner,
                                              MasterCategory parent, ICmPossibilityList posList,
                                              out int newOwningFlid, out int insertLocation)
        {
            // The XML node is from a file shipped with FieldWorks. It is quite likely multiple users
            // of a project could independently add the same items, so we create them with fixed guids
            // so merge will recognize them as the same objects.
            //// LT-14511 However, if the partOfSpeech is being added to a reversal index, a different guid needs to be used
            //// than the ones in the file shipped with FieldWorks. In this case if two users add the same POS to the
            //// reversal index at the same time and then do a Send/Receive operation, then a merge conflict report
            //// will probably be created for this. This scenario is not likely to occur very often at all so having
            //// a conflict report created for when this happens is something we can live with.
            var guid = posList.Owner is IReversalIndex?Guid.NewGuid() : new Guid(XmlUtils.GetAttributeValue(m_node, "guid"));

            var posFactory = cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>();

            if (subItemOwner != null)
            {
                newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                POS            = posFactory.Create(guid, subItemOwner);
            }
            else if (parent?.POS != null)
            {
                newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                insertLocation = parent.POS.SubPossibilitiesOS.Count;
                POS            = posFactory.Create(guid, parent.POS);
            }
            else
            {
                newOwningFlid  = CmPossibilityListTags.kflidPossibilities;
                insertLocation = posList.PossibilitiesOS.Count;
                POS            = posFactory.Create(guid, posList);     // automatically adds to parent.
            }
        }
Exemplo n.º 5
0
            private int DeterminePOSLocationInfo(IPartOfSpeech subItemOwner, MasterCategory parent, ICmPossibilityList posList, out int newOwningFlid, out int insertLocation)
            {
                int newOwner;

                // This is the index of the new object in the list.  See LT-5608.
                if (subItemOwner != null)
                {
                    newOwner       = subItemOwner.Hvo;
                    newOwningFlid  = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)subItemOwner.SubPossibilitiesOS.Append(new PartOfSpeech());
                }
                else if (parent != null && parent.m_pos != null)
                {
                    newOwner       = parent.m_pos.Hvo;
                    newOwningFlid  = (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = parent.m_pos.SubPossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)parent.m_pos.SubPossibilitiesOS.Append(new PartOfSpeech());
                }
                else
                {
                    newOwner       = posList.Hvo;
                    newOwningFlid  = (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities;
                    insertLocation = posList.PossibilitiesOS.Count;
                    m_pos          = (IPartOfSpeech)posList.PossibilitiesOS.Append(new PartOfSpeech());
                }
                return(newOwner);
            }
Exemplo n.º 6
0
        public void AddToDatabase(LcmCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner)
        {
            // It's already in the database, so nothing more can be done.
            if (InDatabase)
            {
                return;
            }

            UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateCategory, LexTextControls.ksRedoCreateCategory,
                                        cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
            {
                DeterminePOSLocationInfo(cache, subItemOwner, parent, posList, out _, out _);
                Debug.Assert(POS != null);
                if (m_node == null)
                {
                    // should not happen, but just in case... we still get something useful
                    var wsf      = cache.WritingSystemFactory;
                    var termWs   = wsf.GetWsFromStr(m_termWs);
                    var abbrevWs = wsf.GetWsFromStr(m_abbrevWs);
                    var defWs    = wsf.GetWsFromStr(m_defWs);
                    POS.Name.set_String(termWs, TsStringUtils.MakeString(m_term, termWs));
                    POS.Abbreviation.set_String(abbrevWs, TsStringUtils.MakeString(m_abbrev, abbrevWs));
                    POS.Description.set_String(defWs, TsStringUtils.MakeString(m_def, defWs));
                }
                else
                {
                    UpdatePOSStrings(cache, m_node, POS);
                }

                POS.CatalogSourceId = m_id;
            });
        }
Exemplo n.º 7
0
        private void m_tvMasterList_AfterCollapse(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            MasterCategory selMC = e.Node.Tag as MasterCategory;

            if (selMC.IsGroup)
            {
                e.Node.ImageIndex         = 0;
                e.Node.SelectedImageIndex = 0;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Cancel, if it is already in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_tvMasterList_BeforeCheck(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
        {
            if (m_skipEvents)
            {
                return;
            }

            MasterCategory selMC = e.Node.Tag as MasterCategory;

            e.Cancel = selMC.InDatabase;
        }
Exemplo n.º 9
0
        private void m_tvMasterList_DoubleClick(object sender, System.EventArgs e)
        {
            TreeNode tn = m_tvMasterList.GetNodeAt(m_tvMasterList.PointToClient(Cursor.Position));

            m_tvMasterList.SelectedNode = tn;
            MasterCategory mc = tn.Tag as MasterCategory;

            if (!mc.InDatabase)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 10
0
        private XmlNode m_node;         // need to remember the node so can put info for *all* writing systems into database

        public static MasterCategory Create(ISet <IPartOfSpeech> posSet, XmlNode node, LcmCache cache)
        {
            /*
             *      <item type="category" id="Adjective" guid="30d07580-5052-4d91-bc24-469b8b2d7df9">
             *              <abbrev ws="en">adj</abbrev>
             *              <term ws="en">adjective</term>
             *              <def ws="en">An adjective is a part of speech whose members modify nouns. An adjective specifies the attributes of a noun referent. Note: this is one case among many. Adjectives are a class of modifiers.</def>
             *              <citation ws="en">Crystal 1997:8</citation>
             *              <citation ws="en">Mish et al. 1990:56</citation>
             *              <citation ws="en">Payne 1997:63</citation>
             *      </item>
             */

            var mc = new MasterCategory
            {
                IsGroup = node.SelectNodes("item") != null,
                m_id    = XmlUtils.GetMandatoryAttributeValue(node, "id")
            };

            foreach (var pos in posSet)
            {
                if (pos.CatalogSourceId == mc.m_id)
                {
                    mc.POS = pos;
                    break;
                }
            }

            mc.m_node = node;             // remember node, too, so can put info for all WSes in database

            var sDefaultWS = cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Id;

            mc.m_abbrevWs = GetBestWritingSystemForNamedNode(node, "abbrev", sDefaultWS, cache, out var sContent);
            mc.m_abbrev   = sContent;

            mc.m_termWs = GetBestWritingSystemForNamedNode(node, "term", sDefaultWS, cache, out sContent);
            mc.m_term   = NameFixer(sContent);

            mc.m_defWs = GetBestWritingSystemForNamedNode(node, "def", sDefaultWS, cache, out sContent);
            mc.m_def   = sContent;

            // ReSharper disable once PossibleNullReferenceException
            foreach (XmlNode citNode in node.SelectNodes("citation"))
            {
                mc.m_citations.Add(new MasterCategoryCitation(XmlUtils.GetMandatoryAttributeValue(citNode, "ws"), citNode.InnerText));
            }
            return(mc);
        }
Exemplo n.º 11
0
        /// <summary>
        /// If OK, then add relevant POSes to DB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MasterCategoryListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            switch (DialogResult)
            {
            default:
                m_selPOS = null;
                break;

            case DialogResult.OK:
            {
                // Closing with normal selection(s).
                foreach (TreeNode tn in m_nodes)
                {
                    MasterCategory mc = tn.Tag as MasterCategory;
                    Debug.Assert(mc != null);
                    if ((tn.Checked || (tn == m_tvMasterList.SelectedNode)) &&
                        !mc.InDatabase)
                    {
                        // if this.m_subItemOwner != null, it indicates where to put the newly chosed POS
                        mc.AddToDatabase(m_cache,
                                         m_posList,
                                         (tn.Parent == null) ? null : tn.Parent.Tag as MasterCategory,
                                         m_subItemOwner);
                    }
                }
                MasterCategory mc2 = m_tvMasterList.SelectedNode.Tag as MasterCategory;
                Debug.Assert(mc2 != null);
                m_selPOS = mc2.POS;
                Debug.Assert(m_selPOS != null);
                break;
            }

            case DialogResult.Yes:
            {
                // Closing via the hotlink.
                // Do nothing special, except avoid setting m_selPOS to null, as in the default case.
                break;
            }
            }

            if (m_mediator != null)
            {
                m_mediator.PropertyTable.SetProperty("masterCatListDlgLocation", Location);
                m_mediator.PropertyTable.SetProperty("masterCatListDlgSize", Size);
            }
        }
Exemplo n.º 12
0
            private XmlNode m_node;             // need to remember the node so can put info for *all* writing systems into databas

            public static MasterCategory Create(Set <ICmPossibility> posSet, XmlNode node, FdoCache cache)
            {
                /*
                 * <item type="category" id="adjective">
                 *      <abbrev ws="en">adj</abbrev>
                 *      <term ws="en">adjective</term>
                 *      <def ws="en">An adjective is a part of speech whose members modify nouns. An adjective specifies the attributes of a noun referent. Note: this is one case among many. Adjectives are a class of modifiers.</def>
                 *      <citation ws="en">Crystal 1997:8</citation>
                 *      <citation ws="en">Mish et al. 1990:56</citation>
                 *      <citation ws="en">Payne 1997:63</citation>
                 * </item>
                 */

                MasterCategory mc = new MasterCategory();

                mc.m_isGroup = node.SelectNodes("item") != null;
                mc.m_id      = XmlUtils.GetManditoryAttributeValue(node, "id");
                mc.m_pos     = PartOfSpeech.GoldPOS(posSet, mc.m_id);

                mc.m_node = node;                 // remember node, too, so can put info for all WSes in database

                string sDefaultWS = cache.LangProject.DefaultAnalysisWritingSystemICULocale;
                string sContent;

                mc.m_abbrevWs = GetBestWritingSystemForNamedNode(node, "abbrev", sDefaultWS, cache, out sContent);
                mc.m_abbrev   = sContent;

                mc.m_termWs = GetBestWritingSystemForNamedNode(node, "term", sDefaultWS, cache, out sContent);
                mc.m_term   = NameFixer(sContent);

                mc.m_defWs = GetBestWritingSystemForNamedNode(node, "def", sDefaultWS, cache, out sContent);
                mc.m_def   = sContent;

                foreach (XmlNode citNode in node.SelectNodes("citation"))
                {
                    mc.m_citations.Add(new MasterCategoryCitation(XmlUtils.GetManditoryAttributeValue(citNode, "ws"), citNode.InnerText));
                }
                return(mc);
            }
Exemplo n.º 13
0
            public void AddToDatabase(FdoCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner)
            {
                CheckDisposed();

                if (m_pos != null)
                {
                    return;                     // It's already in the database, so nothing more can be done.
                }
                cache.BeginUndoTask(LexTextControls.ksUndoCreateCategory,
                                    LexTextControls.ksRedoCreateCategory);
                int newOwningFlid;
                int insertLocation;
                int newOwner =
                    DeterminePOSLocationInfo(subItemOwner, parent, posList, out newOwningFlid, out insertLocation);
                ILgWritingSystemFactory wsf = cache.LanguageWritingSystemFactoryAccessor;

                Debug.Assert(m_pos != null);

                if (m_node == null)
                {                 // should not happen, but just in case... we still get something useful
                    m_pos.Name.SetAlternative(m_term, wsf.GetWsFromStr(m_termWs));
                    m_pos.Abbreviation.SetAlternative(m_abbrev, wsf.GetWsFromStr(m_abbrevWs));
                    m_pos.Description.SetAlternative(m_def, wsf.GetWsFromStr(m_defWs));
                }
                else
                {
                    SetContentFromNode(cache, "abbrev", false, m_pos.Abbreviation);
                    SetContentFromNode(cache, "term", true, m_pos.Name);
                    SetContentFromNode(cache, "def", false, m_pos.Description);
                }

                m_pos.CatalogSourceId = m_id;
                // Need a PropChanged, since it isn't done in the 'Append' for some reason.
                cache.PropChanged(null, PropChangeType.kpctNotifyAll,
                                  newOwner, newOwningFlid, insertLocation, 1, 0);
                cache.EndUndoTask();
            }
Exemplo n.º 14
0
            public void AddToDatabase(FdoCache cache, ICmPossibilityList posList, MasterCategory parent, IPartOfSpeech subItemOwner)
            {
                if (m_pos != null)
                {
                    return;                     // It's already in the database, so nothing more can be done.
                }
                UndoableUnitOfWorkHelper.Do(LexTextControls.ksUndoCreateCategory, LexTextControls.ksRedoCreateCategory,
                                            cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    int newOwningFlid;
                    int insertLocation;
                    int newOwner =
                        DeterminePOSLocationInfo(cache, subItemOwner, parent, posList, out newOwningFlid, out insertLocation);
                    ILgWritingSystemFactory wsf = cache.WritingSystemFactory;
                    Debug.Assert(m_pos != null);

                    int termWs        = wsf.GetWsFromStr(m_termWs);
                    int abbrevWs      = wsf.GetWsFromStr(m_abbrevWs);
                    int defWs         = wsf.GetWsFromStr(m_defWs);
                    ITsStrFactory tsf = cache.TsStrFactory;
                    if (m_node == null)
                    {                     // should not happen, but just in case... we still get something useful
                        m_pos.Name.set_String(termWs, tsf.MakeString(m_term, termWs));
                        m_pos.Abbreviation.set_String(abbrevWs, tsf.MakeString(m_abbrev, abbrevWs));
                        m_pos.Description.set_String(defWs, tsf.MakeString(m_def, defWs));
                    }
                    else
                    {
                        SetContentFromNode(cache, "abbrev", false, m_pos.Abbreviation);
                        SetContentFromNode(cache, "term", true, m_pos.Name);
                        SetContentFromNode(cache, "def", false, m_pos.Description);
                    }

                    m_pos.CatalogSourceId = m_id;
                });
            }
Exemplo n.º 15
0
            private int DeterminePOSLocationInfo(FdoCache cache, IPartOfSpeech subItemOwner, MasterCategory parent, ICmPossibilityList posList,
                                                 out int newOwningFlid, out int insertLocation)
            {
                int newOwner;
                // This is the index of the new object in the list.  See LT-5608.
                var posFactory = cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>();

                if (subItemOwner != null)
                {
                    newOwner       = subItemOwner.Hvo;
                    newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = subItemOwner.SubPossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    subItemOwner.SubPossibilitiesOS.Add(m_pos);
                }
                else if (parent != null && parent.m_pos != null)
                {
                    newOwner       = parent.m_pos.Hvo;
                    newOwningFlid  = CmPossibilityTags.kflidSubPossibilities;
                    insertLocation = parent.m_pos.SubPossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    parent.m_pos.SubPossibilitiesOS.Add(m_pos);
                }
                else
                {
                    newOwner       = posList.Hvo;
                    newOwningFlid  = CmPossibilityListTags.kflidPossibilities;
                    insertLocation = posList.PossibilitiesOS.Count;
                    m_pos          = posFactory.Create();
                    posList.PossibilitiesOS.Add(m_pos);
                }
                return(newOwner);
            }