Пример #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);
        }
Пример #2
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);
        }
Пример #3
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));
        }
Пример #4
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);
        }
Пример #5
0
 private void AddCmFileToCmFolder(ICmFolder cmFolder, string fileInsideLinkedFiles)
 {
     var file = DomainObjectServices.FindOrCreateFile(cmFolder, fileInsideLinkedFiles);
 }