Exemple #1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
 /// file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">List of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteType">The CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</param>
 /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
 /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
 /// must start on a new line, but Paratext considers all backslashes in the data to be
 /// SF markers.)</param>
 /// ------------------------------------------------------------------------------------
 internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                            string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) :
     this(file.AbsoluteInternalPath, mappingList, domain, wsId, noteType,
          scanInlineBackslashMarkers)
 {
     m_file = file;
 }
Exemple #2
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);
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Update the properties of a CmPicture with the given file, caption, and folder.
        /// </summary>
        /// <param name="srcFilename">The full path to the original filename (an internal copy
        /// will be made in this method)</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)
        {
            // Locate CmFolder with given name or create it, if neccessary
            ICmFolder folder = CmFolder.FindOrCreateFolder(m_cache, (int)LangProject.LangProjectTags.kflidPictures, sFolder);
            ICmFile   file   = PictureFileRA;

            if (file == null)
            {
                file          = folder.FilesOC.Add(new CmFile());
                PictureFileRA = file;
            }
            // (The case-independent comparison is valid only for Microsoft Windows.)
            string sInternalAbsPath = file.AbsoluteInternalPath;

            if (srcFilename != null &&
                !srcFilename.Equals(sInternalAbsPath, StringComparison.InvariantCultureIgnoreCase))
            {
                ((CmFile)file).SetInternalPath(srcFilename);
            }
            Caption.SetAlternative(captionTss, ws);
            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);
        }
Exemple #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
 /// file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">List of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="icuLocale">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="noteTypeHvo">The HVO of the CmAnnotationDefn of the source to which
 /// this file belongs (only used for Note sources)</param>
 /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
 /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
 /// must start on a new line, but Paratext considers all backslashes in the data to be
 /// SF markers.)</param>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                          string icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers) :
     this(file.AbsoluteInternalPath, mappingList, domain, icuLocale, noteTypeHvo,
          scanInlineBackslashMarkers)
 {
     m_file = file;
 }
Exemple #5
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);
        }
Exemple #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Override to make sure any CmFiles that are only there only for this picture are
        /// deleted as well
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void DeleteObjectSideEffects(Set <int> objectsToDeleteAlso, SIL.FieldWorks.Common.Controls.ProgressState state)
        {
            ICmFile cmFile = PictureFileRA;

            // Check to make sure there is a picture file associated with this picture and that the only thing that CmFile is
            // around for is to provide a file for this picture.  Checking that the backreference of the file that this picture
            // uses is 1 is a valid way to make sure of this.
            // If this CmFile serves no other purpose, we should get rid of it.
            if (cmFile != null && cmFile.BackReferences.Count == 1)
            {
                objectsToDeleteAlso.Add(cmFile.Hvo);
            }

            base.DeleteObjectSideEffects(objectsToDeleteAlso, state);
        }
Exemple #7
0
 public void Init(Mediator mediator, ICmFile obj, int flid)
 {
     CheckDisposed();
     m_fdoCache = (FdoCache)mediator.PropertyTable.GetValue("cache");
     m_file     = obj;
     m_flid     = flid;
     if (m_rootb == null)
     {
         MakeRoot();
     }
     else if (m_file != null)
     {
         m_rootb.SetRootObject(m_file.Hvo, m_vc, AudioVisualView.kfragPathname,
                               m_rootb.Stylesheet);
         m_rootb.Reconstruct();
     }
 }
Exemple #8
0
 public void Init(ICmFile obj, int flid, PropertyTable propertyTable)
 {
     CheckDisposed();
     m_propertyTable = propertyTable;
     m_cache         = m_propertyTable.GetValue <LcmCache>("cache");
     m_file          = obj;
     m_flid          = flid;
     if (m_rootb == null)
     {
         MakeRoot();
     }
     else if (m_file != null)
     {
         m_rootb.SetRootObject(m_file.Hvo, m_vc, kfragPathname,
                               m_rootb.Stylesheet);
         m_rootb.Reconstruct();
     }
 }
Exemple #9
0
        public void CmFileFinder_OrigFilesMatch()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("garbage.jpg", true))
            {
                ICmFile fileOrig = new CmFile();
                folder.FilesOC.Add(fileOrig);
                fileOrig.InternalPath = maker.Filename;

                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.AreEqual(fileOrig, file);
            }
        }
