예제 #1
0
		/// <summary>
		/// This method is the one to override if you need side effects when DeleteUnderlyingObject
		/// is called. If other objects should be deleted also, do NOT delete them directly; this
		/// tends to produce abysmal performance. Rather, add them to objectsToDeleteAlso, and the
		/// whole lot (including this) will be deleted in one relatively efficient operation.
		/// You should not modify objectsToDeleteAlso except to add HVOs to it.
		/// You must not use the FDO object after calling this, it has been put into the deleted state.
		/// </summary>
		/// <param name="objectsToDeleteAlso">hashtable of HVOs (value typically just true, it's really a set).</param>
		/// <param name="state"></param>
		public override void DeleteObjectSideEffects(Set<int> objectsToDeleteAlso, ProgressState state)
		{
			objectsToDeleteAlso.AddRange(FeatureConstraints);

			base.DeleteObjectSideEffects(objectsToDeleteAlso, state);
		}
예제 #2
0
		/// <summary>
		/// Get a set of hvos that are suitable for targets to a reference property.
		/// Subclasses should override this method to return a sensible list of IDs.
		/// </summary>
		/// <param name="flid">The reference property that can store the IDs.</param>
		/// <returns>A set of hvos.</returns>
		public override Set<int> ReferenceTargetCandidates(int flid)
		{
			Set<int> set = null;
			switch (flid)
			{
				case (int)PhPhoneme.PhPhonemeTags.kflidFeatures:
					set = new Set<int>();
					set.AddRange(m_cache.LangProject.PhFeatureSystemOA.FeaturesOC.HvoArray);
					break;
				default:
					set = base.ReferenceTargetCandidates(flid);
					break;
			}
			return set;
		}
예제 #3
0
		/// <summary>
		/// Get a set of hvos that are suitable for targets to a reference property.
		/// Subclasses should override this method to return a sensible list of IDs.
		/// </summary>
		/// <param name="flid">The reference property that can store the IDs.</param>
		/// <returns>A set of hvos.</returns>
		public override Set<int> ReferenceTargetCandidates(int flid)
		{
			Set<int> set = null;
			switch (flid)
			{
				case (int)PhNCSegments.PhNCSegmentsTags.kflidSegments:
					set = new Set<int>();
					foreach(IPhPhonemeSet ps in m_cache.LangProject.PhonologicalDataOA.PhonemeSetsOS)
						set.AddRange(ps.PhonemesOC.HvoArray);
					break;
				default:
					set = base.ReferenceTargetCandidates(flid);
					break;
			}
			return set;
		}
예제 #4
0
 /// <summary>
 /// Confirm the set of cache rules in the given execution context includes a set of expected ones; assertion failure if not.
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="rules"></param>
 void VerifyCacheRules(ExecutionContext ctx, IList rules)
 {
     Set set = new Set();
     foreach (CacheRule rule in ctx.CacheRules)
         set.AddRange(rule.AllLeafRules);
     foreach (CacheRule r in rules)
     {
         Assert.IsTrue(set.Contains(r), "Unable to find expected CacheRule (" + r.Description + ")");
         set.Remove(r);
     }
 }
예제 #5
0
		/// <summary>
		/// Get a set of hvos that are suitable for targets to a reference property.
		/// Subclasses should override this method to return a sensible list of IDs.
		/// </summary>
		/// <param name="flid">The reference property that can store the IDs.</param>
		/// <returns>A set of hvos.</returns>
		public override Set<int> ReferenceTargetCandidates(int flid)
		{
			Set<int> set = null;
			switch (flid)
			{
				case (int)PartOfSpeech.PartOfSpeechTags.kflidDefaultInflectionClass:
					set = new Set<int>();
					foreach (IMoInflClass ic in AllInflectionClasses)
						set.Add(ic.Hvo);
					break;
				case (int)PartOfSpeech.PartOfSpeechTags.kflidBearableFeatures:
					set = new Set<int>();
					ILangProject lp = m_cache.LangProject;
					if (lp != null)
					{
						IFsFeatStrucType exceps = lp.ExceptionFeatureType;
						set.AddRange(exceps.FeaturesRS.HvoArray);
					}
					break;
				case (int)PartOfSpeech.PartOfSpeechTags.kflidInflectableFeats:
					set = new Set<int>();
					set.AddRange(m_cache.LangProject.MsFeatureSystemOA.FeaturesOC.HvoArray);
					break;
				default:
					set = base.ReferenceTargetCandidates(flid);
					break;
			}
			return set;
		}
