/// <summary> /// This version is used inside FLEx when the friendly tool is not active. So, we need to /// build the concordance, but on FLEx's list, and we can assume all the parts and layouts /// are loaded. /// </summary> public bool SetDlgInfo(IWfiWordform wf, Mediator mediator, XmlNode configurationParams) { using (var dlg = new ProgressDialogWorkingOn()) { dlg.Owner = ActiveForm; if (dlg.Owner != null) // I think it's only null when debugging? But play safe. dlg.Icon = dlg.Owner.Icon; dlg.Text = MEStrings.ksFindingOccurrences; dlg.WorkingOnText = MEStrings.ksSearchingOccurrences; dlg.ProgressLabel = MEStrings.ksProgress; dlg.Show(ActiveForm); dlg.Update(); dlg.BringToFront(); try { var cache = wf.Cache; m_srcwfiWordform = wf; m_cache = cache; if (m_fDisposeMediator && m_mediator != null) m_mediator.Dispose(); m_fDisposeMediator = false; return SetDlgInfoPrivate(mediator, configurationParams); } finally { dlg.Close(); } } }
/// <summary> /// Parse the given lists of files and create a wordset from them. /// </summary> /// <param name="paths"></param> /// <remarks>This is marked internal so that unit tests can call it</remarks> internal void CreateWordsetFromFiles(string[] paths) { CheckDisposed(); using (ProgressDialogWorkingOn dlg = new ProgressDialogWorkingOn()) { string sWordSetName = GetWordSetName(paths); IWfiWordSet wordSet = WfiWordSet.Create(m_cache, sWordSetName, GetWordSetDescription(paths)); dlg.Owner = FindForm(); dlg.Icon = dlg.Owner.Icon; dlg.Minimum = 0; dlg.Maximum = paths.Length; dlg.Text = String.Format(ParserUIStrings.ksLoadingFilesForWordSetX, sWordSetName); dlg.Show(); dlg.BringToFront(); using (WordImporter importer = new WordImporter(m_cache)) { foreach (string path in paths) { UpdateProgress(path, dlg); importer.PopulateWordset(path, wordSet); } } dlg.Close(); } }
/// <summary> /// Actually make the change indicated in the action (execute the original command, /// from the Apply button in the dialog). /// </summary> public void DoIt(Mediator mediator) { if (m_changes.Count == 0) return; BuildChangedParasInfo(); if (m_changedParas.Count < 10) { CoreDoIt(null, mediator); } else { using (var dlg = new ProgressDialogWorkingOn()) { dlg.Owner = Form.ActiveForm; dlg.Icon = dlg.Owner.Icon; dlg.Minimum = 0; // 2x accounts for two main loops; extra 10 very roughly accounts for final cleanup. dlg.Maximum = m_changedParas.Count * 2 + 10; dlg.Text = MEStrings.ksChangingSpelling; dlg.WorkingOnText = MEStrings.ksChangingSpelling; dlg.ProgressLabel = MEStrings.ksProgress; dlg.Show(); dlg.BringToFront(); CoreDoIt(dlg, mediator); dlg.Close(); } } }
/// <summary> /// Despite being public where the other SetDlgInfo is internal, this is a "special-case" /// initialization method not used in Flex, but in TE, where there is not a pre-existing mediator /// for each main window. This initializer obtains the configuration parameters and sets up a /// suitable mediator. In doing so it duplicates knowledge from various places: /// 1. Along with the code that initializes xWindow and various other places, it 'knows' where /// to find the configuration node for the respeller dialog. /// 2. It duplicates some of the logic in FwXWindow.InitMediatorValues and RestoreProperties, /// knowing the LocalSettingsId and how to use it to restore mediator properties, and what items /// must be in the mediator. Also logic in xWindow for restoring global settings. /// 3. It knows how to initialize a number of virtual properties normally created as part of /// FLEx's startup code. /// 4. It knows how to set up the string table that Flex uses. /// 5. It knows how to initialize the Flex part inventories. /// </summary> public bool SetDlgInfo(IWfiWordform wf, Form parent, IApp app) { if (wf == null) throw new ArgumentNullException("wf"); if (parent == null) throw new ArgumentNullException("parent"); if (app == null) throw new ArgumentNullException("app"); using (var dlg = new ProgressDialogWorkingOn()) { dlg.Owner = parent; dlg.Text = MEStrings.ksFindingOccurrences; dlg.WorkingOnText = MEStrings.ksSearchingOccurrences; dlg.ProgressLabel = MEStrings.ksProgress; dlg.Show(ActiveForm); dlg.Update(); dlg.BringToFront(); //var progressState = new MilestoneProgressState(dlg.ProgressDisplayer); try { m_cache = wf.Cache; m_srcwfiWordform = wf; // Get the parameter node. var path = Path.Combine(FwDirectoryFinder.GetCodeSubDirectory( Path.Combine(FwUtils.ksFlexAppName, Path.Combine("Configuration", "Words"))), "areaConfiguration.xml"); var doc = XWindow.LoadConfigurationWithIncludes(path, true); var paramNode = doc.DocumentElement.SelectSingleNode("listeners/listener[@class=\"SIL.FieldWorks.XWorks.MorphologyEditor.RespellerDlgListener\"]/parameters"); Debug.Assert(paramNode != null); // Initialize a mediator. var mediator = new Mediator(); m_fDisposeMediator = true; // Copied from FwXWindow.InitMediatorValues mediator.PropertyTable.LocalSettingsId = "local"; mediator.PropertyTable.SetProperty("cache", m_cache); mediator.PropertyTable.SetPropertyPersistence("cache", false); string userPath = DirectoryFinder.UserAppDataFolder(app.ApplicationName); Directory.CreateDirectory(userPath); mediator.PropertyTable.UserSettingDirectory = userPath; //// Enhance JohnT: possibly these three lines (also copied) are not needed. //mediator.PropertyTable.SetProperty("DocumentName", GetMainWindowCaption(cache)); //mediator.PropertyTable.SetPropertyPersistence("DocumentName", false); mediator.PathVariables["{DISTFILES}"] = FwDirectoryFinder.CodeDirectory; mediator.PropertyTable.RestoreFromFile(mediator.PropertyTable.GlobalSettingsId); mediator.PropertyTable.RestoreFromFile(mediator.PropertyTable.LocalSettingsId); //progressState.SetMilestone(); // Set this AFTER the restore! Otherwise it goes away! mediator.PropertyTable.SetProperty("window", dlg.Owner); mediator.PropertyTable.SetPropertyPersistence("window", false); string directoryContainingConfiguration = Path.Combine(FwDirectoryFinder.FlexFolder, "Configuration"); StringTable table = new StringTable(directoryContainingConfiguration); mediator.StringTbl = table; mediator.FeedbackInfoProvider = (IFeedbackInfoProvider)app; //progressState.SetMilestone(); //progressState.SetMilestone(); LayoutCache.InitializePartInventories(m_cache.ProjectId.Name, app, m_cache.ProjectId.ProjectFolder); //progressState.SetMilestone(); // Get all the scripture texts. // Review: should we include IText ones too? // NB: The ownership check is designed to exclude archived drafts. // The second half collects footnotes and the title of the book. var stTextRepos = m_cache.ServiceLocator.GetInstance<IStTextRepository>(); var unarchivedScriptureTexts = m_cache.LangProject.TranslatedScriptureOA.StTexts.ToList(); //progressState.SetMilestone(); // Build concordance info, including the occurrence list for our wordform. ProgressState state = new ProgressState(dlg.ProgressDisplayer); // This is an ugly way of getting the state to the RespellingSda method mediator.PropertyTable.SetProperty("SpellingPrepState", state); mediator.PropertyTable.SetPropertyPersistence("SpellingPrepState", false); NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () => { int done = 0; int total = unarchivedScriptureTexts.Count; foreach (var txt in unarchivedScriptureTexts) { done++; foreach (IStTxtPara para in txt.ParagraphsOS) { if (para.ParseIsCurrent) continue; ParagraphParser.ParseParagraph(para, true); } state.PercentDone = 50*done/total; state.Breath(); } }); // Make sure we will include all of Scripture in the occurrences list. InterestingTextList.SetScriptureTextsInPropertyTable(mediator.PropertyTable, unarchivedScriptureTexts); return SetDlgInfoPrivate(mediator, paramNode); } finally { dlg.Close(); } } }
/// <summary> /// Parse the given lists of files and create a wordset from them. /// </summary> /// <param name="paths"></param> /// <remarks>This is marked internal so that unit tests can call it</remarks> internal void CreateWordsetFromFiles(string[] paths) { CheckDisposed(); using (ProgressDialogWorkingOn dlg = new ProgressDialogWorkingOn()) { m_cache.DomainDataByFlid.BeginUndoTask("Import Word Set", "Import Word Set"); string sWordSetName = GetWordSetName(paths); var wordSet = m_cache.ServiceLocator.GetInstance<IWfiWordSetFactory>().Create(); m_cache.LangProject.MorphologicalDataOA.TestSetsOC.Add(wordSet); wordSet.Name.SetAnalysisDefaultWritingSystem(sWordSetName); wordSet.Description.SetAnalysisDefaultWritingSystem(GetWordSetDescription(paths)); dlg.Owner = FindForm(); dlg.Icon = dlg.Owner.Icon; dlg.Minimum = 0; dlg.Maximum = paths.Length; dlg.Text = String.Format(ParserUIStrings.ksLoadingFilesForWordSetX, sWordSetName); dlg.Show(); dlg.BringToFront(); WordImporter importer = new WordImporter(m_cache); foreach (string path in paths) { UpdateProgress(path, dlg); importer.PopulateWordset(path, wordSet); } m_cache.DomainDataByFlid.EndUndoTask(); dlg.Close(); } }
/// <summary> /// Despite being public where the other SetDlgInfo is internal, this is a "special-case" /// initialization method not used in Flex, but in TE, where there is not a pre-existing mediator /// for each main window. This initializer obtains the configuration parameters and sets up a /// suitable mediator. In doing so it duplicates knowledge from various places: /// 1. Along with the code that initializes xWindow and various other places, it 'knows' where /// to find the configuration node for the respeller dialog. /// 2. It duplicates some of the logic in FwXWindow.InitMediatorValues and RestoreProperties, /// knowing the LocalSettingsId and how to use it to restore mediator properties, and what items /// must be in the mediator. Also logic in xWindow for restoring global settings. /// 3. It knows how to initialize a number of virtual properties normally created as part of /// FLEx's startup code. /// 4. It knows how to set up the string table that Flex uses. /// 5. It knows how to initialize the Flex part inventories. /// </summary> /// <returns></returns> public bool SetDlgInfo(IWfiWordform wf) { using (ProgressDialogWorkingOn dlg = new ProgressDialogWorkingOn()) { if (FwApp.App != null) dlg.Owner = FwApp.App.ActiveMainWindow; else dlg.Owner = Form.ActiveForm; if (dlg.Owner != null) // I think it's only null when debugging? But play safe. dlg.Icon = dlg.Owner.Icon; dlg.Text = MEStrings.ksFindingOccurrences; dlg.WorkingOnText = MEStrings.ksSearchingOccurrences; dlg.ProgressLabel = MEStrings.ksProgress; dlg.Show(Form.ActiveForm); dlg.Update(); dlg.BringToFront(); MilestoneProgressState progressState = new MilestoneProgressState(dlg.ProgressDisplayer); try { //progressState.AddMilestone(1.0f); //progressState.AddMilestone(1.0f); //progressState.AddMilestone(1.0f); //progressState.AddMilestone(4.0f); //progressState.AddMilestone(2.0f); FdoCache cache = wf.Cache; m_srcwfiWordform = wf; // Get the parameter node. string path = Path.Combine(DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration\Words"), "areaConfiguration.xml"); XmlDocument doc = XmlUtils.LoadConfigurationWithIncludes(path, true); XmlNode paramNode = doc.DocumentElement.SelectSingleNode("listeners/listener[@class=\"SIL.FieldWorks.XWorks.MorphologyEditor.RespellerDlgListener\"]/parameters"); Debug.Assert(paramNode != null); // Initialize a mediator. Mediator mediator = new Mediator(); // Copied from FwXWindow.InitMediatorValues mediator.PropertyTable.LocalSettingsId = cache.DatabaseName; mediator.PropertyTable.SetProperty("cache", cache); mediator.PropertyTable.SetPropertyPersistence("cache", false); //// Enhance JohnT: possibly these three lines (also copied) are not needed. //mediator.PropertyTable.SetProperty("DocumentName", GetMainWindowCaption(cache)); //mediator.PropertyTable.SetPropertyPersistence("DocumentName", false); mediator.PathVariables["{DISTFILES}"] = DirectoryFinder.FWCodeDirectory; mediator.PropertyTable.RestoreFromFile(mediator.PropertyTable.GlobalSettingsId); mediator.PropertyTable.RestoreFromFile(mediator.PropertyTable.LocalSettingsId); //progressState.SetMilestone(); // Set this AFTER the restore! Otherwise it goes away! mediator.PropertyTable.SetProperty("window", dlg.Owner); mediator.PropertyTable.SetPropertyPersistence("window", false); string directoryContainingConfiguration = DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration"); StringTable table = new SIL.Utils.StringTable(directoryContainingConfiguration); mediator.StringTbl = table; //progressState.SetMilestone(); EnsureVirtuals(cache); //progressState.SetMilestone(); SIL.FieldWorks.Common.Controls.LayoutCache.InitializePartInventories(cache.DatabaseName); //progressState.SetMilestone(); // Get all the scripture texts. // Review: should we include IText ones too? // Note that the ownership check is designed to exclude archived drafts. // The second half collects footnotes and the title of the book. string sql = "select st.id from StText_ st " + "join ScrSection_ ss on st.Owner$ = ss.id " + "join ScrBook_ sb on ss.Owner$ = sb.id " + "join Scripture s on sb.Owner$ = s.id " + "union " + "select st.id from StText_ st " + "join ScrBook_ sb on st.Owner$ = sb.id " + "join Scripture s on sb.Owner$ = s.id"; int[] texts = DbOps.ReadIntArrayFromCommand(cache, sql, null); //progressState.SetMilestone(); // Build concordance info, including the occurrence list for our wordform. // Enhance: possibly we could create the Wfics only for this wordform? try { cache.EnableBulkLoadingIfPossible(true); ParagraphParser.ConcordTexts(cache, texts, progressState); } finally { cache.EnableBulkLoadingIfPossible(false); } m_cache = cache; GetCaptionWfics(texts, wf); return SetDlgInfo1(mediator, paramNode); } finally { dlg.Close(); } } }
/// <summary> /// This version is used inside FLEx when the friendly tool is not active. So, we need to /// build the concordance, but on FLEx's list, and we can assume all the parts and layouts /// are loaded. /// </summary> /// <param name="wf"></param> /// <returns></returns> public bool SetDlgInfo2(IWfiWordform wf, Mediator mediator, XmlNode configurationParams) { using (ProgressDialogWorkingOn dlg = new ProgressDialogWorkingOn()) { dlg.Owner = Form.ActiveForm; if (dlg.Owner != null) // I think it's only null when debugging? But play safe. dlg.Icon = dlg.Owner.Icon; dlg.Text = MEStrings.ksFindingOccurrences; dlg.WorkingOnText = MEStrings.ksSearchingOccurrences; dlg.ProgressLabel = MEStrings.ksProgress; dlg.Show(Form.ActiveForm); dlg.Update(); dlg.BringToFront(); MilestoneProgressState progressState = new MilestoneProgressState(dlg.ProgressDisplayer); try { //progressState.AddMilestone(1.0f); //progressState.AddMilestone(1.0f); //progressState.AddMilestone(1.0f); //progressState.AddMilestone(4.0f); //progressState.AddMilestone(2.0f); FdoCache cache = wf.Cache; m_srcwfiWordform = wf; ConcordanceWordsVirtualHandler handler = cache.VwCacheDaAccessor.GetVirtualHandlerId( WordformInventory.ConcordanceWordformsFlid(cache)) as ConcordanceWordsVirtualHandler; handler.Progress = progressState; // We don't use this value here, we just want it to get computed with our progress // state active. cache.GetVectorSize(cache.LangProject.WordformInventoryOA.Hvo, handler.Tag); handler.Progress = null; m_cache = cache; return SetDlgInfo1(mediator, configurationParams); } finally { dlg.Close(); } } }