示例#1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Prepares the selected files to be uploaded to REAP using RAMP.
        /// </summary>
        /// <param name="owner">RAMP dialog owner</param>
        /// <param name="dialogFont">RAMP dialog font (for localization and consistency)</param>
        /// <param name="localizationDialogIcon"></param>
        /// <param name="filesToArchive"></param>
        /// <param name="propertyTable"></param>
        /// <param name="thisapp"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public bool ArchiveNow(Form owner, Font dialogFont, Icon localizationDialogIcon,
                               IEnumerable <string> filesToArchive, PropertyTable propertyTable, FwApp thisapp, LcmCache cache)
        {
            var viProvider             = new VersionInfoProvider(Assembly.LoadFile(thisapp.ProductExecutableFile), false);
            WritingSystemManager wsMgr = cache.ServiceLocator.WritingSystemManager;
            var appName   = thisapp.ApplicationName;
            var title     = cache.LanguageProject.ShortName;
            var uiLocale  = wsMgr.Get(cache.DefaultUserWs).IcuLocale;
            var projectId = cache.LanguageProject.ShortName;

            var model = new RampArchivingDlgViewModel(Application.ProductName, title, projectId, /*appSpecificArchivalProcessInfo:*/ string.Empty, SetFilesToArchive(filesToArchive), GetFileDescription);

            // image files should be labeled as Graphic rather than Photograph (the default).
            model.ImagesArePhotographs = false;

            // show the count of media files, not the duration
            model.ShowRecordingCountNotLength = true;

            // set the general description, in each available language
            IMultiString descr        = cache.LanguageProject.Description;
            var          descriptions = new Dictionary <string, string>();

            foreach (int wsid in descr.AvailableWritingSystemIds)
            {
                var descrText = descr.get_String(wsid).Text;
                if ((!string.IsNullOrEmpty(descrText)) && (descrText != "***"))
                {
                    descriptions[wsMgr.Get(wsid).GetIso3Code()] = descrText;
                }
            }

            if (descriptions.Count > 0)
            {
                model.SetDescription(descriptions);
            }

            AddMetsPairs(model, viProvider.ShortNumericAppVersion, cache);

            // create the dialog
            using (var dlg = new ArchivingDlg(model, "Palaso", dialogFont, new FormSettings()))
                using (var reportingAdapter = new SilErrorReportingAdapter(dlg, propertyTable))
                {
                    ErrorReport.SetErrorReporter(reportingAdapter);
                    dlg.ShowDialog(owner);
                    ErrorReport.SetErrorReporter(null);
                }

            return(true);
        }
