From: <mcu...@us...> - 2008-08-13 00:55:10
|
Revision: 1317 http://orm.svn.sourceforge.net/orm/?rev=1317&view=rev Author: mcurland Date: 2008-08-13 00:55:19 +0000 (Wed, 13 Aug 2008) Log Message: ----------- Allow multiple Snippets elements per Language element in verbalization customization files, automatically add base identifier options for explicitly targeted snippets (fixes assert in available snippets picker), and add a file watcher to reload modified snippets on next verbalization request. refs #315 Modified Paths: -------------- trunk/ORMModel/ObjectModel/Design/Editors/AvailableVerbalizationSnippetsPicker.cs trunk/ORMModel/ObjectModel/VerbalizationSnippetSetsManager.cs trunk/ORMModel/ObjectModel/VerbalizationUntypedSnippets.xsd trunk/ORMModel/Shell/ORMDocDataServices.cs Modified: trunk/ORMModel/ObjectModel/Design/Editors/AvailableVerbalizationSnippetsPicker.cs =================================================================== --- trunk/ORMModel/ObjectModel/Design/Editors/AvailableVerbalizationSnippetsPicker.cs 2008-08-13 00:47:52 UTC (rev 1316) +++ trunk/ORMModel/ObjectModel/Design/Editors/AvailableVerbalizationSnippetsPicker.cs 2008-08-13 00:55:19 UTC (rev 1317) @@ -513,7 +513,7 @@ TargetedTypeData[] typeData = new TargetedTypeData[targetedTypesCount]; for (int i = 0; i < targetedTypesCount; ++i) { - typeData[i] = new TargetedTypeData(GetVerbalizationTargetDisplayName(myTargetedTypes[firstTargetedType + 1].Target), firstTargetedType + i + 1); + typeData[i] = new TargetedTypeData(GetVerbalizationTargetDisplayName(myTargetedTypes[firstTargetedType + i + 1].Target), firstTargetedType + i + 1); } return new TypeBranchWithExplicitTargets(this, firstTargetedType, typeData); } Modified: trunk/ORMModel/ObjectModel/VerbalizationSnippetSetsManager.cs =================================================================== --- trunk/ORMModel/ObjectModel/VerbalizationSnippetSetsManager.cs 2008-08-13 00:47:52 UTC (rev 1316) +++ trunk/ORMModel/ObjectModel/VerbalizationSnippetSetsManager.cs 2008-08-13 00:55:19 UTC (rev 1317) @@ -664,7 +664,7 @@ myEnumTypeName = enumTypeName; myLangId = languageId; myId = id; - myDescription = null; + myDescription = description; myTarget = target ?? DefaultTarget; } #endregion // Constructors @@ -1533,6 +1533,15 @@ { // Fallback case, base is not defined baseSnippets = (IVerbalizationSets<TEnum>)processedSets[defaultSnippetsIdentifier]; + if (currentBaseId.Target != VerbalizationSnippetsIdentifier.DefaultTarget && + currentBaseId.IsTargetedDefaultIdentifier(currentBaseId.Target)) + { + if (string.IsNullOrEmpty(currentBaseId.Description)) + { + currentBaseId = new VerbalizationSnippetsIdentifier(currentBaseId.EnumTypeName, currentBaseId.Target, currentBaseId.LanguageId, currentBaseId.Id, defaultSnippetsIdentifier.Description); + } + processedSets.Add(currentBaseId, baseSnippets); + } } } Debug.Assert(baseSnippets != null); // Should always have some base at this point Modified: trunk/ORMModel/ObjectModel/VerbalizationUntypedSnippets.xsd =================================================================== --- trunk/ORMModel/ObjectModel/VerbalizationUntypedSnippets.xsd 2008-08-13 00:47:52 UTC (rev 1316) +++ trunk/ORMModel/ObjectModel/VerbalizationUntypedSnippets.xsd 2008-08-13 00:55:19 UTC (rev 1317) @@ -39,7 +39,7 @@ </xs:simpleType> <xs:complexType name="LanguageType"> <xs:sequence> - <xs:element name="Snippets" minOccurs="1" maxOccurs="1"> + <xs:element name="Snippets" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Snippet" minOccurs="0" maxOccurs="unbounded"> @@ -105,7 +105,13 @@ <xs:element name="Languages"> <xs:complexType> <xs:sequence> - <xs:element name="Language" type="LanguageType" minOccurs="1" maxOccurs="unbounded"/> + <xs:element name="Language" type="LanguageType" minOccurs="1" maxOccurs="unbounded"> + <xs:unique name="SnippetsNameAndTargetUnique"> + <xs:selector xpath="ve:Snippets"/> + <xs:field xpath="@name"/> + <xs:field xpath="@target"/> + </xs:unique> + </xs:element> </xs:sequence> </xs:complexType> <xs:key name="LanguageCodeKey"> Modified: trunk/ORMModel/Shell/ORMDocDataServices.cs =================================================================== --- trunk/ORMModel/Shell/ORMDocDataServices.cs 2008-08-13 00:47:52 UTC (rev 1316) +++ trunk/ORMModel/Shell/ORMDocDataServices.cs 2008-08-13 00:55:19 UTC (rev 1317) @@ -39,6 +39,7 @@ using Neumont.Tools.ORM.ObjectModel; using Neumont.Tools.ORM.ShapeModel; using MSOLE = Microsoft.VisualStudio.OLE.Interop; +using System.IO; namespace Neumont.Tools.ORM.Shell { @@ -1122,6 +1123,9 @@ private IORMToolTaskProvider myTaskProvider; private string myLastVerbalizationSnippetsOptions; private IDictionary<string, IDictionary<Type, IVerbalizationSets>> myTargetedVerbalizationSnippets; + private uint myInstanceVerbalizationChangeCookie; + private static FileSystemWatcher myVerbalizationChangeWatcher; + private static uint myVerbalizationChangeCookie; private IDictionary<string, VerbalizationTargetData> myVerbalizationTargets; private IDictionary<Type, LayoutEngineData> myLayoutEngines; private int myCustomBlockCanAddTransactionCount; @@ -1230,7 +1234,7 @@ verbalizationOptions = ""; } bool loadTarget = false; - if (targetedSnippets == null || (currentSnippetsOptions == null || currentSnippetsOptions != verbalizationOptions)) + if (targetedSnippets == null || myInstanceVerbalizationChangeCookie != myVerbalizationChangeCookie || (currentSnippetsOptions == null || currentSnippetsOptions != verbalizationOptions)) { // UNDONE: See comments in LoadSnippetsDictionary about loading // a dictionary with all type/target combinations then wrapping it @@ -1242,6 +1246,7 @@ { targetedSnippets.Clear(); } + myInstanceVerbalizationChangeCookie = myVerbalizationChangeCookie; } else if (targetedSnippets != null) { @@ -1257,11 +1262,50 @@ if (targetedSnippets == null) { myTargetedVerbalizationSnippets = targetedSnippets = new Dictionary<string, IDictionary<Type, IVerbalizationSets>>(); + if (myVerbalizationChangeWatcher == null) + { + FileSystemWatcher changeWatcher = new FileSystemWatcher(ORMDesignerPackage.VerbalizationDirectory, "*.xml"); + changeWatcher.IncludeSubdirectories = true; + changeWatcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime; + FileSystemEventHandler handler = new FileSystemEventHandler(VerbalizationCustomizationsChanged); + changeWatcher.Created += handler; + changeWatcher.Changed += handler; + changeWatcher.Deleted += handler; + changeWatcher.Renamed += new RenamedEventHandler(VerbalizationCustomizationsRenamed); + changeWatcher.EnableRaisingEvents = true; + FileSystemWatcher useWatcher = System.Threading.Interlocked.CompareExchange<FileSystemWatcher>(ref myVerbalizationChangeWatcher, changeWatcher, null); + if (useWatcher != null) + { + changeWatcher.Dispose(); + } + } } targetedSnippets[target] = retVal; } return retVal; } + /// <summary> + /// Track changes to the verbalization dictionary so that we can + /// reload snippets files as they change. + /// </summary> + private static void VerbalizationCustomizationsChanged(object sender, FileSystemEventArgs e) + { + unchecked + { + ++myVerbalizationChangeCookie; + }; + } + /// <summary> + /// Track changes to the verbalization dictionary so that we can + /// reload snippets files as they change. + /// </summary> + private static void VerbalizationCustomizationsRenamed(object sender, RenamedEventArgs e) + { + unchecked + { + ++myVerbalizationChangeCookie; + }; + } IDictionary<Type, IVerbalizationSets> IORMToolServices.GetVerbalizationSnippetsDictionary(string target) { return GetVerbalizationSnippetsDictionary(target); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |