/// ------------------------------------------------------------------------------------ /// <summary> /// Load the scripture project and enumerator, preparing us to read the data files. /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// ------------------------------------------------------------------------------------ public void LoadScriptureProject(IScrImportSet settings) { m_settings = settings; m_ImportType = settings.ImportTypeEnum; // Load ScriptureText object switch (TypeOfImport) { case TypeOfImport.Paratext6: if ((!settings.ImportTranslation && !settings.ImportAnnotations) || !LoadParatextVernacularProject()) if (!LoadParatextBackTranslationProject()) if (!LoadParatextNotesProject()) throw new InvalidOperationException("There was nothing worth loading."); break; case TypeOfImport.Other: case TypeOfImport.Paratext5: ScrVers versification = m_settings.Cache.LangProject.TranslatedScriptureOA.Versification; m_settings.CheckForOverlappingFilesInRange( new ScrReference(m_settings.StartRef, versification), new ScrReference(m_settings.EndRef, versification)); m_scSfmText = new SCScriptureText(settings, ImportDomain.Main); // Now initialize the TextEnum with the range of scripture text we want m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef); break; default: Debug.Assert(false, "bogus TypeOfImport"); break; } }
///------------------------------------------------------------------------------- /// <summary> /// Constructor for import dialog, requiring a language project. /// Use this constructor at run time. /// </summary> ///------------------------------------------------------------------------------- public ImportDialog(FwStyleSheet styleSheet, FdoCache cache, IScrImportSet settings, IHelpTopicProvider helpTopicProvider, IApp app) : this() { m_StyleSheet = styleSheet; m_helpTopicProvider = helpTopicProvider; m_app = app; m_scr = cache.LangProject.TranslatedScriptureOA; m_importSettings = settings; //InitBookNameList(); // Set the initial values for the controls from the static variables. radImportEntire.Checked = ImportEntire; radImportRange.Checked = !ImportEntire; chkTranslation.Checked = ImportTranslation; chkBackTranslation.Checked = ImportBackTranslation; chkBookIntros.Checked = ImportBookIntros; chkOther.Checked = ImportAnnotations; // Restore any saved settings. if (s_StartRef != null) StartRef = s_StartRef; else SetStartRefToFirstImportableBook(); if (s_EndRef != null) EndRef = s_EndRef; else SetEndRefToLastImportableBook(); // Finish constructing the ScrBookControl objects. InitializeStartAndEndRefControls(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Populate settings as if user had used the Import Wizard to choose a SF project /// and set up mappings appropriate for TOB data files. /// </summary> /// <param name="settings">The settings object to be populated</param> /// ------------------------------------------------------------------------------------ static public void MakeSFImportTestSettings(IScrImportSet settings) { settings.ImportTypeEnum = TypeOfImport.Other; // add a bogus file to the project settings.AddFile(DriveUtil.BootDrive + @"IDontExist.txt", ImportDomain.Main, null, null); // Set up the mappings SetUpMappings(settings); }
private static bool SFProjectFilesAccessible(IScrImportSet importSettings, out StringCollection filesNotFound) { filesNotFound = new StringCollection(); bool fProjectFileFound = false; fProjectFileFound |= FilesAreAccessible(importSettings.GetImportFiles(ImportDomain.Main), ref filesNotFound); fProjectFileFound |= FilesAreAccessible(importSettings.GetImportFiles(ImportDomain.BackTrans), ref filesNotFound); fProjectFileFound |= FilesAreAccessible(importSettings.GetImportFiles(ImportDomain.Annotations), ref filesNotFound); return (fProjectFileFound); }
private static bool ParatextProjectsAccessible(IScrImportSet importSettings, out StringCollection projectsNotFound) { projectsNotFound = new StringCollection(); if (importSettings.ParatextScrProj == null) return false; // Paratext seems to want to have write access to do an import... string filename = Path.Combine(ParatextHelper.ProjectsDirectory, importSettings.ParatextScrProj + ".ssf"); if (!FileUtils.IsFileReadableAndWritable(filename) || !ParatextHelper.GetProjectBooks(importSettings.ParatextScrProj).Any()) { projectsNotFound.Add(importSettings.ParatextScrProj); } if (importSettings.ParatextBTProj != null) { filename = Path.Combine(ParatextHelper.ProjectsDirectory, importSettings.ParatextBTProj + ".ssf"); if (!FileUtils.IsFileReadableAndWritable(filename) || !ParatextHelper.GetProjectBooks(importSettings.ParatextBTProj).Any()) { projectsNotFound.Add(importSettings.ParatextBTProj); } } if (importSettings.ParatextNotesProj != null) { filename = Path.Combine(ParatextHelper.ProjectsDirectory, importSettings.ParatextNotesProj + ".ssf"); if (!FileUtils.IsFileReadableAndWritable(filename) || !ParatextHelper.GetProjectBooks(importSettings.ParatextNotesProj).Any()) { projectsNotFound.Add(importSettings.ParatextNotesProj); } } return (projectsNotFound.Count == 0); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="SCTextEnum"/> class. /// </summary> /// <param name="settings">The import settings</param> /// <param name="domain">The source domain</param> /// <param name="startRef">first reference to retrieve</param> /// <param name="endRef">last reference to retrieve</param> /// <param name="encConverters">The encoding converters repository</param> /// ------------------------------------------------------------------------------------ public SCTextEnum(IScrImportSet settings, ImportDomain domain, BCVRef startRef, BCVRef endRef, IEncConverters encConverters) { m_settings = settings; m_domain = domain; m_startRef = new BCVRef(startRef); m_endRef = new BCVRef(endRef); m_mappingSet = m_settings.GetMappingSetForDomain(domain); // Gets the set of encoding converters m_encConverters = encConverters; // make a list of all of the begin and end markers for inline markers // Also build the map of encoding converters m_InlineBeginAndEndMarkers = new List<string>(); foreach (ImportMappingInfo mapping in m_settings.GetMappingListForDomain(domain)) { if (mapping.IsInline || m_settings.ImportTypeEnum == TypeOfImport.Paratext5) { m_InlineBeginAndEndMarkers.Add(mapping.BeginMarker); if (mapping.IsInline) m_InlineBeginAndEndMarkers.Add(mapping.EndMarker); } } m_InlineBeginAndEndMarkers.Sort(new StrLengthComparer(false)); // Build a list of all of the characters that inline markers start with Set<char> tempCharList = new Set<char>(); foreach (string marker in m_InlineBeginAndEndMarkers) tempCharList.Add(marker[0]); // Set ignores duplicates. m_InlineMarkerStartChars = tempCharList.ToArray(); // Get the import file source that will provide the files to import. m_importSource = settings.GetImportFiles(domain); m_importSourceEnum = m_importSource.GetEnumerator(); }
/// ------------------------------------------------------------------------------------ /// <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); }
///------------------------------------------------------------------------------- /// <summary> /// When the Source button is clicked, display the import wizard. /// </summary> ///------------------------------------------------------------------------------- private void btnSource_Click(object sender, System.EventArgs e) { using (ImportWizard importWizard = new ImportWizard(m_scr.Cache.ProjectId.Name, m_scr, m_StyleSheet, m_helpTopicProvider, m_app)) { using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(ActionHandler)) { if (importWizard.ShowDialog() == DialogResult.Cancel) { // Ditch any in-memory changes made to the settings. Reload from the DB. m_importSettings.RevertToSaved(); } else undoHelper.RollBack = false; } // If there are no files after showing the wizard, close the import dialog if (InitBookNameList() == 0) { MessageBox.Show(this, DlgResources.ResourceString("kstidImportFilesUnavailable"), m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); return; } // The default set of settings may have changed. m_importSettings = m_scr.DefaultImportSettings; // Update the file ranges for import because they may have changed. InitializeStartAndEndRefControls(); // Update the passage controls to reflect the new range of files available // Only make changes that do not expand the available range of books since a // range may have been specified before the wizard was run that we do not // want to overwrite if (!scrPsgFrom.IsReferenceValid(scrPsgFrom.ScReference)) SetStartRefToFirstImportableBook(); if (!scrPsgTo.IsReferenceValid(scrPsgTo.ScReference)) SetEndRefToLastImportableBook(); } btnOK.Focus(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Defines the import settings given a type of import (Paratext5, Paratext6 or Other). /// Either we find import settings in the database or create a new set. /// </summary> /// <param name="importType">Type of the import.</param> /// ------------------------------------------------------------------------------------ private void DefineImportSettings(TypeOfImport importType) { NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ActionHandlerAccessor, () => { m_settings = m_scr.FindOrCreateDefaultImportSettings(importType); }); InitializeScrImportSettings(); }
/// <summary> /// Removes the project info from the given importSettings /// </summary> private static void ClearImportSettings(IScrImportSet importSettings) { importSettings.ParatextScrProj = null; importSettings.ParatextBTProj = null; importSettings.ParatextNotesProj = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Call this static method to Import Scripture /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// <param name="cache">The cache used to import to and get misc. info. from.</param> /// <param name="styleSheet">Stylesheet from which to get scripture styles.</param> /// <param name="undoManager">The undo import manager (which is responsible for creating /// and maintaining the archive of original books being overwritten and maintaining /// the book filter).</param> /// <param name="importCallbacks">UI callbacks</param> /// <returns> /// The Scripture reference of the first thing that was imported /// </returns> /// ------------------------------------------------------------------------------------ public static ScrReference Import(IScrImportSet settings, FdoCache cache, FwStyleSheet styleSheet, UndoImportManager undoManager, TeImportUi importCallbacks) { using (TeSfmImporter importer = new TeSfmImporter(settings, cache, styleSheet, undoManager, importCallbacks)) { importer.Import(); return importer.m_firstImportedRef; } // Dispose() releases any hold on ICU character properties. }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. } // Dispose unmanaged resources here, whether disposing is true or false. if (m_cpe != null && Marshal.IsComObject(m_cpe)) Marshal.ReleaseComObject(m_cpe); m_cpe = null; m_settings = null; m_SOWrapper = null; m_sSegmentText = null; m_sMarker = null; m_styleProxy = null; m_vernParaStyleProxy = null; m_vernTextProps = null; m_analTextProps = null; m_styleProxies = null; m_notesStyleProxies = null; m_lastPara = null; m_BookTitleParaProxy = null; m_DefaultFootnoteParaProxy = null; m_TsStringFactory = null; m_BTFootnoteStrBldr = null; m_CurrParaPictures = null; m_CurrParaFootnotes = null; m_BTPendingPictures = null; m_CurrBTFootnote = null; m_sBtFootnoteParaStyle = null; m_BtFootnoteStrBldrs = null; m_PendingAnnotations = null; m_BTfootnoteIndex = null; m_sCharStyleEndMarker = null; m_sFootnoteEndMarker = null; m_sCharStyleBeginMarker = null; m_sFootnoteBeginMarker = null; m_scrTranslatorAnnotationDef = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Iterate through the ScriptureTexts' lists of tags. If any missing mappings are found /// return true to give the user a chance to use the ImportWizard to map everything. /// </summary> /// <param name="settings">Import settings object</param> /// <returns><c>true</c> if the settings represent a P6 project which has markers (tags) /// in its stylesheet which the user has not had a chance to map in the import wizard. /// </returns> /// ------------------------------------------------------------------------------------ protected bool ParatextProjHasUnmappedMarkers(IScrImportSet settings) { // Load ScriptureText object if (settings.ImportTypeEnum != TypeOfImport.Paratext6) return false; return (ParatextProjHasUnmappedMarkers(settings.ParatextScrProj) || ParatextProjHasUnmappedMarkers(settings.ParatextBTProj) || ParatextProjHasUnmappedMarkers(settings.ParatextNotesProj)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test setup stuff /// </summary> /// ------------------------------------------------------------------------------------ public override void TestSetup() { base.TestSetup(); m_importSettings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create(); m_scr.ImportSettingsOC.Add(m_importSettings); m_translatorNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().TranslatorAnnotationDefn; m_consultantNoteDefn = Cache.ServiceLocator.GetInstance<ICmAnnotationDefnRepository>().ConsultantAnnotationDefn; m_fileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_fileOs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Populate settings as if user had used the Import Wizard to choose a Paratext /// project and set up mappings. /// </summary> /// <param name="settings">The settings object to be populated</param> /// ------------------------------------------------------------------------------------ static public void MakeParatextTestSettings(IScrImportSet settings) { settings.ImportTypeEnum = TypeOfImport.Paratext6; settings.ParatextScrProj = "TEV"; settings.ParatextBTProj = "KAM"; settings.ParatextNotesProj = "HMM"; SetUpMappings(settings); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor to use when using an in-memory cache /// </summary> /// ------------------------------------------------------------------------------------ public DummyTeImporter(IScrImportSet settings, FdoTestBase testBase, FwStyleSheet styleSheet) : base(settings, testBase.Cache, styleSheet, new DummyUndoImportManager(testBase), new TeImportNoUi()) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set up appropriate mappings for the TEV and TOB data files. /// </summary> /// <param name="settings">The settings object to be set up</param> /// ------------------------------------------------------------------------------------ static public void SetUpMappings(IScrImportSet settings) { // Map styles without end markers settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\b", null, "Stanza Break")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\c", null, ScrStyleNames.ChapterNumber)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\inp", null, "Block Quote Paragraph")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\ip", null, "Intro Paragraph")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\is", null, "Intro Section Head")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\ip_", null, "Background Paragraph")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\is_", null, "UnknownTEStyle")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\imt", null, "Intro Title Main")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\ist", null, "Intro Title Secondary")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\iot", null, "Intro Section Head")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\io1", null, "Intro List Item1")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\io2", null, "Intro List Item2")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\li1", null, "List Item1")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\li2", null, "List Item2")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\li3", null, "List Item3")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\p", null, "Paragraph")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\m", null, "Paragraph Continuation")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mr", null, "Section Range Paragraph")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\ms", null, "Section Head Major")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mt", null, "Title Main")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mt", null, "Title Main")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mt1", null, "Title Main")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\q", null, "Line1")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\q2", null, "Line2")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\q3", null, "Line3")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\qc", null, "Doxology")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\r", null, "Parallel Passage Reference")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\s", null, ScrStyleNames.SectionHead)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\s2", null, "Section Head Minor")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\v", null, ScrStyleNames.VerseNumber)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\vt", null, "Default Paragraph Characters")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\h", null, false, MappingTargetType.TitleShort, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\fig", null, false, MappingTargetType.Figure, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\cap", null, false, MappingTargetType.FigureCaption, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\cat", null, false, MappingTargetType.FigureFilename, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figcap", null, false, MappingTargetType.FigureCaption, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figcat", null, false, MappingTargetType.FigureFilename, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figcopy", null, false, MappingTargetType.FigureCopyright, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figdesc", null, false, MappingTargetType.FigureDescription, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figdesc_es", null, false, MappingTargetType.FigureDescription, MarkerDomain.Default, null, "es")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figlaypos", null, false, MappingTargetType.FigureLayoutPosition, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figrefrng", null, false, MappingTargetType.FigureRefRange, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\figscale", null, false, MappingTargetType.FigureScale, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\vern", MarkerDomain.Note, "Default Paragraph Characters", "qaa-x-kal", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\rt", MarkerDomain.Note, "Default Paragraph Characters", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\de", MarkerDomain.Default, "Emphasis", "de", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\em", @"\em*", "Emphasis")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mt2", null, "Title Secondary")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\mt2_", null, "Book Title Secondary")); // Not a real style settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\st", null, "Title Secondary")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\st2", null, "Title Tertiary")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\st3", null, "Title Tertiary")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\quot", null, "Quoted Text")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\h_", null, "Header & Footer")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\bogus", null, true, MappingTargetType.TEStyle, MarkerDomain.Default, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\fr", MarkerDomain.Footnote, ScrStyleNames.FootnoteTargetRef, null, null)); // TE-7718 - Added ending marker for \ft so that test data could include it - the ending marker // is added by Paratext if user sets selected text to the "ft" style. settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\ft", @"\ft*", MarkerDomain.Footnote, "Default Paragraph Characters", null, null)); if (settings.HasNonInterleavedNotes) { settings.SetMapping(MappingSet.Notes, new ImportMappingInfo(@"\c", null, ScrStyleNames.ChapterNumber)); settings.SetMapping(MappingSet.Notes, new ImportMappingInfo(@"\v", null, ScrStyleNames.VerseNumber)); settings.SetMapping(MappingSet.Notes, new ImportMappingInfo(@"\rem", MarkerDomain.Default, ScrStyleNames.Remark, "en", null)); settings.SetMapping(MappingSet.Notes, new ImportMappingInfo(@"\crem", MarkerDomain.Default, ScrStyleNames.Remark, "en", s_consultantNoteDefn)); // need one character style for testing problem reported in TE-5071 settings.SetMapping(MappingSet.Notes, new ImportMappingInfo(@"\em", @"\em*", "Emphasis")); } // Map styles with end markers; Note that although we use some of these markers in import tests // which purport to be "Other" SF, these tests really simulate segments as they would be mapped // coming from P6, since TE's UI for "Other" currently doesn't allow the user to indicate end // markers for normal backslash markers, only for in-line markers (which don't typically start // with a backslash in Shoebox/Toolbox data). settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\bk", @"\bk*", ScrStyleNames.BookTitleInText)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\kw", @"\kw*", "Key Word")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\uw", @"\uw*", false, MappingTargetType.TEStyle, MarkerDomain.Default, "Untranslated Word", "qaa-x-kal")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\gls", @"\gls*", "Gloss")); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\rem", MarkerDomain.Note, ScrStyleNames.Remark, "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\crem", MarkerDomain.Note, ScrStyleNames.Remark, "en", s_consultantNoteDefn)); if (settings.ImportTypeEnum == TypeOfImport.Other) { settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\f", null, false, MappingTargetType.TEStyle, MarkerDomain.Footnote, ScrStyleNames.NormalFootnoteParagraph, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\x", null, false, MappingTargetType.TEStyle, MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\fte", null, "Default Paragraph Characters")); // Footnote end settings.SetMapping(MappingSet.Main, new ImportMappingInfo("|fm ", "|fm*", MarkerDomain.Footnote, ScrStyleNames.FootnoteMarker, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo("|ft ", "|ft*", MarkerDomain.Footnote, "Default Paragraph Characters", null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo("|fr ", "|fr*", MarkerDomain.Footnote, ScrStyleNames.FootnoteTargetRef, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\fq", null, MarkerDomain.Footnote, "Quoted Text", null, null)); } else { settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\f", @"\f*", false, MappingTargetType.TEStyle, MarkerDomain.Footnote, ScrStyleNames.NormalFootnoteParagraph, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\x", @"\x*", false, MappingTargetType.TEStyle, MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\fq", @"\fq*", MarkerDomain.Footnote, "Quoted Text", null, null)); } // Map styles for Back-Translation domain settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btip", MarkerDomain.BackTrans, "Intro Paragraph", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvt", MarkerDomain.BackTrans, "Default Paragraph Characters", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btv", MarkerDomain.BackTrans, "Verse Number", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvt_default", MarkerDomain.BackTrans, "Default Paragraph Characters", null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvt_de", MarkerDomain.BackTrans, "Default Paragraph Characters", "de", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvt_es", MarkerDomain.BackTrans, "Default Paragraph Characters", "es", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvt_default", MarkerDomain.BackTrans, "Default Paragraph Characters", null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btis", MarkerDomain.BackTrans, "Intro Section Head", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btp", MarkerDomain.BackTrans, "Paragraph", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btmt", MarkerDomain.BackTrans, "Title Main", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btst", MarkerDomain.BackTrans, "Title Secondary", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btq", MarkerDomain.BackTrans, "Line1", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btq2", MarkerDomain.BackTrans, "Line2", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btr", MarkerDomain.BackTrans, "Parallel Passage Reference", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\bts", MarkerDomain.BackTrans, "Section Head", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\bts2", MarkerDomain.BackTrans, "Section Head Minor", "en", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btvw", MarkerDomain.BackTrans, "Untranslated Word", "qaa-x-kal", null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btft", MarkerDomain.Footnote | MarkerDomain.BackTrans, "Default Paragraph Characters", null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btf", MarkerDomain.Footnote | MarkerDomain.BackTrans, ScrStyleNames.NormalFootnoteParagraph, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btfig", null, false, MappingTargetType.Figure, MarkerDomain.BackTrans, null, null)); // Figure is treated just like FigureCaption in the BT domain settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btcap", null, false, MappingTargetType.FigureCaption, MarkerDomain.BackTrans, null, null)); settings.SetMapping(MappingSet.Main, new ImportMappingInfo(@"\btfigcopy", null, false, MappingTargetType.FigureCopyright, MarkerDomain.BackTrans, null, null)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ protected override void CreateTestData() { m_settings = Cache.ServiceLocator.GetInstance<IScrImportSetFactory>().Create(); Cache.LangProject.TranslatedScriptureOA.ImportSettingsOC.Add(m_settings); m_settings.ImportTypeEnum = TypeOfImport.Other; m_converters = null; m_fileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_fileOs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the mappings for a Paratext 6/7 project into the specified import settings. /// </summary> /// ------------------------------------------------------------------------------------ public static void LoadProjectMappings(IScrImportSet importSettings) { s_ptHelper.LoadProjectMappings(importSettings); }
private ScrReference InternalImport(IScrImportSet importSettings, bool fDisplayUi) { ScrReference firstImported = ScrReference.Empty; bool fPartialBtImported = false; try { Logger.WriteEvent("Starting import"); using (var progressDlg = new ProgressDialogWithTask(m_mainWnd)) { progressDlg.CancelButtonText = TeResourceHelper.GetResourceString("kstidStopImporting"); progressDlg.Title = TeResourceHelper.GetResourceString("kstidImportProgressCaption"); progressDlg.Message = TeResourceHelper.GetResourceString("kstidImportInitializing"); using (TeImportUi importUi = CreateTeImportUi(progressDlg)) { firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi, ImportTask, importSettings, m_undoImportManager, importUi); } } } catch (WorkerThreadException e) { if (e.InnerException is ScriptureUtilsException) { var se = (ScriptureUtilsException)e.InnerException; if (m_helpTopicProvider != null) { string sCaption = GetDialogCaption(se.ImportErrorCodeType); // TODO-Linux: Help is not implemented in Mono MessageBox.Show(m_mainWnd, se.Message, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, m_helpTopicProvider.HelpFile, HelpNavigator.Topic, se.HelpTopic); } if (se.ImportErrorCodeType == ErrorCodeType.BackTransErrorCode && !se.InterleavedImport) fPartialBtImported = true; } else if (e.InnerException is ParatextLoadException) { if (!MiscUtils.RunningTests) { Logger.WriteError(e); string sCaption = ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"); Exception innerE = e.InnerException; var sbMsg = new StringBuilder(innerE.Message); while (innerE.InnerException != null) { innerE = innerE.InnerException; sbMsg.AppendLine(); sbMsg.Append(innerE.Message); } MessageBoxUtils.Show(m_mainWnd, sbMsg.ToString(), sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (!(e.InnerException is CancelException)) { // User didn't just cancel import in the middle of a book -- let's die. throw; } } if (m_undoImportManager.ImportedBooks.Count == 0 && !fPartialBtImported) { Logger.WriteEvent("Nothing imported. Undoing Import."); // Either there was nothing in the file, or the user canceled during the first book. // In any case, we didn't get any books, so whatever has been done should be undone. m_undoImportManager.UndoEntireImport(); return null; } return firstImported; }
/// <summary> /// Calls the importer. /// </summary> /// <param name="importSettings">The import settings.</param> /// <param name="undoManager">The undo manager.</param> /// <param name="importUi">The import UI.</param> /// <returns></returns> protected virtual ScrReference Import(IScrImportSet importSettings, UndoImportManager undoManager, TeImportUi importUi) { if (importSettings != null) { return TeSfmImporter.Import(importSettings, m_cache, m_styleSheet, undoManager, importUi, m_fParatextStreamlinedImport); } return (ScrReference) TeXmlImporter.Import(m_cache, m_styleSheet, m_sOXESFile, undoManager, importUi); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="SCScriptureText"/> class. /// </summary> /// <param name="settings">The import settings</param> /// <param name="domain">The source domain</param> /// ------------------------------------------------------------------------------------ public SCScriptureText(IScrImportSet settings, ImportDomain domain) { Debug.Assert(settings != null); m_settings = settings; m_domain = domain; }
private ScrReference InternalImport(IScrImportSet importSettings, bool fDisplayUi) { ScrReference firstImported = ScrReference.Empty; bool fPartialBtImported = false; try { Logger.WriteEvent("Starting import"); using (var progressDlg = new ProgressDialogWithTask(m_mainWnd)) { progressDlg.CancelButtonText = TeResourceHelper.GetResourceString("kstidStopImporting"); progressDlg.Title = TeResourceHelper.GetResourceString("kstidImportProgressCaption"); progressDlg.Message = TeResourceHelper.GetResourceString("kstidImportInitializing"); using (TeImportUi importUi = CreateTeImportUi(progressDlg)) { firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi, ImportTask, importSettings, m_undoImportManager, importUi); } } } catch (WorkerThreadException e) { if (e.InnerException is ScriptureUtilsException) { var se = (ScriptureUtilsException)e.InnerException; if (m_helpTopicProvider != null) { string sCaption = GetDialogCaption(se.ImportErrorCodeType); // TODO-Linux: Help is not implemented in Mono MessageBox.Show(m_mainWnd, se.Message, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, m_helpTopicProvider.HelpFile, HelpNavigator.Topic, se.HelpTopic); } if (se.ImportErrorCodeType == ErrorCodeType.BackTransErrorCode && !se.InterleavedImport) { fPartialBtImported = true; } } else if (e.InnerException is ParatextLoadException) { if (!MiscUtils.RunningTests) { Logger.WriteError(e); string sCaption = ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"); Exception innerE = e.InnerException; var sbMsg = new StringBuilder(innerE.Message); while (innerE.InnerException != null) { innerE = innerE.InnerException; sbMsg.AppendLine(); sbMsg.Append(innerE.Message); } MessageBoxUtils.Show(m_mainWnd, sbMsg.ToString(), sCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (!(e.InnerException is CancelException)) { // User didn't just cancel import in the middle of a book -- let's die. throw e; } } if (m_undoImportManager.ImportedBooks.Count == 0 && !fPartialBtImported) { Logger.WriteEvent("Nothing imported. Undoing Import."); // Either there was nothing in the file, or the user canceled during the first book. // In any case, we didn't get any books, so whatever has been done should be undone. m_undoImportManager.UndoEntireImport(); return(null); } return(firstImported); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="DummyImportDialog"/> class. /// </summary> /// <param name="styleSheet">The style sheet.</param> /// <param name="cache">The cache.</param> /// <param name="settings">The settings.</param> /// ------------------------------------------------------------------------------------ public DummyImportDialog(FwStyleSheet styleSheet, FdoCache cache, IScrImportSet settings) : base(styleSheet, cache, settings, null, null) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// This static method imports Scripture (This overload used only for testing w/o merge /// or overwrite dialog.) /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// <param name="cache">The cache used to import to and get misc. info. from.</param> /// <param name="styleSheet">Stylesheet from which to get scripture styles.</param> /// <param name="undoManager">The undo import manager (which is responsible for creating /// and maintaining the archive of original books being overwritten and maintaining /// the book filter).</param> /// <returns>The reference of the first thing that was imported</returns> /// ------------------------------------------------------------------------------------ public static ScrReference Import(IScrImportSet settings, FdoCache cache, FwStyleSheet styleSheet, UndoImportManager undoManager) { return Import(settings, cache, styleSheet, undoManager, null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Just call the base class' import method. /// </summary> /// <param name="settings"></param> /// ------------------------------------------------------------------------------------ public void Import(IScrImportSet settings) { TestImportManager.ImportWithUndoTask(this, settings); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the TeSfmImporter class /// </summary> /// <param name="settings">Import settings object (filled in by wizard)</param> /// <param name="cache">The cache used to import to and get misc. info. from.</param> /// <param name="styleSheet">Stylesheet from which to get scripture styles.</param> /// <param name="undoManager">The undo import manager(which is responsible for creating /// and maintainging the archive of original books being overwritten).</param> /// <param name="importCallbacks">UI callbacks</param> /// ------------------------------------------------------------------------------------ protected TeSfmImporter(IScrImportSet settings, FdoCache cache, FwStyleSheet styleSheet, UndoImportManager undoManager, TeImportUi importCallbacks) { Debug.Assert(cache != null); Debug.Assert(styleSheet != null); m_settings = settings; m_cache = cache; m_styleSheet = styleSheet; m_undoManager = undoManager; m_importCallbacks = importCallbacks; m_importCallbacks.Importer = this; Debug.Assert(m_settings.BasicSettingsExist); // ENHANCE (TomB): Make it possible to start importing in the middle // of a book. (m_settings as ScrImportSet).StartRef = new BCVRef((m_settings as ScrImportSet).StartRef.Book, 1, 0); }
public override void TestTearDown() { try { m_dlg.Dispose(); m_dlg = null; m_settings = null; } finally { base.TestTearDown(); } }
/// <summary></summary> public DummySCTextEnum(IScrImportSet settings, ImportDomain domain, BCVRef startRef, BCVRef endRef) : base(settings, domain, startRef, endRef) { DynamicMock mockConverters = new DynamicMock(typeof(IEncConverters)); mockConverters.SetupResultForParams("Item", new DummyEncConverter(), "UPPERCASE"); m_encConverters = (IEncConverters)mockConverters.MockInstance; }
public override void TestSetup() { base.TestSetup(); m_mockFileOs = new MockFileOS(); FileUtils.Manager.SetFileAdapter(m_mockFileOs); string fileGen = m_mockFileOs.MakeSfFile("GEN", @"\c 1"); string fileRev = m_mockFileOs.MakeSfFile("REV", @"\c 1"); m_settings = m_scr.FindOrCreateDefaultImportSettings(TypeOfImport.Other); m_settings.AddFile(fileGen, ImportDomain.Main, null, null); m_settings.AddFile(fileRev, ImportDomain.Main, null, null); m_dlg = new DummyImportDialog(null, Cache, m_settings); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Perform the import with an undo task, including the code that handles displaying the /// ImportedBooks dialog box, issuing synch messages, etc. /// </summary> /// ------------------------------------------------------------------------------------ public static void ImportWithUndoTask(TeMainWnd mainWnd, IScrImportSet settings) { TestImportManager mgr = new TestImportManager(mainWnd); mgr.CompleteImport(mgr.ImportWithUndoTask(settings, false, string.Empty)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Test to see if the ImportProjectIsAccessible method works for projects other than /// Paratext 6. /// </summary> /// ------------------------------------------------------------------------------------ private void ImportProjectIsAccessible_helper(IScrImportSet importSettings) { var fileOs = new MockFileOS(); try { FileUtils.Manager.SetFileAdapter(fileOs); string scrFile1 = fileOs.MakeSfFile("GEN", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile2 = fileOs.MakeSfFile("EXO", @"\p", @"\c 1", @"\v 1", @"\v 2"); string scrFile3 = fileOs.MakeSfFile("LEV", @"\p", @"\c 1", @"\v 1", @"\v 2"); string btFileDef = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string btFileSpan = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileCons = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); string annotFileTrans = fileOs.MakeSfFile("GEN", @"\p", @"\c 3", @"\v 1"); importSettings.AddFile(scrFile1, ImportDomain.Main, null, null); importSettings.AddFile(scrFile2, ImportDomain.Main, null, null); importSettings.AddFile(scrFile3, ImportDomain.Main, null, null); importSettings.AddFile(btFileDef, ImportDomain.BackTrans, null, null); importSettings.AddFile(btFileSpan, ImportDomain.BackTrans, "es", null); var annDefnRepo = Cache.ServiceLocator.GetInstance <ICmAnnotationDefnRepository>(); importSettings.AddFile(annotFileCons, ImportDomain.Annotations, null, annDefnRepo.ConsultantAnnotationDefn); importSettings.AddFile(annotFileTrans, ImportDomain.Annotations, null, annDefnRepo.TranslatorAnnotationDefn); StringCollection filesNotFound; Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(0, filesNotFound.Count); importSettings.SaveSettings(); // Blow away some project files: should still return true, but should // report missing files. FileUtils.Delete(scrFile2); FileUtils.Delete(scrFile3); FileUtils.Delete(btFileDef); FileUtils.Delete(annotFileCons); FileUtils.Delete(annotFileTrans); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsTrue(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(5, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); importSettings.SaveSettings(); // Blow away the rest of the project files: should return false and report // missing files. FileUtils.Delete(scrFile1); FileUtils.Delete(btFileSpan); // Now that we've saved the settings, we'll "revert" in order to re-load from the DB importSettings.RevertToSaved(); Assert.IsFalse(importSettings.ImportProjectIsAccessible(out filesNotFound)); Assert.AreEqual(7, filesNotFound.Count); Assert.IsTrue(filesNotFound.Contains(scrFile1)); Assert.IsTrue(filesNotFound.Contains(scrFile2)); Assert.IsTrue(filesNotFound.Contains(scrFile3)); Assert.IsTrue(filesNotFound.Contains(btFileDef)); Assert.IsTrue(filesNotFound.Contains(btFileSpan)); Assert.IsTrue(filesNotFound.Contains(annotFileCons)); Assert.IsTrue(filesNotFound.Contains(annotFileTrans)); } finally { FileUtils.Manager.Reset(); } }
/// ------------------------------------------------------------------------------------ /// <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); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Does the import. /// </summary> /// <param name="importSettings">The import settings (can be null, as is the case for /// OXES import).</param> /// <param name="updateDescription">description of the data update being done (i.e., /// which type of import).</param> /// <returns><c>true</c> if something got imported; <c>false</c> otherwise</returns> /// ------------------------------------------------------------------------------------ private bool DoImport(IScrImportSet importSettings, string updateDescription) { try { ScrReference firstImported; using (new WaitCursor(m_mainWnd, true)) { m_app.EnableMainWindows(false); firstImported = ImportWithUndoTask(importSettings, true, updateDescription); } firstImported = CompleteImport(firstImported); if (!m_fParatextStreamlinedImport) SetSelectionsAfterImport(firstImported); return (firstImported != ScrReference.Empty); } finally { m_app.EnableMainWindows(true); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Import scripture and embed it in a Undo task so that it is undoable. /// Nb: this creates a Mark in the undo stack (unless no books at all are imported or an /// error occurs), which is designed to be 'collapsed' to after all books in the batch /// are imported, so we get a single Undo task for the whole Import in the end. Code /// (such as tests) that calls this directly should call /// UndoManager.CollapseAllUndoActions(). /// </summary> /// <param name="importSettings">The SFM import settings. If null, then this is an XML import.</param> /// <param name="fDisplayUi">set to <c>true</c> to display the progress dialog, /// <c>false</c> to run without UI.</param> /// <param name="updateDescription">description of the data update being done (i.e., /// which type of import).</param> /// <returns>The reference of the first thing that was imported</returns> /// ------------------------------------------------------------------------------------ protected ScrReference ImportWithUndoTask(IScrImportSet importSettings, bool fDisplayUi, string updateDescription) { m_undoImportManager = new UndoImportManager(m_cache); if (m_mainWnd == null) { // Can happen in tests (and is probably the only time we'll get here). return InternalImport(importSettings, fDisplayUi); } using (new DataUpdateMonitor(m_mainWnd, updateDescription)) { return InternalImport(importSettings, fDisplayUi); } }
/// <summary> /// Perform a Paratext streamlined import /// </summary> /// <param name="mainWnd">The main window.</param> /// <param name="cache"></param> /// <param name="importSettings">Import settings for this import. Theory has it it is only one book.</param> /// <param name="stylesheet">The Scripture stylesheet.</param> /// <param name="app">The app.</param> /// <returns><c>true</c> if something got imported; <c>false</c> otherwise</returns> /// <remarks> /// Called using Reflection from TextsTriStateTreeView. /// </remarks> public static bool ImportParatext(Form mainWnd, LcmCache cache, IScrImportSet importSettings, LcmStyleSheet stylesheet, IApp app) { var mgr = new ParatextImportManager(mainWnd, cache, importSettings, stylesheet, app); return(mgr.ImportSf()); }