예제 #6
0
		/// <summary>
		/// Return the possible writing systems that we might want to preload for the given fragment.
		/// Note that currently this is for optimization and preloading; it is not (yet) guaranteed to
		/// return EVERY writing system that might be displayed by the given fragment.
		/// </summary>
		/// <param name="frag"></param>
		/// <param name="cache"></param>
		/// <returns></returns>
		public static Set<int> GetWritingSystems(XmlNode frag, FdoCache cache)
		{
			string wsSpec = null;
			XmlAttribute xa = frag.Attributes["ws"];
			if (xa == null)
				return new Set<int>(0);
			wsSpec = GetWsSpecWithoutPrefix(xa.Value);
			Set<int> result = new Set<int>();

			switch (wsSpec)
			{
				case "vernacular":
					result.Add(cache.DefaultVernWs);
					break;
				case "analysis":
					result.Add(cache.DefaultAnalWs);
					break;
				case "pronunciation":
				case "all pronunciation":
					result.Add(cache.LangProject.DefaultPronunciationWritingSystem);
					break;
				case "current":
					break;
				case "reversal":
					// Enhance JohnT: make this (currently for optimization preloading) routine work
					// better for reversal views
					//actualWS = GetReversalIndexEntryWritingSystem(cache, hvoObj, wsDefault);
					break;
				case "best analorvern":
				case "best vernoranal":
					return cache.LangProject.CurrentAnalysisAndVernWss;
				// Enhance JohnT: make this (currently for optimization preloading) routine work
				// better for the above two cases: possibly add all current analysis and vernacular writing systems
				case "analysis vernacular":
				case "av":
				case "vernacular analysis":
				case "va":
					result.Add(cache.DefaultVernWs);
					result.Add(cache.DefaultAnalWs);
					break;
				case "user":
					result.Add(cache.DefaultUserWs);
					break;
				case "best analysis":
				case "all analysis":
					result.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
					break;
				case "best vernacular":
				case "all vernacular":
					result.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
					break;
				default:
					// See if we can get anywhere by treating it as an ICU locale.
					// Note that it is important to do this in a way that won't create a new writing system for
					// an invalid locale name, for example, if 'all analysis' is mistakenly passed to this routine.
					// Note however that the behavior of recognizing an ICU locale name for an existing writing system
					// definitely IS needed, e.g., when the user configures a Browse view to show an explicit writing system.
					int wsT = cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(wsSpec);
					if (wsT != 0)
						result.Add(wsT);
					break;
			}
			return result;
		}
예제 #7
0
		private Set<int> FindCorrespondingItemsInCurrentList(IDictionary<int, object> itemAndListSourceTokenPairs, PartOwnershipTree pot)
		{
			// create a reverse index of classes to a list of items
			IDictionary<int, Set<int>> sourceFlidsToItems = MapSourceFlidsToItems(itemAndListSourceTokenPairs);

			Set<int> relativesInCurrentList = new Set<int>();
			foreach (KeyValuePair<int, Set<int>> sourceFlidToItems in sourceFlidsToItems)
			{
				Set<int> commonAncestors;
				relativesInCurrentList.AddRange(pot.FindCorrespondingItemsInCurrentList(sourceFlidToItems.Key,
																		 sourceFlidToItems.Value, m_flid,
																		 out commonAncestors));
			}
			return relativesInCurrentList;
		}
예제 #8
0
		/// <summary>
		/// kludge: filter to allow only complex entry references.
		/// </summary>
		/// <param name="hvoItem"></param>
		/// <returns></returns>
		protected override bool DisableItem(int hvoItem)
		{
			if (m_complexEntryRefs == null)
			{
				m_complexEntryRefs = new Set<int>();
				Dictionary<int, List<int>> dict = new Dictionary<int,List<int>>();
				LexEntry.LoadAllComplexFormEntryRefs(m_cache, dict);
				// go through each list and add the values to our set.
				foreach (List<int> refs in dict.Values)
					m_complexEntryRefs.AddRange(refs);
			}
			return !m_complexEntryRefs.Contains(hvoItem);
		}
        /// <summary>
        /// Given a Set of effects over abstract heap locations,
        /// computes a set of effects over the method parameters
        /// or in the global scope
        /// </summary>
        /// <param name="Effects"></param>
        /// <returns></returns>
        public Set<VariableEffect> ComputeEffects(AbstractEffects Effects)
        {
            Set<VariableEffect> variableEffects = new Set<VariableEffect>();

            // Traverse every write effect
            foreach (AField af in Effects)
              variableEffects.AddRange(EffectsInVariables(af));
            return variableEffects;
        }
