Exemplo n.º 1
0
        ///// ------------------------------------------------------------------------------------
        ///// <summary>
        ///// Append a picture to the end of the paragraph using the given writing system.
        ///// </summary>
        ///// <param name="ws">given writing system</param>
        ///// <param name="strBldr">The string builder for the paragraph being composed</param>
        ///// ------------------------------------------------------------------------------------
        //public void AppendPicture(int ws, ITsStrBldr strBldr)
        //{
        //    // Make a TsTextProps with the relevant object data and the same ws as its
        //    // context.
        //    byte[] objData = MiscUtils.GetObjData(this.Guid,
        //        (byte)FwObjDataTypes.kodtGuidMoveableObjDisp);
        //    ITsPropsBldr propsBldr = TsStringUtils.MakePropsBldr();
        //    propsBldr.SetStrPropValueRgch((int)FwTextPropType.ktptObjData,
        //        objData, objData.Length);
        //    propsBldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, ws);

        //    // Insert the orc with the resulting properties.
        //    strBldr.Replace(strBldr.Length, strBldr.Length,
        //        new string(TsStringUtils.kChObject, 1), propsBldr.GetTextProps());
        //}

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Update the properties of a CmPicture with the given file, caption, and folder.
        /// </summary>
        /// <param name="srcFilename">The full path to the filename (this might be an "internal"
        /// copy of the original the user chose)</param>
        /// <param name="captionTss">The caption</param>
        /// <param name="sFolder">The name of the CmFolder where picture should be stored</param>
        /// <param name="ws">The WS for the location in the caption MultiUnicode to put the
        /// caption</param>
        /// ------------------------------------------------------------------------------------
        public void UpdatePicture(string srcFilename, ITsString captionTss, string sFolder, int ws)
        {
            // Set the caption first since creating the CmFile will throw if srcFilename is empty.
            if (ws != 0)
            {
                Caption.set_String(ws, captionTss);
            }

            ICmFile file = PictureFileRA;

            if (file == null)
            {
                ICmFolder folder = DomainObjectServices.FindOrCreateFolder(m_cache, LangProjectTags.kflidPictures, sFolder);
                PictureFileRA = DomainObjectServices.FindOrCreateFile(folder, srcFilename);
            }
            else
            {
                Debug.Assert(sFolder == CmFolderTags.LocalPictures,
                             "TODO: If we ever actually support use of different folders, we need to handle folder changes.");
                if (srcFilename != null && !FileUtils.PathsAreEqual(srcFilename, file.AbsoluteInternalPath))
                {
                    file.InternalPath = srcFilename;
                }
            }
            // We shouldn't need to this in the new LCM.
            //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, Hvo,
            //    (int)CmPicture.CmPictureTags.kflidCaption, ws, 0 , 0);
            //m_cache.PropChanged(null, PropChangeType.kpctNotifyAll, file.Hvo,
            //    (int)CmFile.CmFileTags.kflidInternalPath, 0, 1, 1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// this is called when XCore wants to display something that relies on the list with the id "WritingSystemList"
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <param name="display">The display.</param>
        /// <returns></returns>
        public bool OnDisplayWritingSystemList(object parameter, ref UIListDisplayProperties display)
        {
            CheckDisposed();

            display.List.Clear();
            FdoCache         cache    = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
            string           wsSet    = parameter as string;
            WritingSystemSet setToUse = m_currentSet;

            if (wsSet != null)
            {
                // JohnT: This is a patch to fix LT-5059. The problem is that the WritingSystemList set
                // (with the pronunciation subset) is used in the Pronuciation field pull-down menu.
                // All other code that I can find currently does not specify it. Therefore, after this
                // menu is displayed once, m_currentSet is set to pronunciation and stays there.
                // It seems that we actually have no current use for any other subset, nor for remembering
                // the most recent one specified. However, in the interests of making the change minimal,
                // and in case there is some anticipated application of tracking the current set which
                // I am not aware of, I made a way for that one menu item to get the list it needs
                // without making a persistent change.
                string tempPrefix = "temp:";
                bool   fTemp      = wsSet.StartsWith(tempPrefix);
                if (fTemp)
                {
                    setToUse = DecodeSetName(wsSet.Substring(tempPrefix.Length));
                }
                else
                {
                    m_currentSet = setToUse = DecodeSetName(wsSet);
                }
            }
            switch (setToUse)
            {
            default:
                throw new NotImplementedException("That writing system set needs to be implemented");

            case WritingSystemSet.All:
                AddWritingSystemList(display, cache.ServiceLocator.WritingSystemManager.LocalWritingSystems);
                break;

            case WritingSystemSet.AllCurrent:
                AddWritingSystemList(display, cache.ServiceLocator.WritingSystems.AllWritingSystems);
                break;

            case WritingSystemSet.CurrentAnalysis:
                AddWritingSystemList(display, cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems);
                break;

            case WritingSystemSet.CurrentVernacular:
                AddWritingSystemList(display, cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems);
                break;

            case WritingSystemSet.CurrentPronounciation:
                AddWritingSystemList(display, cache.ServiceLocator.WritingSystems.CurrentPronunciationWritingSystems);
                string sValue = DomainObjectServices.JoinIds(cache.ServiceLocator.WritingSystems.CurrentPronunciationWritingSystems.Select(ws => ws.Handle).ToArray(), ",");
                m_mediator.PropertyTable.SetProperty("PronunciationWritingSystemHvos", sValue);
                break;
            }
            return(true);           //we handled this, no need to ask anyone else.
        }
Exemplo n.º 3
0
        private void GetMainEntryAndSense(ILexEntry entryOrVariant, out ILexEntry mainEntry, out ILexSense sense)
        {
            sense = null;
            // first see if this is a variant of another entry.
            var entryRef = DomainObjectServices.GetVariantRef(entryOrVariant, true);

            if (entryRef != null)
            {
                // get the main entry or sense.
                var component = entryRef.ComponentLexemesRS[0] as IVariantComponentLexeme;
                if (component is ILexSense)
                {
                    sense     = component as ILexSense;
                    mainEntry = sense.Entry;
                }
                else
                {
                    mainEntry = component as ILexEntry;
                    // consider using the sense of the variant, if it has one. (LT-9681)
                }
            }
            else
            {
                mainEntry = entryOrVariant;
            }
        }
Exemplo n.º 4
0
        private int GetHvoCommonAncestor(int hvoBeforeListChange, int prevListItemsClass, int newListItemsClass)
        {
            XmlNode prevClassNode     = GetTreeNode(prevListItemsClass);
            XmlNode newClassNode      = GetTreeNode(newListItemsClass);
            int     hvoCommonAncestor = 0;
            // NOTE: the class of hvoBeforeListChange could be different then prevListItemsClass, if the item is a ghost (owner).
            int classOfHvoBeforeListChange = Cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoBeforeListChange).ClassID;
            // so go up the parent of the previous one until it's an ancestor of the newClass.
            XmlNode ancestorOfPrev = prevClassNode.ParentNode;

            while (ancestorOfPrev != null)
            {
                if (newClassNode.SelectSingleNode("ancestor::" + ancestorOfPrev.Name) != null)
                {
                    XmlNode commonAncestor      = ancestorOfPrev;
                    var     classCommonAncestor = Cache.MetaDataCacheAccessor.GetClassId(commonAncestor.Name);
                    if (DomainObjectServices.IsSameOrSubclassOf(Cache.DomainDataByFlid.MetaDataCache, classOfHvoBeforeListChange, classCommonAncestor))
                    {
                        hvoCommonAncestor = hvoBeforeListChange;
                    }
                    else
                    {
                        var obj = Cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoBeforeListChange);
                        hvoCommonAncestor = obj.OwnerOfClass(classCommonAncestor).Hvo;
                    }
                    break;
                }
                ancestorOfPrev = ancestorOfPrev.ParentNode;
            }
            return(hvoCommonAncestor);
        }
