From: jpbruyere Date: Fri, 12 Aug 2016 15:17:05 +0000 (+0200) Subject: default template searched in embedded resources with .template extension X-Git-Tag: v0.4~7^2~9 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=86acbb4902a25100a183da7ce9e7a5662de8b4cb;p=jp%2Fcrow.git default template searched in embedded resources with .template extension --- diff --git a/Crow.csproj b/Crow.csproj index 45f60ec9..0de00b5c 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -177,16 +177,10 @@ - - - - - - @@ -194,9 +188,7 @@ - - @@ -211,23 +203,65 @@ - - - - - - - - - + + Crow.Button.template + + + Crow.CheckBox.template + + + Crow.ComboBox.template + + + Crow.Expandable.template + + + Crow.DirectoryView.template + + + Crow.FileDialog.template + + + Crow.GroupBox.template + + + Crow.ListBox.template + + + Crow.MessageBox.template + + + Crow.Popper.template + + + Crow.RadioButton.template + + + Crow.ScrollBar.template + + + Crow.Slider.template + + + Crow.Spinner.template + + + Crow.TabItem.template + + + Crow.TreeView.template + + + Crow.Window.template + diff --git a/Templates/Button.crow b/Templates/Button.crow deleted file mode 100755 index 959ad8cc..00000000 --- a/Templates/Button.crow +++ /dev/null @@ -1,11 +0,0 @@ - - - - \ No newline at end of file diff --git a/Templates/Button.template b/Templates/Button.template new file mode 100755 index 00000000..959ad8cc --- /dev/null +++ b/Templates/Button.template @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/Templates/CheckBox.goml b/Templates/CheckBox.goml deleted file mode 100755 index a3c0f23d..00000000 --- a/Templates/CheckBox.goml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/Templates/CheckBox.template b/Templates/CheckBox.template new file mode 100755 index 00000000..a3c0f23d --- /dev/null +++ b/Templates/CheckBox.template @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Templates/ComboBox.goml b/Templates/ComboBox.goml deleted file mode 100755 index 9688721a..00000000 --- a/Templates/ComboBox.goml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - diff --git a/Templates/ComboBox.template b/Templates/ComboBox.template new file mode 100755 index 00000000..9688721a --- /dev/null +++ b/Templates/ComboBox.template @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/Templates/DirectoryView.crow b/Templates/DirectoryView.crow deleted file mode 100755 index e861ef8e..00000000 --- a/Templates/DirectoryView.crow +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Templates/DirectoryView.template b/Templates/DirectoryView.template new file mode 100755 index 00000000..e861ef8e --- /dev/null +++ b/Templates/DirectoryView.template @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Templates/Expandable.goml b/Templates/Expandable.goml deleted file mode 100755 index 3d75afaf..00000000 --- a/Templates/Expandable.goml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/Templates/Expandable.template b/Templates/Expandable.template new file mode 100755 index 00000000..3d75afaf --- /dev/null +++ b/Templates/Expandable.template @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/Templates/FileDialog.goml b/Templates/FileDialog.goml deleted file mode 100644 index c8a10c8d..00000000 --- a/Templates/FileDialog.goml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Templates/ScrollBar.template b/Templates/ScrollBar.template new file mode 100755 index 00000000..4164c30d --- /dev/null +++ b/Templates/ScrollBar.template @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/Templates/Slider.goml b/Templates/Slider.goml deleted file mode 100755 index 9c7bb705..00000000 --- a/Templates/Slider.goml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Templates/Slider.template b/Templates/Slider.template new file mode 100755 index 00000000..9c7bb705 --- /dev/null +++ b/Templates/Slider.template @@ -0,0 +1 @@ + diff --git a/Templates/Spinner.goml b/Templates/Spinner.goml deleted file mode 100755 index b07e17b3..00000000 --- a/Templates/Spinner.goml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - diff --git a/Templates/Spinner.template b/Templates/Spinner.template new file mode 100755 index 00000000..b07e17b3 --- /dev/null +++ b/Templates/Spinner.template @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/Templates/TabItem.crow b/Templates/TabItem.crow deleted file mode 100644 index c5852142..00000000 --- a/Templates/TabItem.crow +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - diff --git a/Templates/TabItem.template b/Templates/TabItem.template new file mode 100644 index 00000000..ce2a270e --- /dev/null +++ b/Templates/TabItem.template @@ -0,0 +1,22 @@ + + + + + + + diff --git a/Templates/TreeView.crow b/Templates/TreeView.crow deleted file mode 100644 index 1dc291fc..00000000 --- a/Templates/TreeView.crow +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - diff --git a/Templates/TreeView.template b/Templates/TreeView.template new file mode 100644 index 00000000..bd50e54a --- /dev/null +++ b/Templates/TreeView.template @@ -0,0 +1,16 @@ + + + + + + + diff --git a/Templates/Window.goml b/Templates/Window.goml deleted file mode 100755 index 3a252cab..00000000 --- a/Templates/Window.goml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/Templates/Window.template b/Templates/Window.template new file mode 100755 index 00000000..3a252cab --- /dev/null +++ b/Templates/Window.template @@ -0,0 +1,22 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/OpenTKGameWindow.cs b/Tests/OpenTKGameWindow.cs index 9b4d0a06..f67d755d 100644 --- a/Tests/OpenTKGameWindow.cs +++ b/Tests/OpenTKGameWindow.cs @@ -110,8 +110,6 @@ namespace Crow void interfaceThread() { - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - CrowInterface.Quit += Quit; CrowInterface.MouseCursorChanged += CrowInterface_MouseCursorChanged; while (CrowInterface.ClientRectangle.Size.Width == 0) diff --git a/src/GraphicObjects/AnalogMeter.cs b/src/GraphicObjects/AnalogMeter.cs index 80e0e850..1d60850c 100644 --- a/src/GraphicObjects/AnalogMeter.cs +++ b/src/GraphicObjects/AnalogMeter.cs @@ -5,7 +5,6 @@ using Cairo; namespace Crow { - [DefaultTemplate("#Crow.Templates.AnalogMeter0.goml")] public class AnalogMeter : NumericControl { #region CTOR diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 92238e69..59762182 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -12,7 +12,6 @@ using System.ComponentModel; namespace Crow { - [DefaultTemplate("#Crow.Templates.Button.crow")] public class Button : TemplatedContainer { string caption; @@ -74,7 +73,7 @@ namespace Crow } #endregion - [XmlAttributeAttribute()][DefaultValue("Button")] + [XmlAttributeAttribute][DefaultValue("Button")] public string Caption { get { return caption; } set { @@ -84,7 +83,7 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } - [XmlAttributeAttribute()][DefaultValue("#Crow.Images.button.svg")] + [XmlAttributeAttribute][DefaultValue("#Crow.Images.button.svg")] public string Image { get { return image; } set { @@ -94,7 +93,7 @@ namespace Crow NotifyValueChanged ("Image", image); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public bool IsPressed { get { return isPressed; } diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs index 61b581ed..46d77e76 100644 --- a/src/GraphicObjects/CheckBox.cs +++ b/src/GraphicObjects/CheckBox.cs @@ -25,7 +25,6 @@ using System.Xml.Serialization; namespace Crow { - [DefaultTemplate("#Crow.Templates.CheckBox.goml")] public class CheckBox : TemplatedControl { string caption; diff --git a/src/GraphicObjects/ComboBox.cs b/src/GraphicObjects/ComboBox.cs index d2b0567e..becee3ce 100644 --- a/src/GraphicObjects/ComboBox.cs +++ b/src/GraphicObjects/ComboBox.cs @@ -24,7 +24,6 @@ using System.Xml.Serialization; namespace Crow { - [DefaultTemplate("#Crow.Templates.ComboBox.goml")] public class ComboBox : ListBox { #region CTOR diff --git a/src/GraphicObjects/DirectoryView.cs b/src/GraphicObjects/DirectoryView.cs index ac53ee8b..586b1b26 100644 --- a/src/GraphicObjects/DirectoryView.cs +++ b/src/GraphicObjects/DirectoryView.cs @@ -25,7 +25,6 @@ using System.IO; namespace Crow { - [DefaultTemplate("#Crow.Templates.DirectoryView.crow")] public class DirectoryView : TemplatedControl { #region CTOR diff --git a/src/GraphicObjects/DummyTemplate.cs b/src/GraphicObjects/DummyTemplate.cs index 68597d18..891499ff 100644 --- a/src/GraphicObjects/DummyTemplate.cs +++ b/src/GraphicObjects/DummyTemplate.cs @@ -22,7 +22,6 @@ using System; namespace Crow { - [DefaultTemplate("#Crow.Templates.Dummy.goml")] public class DummyTemplate : TemplatedControl { public DummyTemplate () : base() diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 819987eb..059cab8b 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -25,7 +25,6 @@ using System.Xml.Serialization; namespace Crow { - [DefaultTemplate("#Crow.Templates.Expandable.goml")] public class Expandable : TemplatedContainer { #region CTOR diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs index 886e7964..db457282 100644 --- a/src/GraphicObjects/GroupBox.cs +++ b/src/GraphicObjects/GroupBox.cs @@ -25,7 +25,6 @@ using System.ComponentModel; namespace Crow { - [DefaultTemplate("#Crow.Templates.GroupBox.goml")] public class GroupBox : TemplatedContainer { string caption; diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index ab349ed4..e1b82f19 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -30,7 +30,6 @@ using System.Threading; namespace Crow { - [DefaultTemplate("#Crow.Templates.ListBox.goml")] public class ListBox : TemplatedControl { #region CTOR diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index 550f5b72..dbca769d 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -23,7 +23,6 @@ using System.ComponentModel; namespace Crow { - [DefaultTemplate("#Crow.Templates.MessageBox.goml")] public class MessageBox : Window { public MessageBox ():base(){} diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index ea11435a..029a9837 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -26,7 +26,6 @@ using OpenTK.Input; namespace Crow { - [DefaultTemplate("#Crow.Templates.Popper.goml")] public class Popper : TemplatedContainer { #region CTOR diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index 35c96c30..ede16475 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -25,7 +25,6 @@ using System.Xml.Serialization; namespace Crow { - [DefaultTemplate("#Crow.Templates.RadioButton.goml")] public class RadioButton : TemplatedControl { string caption; diff --git a/src/GraphicObjects/ScrollBar.cs b/src/GraphicObjects/ScrollBar.cs index 017b50ac..5660c00b 100644 --- a/src/GraphicObjects/ScrollBar.cs +++ b/src/GraphicObjects/ScrollBar.cs @@ -5,7 +5,6 @@ using OpenTK.Input; namespace Crow { - [DefaultTemplate("#Crow.Templates.ScrollBar.goml")] public class ScrollBar : NumericControl { Orientation _orientation; diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs index 0806d4d3..7fc34ae8 100644 --- a/src/GraphicObjects/Spinner.cs +++ b/src/GraphicObjects/Spinner.cs @@ -22,7 +22,6 @@ using System; namespace Crow { - [DefaultTemplate("#Crow.Templates.Spinner.goml")] public class Spinner : NumericControl { #region CTOR diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 2d2ba453..c06a43a9 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -25,7 +25,6 @@ using System.Diagnostics; namespace Crow { - [DefaultTemplate("#Crow.Templates.TabItem.crow")] public class TabItem : TemplatedContainer { #region Private fields diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 422a45ec..4745b87b 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -31,27 +31,6 @@ using System.Reflection; namespace Crow { - [AttributeUsage(AttributeTargets.Class)] - public class TemplateAttribute : Attribute - { - public string Path = ""; - public TemplateAttribute(string path) - { - Path = path; - } - } - - [AttributeUsage(AttributeTargets.Class)] - public class DefaultTemplate : TemplateAttribute - { - public DefaultTemplate(string path) : base(path){} - } - [AttributeUsage(AttributeTargets.Class)] - public class DefaultItemTemplate : TemplateAttribute - { - public DefaultItemTemplate(string path) : base(path){} - } - public abstract class TemplatedControl : PrivateContainer, IXmlSerializable { #region CTOR @@ -116,8 +95,9 @@ namespace Crow protected virtual void loadTemplate(GraphicObject template = null) { if (template == null) { - DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault(); - this.SetChild (Interface.Load (dt.Path)); + if (!Interface.DefaultTemplates.ContainsKey (this.GetType ().FullName)) + throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName)); + this.SetChild (Interface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); }else this.SetChild (template); diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 51080281..b7de4b69 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -27,7 +27,6 @@ namespace Crow { //treeview expect expandable child (or not) //if their are expandable, some functions and events are added - [DefaultTemplate("#Crow.Templates.TreeView.crow")] public class TreeView : ListBox { GraphicObject selectedItemContainer = null; diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index be482e43..9fb6bd29 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -26,7 +26,6 @@ using System.Diagnostics; namespace Crow { - [DefaultTemplate("#Crow.Templates.Window.goml")] public class Window : TemplatedContainer { enum Direction diff --git a/src/IMLReader.cs b/src/IMLReader.cs index f8fd34ed..78f1880a 100644 --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@ -147,21 +147,16 @@ namespace Crow } if (!inlineTemplate) { + reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref if (string.IsNullOrEmpty (templatePath)) { - DefaultTemplate dt = (DefaultTemplate)crowType.GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault (); - if (dt!=null) - templatePath = dt.Path; - } - - if (!string.IsNullOrEmpty (templatePath)) { - reader.il.Emit (OpCodes.Ldloc_0);//Load this templateControl ref - + reader.il.Emit (OpCodes.Ldnull);//default template loading + }else{ reader.il.Emit (OpCodes.Ldstr, templatePath); //Load template path string reader.il.Emit (OpCodes.Callvirt,//call Interface.Load(path) - typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); - reader.il.Emit (OpCodes.Callvirt,//add child - crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic)); + typeof(Interface).GetMethod ("Load", BindingFlags.Static | BindingFlags.Public)); } + reader.il.Emit (OpCodes.Callvirt,//load template + crowType.GetMethod ("loadTemplate", BindingFlags.Instance | BindingFlags.NonPublic)); } foreach (string[] iTempId in itemTemplateIds) { reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref diff --git a/src/Interface.cs b/src/Interface.cs index 6997f6ba..2ffebdbd 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -45,8 +45,9 @@ namespace Crow { #region CTOR static Interface(){ - LoadCursors (); - LoadStyling (); + loadCursors (); + loadStyling (); + findAvailableTemplates (); FontRenderingOptions = new FontOptions (); FontRenderingOptions.Antialias = Antialias.Subpixel; @@ -121,18 +122,13 @@ namespace Crow public static Dictionary DefaultValuesLoader = new Dictionary(); public static Dictionary Styling; /// parse all styling data's and build global Styling Dictionary - static void LoadStyling() { - System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - + static void loadStyling() { Styling = new Dictionary (); //fetch styling info in this order, if member styling is alreadey referenced in previous //assembly, it's ignored. loadStylingFromAssembly (Assembly.GetEntryAssembly ()); loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); - - Thread.CurrentThread.CurrentCulture = savedCulture; } /// Search for .style resources in assembly static void loadStylingFromAssembly (Assembly assembly) { @@ -143,7 +139,7 @@ namespace Crow .Dispose (); } } - static void LoadCursors(){ + static void loadCursors(){ //Load cursors XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0]; XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0]; @@ -156,6 +152,23 @@ namespace Crow } #endregion + #region Templates + public static Dictionary DefaultTemplates = new Dictionary(); + static void findAvailableTemplates(){ + searchTemplatesIn (Assembly.GetEntryAssembly ()); + searchTemplatesIn (Assembly.GetExecutingAssembly ()); + } + static void searchTemplatesIn(Assembly assembly){ + foreach (string resId in assembly + .GetManifestResourceNames () + .Where (r => r.EndsWith (".template", StringComparison.OrdinalIgnoreCase))) { + string clsName = resId.Substring (0, resId.Length - 9); + if (DefaultTemplates.ContainsKey (clsName)) + continue; + DefaultTemplates[clsName] = "#" + resId; + } + } + #endregion #region Load/Save public static Stream GetStreamFromPath (string path) @@ -194,16 +207,11 @@ namespace Crow } public static GraphicObject Load (string path) { - System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - try { return GetInstantiator (path).CreateInstance (); } catch (Exception ex) { throw new Exception ("Error loading <" + path + ">:", ex); } - - Thread.CurrentThread.CurrentCulture = savedCulture; } /// /// fetch it from cache or create it