예제 #10
0
			private int GetBestAlt(int hvo, int tag, int wsPreferred, int wsDefault, int[] wsList)
			{
				Set<int> wsSet = new Set<int>();
				if (wsPreferred != 0)
					wsSet.Add(wsPreferred);
				wsSet.AddRange(wsList);
				// We're not dealing with a real cache, so can't call something like this:
				//ws = LangProject.InterpretWsLabel(m_caches.MainCache,
				//    LangProject.GetMagicWsNameFromId(ws),
				//    m_caches.MainCache.DefaultAnalWs,
				//    hvo, spec.StringFlid, null);
				int wsActual = 0;
				foreach (int ws1 in wsSet.ToArray())
				{
					ITsString tssTest = m_caches.DataAccess.get_MultiStringAlt(hvo, tag, ws1);
					if (tssTest != null && tssTest.Length != 0)
					{
						wsActual = ws1;
						break;
					}
				}
				// Enhance JohnT: to be really picky here we should do like the real InterpretWsLabel
				// and fall back to default UI language, then English.
				// But we probably aren't even copying those alternatives to the sandbox cache.
				if (wsActual == 0)
					wsActual = wsDefault;
				return wsActual;
			}
예제 #11
0
		internal Set<int> ItemsToChange(bool fOnlyIfSelected)
		{
			CheckDisposed();

			Set<int> itemsToChange = new Set<int>();
			if (fOnlyIfSelected)
			{
				itemsToChange.AddRange(m_bv.CheckedItems);
			}
			else
			{
				itemsToChange.AddRange(m_bv.AllItems);
			}

			return itemsToChange;
		}
예제 #12
0
		public void CheckboxBehavior_SiblingClassesItemsShouldInheritSelectionThroughParent_UnselectAll()
		{
			// first create an entry with a pronunciation and some senses.
			ILexPronunciation pronunciation;
			ILexEntry parentEntry = CreateZZZparentEntryWithMultipleSensesAndPronunciation(out pronunciation);
			// some entries (like variants) don't have senses, so we need to factor those into our results.
			ICollection<ILexEntry> entriesWithoutSenses = FindEntriesWithoutSenses();

			m_bulkEditBar.SwitchTab("BulkCopy");
			m_bv.ShowColumn("Allomorph");
			m_bulkEditBar.SetTargetField("Glosses");
			RecordClerk clerk = (m_bv.Parent as RecordBrowseViewForTests).Clerk;

			// Unselect All
			m_bv.OnUncheckAll();
			// now switch to allomorphs
			using (FilterBehavior.Create(this))
				m_bulkEditBar.SetTargetField("Allomorphs");
			// validate that everything (except variant allomorph?) is still not selected.
			Set<int> checkedItems = new Set<int>(m_bv.CheckedItems);
			Set<int> selectedEntries = new Set<int>();
			selectedEntries.AddRange(FdoVectorUtils.ConvertCmObjectsToHvos<ILexEntry>(entriesWithoutSenses));
			Assert.AreEqual(selectedEntries.Count, checkedItems.Count);
		}
예제 #13
0
		public void CheckboxBehavior_ParentClassesItemsShouldInheritSelection_Selected()
		{
			// find a lex entry that has multiple senses (i.e. descendents).
			ILexEntry entryWithMultipleDescendents = CreateZZZparentEntryWithMultipleSensesAndPronunciation_AndUpdateList();
			// some entries (like variants) don't have senses, so we need to factor those into our results.
			ICollection<ILexEntry> entriesWithoutSenses = FindEntriesWithoutSenses();

			m_bulkEditBar.SwitchTab("BulkCopy");
			m_bulkEditBar.SetTargetField("Glosses");
			Assert.AreEqual(LexSense.kclsidLexSense, m_bv.ListItemsClass);
			RecordClerk clerk = (m_bv.Parent as RecordBrowseViewForTests).Clerk;

			m_bv.OnUncheckAll();
			// select the sense.
			m_bv.SetCheckedItems(new int[] { entryWithMultipleDescendents.AllSenses[0].Hvo });

			using (FilterBehavior.Create(this))
				m_bulkEditBar.SetTargetField("Lexeme Form");

			Set<int> selectedEntries = new Set<int>(new int[] {entryWithMultipleDescendents.Hvo});
			selectedEntries.AddRange(FdoVectorUtils.ConvertCmObjectsToHvos<ILexEntry>(entriesWithoutSenses));
			Set<int> checkedItems = new Set<int>(m_bv.CheckedItems);
			Assert.AreEqual(selectedEntries.Count, checkedItems.Count, "Checked items mismatched.");
			Assert.IsTrue(checkedItems.Equals(selectedEntries), "Checked items mismatched.");
		}