示例#2
0
        /// <summary>
        /// Common code for loading a MultiStringAccessor.
        /// </summary>
        internal static void LoadMultiStringAccessor(ICmObject obj, int flid, XElement reader,
                                                     ref IMultiString multiStringProperty, ILgWritingSystemFactory wsf)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            // Deal with MultiUnicode data type.
            multiStringProperty = new MultiStringAccessor(obj, flid);
            ((MultiAccessor)multiStringProperty).LoadFromDataStoreInternal(reader, wsf);
        }
        public void FindNextMissingBtFootnoteMarker_BtSectionHeadToFootnoteInSecondParaAfterSkippingOne()
        {
            IScrSection section = m_exodus.SectionsOS[1];

            ITsStrFactory strfact     = TsStrFactoryClass.Create();
            IStTxtPara    contentPara = section.ContentOA[0];
            ITsStrBldr    strBldr     = contentPara.Contents.GetBldr();
            IStFootnote   foot        = m_exodus.InsertFootnoteAt(0, strBldr, 7);

            contentPara.Contents = strBldr.GetString();
            IScrTxtPara footPara = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);

            footPara.Contents = strfact.MakeString("This is footnote text for footnote 1", Cache.DefaultVernWs);

            IMultiString trans = contentPara.SegmentsOS[1].FreeTranslation;
            ITsStrBldr   bldr  = trans.get_String(Cache.DefaultAnalWs).GetBldr();

            TsStringUtils.InsertOrcIntoPara(foot.Guid, FwObjDataTypes.kodtNameGuidHot, bldr, 0, 0, Cache.DefaultAnalWs);
            trans.set_String(Cache.DefaultAnalWs, bldr.GetString());

            contentPara          = section.ContentOA[1];
            strBldr              = contentPara.Contents.GetBldr();
            foot                 = m_exodus.InsertFootnoteAt(0, strBldr, 6);
            contentPara.Contents = strBldr.GetString();
            footPara             = Cache.ServiceLocator.GetInstance <IScrTxtParaFactory>().CreateWithStyle(
                foot, ScrStyleNames.NormalFootnoteParagraph);
            footPara.Contents = strfact.MakeString("This is footnote text for footnote 2", Cache.DefaultVernWs);

            m_draftView.TeEditingHelper.SelectRangeOfChars(0, 0, ScrSectionTags.kflidHeading,
                                                           0, 1, 0, 0, true, true, false, VwScrollSelOpts.kssoDefault);

            m_draftView.CallNextMissingBtFootnoteMarker();

            SelectionHelper helper = m_draftView.EditingHelper.CurrentSelection;

            Assert.AreEqual(1, helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor)[0].ihvo, "IP should be in first non-label segment.");
            Assert.AreEqual(0, helper.IchAnchor, "IP should be at start of segment.");
            Assert.AreEqual(0, m_draftView.TeEditingHelper.BookIndex);
            Assert.AreEqual(1, m_draftView.TeEditingHelper.SectionIndex);
            Assert.AreEqual(1, m_draftView.ParagraphIndex);
            Assert.AreEqual(ScrSectionTags.kflidContent, m_draftView.EditingHelper.CurrentSelection.LevelInfo[2].tag);
            Assert.IsTrue(m_draftView.TeEditingHelper.IsBackTranslation);
        }
示例#4
0
 /// <summary>
 /// Reads multilingual string data from XML fragments like
 /// &lt;Description&gt;
 ///		&lt;AStr ws="en"&gt;
 ///			&lt;Run ws="en"&gt;This list contains categories.&lt;/Run&gt;
 ///		&lt;/AStr&gt;
 ///	&lt;/Description&gt;
 /// </summary>
 private void SetMultiStringFromXml(XmlReader xrdr, IMultiString ms)
 {
     if (xrdr.IsEmptyElement)
     {
         xrdr.Read();
         return;
     }
     if (xrdr.ReadToDescendant("AStr"))
     {
         do
         {
             string sWs  = xrdr.GetAttribute("ws");
             string sXml = xrdr.ReadOuterXml();
             int    ws   = m_wsf.GetWsFromStr(sWs);
             if (ws != 0)
             {
                 ITsString tss = TsStringSerializer.DeserializeTsStringFromXml(sXml, m_wsf);
                 ms.set_String(ws, tss);
             }
         } while (xrdr.ReadToNextSibling("AStr"));
     }
     xrdr.Read();                // read the end tag.
 }
示例#5
0
 private void SetMultiStringFromXml(XmlReader xrdr, IMultiString ms)
 {
     if (xrdr.IsEmptyElement)
     {
         xrdr.Read();
         return;
     }
     if (xrdr.ReadToDescendant("AStr"))
     {
         do
         {
             string sWs  = xrdr.GetAttribute("ws");
             string sXml = xrdr.ReadOuterXml();
             if (sWs == "en")
             {
                 continue;                                       // don't overwrite the English string
             }
             int       ws  = GetWsFromStr(sWs);
             ITsString tss = TsStringSerializer.DeserializeTsStringFromXml(sXml, m_wsf);
             ms.set_String(ws, tss);
         } while (xrdr.ReadToNextSibling("AStr"));
     }
     xrdr.Read();                // read the end tag.
 }
