protected override DummyCmObject GetMergeinfo(WindowParams wp, List<DummyCmObject> mergeCandidates, out string guiControl, out string helpTopic) { wp.m_title = FdoUiStrings.ksMergeReversalEntry; wp.m_label = FdoUiStrings.ksEntries; var rie = (IReversalIndexEntry) Object; var filteredHvos = new HashSet<int>(rie.AllOwnedObjects.Select(obj => obj.Hvo)) { rie.Hvo }; // exclude `rie` and all of its subentries var wsIndex = m_cache.ServiceLocator.WritingSystemManager.GetWsFromStr(rie.ReversalIndex.WritingSystem); mergeCandidates.AddRange(from rieInner in rie.ReversalIndex.AllEntries where !filteredHvos.Contains(rieInner.Hvo) select new DummyCmObject(rieInner.Hvo, rieInner.ShortName, wsIndex)); guiControl = "MergeReversalEntryList"; helpTopic = "khtpMergeReversalEntry"; return new DummyCmObject(m_hvo, rie.ShortName, wsIndex); }
private List<int> CollectSegmentForms(int ichMinCurSeg, int ichLimCurSeg, ref int ichLimLast, ref ITsString tssFirstWordOfNextSegment) { List<int> formsInSegment = new List<int>(); List<int> punctuationAnnotations = new List<int>(); int ichMin, ichLim; m_wordMaker.CurrentCharOffset = ichMinCurSeg; ITsString tssWord; if (tssFirstWordOfNextSegment != null) { tssWord = tssFirstWordOfNextSegment; // back up by this word. ichLim = ichMinCurSeg; ichMin = ichLim - tssWord.Length; } else { tssWord = m_wordMaker.NextWord(out ichMin, out ichLim); } int ctwfics = 0; do { if (tssWord == null) { // we've run out of twfics. collect the last remaining punctuation annotations. //Debug.Assert(m_tssPara.Length == ichLimCurSeg); CreatePunctAnnotations(ichLimLast, ichLimCurSeg, punctuationAnnotations); break; } if (ichLimLast != ichMin) { // we need to add punctuations to the current segment. CreatePunctAnnotations(ichLimLast, Math.Min(ichMin, ichLimCurSeg), punctuationAnnotations); formsInSegment.AddRange(punctuationAnnotations); punctuationAnnotations.Clear(); if (ichMin >= ichLimCurSeg) { // we need to add this twfic to the next segment. tssFirstWordOfNextSegment = tssWord; ichLimLast = ichLimCurSeg; break; } } // Create (or reuse if possible) twfic annotations. ITsString tssWordAnn; formsInSegment.Add(CreateOrReuseAnnotation(tssWord, ichMin, ichLim, ctwfics, out tssWordAnn)); if (tssWordAnn != null && tssWord.Length < tssWordAnn.Length) { // this must be a phrase, so advance appropriately in the text. ichLimLast = ichMin + tssWordAnn.Length; m_wordMaker.CurrentCharOffset = ichLimLast; } else { // still stepping by the word boundary. ichLimLast = ichLim; } ctwfics++; tssWord = m_wordMaker.NextWord(out ichMin, out ichLim); } while (true); formsInSegment.AddRange(punctuationAnnotations); return formsInSegment; }
private void ProcessAnalysesAndLexEntries(ProgressDialogWorkingOn progress, IWfiWordform wfOld, IWfiWordform wfNew) { wfOld.SpellingStatus = (int)SpellingStatusStates.incorrect; //if (UpdateLexicalEntries) //{ // foreach (IWfiAnalysis wa in wfOld.AnalysesOC) // { // if (wa.MorphBundlesOS.Count == 1) // { // } // } //} if (!KeepAnalyses) { // Remove multi-morpheme anals in src wf. List<IWfiAnalysis> goners = new List<IWfiAnalysis>(); foreach (IWfiAnalysis goner in wfOld.AnalysesOC) { if (goner.MorphBundlesOS.Count > 1) { goners.Add(goner); } } foreach (IWfiAnalysis goner in goners) { IWfiWordform wf = goner.OwnerOfClass<IWfiWordform>(); wf.AnalysesOC.Remove(goner); } goners.Clear(); } if (UpdateLexicalEntries) { // Change LE allo on single morpheme anals. foreach (IWfiAnalysis update in wfOld.AnalysesOC) { if (update.MorphBundlesOS.Count != 1) continue; // Skip any with zero or more than one. IWfiMorphBundle mb = update.MorphBundlesOS[0]; ITsString tss = mb.Form.get_String(m_vernWs); string srcForm = tss.Text; if (srcForm != null) { // Change morph bundle form. mb.Form.set_String(m_vernWs, NewSpelling); } IMoForm mf = mb.MorphRA; if (mf != null) { mf.Form.set_String(m_vernWs, NewSpelling); } } } // Move remaining anals from src wf to new wf. // This changes the owners of the remaining ones, // since it is an owning property. var analyses = new List<IWfiAnalysis>(); analyses.AddRange(wfOld.AnalysesOC); foreach (var anal in analyses) wfNew.AnalysesOC.Add(anal); }
protected override void ComputeValue(List<ICmObject> chosenObjs, int hvoItem, out List<ICmObject> oldVals, out List<ICmObject> newVal) { if (!m_doingSuggest) { base.ComputeValue(chosenObjs, hvoItem, out oldVals, out newVal); return; } oldVals = GetOldVals(hvoItem); // ComputeValue() is used by FakeDoIt to put values in the suggestion cache, // and by DoIt to get values from the cache (and thereby not repeat the search). if (m_suggestionCache.TryGetValue(hvoItem, out newVal)) { return; // This must be the DoIt pass; MakeSuggestions clears out the cache each time. } // resist the temptation to do "newVal = oldVals" // if we change newVal we don't want oldVals to change newVal = new List<ICmObject>(); newVal.AddRange(oldVals); var curObject = m_cache.ServiceLocator.GetObject(hvoItem) as ILexSense; if (curObject == null) return; var matches = m_semDomRepo.FindCachedDomainsThatMatchWordsInSense(m_searchCache, curObject); foreach (var domain in matches) { if (!newVal.Contains(domain)) newVal.Add(domain); } m_suggestionCache[hvoItem] = newVal; // This must be the FakeDoIt pass; cache semantic domains. }
public override void AddItem(int hvoNew) { CheckDisposed(); List<int> lexemes = new List<int>(); ILexEntryRef ler = m_obj as ILexEntryRef; if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes) lexemes.AddRange(ler.ComponentLexemesRS.HvoArray); else if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes) lexemes.AddRange(ler.PrimaryLexemesRS.HvoArray); // don't add a duplicate items. if (!lexemes.Contains(hvoNew)) { lexemes.Add(hvoNew); SetItems(lexemes); } }
/// <summary> /// /// </summary> /// <param name="control"></param> /// <returns>List contain zero or more IVwRootbox objects.</returns> private List<IVwRootBox> FindAllRootBoxes(Control control) { List<IVwRootBox> rootboxes = new List<IVwRootBox>(); if (control is IRootSite) { rootboxes.AddRange((control as IRootSite).AllRootBoxes()); } foreach (Control c in control.Controls) { rootboxes.AddRange(FindAllRootBoxes(c)); } return rootboxes; }
private static void AddSimpleItems(List<string> results, string remaining) { if (string.IsNullOrWhiteSpace(remaining)) return; results.AddRange(remaining.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x))); }
private List<LayoutTreeNode> BuildLayoutTree(XmlNode xnLayoutType) { // configure LayoutType via its child configure nodes List<LayoutTreeNode> rgltn = new List<LayoutTreeNode>(); foreach (XmlNode config in xnLayoutType.ChildNodes) { // expects a configure element if (config is XmlComment || config.Name != "configure") continue; var ltn = BuildMainLayout(config); if (XmlUtils.GetOptionalBooleanAttributeValue(config, "hideConfig", false)) rgltn.AddRange(ltn.Nodes.Cast<LayoutTreeNode>()); else rgltn.Add(ltn); } return rgltn; }
/// ------------------------------------------------------------------------------------ /// <summary> /// A list of zero or more internal rootboxes. /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public virtual List<IVwRootBox> AllRootBoxes() { CheckDisposed(); List<IVwRootBox> rootboxes = new List<IVwRootBox>(); for (int i = 0; i < m_slaves.Count; i++) { if (m_slaves[i] is IRootSite) { IRootSite rs = (IRootSite)m_slaves[i]; rootboxes.AddRange(rs.AllRootBoxes()); } } return rootboxes; }
/// <summary> /// return an array of all of the objects which should /// 1) be queried when looking for someone to deliver a message to /// 2) be potential recipients of a broadcast /// </summary> /// <returns></returns> public IxCoreColleague[] GetMessageTargets() { CheckDisposed(); List<IxCoreColleague> colleagues = new List<IxCoreColleague>(); if (m_list != null && m_list is IxCoreColleague) colleagues.AddRange((m_list as IxCoreColleague).GetMessageTargets()); colleagues.Add(this); return colleagues.ToArray(); }
private void CreateComboAndTreeItems(string sLayoutType) { var configureLayouts = XmlUtils.FindNode(m_configurationParameters, "configureLayouts"); var layoutTypes = new List<XmlNode>(); layoutTypes.AddRange(configureLayouts.ChildNodes.OfType<XmlNode>().Where(x => x.Name == "layoutType")); Debug.Assert(layoutTypes.Count > 0); var xnConfig = layoutTypes[0].SelectSingleNode("configure"); Debug.Assert(xnConfig != null); var configClass = XmlUtils.GetManditoryAttributeValue(xnConfig, "class"); foreach (var xn in m_layouts.GetLayoutTypes()) { var xnConfigure = xn.SelectSingleNode("configure"); if (XmlUtils.GetManditoryAttributeValue(xnConfigure, "class") == configClass) layoutTypes.Add(xn); } foreach (var xnLayoutType in layoutTypes) { if (xnLayoutType is XmlComment || xnLayoutType.Name != "layoutType") continue; string sLabel = XmlUtils.GetAttributeValue(xnLayoutType, "label"); if (sLabel == "$wsName") { string sLayout = XmlUtils.GetAttributeValue(xnLayoutType, "layout"); Debug.Assert(sLayout.EndsWith("-$ws")); bool fReversalIndex = true; foreach (XmlNode config in xnLayoutType.ChildNodes) { if (config is XmlComment || config.Name != "configure") continue; string sClass = XmlUtils.GetAttributeValue(config, "class"); if (sClass != "ReversalIndexEntry") { fReversalIndex = false; break; } } if (!fReversalIndex) continue; foreach (IReversalIndex ri in m_cache.LangProject.LexDbOA.CurrentReversalIndices) { IWritingSystem ws = m_cache.ServiceLocator.WritingSystemManager.Get(ri.WritingSystem); string sWsTag = ws.Id; m_layouts.ExpandWsTaggedNodes(sWsTag); // just in case we have a new index. // Create a copy of the layoutType node for the specific writing system. XmlNode xnRealLayout = CreateWsSpecficLayoutType(xnLayoutType, ws.DisplayLabel, sLayout.Replace("$ws", sWsTag), sWsTag); List<LayoutTreeNode> rgltnStyle = BuildLayoutTree(xnRealLayout); m_cbDictType.Items.Add(new LayoutTypeComboItem(xnRealLayout, rgltnStyle)); } } else { List<LayoutTreeNode> rgltnStyle = BuildLayoutTree(xnLayoutType); m_cbDictType.Items.Add(new LayoutTypeComboItem(xnLayoutType, rgltnStyle)); } } int idx = -1; for (int i = 0; i < m_cbDictType.Items.Count; ++i) { var item = m_cbDictType.Items[i] as LayoutTypeComboItem; if (item != null && item.LayoutName == sLayoutType) { idx = i; break; } } if (idx < 0) idx = 0; m_cbDictType.SelectedIndex = idx; }
/// <summary> /// Core of the DoIt method, may be called with or without progress dialog. /// </summary> /// <param name="dlg"></param> private void CoreDoIt(ProgressDialogWorkingOn dlg) { // While we do the changes which we can much more efficiently Undo/Redo in this action, // we don't want the various changes we make generating masses of SqlUndoActions. IActionHandler handler = m_cache.ActionHandlerAccessor; m_cache.MainCacheAccessor.SetActionHandler(null); m_hvoNewWf = WfiWordform.FindOrCreateWordform(m_cache, m_newSpelling, m_vernWs, true); try { foreach (KeyValuePair<int, ParaChangeInfo> pair in m_changedParas) { UpdateOffsets(pair.Key, pair.Value); // Review JohnT: should we do the PropChanged, or not?? If not, we should force // a Refresh when the dialog closes. if (!pair.Value.OldContents.Equals(pair.Value.NewContents)) pair.Value.SetString(m_cache, pair.Value.NewContents, true); UpdateProgress(dlg); } UpdateInstanceOf(m_hvoNewWf, dlg); } finally { m_cache.MainCacheAccessor.SetActionHandler(handler); } if (dlg != null) dlg.WorkingOnText = MEStrings.ksDealingAnalyses; m_cache.BeginUndoTask(string.Format(MEStrings.ksUndoChangeSpelling, m_oldSpelling, m_newSpelling), string.Format(MEStrings.ksRedoChangeSpelling, m_oldSpelling, m_newSpelling)); m_cache.ActionHandlerAccessor.AddAction(this); UpdateProgress(dlg); // The destination wordform really exists and should be marked correct. IWfiWordform wf = WfiWordform.CreateFromDBObject(m_cache, m_hvoNewWf); m_oldOccurrencesNewWf = wf.OccurrencesInTexts.ToArray(); m_fWasNewSpellingCorrect = wf.SpellingStatus == (int)SpellingStatusStates.correct; wf.SpellingStatus = (int)SpellingStatusStates.correct; EnchantHelper.SetSpellingStatus(m_newSpelling, m_vernWs, m_cache.LanguageWritingSystemFactoryAccessor, true); UpdateProgress(dlg); m_hvoOldWf = WfiWordform.FindOrCreateWordform(m_cache, m_oldSpelling, m_vernWs, true); IWfiWordform wfOld = WfiWordform.CreateFromDBObject(m_cache, m_hvoOldWf); m_oldOccurrencesOldWf = wfOld.OccurrencesInTexts.ToArray(); m_fWasOldSpellingCorrect = wfOld.SpellingStatus == (int)SpellingStatusStates.correct; UpdateProgress(dlg); // Compute new occurrence lists, save and cache Set<int> changes = new Set<int>(); foreach (ParaChangeInfo info in m_changedParas.Values) changes.AddRange(info.Changes); if (AllChanged) { m_newOccurrencesOldWf = new int[0]; // no remaining occurrences } else { // Only some changed, need to figure m_newOccurrences List<int> newOccurrencesOldWf = new List<int>(); foreach (int hvo in m_oldOccurrencesOldWf) if (!changes.Contains(hvo)) newOccurrencesOldWf.Add(hvo); m_newOccurrencesOldWf = newOccurrencesOldWf.ToArray(); } UpdateProgress(dlg); List<int> newOccurrences = new List<int>(m_oldOccurrencesNewWf.Length + changes.Count); newOccurrences.AddRange(m_oldOccurrencesNewWf); foreach (int hvo in changes) { if (m_cache.IsDummyObject(hvo)) // if this is a dummy annotation, make sure we update the owner m_cache.VwCacheDaAccessor.CacheObjProp(hvo, (int)CmObjectFields.kflidCmObject_Owner, m_hvoNewWf); newOccurrences.Add(hvo); } m_newOccurrencesNewWf = newOccurrences.ToArray(); int vhId = BaseVirtualHandler.GetInstalledHandlerTag(m_cache, "WfiWordform", "OccurrencesInTexts"); m_cache.VwCacheDaAccessor.CacheVecProp(m_hvoOldWf, vhId, m_newOccurrencesOldWf, m_newOccurrencesOldWf.Length); m_cache.VwCacheDaAccessor.CacheVecProp(m_hvoNewWf, vhId, m_newOccurrencesNewWf, m_newOccurrencesNewWf.Length); SendCountVirtualPropChanged(m_hvoNewWf); SendCountVirtualPropChanged(m_hvoOldWf); UpdateProgress(dlg); // Deal with analyses. if (CopyAnalyses) { foreach (WfiAnalysis analysis in wfOld.AnalysesOC) { // Only copy approved analyses. if (analysis.GetAgentOpinion(m_cache.LangProject.DefaultUserAgent) != Opinions.approves) continue; IWfiAnalysis newAnalysis = wf.AnalysesOC.Add(new WfiAnalysis()); foreach (WfiGloss gloss in analysis.MeaningsOC) { IWfiGloss newGloss = newAnalysis.MeaningsOC.Add(new WfiGloss()); newGloss.Form.CopyAlternatives(gloss.Form); } foreach (WfiMorphBundle bundle in analysis.MorphBundlesOS) { IWfiMorphBundle newBundle = newAnalysis.MorphBundlesOS.Append(new WfiMorphBundle()); newBundle.Form.CopyAlternatives(bundle.Form); newBundle.SenseRA = bundle.SenseRA; newBundle.MorphRA = bundle.MorphRA; newBundle.MsaRA = bundle.MsaRA; } } } UpdateProgress(dlg); if (AllChanged) { wfOld.SpellingStatus = (int)SpellingStatusStates.incorrect; EnchantHelper.SetSpellingStatus(m_oldSpelling, m_vernWs, m_cache.LanguageWritingSystemFactoryAccessor, false); if (UpdateLexicalEntries) { foreach (WfiAnalysis wa in wfOld.AnalysesOC) { if (wa.MorphBundlesOS.Count == 1) { } } } if (!KeepAnalyses) { // Remove multi-morpheme anals in src wf. List<IWfiAnalysis> goners = new List<IWfiAnalysis>(); foreach (IWfiAnalysis goner in wfOld.AnalysesOC) { if (goner.MorphBundlesOS.Count > 1) goners.Add(goner); } foreach (IWfiAnalysis goner in goners) { goner.DeleteUnderlyingObject(); // This will shift twfic pointers up to wordform, if needed. } goners.Clear(); } if (UpdateLexicalEntries) { // Change LE allo on single morpheme anals. foreach (IWfiAnalysis update in wfOld.AnalysesOC) { if (update.MorphBundlesOS.Count == 1) { IWfiMorphBundle mb = update.MorphBundlesOS[0]; TsStringAccessor tsa = mb.Form.GetAlternative(m_vernWs); string srcForm = tsa.Text; if (srcForm != null) { // Change morph bundle form. mb.Form.SetAlternative(m_newSpelling, m_vernWs); } IMoForm mf = mb.MorphRA; if (mf != null) { mf.Form.SetAlternative(m_newSpelling, m_vernWs); } } } } // Move remaining anals from src wf to new wf. // This changes the owners of the remaining ones, // since it is an owning property. wf.AnalysesOC.Add(wfOld.AnalysesOC.HvoArray); SendAnalysisVirtualPropChanged(m_hvoNewWf); SendAnalysisVirtualPropChanged(m_hvoOldWf); UpdateProgress(dlg); } m_cache.EndUndoTask(); }
internal static List<int> ConcordParagraphsOfTexts(FdoCache cache, int[] hvosStText, ProgressState progress, IMatcher matcher, ConcordanceControl.ConcordanceLines line) { using (ParagraphParser pp = new ParagraphParser(cache)) { // this will effectively clear ConcordanceWordforms, which seems overkill, but // since we are changing the occurrences on those wordforms, // and also possibly adding many new wordforms, we should just allow RecordLists that use // ConcordanceWordforms to reload the list. // (Enhance: is there any way we can make those lists be smart about when they need to reload, // rather than forcing them to?) (pp.m_wfi as WordformInventory).SuspendUpdatingConcordanceWordforms = true; pp.CreateDummyWordforms = true; pp.m_hvosStText = hvosStText; if (matcher != null) pp.m_matchingAnnotations = new List<int>(); ParagraphParser.ResetParseSessionDependentStaticData(); List<int> hvosParas = new List<int>(); ISilDataAccess sda = cache.MainCacheAccessor; foreach (int hvo in hvosStText) { int chvoMax = sda.get_VecSize(hvo, (int)StText.StTextTags.kflidParagraphs); using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoMax, typeof(int))) { int chvo; sda.VecProp(hvo, (int)StText.StTextTags.kflidParagraphs, chvoMax, out chvo, arrayPtr); Debug.Assert(chvo == chvoMax); hvosParas.AddRange((int[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(int))); } } int[] hvosStTxtPara = hvosParas.ToArray(); // Estimate the number of total number of milestones we'll set. // Enhance: we could construct a way to set percentage done based upon // number of texts and paragraphs in each text. if (progress is MilestoneProgressState) { MilestoneProgressState mp = progress as SIL.FieldWorks.Common.Controls.MilestoneProgressState; for (int i = 0; i < hvosStTxtPara.Length; ++i) { mp.AddMilestone(1); } } // Preload all the paragraphs. cache.PreloadIfMissing(hvosStTxtPara, (int)StTxtPara.StTxtParaTags.kflidContents, 0, false); // Parse each text to load our paragraph and wordform segment annotations. int cPara = 0; using (SuppressSubTasks suppressor = new SuppressSubTasks(cache, true)) { foreach (IStTxtPara para in new FdoObjectSet<IStTxtPara>(cache, hvosStTxtPara, false)) { ++cPara; pp.Parse(para, matcher, line); progress.SetMilestone(); progress.Breath(); if (pp.m_matchingAnnotations != null && pp.m_matchingAnnotations.Count >= ConcordanceControl.MaxConcordanceMatches()) { MessageBox.Show(String.Format(ITextStrings.ksShowingOnlyTheFirstXXXMatches, pp.m_matchingAnnotations.Count, cPara, hvosStTxtPara.Length), ITextStrings.ksNotice, MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } pp.CleanupLeftoverAnnotations(progress); } progress.SetMilestone(); progress.Breath(); (pp.m_wfi as WordformInventory).SuspendUpdatingConcordanceWordforms = false; return pp.m_matchingAnnotations; } }
private static int[] appendIntArray(int[] first, int[] second) { if (first.Length == 0) return second; if (second.Length == 0) return first; List<int> result = new List<int>(first); result.AddRange(second); return result.ToArray(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Save misc. view settings. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnLoadSettings(RegistryKey key) { base.OnLoadSettings(key); if (m_availableChecksTree.Nodes.Count == 0) return; string value = key.GetValue("SelectedCheck", null) as string; if (string.IsNullOrEmpty(value)) { m_availableChecksTree.SelectedNode = m_availableChecksTree.Nodes[0]; return; } Guid checkId = new Guid(value); // Get all the checked ScrChkTreeNodes List<TreeNode> nodes = new List<TreeNode>(m_availableChecksTree.GetNodesOfTypeWithState( typeof(ScrChkTreeNode), TriStateTreeView.CheckState.Checked)); // Add to it, all the unchecked ScrChkTreeNodes nodes.AddRange(m_availableChecksTree.GetNodesOfTypeWithState( typeof(ScrChkTreeNode), TriStateTreeView.CheckState.Unchecked)); // Find the node corresponding to the check id that was found in the registry. foreach (TreeNode node in nodes) { if (((ScrChkTreeNode)node).ScrCheck.CheckId == checkId) { m_availableChecksTree.SelectedNode = node; return; } } }
/// <summary> /// make sure we can get a PartNode for this child, if not, /// try to (recursively) generate parts refering to the parent(s) until we can find the owner of the layout. /// /// clone this (generic) part: /// /// <code> /// <part id="{className}-Jt-$fieldName" type="jtview"> /// <obj class="{className}" field="{OwnerOfClassVirtualProperty}" layout="$fieldName"/> /// </part> /// </code> /// /// into this (specific) part: /// /// <code> /// <part id="{className}-Jt-{layoutName}" type="jtview"> /// <obj class="{className}" field="{OwnerOfClassVirtualProperty}" layout="{layoutName}"/> /// </part> /// </code> /// </summary> /// <param name="layoutClass"></param> /// <param name="fieldNameForReplace"></param> /// <param name="fieldIdForWs"></param> /// <param name="layoutNode"></param> /// <returns>list of part nodes generated</returns> protected List<XmlNode> GeneratePartsFromLayouts(int layoutClass, string fieldNameForReplace, int fieldIdForWs, ref XmlNode layoutNode) { if (m_vc == null || layoutClass == 0) return null; string layout = XmlUtils.GetOptionalAttributeValue(layoutNode, "layout"); if (layout == null) return null; string className = m_mdc.GetClassName(layoutClass); string layoutGeneric = ""; string layoutSpecific = ""; if (layout.Contains("$fieldName") && !fieldNameForReplace.Contains("$fieldName")) { // this is generic layout name that requires further specification. layoutGeneric = layout; // first try to substitute the field name to see if we can get an existing part. XmlNode layoutNodeForCustomField = layoutNode.CloneNode(true); ReplaceParamsInAttributes(layoutNodeForCustomField, "", fieldNameForReplace, fieldIdForWs, className); layoutSpecific = XmlUtils.GetOptionalAttributeValue(layoutNodeForCustomField, "layout"); } else { // possibly need to look for the most generic layout name by default. layoutGeneric = "$fieldName"; layoutSpecific = layout; } XmlNode partNode = m_vc.GetNodeForPart(layoutSpecific, false, layoutClass); if (partNode != null) { // Enhance: Validate existing part! // specific part already exists, just keep it. return null; } // couldn't find a specific part, so get the generic part in order to generate the specific part partNode = m_vc.GetNodeForPart(layoutGeneric, false, layoutClass); if (partNode == null) #if !__MonoCS__ throw new ApplicationException("Couldn't find generic Part (" + className + "-Jt-" + layout + ")"); #else // TODO-Linux: Fix this in the correct way. return null; #endif if (partNode != null) { var generatedParts = new List<XmlNode>(); // clone the generic node so we can substitute any attributes that need to be substituted. XmlNode generatedPartNode = partNode.CloneNode(true); ReplaceParamsInAttributes(generatedPartNode, "", fieldNameForReplace, fieldIdForWs, className); Inventory.GetInventory("parts", m_vc.Cache.ProjectId.Name).AddNodeToInventory(generatedPartNode); generatedParts.Add(generatedPartNode); // now see if we need to create other parts from further generic layouts. if (fieldNameForReplace.Contains("$fieldName")) { // use the generated part, since it contains a template reference. partNode = generatedPartNode; } XmlNode nextLayoutNode = null; XmlAttribute layoutAttr = partNode.Attributes["layout"]; if (layoutAttr != null && layoutAttr.Value.Contains("$fieldName")) nextLayoutNode = partNode; else if (partNode.ChildNodes.Count > 0) nextLayoutNode = partNode.SelectSingleNode(".//*[contains(@layout, '$fieldName')]"); if (nextLayoutNode != null) { // now build the new node from its layouts string fieldName = XmlUtils.GetManditoryAttributeValue(nextLayoutNode, "field"); int field = m_vc.Cache.DomainDataByFlid.MetaDataCache.GetFieldId(className, fieldName, true); int nextLayoutClass = m_vc.Cache.GetDestinationClass(field); List<XmlNode> furtherGeneratedParts = GeneratePartsFromLayouts(nextLayoutClass, fieldNameForReplace, fieldIdForWs, ref nextLayoutNode); if (furtherGeneratedParts != null) generatedParts.AddRange(furtherGeneratedParts); } return generatedParts; } return null; }
/// <summary> /// return an array of all of the objects which should /// 1) be queried when looking for someone to deliver a message to /// 2) be potential recipients of a broadcast /// </summary> /// <returns></returns> public IxCoreColleague[] GetMessageTargets() { CheckDisposed(); //note: we just let navigation commands go straight to the clerk, which will then send us a message. /* * important note about messages and record clerk: see the top of the recordClerk.cs file. */ List<IxCoreColleague> targets = new List<IxCoreColleague>(); // HACK: This needs to be controlled better, since this method is being called, // while the object is being disposed, which causes the call to the Clerk property to crash // with a null reference exception on the mediator. if (m_mediator != null) { // Additional targets are typically child windows that should have a chance to intercept // messages before the Clerk sees them. targets.AddRange(GetMessageAdditionalTargets()); targets.Add(Clerk); targets.Add(this); } return targets.ToArray(); }
private void DisposeFtMonitor() { if (m_dictFtMonitor.Count > 0) { if (TopLevelControl is Form) (TopLevelControl as Form).FormClosing -= new FormClosingEventHandler(FormClosing); List<int> keys = new List<int>(); keys.AddRange(m_dictFtMonitor.Keys); foreach (int ws in keys) { m_dictFtMonitor[ws].Dispose(); m_dictFtMonitor[ws] = null; } m_dictFtMonitor.Clear(); } //if (m_ftMonitor != null) //{ // if (TopLevelControl is Form) // (TopLevelControl as Form).FormClosing -= new FormClosingEventHandler(FormClosing); // m_ftMonitor.Dispose(); // m_ftMonitor = null; //} }
/// ------------------------------------------------------------------------------------ /// <summary> /// Get the possible message targets, i.e. the view(s) we are showing /// </summary> /// <returns>Message targets</returns> /// ------------------------------------------------------------------------------------ public IxCoreColleague[] GetMessageTargets() { CheckDisposed(); // return list of view windows with focused window being the first one List<IxCoreColleague> targets = new List<IxCoreColleague>(); foreach (Control control in m_rgClientViews.Values) { IxCoreColleague view = control as IxCoreColleague; if (view != null && control != null) { if (control.Focused || control == ActiveView) targets.InsertRange(0, view.GetMessageTargets()); else if (control.Visible || control.ContainsFocus) targets.AddRange(view.GetMessageTargets()); } } targets.Add(this); return targets.ToArray(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Opens the specified project by starting a new FieldWorks.exe process. /// </summary> /// <param name="projectType">Type of the project.</param> /// <param name="projectName">The name of the project.</param> /// <param name="server">The name of the server (can be null).</param> /// <param name="appAbbrev">The abbreviation of the application name (TE, or FLEx).</param> /// <param name="otherArgs">Other command-line arguments to pass to the new FieldWorks /// process.</param> /// <returns>True if the project was opened, false otherwise</returns> /// ------------------------------------------------------------------------------------ internal static Process OpenProjectWithNewProcess(string projectType, string projectName, string server, string appAbbrev, params string[] otherArgs) { Logger.WriteEvent("Starting new FieldWorks.exe process for project " + projectName + ". BEP:" + projectType); List<string> args = new List<string>(); if (!string.IsNullOrEmpty(projectType)) { args.Add("-" + FwAppArgs.kDbType); args.Add(projectType); } if (!string.IsNullOrEmpty(server)) { args.Add("-" + FwAppArgs.kServer); args.Add(server); } args.Add("-" + FwAppArgs.kProject); args.Add(projectName); args.AddRange(otherArgs); return StartFwApp(appAbbrev, args.ToArray()); }
protected override List<IParaFragment> SearchForMatches() { List<IParaFragment> matches = new List<IParaFragment>(); if (m_patternModel.IsPatternEmpty) return matches; using (new WaitCursor(this)) { m_patternModel.Compile(); ParseUnparsedParagraphs(); foreach (IStText text in ConcDecorator.InterestingTexts) matches.AddRange(m_patternModel.Search(text)); } return matches; }
void SetRefs() { var fieldName = XmlUtils.GetManditoryAttributeValue(m_configurationNode, "field"); var refs = ReflectionHelper.GetProperty(m_obj, fieldName); var refsInts = refs as IEnumerable<int>; if (refsInts != null) { m_refs = (from hvo in refsInts select m_cache.ServiceLocator.GetInstance<ILexReferenceRepository>().GetObject(hvo)).ToList(); } else { m_refs = new List<ILexReference>(); IEnumerable refsObjs = refs as IEnumerable; if (refsObjs != null) m_refs.AddRange(refsObjs.Cast<ILexReference>()); else Debug.Fail("LexReferenceSlice could not interpret results from " + fieldName); } var flid = Cache.MetaDataCacheAccessor.GetFieldId2(m_obj.ClassID, fieldName, true); ContainingDataTree.MonitorProp(m_obj.Hvo, flid); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the message targets. /// </summary> /// <returns></returns> /// ------------------------------------------------------------------------------------ public IxCoreColleague[] GetMessageTargets() { CheckDisposed(); // return list of view windows with focused window being the first one List<IxCoreColleague> targets = new List<IxCoreColleague>(); foreach (RootSiteGroup group in m_groups) { foreach (IRootSiteSlave slave in group.Slaves) { if (slave is IxCoreColleague && (((Control)slave).Contains((Control)FocusedRootSite) || slave == FocusedRootSite)) { targets.AddRange(((IxCoreColleague)slave).GetMessageTargets()); break; } } } targets.Add(this); return targets.ToArray(); }
private static IEnumerable<Tuple<string, string>> GetUserDefinedDictLayouts( IEnumerable<string> builtInLayouts, IEnumerable<XmlNode> layouts) { var allUserLayoutTypes = ExtractLayoutsFromLayoutTypeList(layouts); var result = new List<Tuple<string, string>>(); // This part prevents getting Reversal Index layouts or Notebook layouts in our (Dictionary) menu. result.AddRange(from layout in allUserLayoutTypes where builtInLayouts.Any(builtIn => builtIn == BaseLayoutName(layout.Item2)) select layout); return result; }
/// <summary> /// Override method to handle launching of a chooser for selecting lexical entries or senses. /// </summary> protected override void HandleChooser() { Debug.Assert(m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes || m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes); if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidComponentLexemes) { using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg()) { ILexEntry le = null; if (m_obj.ClassID == LexEntry.kclsidLexEntry) { // filter this entry from the list. le = m_obj as ILexEntry; } else { // assume the owner is the entry (e.g. owner of LexEntryRef) int hvoEntry = m_cache.GetOwnerOfObjectOfClass(m_obj.Hvo, LexEntry.kclsidLexEntry); if (hvoEntry != 0) le = LexEntry.CreateFromDBObject(m_cache, hvoEntry); } dlg.SetDlgInfo(m_cache, m_mediator, le); String str = ShowHelp.RemoveSpaces(this.Slice.Label); dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense-" + str); if (dlg.ShowDialog(FindForm()) == DialogResult.OK) AddItem(dlg.SelectedID); } } else if (m_flid == (int)LexEntryRef.LexEntryRefTags.kflidPrimaryLexemes) { string displayWs = "analysis vernacular"; if (m_configurationNode != null) { XmlNode node = m_configurationNode.SelectSingleNode("deParams"); if (node != null) displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower(); } ILexEntryRef ler = m_obj as ILexEntryRef; Debug.Assert(ler != null); List<int> candidates = new List<int>(); candidates.AddRange(ler.ComponentLexemesRS.HvoArray); ObjectLabelCollection labels = new ObjectLabelCollection(m_cache, candidates, m_displayNameProperty, displayWs); using (ReallySimpleListChooser chooser = new ReallySimpleListChooser(null, labels, "PrimaryLexemes", m_cache, ler.PrimaryLexemesRS.HvoArray, false)) { chooser.SetObjectAndFlid(m_obj.Hvo, m_flid); // may set TextParamHvo chooser.Text = "Choose where to show subentry"; //chooser.ReplaceTreeView(Mediator, "WordformsBrowseView"); chooser.InitializeExtras(null,Mediator); chooser.AddLink("Add a Component...", ReallySimpleListChooser.LinkType.kDialogLink, new AddComponentChooserCommand(m_cache, false, null, m_mediator, m_obj, FindForm())); DialogResult res = chooser.ShowDialog(); if (DialogResult.Cancel == res) return; if (chooser.ChosenHvos != null) SetItems(chooser.ChosenHvos); } } }
private IEnumerable<Tuple<string, string>> GatherBuiltInAndUserLayouts() { var layoutList = new List<Tuple<string, string>>(); var configNode = m_mediator.PropertyTable.GetValue("currentContentControlParameters", null); layoutList.AddRange(GetBuiltInLayouts((XmlNode)configNode)); var builtInLayoutList = new List<string>(); builtInLayoutList.AddRange(from layout in layoutList select layout.Item2); var userLayouts = m_mainView.Vc.LayoutCache.LayoutInventory.GetLayoutTypes(); layoutList.AddRange(GetUserDefinedDictLayouts(builtInLayoutList, userLayouts)); return layoutList; }
private void SetNewOccurrencesOfWordforms(ProgressDialogWorkingOn progress) { Set<int> changes = new Set<int>(); foreach (ParaChangeInfo info in m_changedParas.Values) { changes.AddRange(info.Changes); } if (AllChanged) { m_newOccurrencesOldWf = new int[0]; // no remaining occurrences } else { // Only some changed, need to figure m_newOccurrences List<int> newOccurrencesOldWf = new List<int>(); foreach (int hvo in OldOccurrencesOfOldWordform) { //The offsets of our occurrences have almost certainly changed. //Update them so that the respelling dialog view will appear correct. var occur = RespellSda.OccurrenceFromHvo(hvo) as LocatedAnalysisOccurrence; if (occur != null) { occur.ResetSegmentOffsets(); } if (!changes.Contains(hvo)) { newOccurrencesOldWf.Add(hvo); } } m_newOccurrencesOldWf = newOccurrencesOldWf.ToArray(); } UpdateProgress(progress); List<int> newOccurrences = new List<int>(m_oldOccurrencesNewWf.Length + changes.Count); newOccurrences.AddRange(m_oldOccurrencesNewWf); newOccurrences.AddRange(changes); m_newOccurrencesNewWf = newOccurrences.ToArray(); RespellSda.ReplaceOccurrences(OldWordform, m_newOccurrencesOldWf); RespellSda.ReplaceOccurrences(NewWordform, m_newOccurrencesNewWf); SendCountVirtualPropChanged(NewWordform); SendCountVirtualPropChanged(OldWordform); }
/// <summary> /// The default AddHiddenItems appends hidden items to the end. /// </summary> /// <param name="items"></param> protected virtual void AddHiddenItems(List<ICmObject> items) { items.AddRange(GetHiddenItemList()); //add the parent (invisible) reference and any other invisibles back into the collection }
/// <summary> /// Return the list of layout types that the inventory knows about. /// </summary> public List<XmlNode> GetLayoutTypes() { Debug.Assert(m_mainDoc != null); XmlNode root = m_mainDoc["Main"]; Debug.Assert(root != null); var retval = new List<XmlNode>(); var nodes = root.SelectNodes("layoutType"); if (nodes != null) retval.AddRange(nodes.OfType<XmlNode>()); return retval; }
/// <summary> /// Return a list of the combined segments in the two lists, ordered by BeginOffset. /// </summary> /// <param name="cachedSegments"></param> /// <param name="paraSegments"></param> /// <returns></returns> private List<int> CombineSegs(List<int> first, List<int> second) { List<int> result = new List<int>(first.Count + second.Count); int index1 = 0; int index2 = 0; while (index1 < first.Count && index2 < second.Count) { if (first[index1] == second[index2]) { // same segment in both...transfer result.Add(first[index1]); index1++; index2++; continue; } int offset1 = m_cache.GetIntProperty(first[index1], (int) CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset); int offset2 = m_cache.GetIntProperty(second[index2], (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset); if (offset1 < offset2) { result.Add(first[index1]); index1++; } else { result.Add(second[index2]); index2++; } } if (index1 < first.Count) result.AddRange(first.GetRange(index1, first.Count - index1)); else if (index2 < second.Count) result.AddRange(second.GetRange(index2, second.Count - index2)); return result; }