Exemple #10
0
        public void CmFileFinder_NoPreExistingCmFile()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);

            using (DummyFileMaker maker = new DummyFileMaker("junk56.jpg", true))
            {
                ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename);
                Assert.IsNotNull(file, "null CmFile returned");
                Assert.IsNotNull(file.InternalPath, "Internal path not set correctly");
                Assert.IsTrue(file.AbsoluteInternalPath == file.InternalPath, "Files outside LangProject.ExtLinkRootDir are stored as absolute paths");
                m_internalFilesToDelete.Add(file.AbsoluteInternalPath);
                Assert.IsTrue(m_pict.PictureFileRAHvo != file.Hvo);
            }
        }
Exemple #11
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);
        }
Exemple #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a picture (no caption set).
        /// </summary>
        /// <param name="para">Paragraph to insert picture into</param>
        /// <param name="ichPos">The 0-based character offset into the paragraph</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected ICmPicture InsertTestPicture(StTxtPara para, int ichPos)
        {
            // Create the picture
            ICmFolder folder = m_fdoCache.LangProject.PicturesOC.Add(new CmFolder());
            ICmFile   file   = folder.FilesOC.Add(new CmFile());

            file.InternalPath = "there";
            int        newHvo  = m_fdoCache.CreateObject(CmPicture.kClassId);
            ICmPicture picture = new CmPicture(m_fdoCache, newHvo);

            picture.PictureFileRA = file;

            // Update the paragraph contents to include the footnote marker
            ITsStrBldr tsStrBldr = para.Contents.UnderlyingTsString.GetBldr();

            (picture as CmPicture).InsertOwningORCIntoPara(tsStrBldr, ichPos, 0);             // Don't care about ws
            para.Contents.UnderlyingTsString = tsStrBldr.GetString();

            return(picture);
        }
Exemple #13
0
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            CheckDisposed();

            switch (frag)
            {
            case AudioVisualView.kfragPathname:
                // Display the filename.
                ILgWritingSystemFactory wsf =
                    m_cache.LanguageWritingSystemFactoryAccessor;
                vwenv.set_IntProperty((int)FwTextPropType.ktptEditable,
                                      (int)FwTextPropVar.ktpvDefault,
                                      (int)TptEditable.ktptNotEditable);
                ITsString tss;
                Debug.Assert(hvo != 0);
                Debug.Assert(m_cache != null);
                ICmFile file = CmFile.CreateFromDBObject(m_cache, hvo);
                Debug.Assert(file != null);
                string path;
                if (Path.IsPathRooted(file.InternalPath))
                {
                    path = file.InternalPath;
                }
                else
                {
                    path = Path.Combine(m_cache.LangProject.ExternalLinkRootDir,
                                        file.InternalPath);
                }
                tss = m_cache.MakeUserTss(path);
                vwenv.OpenParagraph();
                vwenv.AddString(tss);
                vwenv.CloseParagraph();
                break;

            default:
                throw new ArgumentException(
                          "Don't know what to do with the given frag.", "frag");
            }
        }