Exemplo n.º 5
0
 private IEnumerable <IMoInflAffixSlot> GetSlots()
 {
     if (m_morphType == null)
     {
         // Not called by InsertEntryDlg; need to figure out the morphtype(s)
         var lex = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as ILexEntry;
         if (lex != null)
         {
             return(DomainObjectServices.GetSlots(m_cache, lex, m_selectedMainPOS));
         }
         else
         {
             return(m_selectedMainPOS.AllAffixSlots);
         }
     }
     else
     {             //  Called by InsertEntryDlg so we know the morphtype
         bool fIsPrefixal = MorphServices.IsPrefixishType(m_cache, m_morphType.Hvo);
         bool fIsSuffixal = MorphServices.IsSuffixishType(m_cache, m_morphType.Hvo);
         if (fIsPrefixal && fIsSuffixal)
         {
             return(m_selectedMainPOS.AllAffixSlots);
         }
         else
         {
             return(DomainObjectServices.GetSomeSlots(m_cache, m_selectedMainPOS.AllAffixSlots, fIsPrefixal));
         }
     }
 }
Exemplo n.º 6
0
        public void CmFileFinder_OrigFilesMatch()
        {
            // Setup
            ICmFolder folder = DomainObjectServices.FindOrCreateFolder(Cache,
                                                                       LangProjectTags.kflidPictures, CmFolderTags.LocalPictures);

            ICmFile file = DomainObjectServices.FindOrCreateFile(folder, m_internalPath);

            Assert.AreEqual(m_pict.PictureFileRA, file);
        }
