예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="bookNum">The canonical book number.</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        private IScrBook ImportBook(Form owningForm, int bookNum)
        {
            IScrImportSet importSettings        = null;
            var           haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6, m_scriptureStylesheet, FwDirectoryFinder.FlexStylesPath);
                importSettings.RevertToSaved();
                importSettings.ParatextScrProj = m_associatedPtText.Name;
                importSettings.StartRef        = new BCVRef(bookNum, 0, 0);
                var chapter                          = m_associatedPtText.Versification.LastChapter(bookNum);
                importSettings.EndRef                = new BCVRef(bookNum, chapter, m_associatedPtText.Versification.LastVerse(bookNum, chapter));
                importSettings.ImportTranslation     = true;
                importSettings.ImportBackTranslation = false;
                ParatextHelper.LoadProjectMappings(importSettings);
                var importMap  = importSettings.GetMappingListForDomain(ImportDomain.Main);
                var figureInfo = importMap[@"\fig"];
                if (figureInfo != null)
                {
                    figureInfo.IsExcluded = true;
                }
                importSettings.SaveSettings();
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("ParatextImport.dll", "ParatextImport.ParatextImportManager"), "ImportParatext", owningForm, m_cache, importSettings, m_scriptureStylesheet, App))
            {
                return(m_scr.FindBook(bookNum));
            }
            return(null);
        }
        /// <summary>
        /// This class creates text, it must delete it here when UNDO is commanded
        /// so it can update InterestingTexts.
        /// </summary>

