From: Jean-Philippe Bruyère Date: Tue, 13 Feb 2018 06:57:29 +0000 (+0100) Subject: styling is no longer static in iface to allow different styling context between ifaces X-Git-Tag: 0.7.0~20 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=fab5313c53775a9e6fd74cfbfdc4501a8807d1cb;p=jp%2Fcrow.git styling is no longer static in iface to allow different styling context between ifaces --- diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 6ec60cf3..ad02a544 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -837,17 +837,17 @@ namespace Crow Type thisType = this.GetType (); if (!string.IsNullOrEmpty (Style)) { - if (Interface.DefaultValuesLoader.ContainsKey (Style)) { - Interface.DefaultValuesLoader [Style] (this); + if (CurrentInterface.DefaultValuesLoader.ContainsKey (Style)) { + CurrentInterface.DefaultValuesLoader [Style] (this); return; } } else { - if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { - Interface.DefaultValuesLoader [thisType.FullName] (this); + if (CurrentInterface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { + CurrentInterface.DefaultValuesLoader [thisType.FullName] (this); return; - } else if (!Interface.Styling.ContainsKey (thisType.FullName)) { - if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { - Interface.DefaultValuesLoader [thisType.Name] (this); + } else if (!CurrentInterface.Styling.ContainsKey (thisType.FullName)) { + if (CurrentInterface.DefaultValuesLoader.ContainsKey (thisType.Name)) { + CurrentInterface.DefaultValuesLoader [thisType.Name] (this); return; } } @@ -862,17 +862,17 @@ namespace Crow // those files being placed in a Styles folder string styleKey = Style; if (!string.IsNullOrEmpty (Style)) { - if (Interface.Styling.ContainsKey (Style)) { - styling.Add (Interface.Styling [Style]); + if (CurrentInterface.Styling.ContainsKey (Style)) { + styling.Add (CurrentInterface.Styling [Style]); } } - if (Interface.Styling.ContainsKey (thisType.FullName)) { - styling.Add (Interface.Styling [thisType.FullName]); + if (CurrentInterface.Styling.ContainsKey (thisType.FullName)) { + styling.Add (CurrentInterface.Styling [thisType.FullName]); if (string.IsNullOrEmpty (styleKey)) styleKey = thisType.FullName; } - if (Interface.Styling.ContainsKey (thisType.Name)) { - styling.Add (Interface.Styling [thisType.Name]); + if (CurrentInterface.Styling.ContainsKey (thisType.Name)) { + styling.Add (CurrentInterface.Styling [thisType.Name]); if (string.IsNullOrEmpty (styleKey)) styleKey = thisType.Name; } @@ -942,8 +942,8 @@ namespace Crow #endregion try { - Interface.DefaultValuesLoader[styleKey] = (Interface.LoaderInvoker)dm.CreateDelegate(typeof(Interface.LoaderInvoker)); - Interface.DefaultValuesLoader[styleKey] (this); + CurrentInterface.DefaultValuesLoader[styleKey] = (Interface.LoaderInvoker)dm.CreateDelegate(typeof(Interface.LoaderInvoker)); + CurrentInterface.DefaultValuesLoader[styleKey] (this); } catch (Exception ex) { throw new Exception ("Error applying style <" + styleKey + ">:", ex); } diff --git a/src/Instantiator.cs b/src/Instantiator.cs index f5355c17..c75c8b9f 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -146,11 +146,14 @@ namespace Crow.IML /// store indices of template delegate to be handled by root parentChanged event /// List templateCachedDelegateIndices = new List(); + /// + /// Store template bindings in the instantiator + /// Delegate templateBinding; #region IML parsing /// - /// Parses IML and build a dynamic method that will be used to instanciate one or multiple occurence of the IML file or fragment + /// Parses IML and build a dynamic method that will be used to instantiate one or multiple occurences of the IML file or fragment /// void parseIML (XmlReader reader) { IMLContext ctx = new IMLContext (findRootType (reader)); diff --git a/src/Interface.cs b/src/Interface.cs index d4cc63c4..03ea9308 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -76,7 +76,6 @@ namespace Crow Directory.CreateDirectory (CrowConfigRoot); loadCursors (); - loadStyling (); findAvailableTemplates (); FontRenderingOptions = new FontOptions (); @@ -88,7 +87,7 @@ namespace Crow public Interface(){ CurrentInterface = this; CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - + loadStyling (); initTooltip (); } #endregion @@ -204,11 +203,11 @@ namespace Crow /// The compilation is done on the first object instancing, and is also done for custom widgets public delegate void LoaderInvoker(object instance); /// Store one loader per StyleKey - public static Dictionary DefaultValuesLoader = new Dictionary(); + public Dictionary DefaultValuesLoader = new Dictionary(); /// Store dictionnary of member/value per StyleKey - public static Dictionary Styling; + public Dictionary Styling; /// parse all styling data's during application startup and build global Styling Dictionary - static void loadStyling() { + protected virtual void loadStyling() { Styling = new Dictionary (); //fetch styling info in this order, if member styling is alreadey referenced in previous @@ -217,14 +216,16 @@ namespace Crow loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); } /// Search for .style resources in assembly - static void loadStylingFromAssembly (Assembly assembly) { + void loadStylingFromAssembly (Assembly assembly) { if (assembly == null) return; foreach (string s in assembly .GetManifestResourceNames () .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { - new StyleReader (assembly, s) - .Dispose (); + using (Stream stream = assembly.GetManifestResourceStream (s)) { + new StyleReader (this, stream, s); + } + } } static void loadCursors(){ diff --git a/src/StyleReader.cs b/src/StyleReader.cs index 8a79cd4a..26037091 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -43,8 +43,8 @@ namespace Crow int column = 1; int line = 1; - public StyleReader (Assembly assembly, string resId) - : base(assembly.GetManifestResourceStream (resId)) + public StyleReader (Interface iface, Stream stream, string resId) + : base(stream) { resourceId = resId; string styleKey = resId.Substring (0, resId.Length - 6); @@ -137,11 +137,11 @@ namespace Crow string expression = token.Trim (); foreach (string tc in targetsClasses) { - if (!Interface.Styling.ContainsKey (tc)) - Interface.Styling [tc] = new Style (); - else if (Interface.Styling [tc].ContainsKey (currentProperty)) + if (!iface.Styling.ContainsKey (tc)) + iface.Styling [tc] = new Style (); + else if (iface.Styling [tc].ContainsKey (currentProperty)) continue; - Interface.Styling [tc] [currentProperty] = expression; + iface.Styling [tc] [currentProperty] = expression; } token = ""; }