/// ------------------------------------------------------------------------------------
        /// <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.
            }
            int cws = wsf.NumberOfWs;

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

                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                }
            }

            return(PasteStatus.PreserveWs);
        }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if all writing systems in the pasted string are in this
        /// project. If so, we will keep the writing system formatting. Otherwise, we will
        /// use the destination writing system (at the selection). We don't want to add new
        /// writing systems from a paste into an FwMultiParaTextBox.
        /// </summary>
        /// <param name="wsf">writing system factory containing the writing systems in the
        /// pasted ITsString</param>
        /// <param name="destWs">[out] 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 = m_innerMultiParaFwTextBox.CurrentWs;
            }

            return(AllWritingSystemsDefined(wsf) ? PasteStatus.PreserveWs : PasteStatus.UseDestWs);
        }
        /// ------------------------------------------------------------------------------------
        /// <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);
        }