/// <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(); } } }
/// <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(); } } }
private static void AddParseTextMilestones(MilestoneProgressState mp) { // we currently have 5 milestones per text. mp.AddMilestone(1); mp.AddMilestone(1); mp.AddMilestone(1); mp.AddMilestone(1); mp.AddMilestone(1); }