示例#6
0
		/// <summary>
		/// Reads multilingual string data from XML fragments like
		/// &lt;Description&gt;
		///		&lt;AStr ws="en"&gt;
		///			&lt;Run ws="en"&gt;This list contains categories.&lt;/Run&gt;
		///		&lt;/AStr&gt;
		///	&lt;/Description&gt;
		/// </summary>
		private void SetMultiStringFromXml(XmlReader xrdr, IMultiString ms)
		{
			if (xrdr.IsEmptyElement)
			{
				xrdr.Read();
				return;
			}
			if (xrdr.ReadToDescendant("AStr"))
			{
				do
				{
					string sWs = xrdr.GetAttribute("ws");
					string sXml = xrdr.ReadOuterXml();
					int ws = m_wsf.GetWsFromStr(sWs);
					if (ws != 0)
					{
						ITsString tss = TsStringSerializer.DeserializeTsStringFromXml(sXml, m_wsf);
						ms.set_String(ws, tss);
					}
				} while (xrdr.ReadToNextSibling("AStr"));
			}
			xrdr.Read();	// read the end tag.
		}
示例#7
0
		void SetString(IMultiString target, int ws, string text)
		{
			target.set_String(ws, Cache.TsStrFactory.MakeString(text,ws));
		}
示例#8
0
 void SetString(IMultiString target, int ws, string text)
 {
     target.set_String(ws, Cache.TsStrFactory.MakeString(text, ws));
 }
示例#9
0
		private void WriteAllForms(TextWriter w, string wrappingElementName, string attrs,
			string elementName, IMultiString multi)
		{
			if (multi == null || multi.StringCount == 0)
				return;
			if (!String.IsNullOrEmpty(wrappingElementName))
			{
				if (String.IsNullOrEmpty(attrs))
					w.WriteLine("<{0}>", wrappingElementName);
				else
					w.WriteLine("<{0} {1}>", wrappingElementName, attrs);
			}
			for (var i = 0; i < multi.StringCount; ++i)
			{
				int ws;
				var tssForm = multi.GetStringFromIndex(i, out ws);
				var sLang = m_cache.WritingSystemFactory.GetStrFromWs(ws);
				w.WriteLine("<{0} lang=\"{1}\"><text>{2}</text></{0}>", elementName,
					MakeSafeAndNormalizedAttribute(sLang),
					ConvertTsStringToLiftXml(tssForm, ws));
			}
			if (!String.IsNullOrEmpty(wrappingElementName))
				w.WriteLine("</{0}>", wrappingElementName);
		}
示例#10
0
            private void ExportMultiString(TextWriter w, TextWriterStream stream,
				IMultiString ms)
            {
                ITsString tssEnglish = ms.get_String(m_wsEn);
                if (tssEnglish.Length == 0)
                    return;
                string sField = m_cache.MetaDataCacheAccessor.GetFieldName(ms.Flid);
                w.WriteLine(String.Format("<{0}>", sField));
                tssEnglish.WriteAsXml(stream, m_cache.WritingSystemFactory, 0, m_wsEn, false);
                foreach (int ws in m_mapWsCode.Keys)
                {
                    ITsString tssValue = ms.get_String(ws);
                    tssValue.WriteAsXml(stream, m_cache.WritingSystemFactory, 0, ws, false);
                }
                w.WriteLine(String.Format("</{0}>", sField));
            }
