diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-12 17:17:05 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-12 17:17:05 +0200 |
| commit | 86acbb4902a25100a183da7ce9e7a5662de8b4cb (patch) | |
| tree | 6fb2b3897704267d3fdb5b260df51b29135577f2 /src | |
| parent | ed815a31113235890cf6c902c754fb3dc7536708 (diff) | |
default template searched in embedded resources with .template extension
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/AnalogMeter.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Button.cs | 7 | ||||
| -rw-r--r-- | src/GraphicObjects/CheckBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/ComboBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/DirectoryView.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/DummyTemplate.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Expandable.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/GroupBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/ListBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/MessageBox.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Popper.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/RadioButton.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/ScrollBar.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Spinner.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/TabItem.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedControl.cs | 26 | ||||
| -rw-r--r-- | src/GraphicObjects/TreeView.cs | 1 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 1 | ||||
| -rw-r--r-- | src/IMLReader.cs | 17 | ||||
| -rw-r--r-- | src/Interface.cs | 36 |
20 files changed, 34 insertions, 68 deletions
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<String, LoaderInvoker> DefaultValuesLoader = new Dictionary<string, LoaderInvoker>(); public static Dictionary<string, Style> Styling; /// <summary> parse all styling data's and build global Styling Dictionary </summary> - static void LoadStyling() { - System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - + static void loadStyling() { Styling = new Dictionary<string, Style> (); //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; } /// <summary> Search for .style resources in assembly </summary> 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<String, string> DefaultTemplates = new Dictionary<string, string>(); + 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; } /// <summary> /// fetch it from cache or create it |