/*		public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 *              {
 *                      if (cvDel != 1)
 *                              return;
 *                      SaveOnChangeRecord();
 *                      SuppressSaveOnChangeRecord = true;
 *                      try
 *                      {
 *                              m_list.DeleteCurrentObject();
 *                      }
 *                      finally
 *                      {
 *                              SuppressSaveOnChangeRecord = false;
 *                      }
 *                      GetInterestingTextList().UpdateInterestingTexts();
 *              } */

        #region IBookImporter Members
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="importBt">True to import only the back translation, false to import
        /// only the main translation</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook Import(int bookNum, Form owningForm, bool importBt)
        {
            IScripture scr = Cache.LangProject.TranslatedScriptureOA;
            bool       haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                IScrImportSet importSettings   = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6);
                importSettings.StyleSheet      = ScriptureStylesheet;
                IScrText paratextProj          = ParatextHelper.GetAssociatedProject(Cache.ProjectId);
                importSettings.ParatextScrProj = paratextProj.Name;
                importSettings.StartRef        = new BCVRef(bookNum, 0, 0);
                int chapter           = paratextProj.Versification.LastChapter(bookNum);
                importSettings.EndRef = new BCVRef(bookNum, chapter, paratextProj.Versification.LastVerse(bookNum, chapter));
                if (!importBt)
                {
                    importSettings.ImportTranslation     = true;
                    importSettings.ImportBackTranslation = false;
                }
                else
                {
                    List <IScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList();
                    if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) ||
                                                 !btProjects.Any(st => st.Name == importSettings.ParatextBTProj)))
                    {
                        importSettings.ParatextBTProj = btProjects[0].Name;
                    }
                    if (string.IsNullOrEmpty(importSettings.ParatextBTProj))
                    {
                        return(false);
                    }
                    importSettings.ImportTranslation     = false;
                    importSettings.ImportBackTranslation = true;
                }
                ParatextHelper.LoadProjectMappings(importSettings);
                ScrMappingList importMap     = importSettings.GetMappingListForDomain(ImportDomain.Main);
                ImportMappingInfo figureInfo = importMap[@"\fig"];
                if (figureInfo != null)
                {
                    figureInfo.IsExcluded = true;
                }
                importSettings.SaveSettings();
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll",
                                                                                                 "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet,
                                                                        (FwApp)m_mediator.PropertyTable.GetValue("App")))
            {
                return(scr.FindBook(bookNum));
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        /// This class creates text, it must delete it here when UNDO is commanded
        /// so it can update InterestingTexts.
        /// </summary>

/*		public override void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 *              {
 *                      if (cvDel != 1)
 *                              return;
 *                      SaveOnChangeRecord();
 *                      SuppressSaveOnChangeRecord = true;
 *                      try
 *                      {
 *                              m_list.DeleteCurrentObject();
 *                      }
 *                      finally
 *                      {
 *                              SuppressSaveOnChangeRecord = false;
 *                      }
 *                      GetInterestingTextList().UpdateInterestingTexts();
 *              } */

        #region IBookImporter Members
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Imports the specified book.
        /// </summary>
        /// <param name="bookNum">The canonical book number.</param>
        /// <param name="owningForm">Form that can be used as the owner of progress dialogs and
        /// message boxes.</param>
        /// <param name="importBt">True to import only the back translation, false to import
        /// only the main translation</param>
        /// <returns>
        /// The ScrBook created to hold the imported data
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook Import(int bookNum, Form owningForm, bool importBt)
        {
            IScripture scr = Cache.LangProject.TranslatedScriptureOA;
            bool       haveSomethingToImport = NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
            {
                IScrImportSet importSettings   = scr.FindOrCreateDefaultImportSettings(TypeOfImport.Paratext6);
                ScrText paratextProj           = ParatextHelper.GetAssociatedProject(Cache.ProjectId);
                importSettings.ParatextScrProj = paratextProj.Name;
                importSettings.IncludeBooks(bookNum, bookNum, paratextProj.Versification);
                if (!importBt)
                {
                    importSettings.ImportTranslation     = true;
                    importSettings.ImportBackTranslation = false;
                }
                else
                {
                    List <ScrText> btProjects = ParatextHelper.GetBtsForProject(paratextProj).ToList();
                    if (btProjects.Count > 0 && (string.IsNullOrEmpty(importSettings.ParatextBTProj) ||
                                                 !btProjects.Any(st => st.Name == importSettings.ParatextBTProj)))
                    {
                        importSettings.ParatextBTProj = btProjects[0].Name;
                    }
                    if (string.IsNullOrEmpty(importSettings.ParatextBTProj))
                    {
                        return(false);
                    }
                    importSettings.ImportTranslation     = false;
                    importSettings.ImportBackTranslation = true;
                }
                return(true);
            });

            if (haveSomethingToImport && ReflectionHelper.GetBoolResult(ReflectionHelper.GetType("TeImportExport.dll",
                                                                                                 "SIL.FieldWorks.TE.TeImportManager"), "ImportParatext", owningForm, ScriptureStylesheet,
                                                                        (FwApp)m_mediator.PropertyTable.GetValue("App")))
            {
                return(scr.FindBook(bookNum));
            }
            return(null);
        }
예제 #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for runtime.
		/// </summary>
		/// <param name="langProjName">Name of the lang proj.</param>
		/// <param name="scr">The Scripture object.</param>
		/// <param name="styleSheet">The styleSheet</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <param name="app">The app.</param>
		/// ------------------------------------------------------------------------------------
		public ImportWizard(string langProjName, IScripture scr, FwStyleSheet styleSheet,
			IHelpTopicProvider helpTopicProvider, IApp app) : this()
		{
			m_LangProjName = langProjName;
			m_scr = scr;
			m_helpTopicProvider = helpTopicProvider;
			m_app = app;
			m_StyleSheet = styleSheet;
			m_resolver = new ConfirmOverlappingFileReplaceDialog(helpTopicProvider);
			m_cache = scr.Cache;

			// Attempt to get the default import settings.
			m_settings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Unknown);
			if (m_settings.ImportTypeEnum == TypeOfImport.Unknown)
				m_settings.ImportTypeEnum = TypeOfImport.Paratext6;

			InitializeScrImportSettings();

			// Initialize controls based on settings provided
			switch (m_settings.ImportTypeEnum)
			{
				case TypeOfImport.Paratext6:
					rbParatext6.Checked = true;
					break;
				case TypeOfImport.Other:
					rbOther.Checked = true;
					break;
				case TypeOfImport.Paratext5:
					rbParatext5.Checked = true;
					break;
			}
			if (m_helpTopicProvider == null)
				m_btnHelp.Visible = false;
			if (m_app != null)
			{
				m_LatestImportFolder = new RegistryStringSetting(FwSubKey.TE, m_scr.Cache.ProjectId.Name,
					"LatestImportDirectory", string.Empty);
				sfFileListBuilder.LatestImportFolder = m_LatestImportFolder.Value;
			}
			sfFileListBuilder.Initialize(m_helpTopicProvider, m_app);

			if (m_StyleSheet != null)
			{
				m_scrViewHelper = new StyleListViewHelper(lvScrMappings, 1);
				m_scrViewHelper.AddStyles(m_StyleSheet, MappingDetailsCtrl.AllPseudoStyles);
				m_annotationViewHelper = new StyleListViewHelper(lvAnnotationMappings, 1);
				m_annotationViewHelper.AddStyles(m_StyleSheet,
					MappingDetailsCtrl.AllPseudoStyles);
			}
		}