Exemplo n.º 7
0
        public void CmFileFinder_OrigFileMissing()
        {
            // Setup
            ICmFolder folder = DomainObjectServices.FindOrCreateFolder(Cache,
                                                                       LangProjectTags.kflidPictures, CmFolderTags.LocalPictures);

            FileUtils.Delete(m_internalPath);
            Assert.IsFalse(FileUtils.IsFileReadable(m_internalPath), "Test cannot proceed. Unable to delete Original file.");

            // Test
            Assert.DoesNotThrow(() => DomainObjectServices.FindOrCreateFile(folder, m_internalPath));
        }
Exemplo n.º 8
0
        private void SetupCacheToTestAgainst()
        {
            var lp = Cache.LangProject;

            lp.LinkedFilesRootDir = m_linkedFilesRootDir;
            ICmFolder picturesfolder  = DomainObjectServices.FindOrCreateFolder(Cache, LangProjectTags.kflidPictures, CmFolderTags.LocalPictures);
            ICmFolder mediafolder     = DomainObjectServices.FindOrCreateFolder(Cache, LangProjectTags.kflidMedia, CmFolderTags.LocalMedia);
            ICmFolder tsStringsfolder = Cache.ServiceLocator.GetInstance <ICmFolderFactory>().Create();

            lp.FilePathsInTsStringsOA = tsStringsfolder;
            tsStringsfolder.Name.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString(CmFolderTags.LocalFilePathsInTsStrings,
                                                                                              WritingSystemServices.FallbackUserWs(Cache));

            AddCmFileToCmFolder(picturesfolder, Path.Combine("Pictures", "JudeAndMeWithBeard.jpg"));
            AddCmFileToCmFolder(tsStringsfolder, Path.Combine("Others", "Chic Skype.png"));
            AddCmFileToCmFolder(mediafolder, Path.Combine("AudioVisual", "Untitled0.WMV"));
        }
Exemplo n.º 9
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            // Setup
            string sNewFile = Path.DirectorySeparatorChar + Path.GetRandomFileName();

            m_fileOs.AddFile(sNewFile, "456", Encoding.Default);

            ICmFolder folder = DomainObjectServices.FindOrCreateFolder(Cache,
                                                                       LangProjectTags.kflidPictures, CmFolderTags.LocalPictures);

            // Test
            ICmFile file = DomainObjectServices.FindOrCreateFile(folder, sNewFile);

            Assert.IsNotNull(file, "null CmFile returned");
            Assert.AreEqual(sNewFile, file.InternalPath, "Internal path not set correctly");
            Assert.AreEqual(sNewFile, file.AbsoluteInternalPath, "Files outside LangProject.LinkedFilesRootDir are stored as absolute paths");
            Assert.AreNotEqual(m_pict.PictureFileRA, file);
            FileUtils.Delete(sNewFile);
        }
Exemplo n.º 10
0
        private RelationshipOfRelatives FindTreeRelationship(int prevListItemsClass, int newListItemsClass)
        {
            RelationshipOfRelatives relationshipOfTarget;

            if (DomainObjectServices.IsSameOrSubclassOf(Cache.DomainDataByFlid.MetaDataCache, prevListItemsClass, newListItemsClass))
            {
                relationshipOfTarget = RelationshipOfRelatives.Sibling;
            }
            else
            {
                // lookup new class in ownership tree and decide how to select the most related object
                string  newClassName  = Cache.DomainDataByFlid.MetaDataCache.GetClassName(newListItemsClass);
                string  prevClassName = Cache.DomainDataByFlid.MetaDataCache.GetClassName(prevListItemsClass);
                XmlNode prevClassNode = m_classOwnershipTree.SelectSingleNode(".//" + prevClassName);
                XmlNode newClassNode  = m_classOwnershipTree.SelectSingleNode(".//" + newClassName);
                // determine if prevClassName is owned (has anscestor) by the new.
                bool fNewIsAncestorOfPrev = prevClassNode.SelectSingleNode("ancestor::" + newClassName) != null;
                if (fNewIsAncestorOfPrev)
                {
                    relationshipOfTarget = RelationshipOfRelatives.Ancestor;
                }
                else
                {
                    // okay, now find most related object in new items list.
                    bool fNewIsChildOfPrev = newClassNode.SelectSingleNode("ancestor::" + prevClassName) != null;
                    if (fNewIsChildOfPrev)
                    {
                        relationshipOfTarget = RelationshipOfRelatives.Descendent;
                    }
                    else
                    {
                        relationshipOfTarget = RelationshipOfRelatives.Cousin;
                    }
                }
            }
            return(relationshipOfTarget);
        }
