Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get a value determining if the new writing systems should be created as a side-effect
		/// of a paste operation.
		/// </summary>
		/// <param name="wsf">writing system factory containing the new writing systems</param>
		/// <param name="destWs">The destination writing system (writing system used at the
		/// selection).</param>
		/// <returns>
		/// 	an indication of how the paste should be handled.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
		{
			// Determine writing system at selection (destination for paste).
			destWs = 0;
			if (CurrentSelection != null)
				destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
			if (destWs <= 0)
				destWs = Cache.DefaultAnalWs; // set to default analysis, if 0.

			// Get list of writing system names.
			List<string> wsMissingNames = new List<string>();
			int cws = wsf.NumberOfWs;

			using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
			{
				wsf.GetWritingSystems(ptr, cws);
				int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));

				IWritingSystem ws;
				for (int iws = 0; iws < cws; iws++)
				{
					if (vws[iws] == 0)
						continue;
					ws = wsf.get_EngineOrNull(vws[iws]);
					if (ws == null)
					{
						// found corrupt writing system--don't want to use any ws in this pasted string
						return PasteStatus.UseDestWs;
					}
					if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0)
						wsMissingNames.Add(ws.LanguageName); // writing system not found in ws factory
				}
			}

			PasteStatus pasteStatus;
			if (wsMissingNames.Count > 0)
			{
				if (!Options.ShowPasteWsChoice)
					return PasteStatus.UseDestWs;

				// Ask user whether to use destination writing system or copy original writing systems.
				LgWritingSystem lgws = new LgWritingSystem(Cache, destWs);
				Debug.Assert(lgws != null);
				using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg(
					m_cache.LangProject.Name.BestAnalysisAlternative.Text,
					lgws.Name.BestAnalysisAlternative.Text, wsMissingNames))
				{
					newWsDlg.ShowDialog(Control.FindForm());
					pasteStatus = newWsDlg.PasteStatus;
				}
			}
			else // no missing writing systems in TsString to paste
				pasteStatus = PasteStatus.PreserveWs;

			return pasteStatus;
		}
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if the new writing systems should be created as a side-effect
        /// of a paste operation.
        /// </summary>
        /// <param name="wsf">writing system factory containing the new writing systems</param>
        /// <param name="destWs">The destination writing system (writing system used at the
        /// selection).</param>
        /// <returns>
        ///     an indication of how the paste should be handled.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
        {
            // Determine writing system at selection (destination for paste).
            destWs = 0;
            if (CurrentSelection != null)
            {
                destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
            }
            if (destWs <= 0)
            {
                destWs = Cache.DefaultAnalWs;                 // set to default analysis, if 0.
            }
            // Get list of writing system names.
            List <string> wsMissingNames = new List <string>();
            int           cws            = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));

                IWritingSystem ws;
                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] == 0)
                    {
                        continue;
                    }
                    ws = wsf.get_EngineOrNull(vws[iws]);
                    if (ws == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                    if (Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(ws.IcuLocale) == 0)
                    {
                        wsMissingNames.Add(ws.LanguageName);                         // writing system not found in ws factory
                    }
                }
            }

            PasteStatus pasteStatus;

            if (wsMissingNames.Count > 0)
            {
                if (!Options.ShowPasteWsChoice)
                {
                    return(PasteStatus.UseDestWs);
                }

                // Ask user whether to use destination writing system or copy original writing systems.
                LgWritingSystem lgws = new LgWritingSystem(Cache, destWs);
                Debug.Assert(lgws != null);
                using (AddWsFromPastedTextDlg newWsDlg = new AddWsFromPastedTextDlg(
                           m_cache.LangProject.Name.BestAnalysisAlternative.Text,
                           lgws.Name.BestAnalysisAlternative.Text, wsMissingNames))
                {
                    newWsDlg.ShowDialog(Control.FindForm());
                    pasteStatus = newWsDlg.PasteStatus;
                }
            }
            else             // no missing writing systems in TsString to paste
            {
                pasteStatus = PasteStatus.PreserveWs;
            }

            return(pasteStatus);
        }