예제 #14
0
		/// <summary>
		/// This will remove the given hvosToRemove (if they exist in our sort items) and any items that refer to invalid objects.
		/// Reload the view if there were any changes, and adjust the CurrentIndex
		/// </summary>
		protected internal void RemoveUnwantedSortItems(List<int> hvosToRemove)
		{
			if (m_sortedObjects == null)
				return;	// nothing to remove.
			bool fUpdatingListOrig = m_fUpdatingList;
			m_fUpdatingList = true;
			try
			{
				int currentIndex = CurrentIndex;
				int cOrigSortObjects = m_sortedObjects.Count;
				// Note: We start with a Set, since it can't have duplicates.
				// First remove the given hvos from our sort items.
				Set<int> unwantedIndices = new Set<int>(IndicesOfSortItems(hvosToRemove));
				// then remove any remaining items that point to invalid objects.
				unwantedIndices.AddRange(IndicesOfInvalidSortItems());
				// Put the now unique indices into a list,
				// so we can make sure they are processed in reverse order.
				List<int> sortedIndices = new List<int>(unwantedIndices.ToArray());
				sortedIndices.Sort();
				sortedIndices.Reverse();
				foreach (int indexOfSortItem in sortedIndices)
				{
					if (indexOfSortItem >= 0)
					{
						m_sortedObjects.RemoveAt(indexOfSortItem);
						if (indexOfSortItem < currentIndex || SortedObjects.Count <= currentIndex)
							currentIndex--;
					}
				}
				if (m_sortedObjects.Count == 0)
					currentIndex = -1;
				else if (currentIndex >= m_sortedObjects.Count)
					currentIndex = m_sortedObjects.Count - 1;
				CurrentIndex = currentIndex;
				if (m_sortedObjects.Count != cOrigSortObjects)
				{
					SendPropChangedOnListChange(CurrentIndex,
						SortedObjects, ListChangedEventArgs.ListChangedActions.Normal);
				}
			}
			finally
			{
				m_fUpdatingList = fUpdatingListOrig;
			}
		}
예제 #15
0
		/// <summary>
		/// This method is the one to override if you need side effects when DeleteUnderlyingObject
		/// is called. If other objects should be deleted also, do NOT delete them directly; this
		/// tends to produce abysmal performance. Rather, add them to objectsToDeleteAlso, and the
		/// whole lot (including this) will be deleted in one relatively efficient operation.
		/// You should not modify objectsToDeleteAlso except to add HVOs to it.
		/// You must not use the FDO object after calling this, it has been put into the deleted state.
		/// </summary>
		/// <param name="objectsToDeleteAlso">hashtable of HVOs (value typically just true, it's really a set).</param>
		/// <param name="state"></param>
		public override void DeleteObjectSideEffects(Set<int> objectsToDeleteAlso, ProgressState state)
		{
			objectsToDeleteAlso.AddRange(MembersRS.HvoArray);

			base.DeleteObjectSideEffects(objectsToDeleteAlso, state);
		}
예제 #16
0
 private void joinCalledMethod(Dictionary<Label, Set<Method>> cm1, Dictionary<Label, Set<Method>> cm2)
 {
   foreach (Label lb in cm2.Keys)
   {
     Set<Method> mths2 = cm2[lb];
     Set<Method> mths1 = new Set<Method>();
     if (cm1.ContainsKey(lb))
     {
       mths1.AddRange(cm1[lb]);
     }
     mths1.AddRange(mths2);
     cm1[lb] = mths1;
   }
 }
예제 #17
0
		/// <summary>
		/// Get a Set of zero or more actual writing system IDs for the given ws identifier.
		/// </summary>
		/// <param name="sWs">One of our magic strings that signifies one or more writing systems</param>
		/// <param name="cache"></param>
		/// <param name="currentWS"></param>
		/// <param name="hvo">object to use in determining 'best' names</param>
		/// <param name="flid">flid to use in determining 'best' names</param>
		/// <returns></returns>
		public static Set<int> GetAllWritingSystems(string sWs, FdoCache cache, IWritingSystem currentWS, int hvo, int flid)
		{
			Set<int> allWsIds = new Set<int>();
			if (sWs != null)
			{
				switch (sWs)
				{
					case "all analysis":
						allWsIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						break;
					case "all vernacular":
						allWsIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						break;
					case "analysis vernacular":
						allWsIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						allWsIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						break;
					case "vernacular analysis":
						allWsIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						allWsIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						break;
					case "all pronunciation":
						cache.LangProject.InitializePronunciationWritingSystems();
						allWsIds.AddRange(cache.LangProject.CurPronunWssRS.HvoArray);
						//if (allWsIds.Count == 0)
						//	allWsIds.Add(cache.LangProject.DefaultPronunciationWritingSystem);
						break;
					default:
						sWs = GetWsSpecWithoutPrefix(sWs);
						string[] rgsWs = sWs.Split(new char[] { ',' });
						for (int i = 0; i < rgsWs.Length; ++i)
						{
							int ws = InterpretWsLabel(cache, rgsWs[i], 0, hvo, flid, currentWS);
							if (ws != 0)
								allWsIds.Add(ws);
						}
						break;
				}
			}

			return allWsIds;
		}