예제 #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the settings for Import, either from database or from wizard
        /// </summary>
        /// <returns>Import settings, or <c>null</c> if user canceled dialog.</returns>
        /// ------------------------------------------------------------------------------------
        protected IScrImportSet GetImportSettings()
        {
            ILangProject  proj           = m_cache.LangProject;
            IScripture    scr            = proj.TranslatedScriptureOA;
            IScrImportSet importSettings = null;

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                importSettings =
                    scr.FindOrCreateDefaultImportSettings(TypeOfImport.Unknown);
            });
            importSettings.StyleSheet = m_styleSheet;

            importSettings.OverlappingFileResolver = new ConfirmOverlappingFileReplaceDialog(m_helpTopicProvider);
            if (!importSettings.BasicSettingsExist)
            {
                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                           m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                {
                    using (ImportWizard importWizard = new ImportWizard(m_cache.ProjectId.Name,
                                                                        scr, m_styleSheet, m_helpTopicProvider, m_app))
                    {
                        if (importWizard.ShowDialog() == DialogResult.Cancel)
                        {
                            return(null);
                        }
                        // Scripture reference range may have changed
                        ImportDialog.ClearDialogReferences();
                        importSettings = scr.DefaultImportSettings;
                    }
                    undoHelper.RollBack = false;
                }
            }
            else
            {
                StringCollection sInvalidFiles;
                bool             fCompletedWizard = false;
                while (!importSettings.ImportProjectIsAccessible(out sInvalidFiles))
                {
                    // Display the "Project Not Found" message box
                    using (ScrImportSetMessage dlg = new ScrImportSetMessage())
                    {
                        string[] files = new string[sInvalidFiles.Count];
                        sInvalidFiles.CopyTo(files, 0);
                        dlg.InvalidFiles       = files;
                        dlg.HelpURL            = m_helpTopicProvider.HelpFile;
                        dlg.HelpTopic          = "/Beginning_Tasks/Import_Standard_Format/Project_Files_Unavailable.htm";
                        dlg.DisplaySetupOption = true;
                        switch (dlg.ShowDialog())
                        {
                        case DialogResult.OK:                                 // Setup...
                        {
                            using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                                       m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                            {
                                using (ImportWizard importWizard = new ImportWizard(
                                           m_cache.ProjectId.Name, scr, m_styleSheet, m_helpTopicProvider, m_app))
                                {
                                    if (importWizard.ShowDialog() == DialogResult.Cancel)
                                    {
                                        return(null);
                                    }
                                    // Scripture reference range may have changed
                                    ImportDialog.ClearDialogReferences();
                                    importSettings   = scr.DefaultImportSettings;
                                    fCompletedWizard = true;
                                }
                                undoHelper.RollBack = false;
                            }
                            break;
                        }

                        case DialogResult.Cancel:
                            return(null);

                        case DialogResult.Retry:
                            // Loop around until user gets tired.
                            break;
                        }
                    }
                }
                if (!fCompletedWizard)
                {
                    if (ParatextProjHasUnmappedMarkers(importSettings))
                    {
                        // TODO: Show message box and then bring up import wizard
                    }
                }
            }

            return(importSettings);
        }