Exemplo n.º 11
0
 private void AddCmFileToCmFolder(ICmFolder cmFolder, string fileInsideLinkedFiles)
 {
     var file = DomainObjectServices.FindOrCreateFile(cmFolder, fileInsideLinkedFiles);
 }
Exemplo n.º 12
0
        /// <summary>
        /// If OK, then make FS have the selected feature value(s).
        /// JohnT: This is a really ugly kludge, which I have only partly repaired.
        /// We need the dialog to return with m_fs set to an FsFeatStruc (if OK was clicked),
        /// since that is what the bulk edit bar wants to copy to MoStemMsas for any items
        /// it is asked to modify. Also, the new FsFeatStruc needs to be in the ReferenceForms
        /// (which is what m_owningFlid apparently always is, currently) so that it will become
        /// one of the items in the combo list and can be selected. However, Andy says this is
        /// not the intended use of ReferenceForms at all.
        /// A further ugliness is that we always make a new FsFeatStruc (unless one was passed
        /// in to one of the SegDlgInfo methods, but AFAIK that override is never used), but
        /// we then delete it if it turns out to be a duplicate. There is no other straightforward
        /// way to detect that the current choices in the dialog correspond to an existing item.
        /// This may cause problems in the new world, where we can't do this "suppress sub tasks"
        /// trick without losing our Undo stack.
        /// It may be possible in the new world to create an object without initially giving it an
        /// owner, and only persist it if it is NOT a duplicate. But even that we don't really want
        /// to be undoable, nor should it clear the undo stack. Really the list of possible choices
        /// for the combo should not be separately persisted as model data, but it should be persisted
        /// somehow...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MsaInflectionFeatureListDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                // making and maybe then deleting the new item for the combo is not undoable
                NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor,
                                               () =>
                {
                    if (m_fs == null)
                    {
                        // Didn't have one to begin with. See whether we want to create one.
                        if (CheckFeatureStructure(m_tvMsaFeatureList.Nodes))
                        {
                            var repo = m_cache.ServiceLocator.GetInstance <IFsFeatStrucRepository>();
                            // FsFeatStruc may be owned atomically or in a colllection. See which fake insertion index we need.
                            int where  = m_cache.MetaDataCacheAccessor.GetFieldType(m_owningFlid) == (int)CellarPropertyType.OwningAtomic ? -2: -1;
                            int hvoNew = m_cache.DomainDataByFlid.MakeNewObject(FsFeatStrucTags.kClassId, m_hvoOwner,
                                                                                m_owningFlid, where);
                            m_fs = repo.GetObject(hvoNew);
                        }
                        else
                        {
                            return;                                             // leave it null.
                        }
                    }
                    // clean out any extant features in the feature structure
                    foreach (var spec in m_fs.FeatureSpecsOC)
                    {
                        m_fs.FeatureSpecsOC.Remove(spec);
                    }
                    UpdateFeatureStructure(m_tvMsaFeatureList.Nodes);
                    // The (usually) newly created one may be a duplicate. If we find a duplicate
                    // delete the one we just made (or were passed) and return the duplicate.
                    int cpt = m_cache.MetaDataCacheAccessor.GetFieldType(m_owningFlid);
                    if (m_hvoOwner != 0 && cpt != (int)CellarPropertyType.OwningAtomic)
                    {
                        int chvo = m_cache.DomainDataByFlid.get_VecSize(m_hvoOwner, m_owningFlid);
                        for (int ihvo = 0; ihvo < chvo; ihvo++)
                        {
                            int hvo = m_cache.DomainDataByFlid.get_VecItem(m_hvoOwner, m_owningFlid, ihvo);
                            if (hvo == m_fs.Hvo)
                            {
                                continue;
                            }
                            IFsFeatStruc fs = m_cache.ServiceLocator.GetInstance <IFsFeatStrucRepository>().GetObject(hvo);
                            if (DomainObjectServices.AreEquivalent(fs, m_fs))
                            {
                                m_cache.DomainDataByFlid.DeleteObj(m_fs.Hvo);
                                m_fs = fs;
                                break;
                            }
                        }
                    }
                    // If the user emptied all the FeatureSpecs (i.e. chose "None of the above" in each area),
                    // then we need to delete the FsFeatStruc. (LT-13596)
                    if (FS.FeatureSpecsOC.Count == 0)
                    {
                        if (m_fs.CanDelete)
                        {
                            m_fs.Delete();
                        }
                        m_fs = null;
                    }
                });
            }

            if (m_propertyTable != null)
            {
                m_propertyTable.SetProperty("msaInflFeatListDlgLocation", Location, true);
                m_propertyTable.SetProperty("msaInflFeatListDlgSize", Size, true);
            }
        }