]> O.S.I.I.S - jp/crow.git/commitdiff
styling is no longer static in iface to allow different styling context between ifaces
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 13 Feb 2018 06:57:29 +0000 (07:57 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 13 Feb 2018 07:19:53 +0000 (08:19 +0100)
src/GraphicObjects/GraphicObject.cs
src/Instantiator.cs
src/Interface.cs
src/StyleReader.cs

index 6ec60cf3e75e6969293342e81c13e4d8fc7120ab..ad02a54430dc0fcf7a2b06352e33eb65d2ad9bde 100644 (file)
@@ -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);
                        }
index f5355c177755376a3e5af940a807db626e85e7ad..c75c8b9f6064ebce98c08988068758aef18e1934 100644 (file)
@@ -146,11 +146,14 @@ namespace Crow.IML
                /// store indices of template delegate to be handled by root parentChanged event
                /// </summary>
                List<int> templateCachedDelegateIndices = new List<int>();
+               /// <summary>
+               /// Store template bindings in the instantiator
+               /// </summary>
                Delegate templateBinding;
 
                #region IML parsing
                /// <summary>
-               /// 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
                /// </summary>
                void parseIML (XmlReader reader) {
                        IMLContext ctx = new IMLContext (findRootType (reader));
index d4cc63c40b3d3efcc2520b3fbb63bf7afb6d304b..03ea9308af626b5034b9d322f3dd7cc892314338 100644 (file)
@@ -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);
                /// <summary>Store one loader per StyleKey</summary>
-               public static Dictionary<String, LoaderInvoker> DefaultValuesLoader = new Dictionary<string, LoaderInvoker>();
+               public Dictionary<String, LoaderInvoker> DefaultValuesLoader = new Dictionary<string, LoaderInvoker>();
                /// <summary>Store dictionnary of member/value per StyleKey</summary>
-               public static Dictionary<string, Style> Styling;
+               public Dictionary<string, Style> Styling;
                /// <summary> parse all styling data's during application startup and build global Styling Dictionary </summary>
-               static void loadStyling() {
+               protected virtual void loadStyling() {
                        Styling = new Dictionary<string, Style> ();
 
                        //fetch styling info in this order, if member styling is alreadey referenced in previous
@@ -217,14 +216,16 @@ namespace Crow
                        loadStylingFromAssembly (Assembly.GetExecutingAssembly ());
                }
                /// <summary> Search for .style resources in assembly </summary>
-               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(){
index 8a79cd4aa05094c4bc3a0992f2a7c475db112506..2603709195337afb23fe0dffdfe71530676f0684 100644 (file)
@@ -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 = "";
                                                }