示例#11
0
		private void RemoveOrc(IMultiString trans, int i, Guid guid)
		{
			int ws;
			ITsString btTss = trans.GetStringFromIndex(i, out ws);
			if (btTss.RunCount > 0 && btTss.Text != null)
			{
				ITsStrBldr btTssBldr = btTss.GetBldr();
				if (TsStringUtils.DeleteOrcFromBuilder(btTssBldr, guid) >= 0)
					trans.set_String(ws, btTssBldr.GetString());
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds any ORCs to the beginning or end of each of the translations.
		/// </summary>
		/// <param name="curSegBaseLine">The baseline text of the current segment.</param>
		/// <param name="transDestSeg">The translation of the destination segment.</param>
		/// <param name="adjacentSegment">An adjacent segment (usually the following one,
		/// but sometimes the preceding one) that can be used to determine which writing
		/// systems have free translations that should get the ORCs in the event that the
		/// destination segement doesn't have any free translations.</param>
		/// <param name="appendOrc">if set to <c>true</c> the ORCs in the baseline will be
		/// appended to the translation, <c>false</c> to prepend to the translation.</param>
		/// <param name="fNeedLeadingSpace">If set to <c>true</c> add a space before the ORC
		/// if there isn't already a space there.</param>
		/// ------------------------------------------------------------------------------------
		private static void AddOrcs(ITsString curSegBaseLine, IMultiString transDestSeg,
			ISegment adjacentSegment, bool appendOrc, bool fNeedLeadingSpace)
		{
			int[] availableWsIds = (transDestSeg.StringCount > 0 || adjacentSegment == null) ?
				transDestSeg.AvailableWritingSystemIds : adjacentSegment.FreeTranslation.AvailableWritingSystemIds;
			foreach (int ws in availableWsIds)
			{
				ITsStrBldr transBldr = transDestSeg.get_String(ws).GetBldr();
				if (fNeedLeadingSpace && transBldr.Length > 0 && !transBldr.Text.EndsWith(" ", StringComparison.Ordinal))
					transBldr.Replace(transBldr.Length, transBldr.Length, " ", null);
				AddOrcsInBaseLineToBldr(transBldr, curSegBaseLine, ws, appendOrc);
				transDestSeg.set_String(ws, transBldr.GetString());
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Copies the translations from the specified source to the specified destination.
		/// </summary>
		/// <param name="transSource">The source translation.</param>
		/// <param name="sourceBaseline">The source baseline.</param>
		/// <param name="transDest">The destination translation.</param>
		/// <param name="destBaseline">The baseline of the destination.</param>
		/// <param name="fAppend">If set to <c>true</c> append the source to the destination,
		/// otherwise prepend to the destination.</param>
		/// ------------------------------------------------------------------------------------
		private static void CopyTranslations(IMultiString transSource, string sourceBaseline,
			IMultiString transDest, string destBaseline, bool fAppend)
		{
			foreach (int ws in transSource.AvailableWritingSystemIds)
			{
				ITsStrBldr transBldr = transDest.get_String(ws).GetBldr();

				ITsString tssSourceTrans = transSource.get_String(ws);
				// Determine if a space needs to be added to the text where the joining is happening
				// and add it if needed.
				if (fAppend && destBaseline.EndsWith(" ", StringComparison.Ordinal) && tssSourceTrans.Length > 0 &&
					!tssSourceTrans.Text.StartsWith(" ", StringComparison.Ordinal) && transBldr.Text != null &&
					!transBldr.Text.EndsWith(" ", StringComparison.Ordinal))
				{
					transBldr.Replace(transBldr.Length, transBldr.Length, " ", StyleUtils.CharStyleTextProps(null, ws));
				}
				else if (!fAppend && sourceBaseline.EndsWith(" ", StringComparison.Ordinal) &&
					!tssSourceTrans.Text.StartsWith(" ", StringComparison.Ordinal) && transBldr.Length > 0)
				{
					transBldr.Replace(0, 0, " ", StyleUtils.CharStyleTextProps(null, ws));
				}

				// Update the values in the multistrings
				int ich = fAppend ? transBldr.Length : 0;
				transBldr.ReplaceTsString(ich, ich, tssSourceTrans);
				transDest.set_String(ws, transBldr.GetString());
			}
		}
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Splits the translation for each writing system at the given locations, moving
			/// any portion after the split location to the destination translation.
			/// </summary>
			/// <param name="splitLocations">The split locations (one per WS).</param>
			/// <param name="srcTrans">The source translation.</param>
			/// <param name="destTrans">The destination translation.</param>
			/// --------------------------------------------------------------------------------
			private static void SplitTranslations(Dictionary<int, int> splitLocations,
				IMultiString srcTrans, IMultiString destTrans)
			{
				foreach (KeyValuePair<int, int> info in splitLocations)
				{
					int ws = info.Key;
					int prevLength = info.Value;
					ITsString tss = srcTrans.get_String(ws);
					srcTrans.set_String(ws, tss.GetSubstring(0, prevLength));
					ITsStrBldr bldr = destTrans.get_String(ws).GetBldr();
					bldr.ReplaceTsString(0, 0, tss.GetSubstring(prevLength, tss.Length));
					destTrans.set_String(ws, bldr.GetString());
				}
			}