예제 #18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Lets the user delete any FW databases that are not currently open
		/// </summary>
		/// <param name="dialogOwner">The owner of the dialog</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// ------------------------------------------------------------------------------------
		internal static void DeleteProject(Form dialogOwner, IHelpTopicProvider helpTopicProvider)
		{
			Set<string> projectsInUse = new Set<string>(ProjectsInUseLocally());
			IClientServerServices css = ClientServerServices.Current;
			ILocalClientServerServices local = null;
			if (css != null)
			{
				local = css.Local;
				if (local != null && local.ShareMyProjects)
					projectsInUse.AddRange(local.ListOpenProjects());
			}
			using (FwDeleteProjectDlg dlg = new FwDeleteProjectDlg(projectsInUse))
			{
				dlg.SetDialogProperties(helpTopicProvider);
				dlg.ShowDialog(dialogOwner);
			}
			if (local != null)
				local.RefreshProjectNames();
		}
예제 #19
0
		/// <summary>
		/// Try to get an actual writing system id from some ws string specification.
		/// If it does not recognize the ws spec string, it returns 0.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="wsSpec"></param>
		/// <param name="wsDefault"></param>
		/// <param name="hvoObj"></param>
		/// <param name="flid"></param>
		/// <param name="currentWS"></param>
		/// <returns>A Set of writing system ids, or an empty Set, if it can't recognize the wsSpec parameter.</returns>
		internal static Set<int> GetWritingSystemIdsFromLabel(FdoCache cache, string wsSpec, int wsDefault, int hvoObj, int flid, IWritingSystem currentWS)
		{
			Set<int> writingSystemIds = new Set<int>();

			switch (wsSpec.Trim().ToLowerInvariant())
			{
				case "all analysis":
					{
						writingSystemIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						break;
					}
				case "all vernacular":
					{
						writingSystemIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						break;
					}
				case "analysis vernacular":
					{
						writingSystemIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						writingSystemIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						break;
					}
				case "vernacular analysis":
					{
						writingSystemIds.AddRange(cache.LangProject.CurVernWssRS.HvoArray);
						writingSystemIds.AddRange(cache.LangProject.CurAnalysisWssRS.HvoArray);
						break;
					}
				default:
					writingSystemIds.Add(InterpretWsLabel(cache, wsSpec, wsDefault, hvoObj, flid, currentWS));
					break;
			}

			return writingSystemIds;
		}
예제 #20
0
		/// <summary>
		/// See documentation for IMultiListSortItemProvider
		/// </summary>
		/// <param name="itemAndListSourceTokenPairs"></param>
		/// <returns></returns>
		public void ConvertItemsToRelativesThatApplyToCurrentList(ref IDictionary<int, object> oldItems)
		{
			Set<int> oldItemsToRemove = new Set<int>();
			Set<int> itemsToAdd = new Set<int>();
			// Create a PartOwnershipTree in a mode that can return more than one descendent relatives.
			using (PartOwnershipTree pot = PartOwnershipTree.Create(Cache, this, false))
			{
				foreach (KeyValuePair<int, object> oldItem in oldItems)
				{
					IDictionary<int, object> dictOneOldItem = new Dictionary<int, object>();
					dictOneOldItem.Add(oldItem);
					Set<int> relatives = FindCorrespondingItemsInCurrentList(dictOneOldItem, pot);

					// remove the old item if we found relatives we could convert over to.
					if (relatives.Count > 0)
					{
						itemsToAdd.AddRange(relatives);
						oldItemsToRemove.Add(oldItem.Key);
					}
				}
			}

			foreach (int itemToRemove in oldItemsToRemove)
				oldItems.Remove(itemToRemove);

			// complete any conversions by adding its relatives.
			object sourceTag = ListSourceToken;
			foreach (int relativeToAdd in itemsToAdd)
			{
				if (!oldItems.ContainsKey(relativeToAdd))
					oldItems.Add(relativeToAdd, sourceTag);
			}
		}