Exemple #14
0
        public void CmFileFinder_OrigFileMissing()
        {
            CheckDisposed();

            // Setup
            ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures,
                                                           StringUtils.LocalPictures);
            string origFile = m_pict.PictureFileRA.AbsoluteInternalPath;

            try
            {
                File.Delete(origFile);
            }
            catch
            {
            }
            Assert.IsFalse(File.Exists(origFile),
                           "Test cannot proceed. Unable to delete Original file.");

            // Test
            ICmFile file = CmFile.FindOrCreateFile(folder, origFile);
        }
		public void Init(Mediator mediator, ICmFile obj, int flid)
		{
			CheckDisposed();
			m_fdoCache = (FdoCache)mediator.PropertyTable.GetValue("cache");
			m_file = obj;
			m_flid = flid;
			if (m_rootb == null)
			{
				MakeRoot();
			}
			else if (m_file != null)
			{
				m_rootb.SetRootObject(m_file.Hvo, m_vc, AudioVisualView.kfragPathname,
					m_rootb.Stylesheet);
				m_rootb.Reconstruct();
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
		/// file list from the database.
		/// </summary>
		/// <param name="file">The CmFile</param>
		/// <param name="mappingList">List of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteType">The CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</param>
		/// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
		/// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
		/// must start on a new line, but Paratext considers all backslashes in the data to be
		/// SF markers.)</param>
		/// ------------------------------------------------------------------------------------
		internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string wsId, ICmAnnotationDefn noteType, bool scanInlineBackslashMarkers) :
			this(file.AbsoluteInternalPath, mappingList, domain, wsId, noteType,
			scanInlineBackslashMarkers)
		{
			m_file = file;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is
		/// used when populating the file list from the database.
		/// </summary>
		/// <param name="file">The CmFile</param>
		/// <param name="mappingList">Sorted list of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="wsId">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
		/// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
		/// must start on a new line, but Paratext considers all backslashes in the data to be
		/// SF markers.)</param>
		/// ------------------------------------------------------------------------------------
		internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string wsId, bool scanInlineBackslashMarkers) :
			this(file, mappingList, domain, wsId, null, scanInlineBackslashMarkers)
		{
		}
Exemple #18
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is
 /// used when populating the file list from the database.
 /// </summary>
 /// <param name="file">The CmFile</param>
 /// <param name="mappingList">Sorted list of mappings to which newly found mappings
 /// should (and will) be added</param>
 /// <param name="domain">The import domain to which this file belongs</param>
 /// <param name="wsId">The ICU locale of the source to which this file belongs
 /// (null for Scripture source)</param>
 /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
 /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
 /// must start on a new line, but Paratext considers all backslashes in the data to be
 /// SF markers.)</param>
 /// ------------------------------------------------------------------------------------
 internal ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
                            string wsId, bool scanInlineBackslashMarkers) :
     this(file, mappingList, domain, wsId, null, scanInlineBackslashMarkers)
 {
 }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a ScrImportFileInfo from a CmFile. This is used when populating the
		/// file list from the database.
		/// </summary>
		/// <param name="file">The CmFile</param>
		/// <param name="mappingList">List of mappings to which newly found mappings
		/// should (and will) be added</param>
		/// <param name="domain">The import domain to which this file belongs</param>
		/// <param name="icuLocale">The ICU locale of the source to which this file belongs
		/// (null for Scripture source)</param>
		/// <param name="noteTypeHvo">The HVO of the CmAnnotationDefn of the source to which
		/// this file belongs (only used for Note sources)</param>
		/// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
		/// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
		/// must start on a new line, but Paratext considers all backslashes in the data to be
		/// SF markers.)</param>
		/// ------------------------------------------------------------------------------------
		public ScrImportFileInfo(ICmFile file, ScrMappingList mappingList, ImportDomain domain,
			string icuLocale, int noteTypeHvo, bool scanInlineBackslashMarkers):
			this(file.AbsoluteInternalPath, mappingList, domain, icuLocale, noteTypeHvo,
			scanInlineBackslashMarkers)
		{
			m_file = file;
		}
Exemple #20
0
		public static void ConsiderDeletingRelatedFile(ICmFile file, Mediator mediator)
		{
			if (file == null)
				return;
			var refs = file.ReferringObjects;
			if (refs.Count > 1)
				return; // exactly one if only this CmPicture uses it.
			var path = file.InternalPath;
			if (Path.IsPathRooted(path))
				return; // don't delete external file
			string msg = String.Format(FdoUiStrings.ksDeleteFileAlso, path);
			if (MessageBox.Show(Form.ActiveForm, msg, FdoUiStrings.ksDeleteFileCaption, MessageBoxButtons.YesNo,
				MessageBoxIcon.Question)
				!= DialogResult.Yes)
			{
				return;
			}
			if (mediator != null)
			{
				var app = mediator.PropertyTable.GetValue("App") as FwApp;
				if (app != null)
					app.PictureHolder.ReleasePicture(file.AbsoluteInternalPath);
				string fileToDelete = file.AbsoluteInternalPath;
				// I'm not sure why, but if we try to delete it right away, we typically get a failure,
				// with an exception indicating that something is using the file, despite the code above that
				// tries to make our picture cache let go of it.
				// However, waiting until idle seems to solve the problem.
				mediator.IdleQueue.Add(IdleQueuePriority.Low, obj =>
					{
						try
						{
							File.Delete(fileToDelete);
						}
						catch (IOException)
						{
							// If we can't actually delete the file for some reason, don't bother the user complaining.
						}
						return true; // task is complete, don't try again.
					});
				file.Delete();
			}
		}