}
void openFileDialog () {
- AddWidget (instFileDlg.CreateInstance(CurrentInterface)).DataSource = this;
+ AddWidget (instFileDlg.CreateInstance()).DataSource = this;
}
void openOptionsDialog(){}
void newFile() {}
base.OnLoad (e);
instFileDlg = Instantiator.CreateFromImlFragment
- ("<FileDialog Caption='Open File' CurrentDirectory='{²CurrentDirectory}' SearchPattern='*.sln' OkClicked='onFileOpen'/>");
+ (CurrentInterface, "<FileDialog Caption='Open File' CurrentDirectory='{²CurrentDirectory}' SearchPattern='*.sln' OkClicked='onFileOpen'/>");
initCommands ();
Instantiator iTmp;
try {
- iTmp = Instantiator.CreateFromImlFragment (imlSource);
+ iTmp = Instantiator.CreateFromImlFragment (imlVE, imlSource);
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine (ex.ToString());
return;
try {
imlVE.ClearInterface ();
if (itor != null)
- imlVE.AddWidget(itor.CreateInstance(imlVE));
+ imlVE.AddWidget(itor.CreateInstance());
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine (ex.ToString());
internal static EventInfo eiLogicalParentChanged = typeof(GraphicObject).GetEvent("LogicalParentChanged");
internal static MethodInfo miIFaceLoad = typeof(Interface).GetMethod ("Load", BindingFlags.Instance | BindingFlags.Public);
- internal static MethodInfo miGetITemp = typeof(Interface).GetMethod ("GetItemTemplate");
+ internal static MethodInfo miGetITemp = typeof(Interface).GetMethod ("GetItemTemplate", BindingFlags.Instance | BindingFlags.Public);
internal static MethodInfo miAddITemp = typeof(Dictionary<string, ItemTemplate>).GetMethod ("set_Item", new Type[] { typeof(string), typeof(ItemTemplate) });
internal static MethodInfo miGetITempFromDic = typeof(Dictionary<string, ItemTemplate>).GetMethod ("get_Item", new Type[] { typeof(string) });
static Instantiator instStack, instSplit, instSpacer;
#region CTOR
static Docker () {
- instStack = Instantiator.CreateFromImlFragment(@"<GenericStack Background='Blue' AllowDrop='true' DragEnter='onStackDragEnter'/>");
- instSplit = Instantiator.CreateFromImlFragment(@"<Splitter/>");
- instSpacer = Instantiator.CreateFromImlFragment(@"<GraphicObject Background='Red' IsEnabled='false'/>");
}
public Docker () : base ()
{
+ instStack = Instantiator.CreateFromImlFragment(CurrentInterface, @"<GenericStack Background='Blue' AllowDrop='true' DragEnter='onStackDragEnter'/>");
+ instSplit = Instantiator.CreateFromImlFragment(CurrentInterface, @"<Splitter/>");
+ instSpacer = Instantiator.CreateFromImlFragment(CurrentInterface, @"<GraphicObject Background='Red' IsEnabled='false'/>");
}
#endregion
return;
lock (CurrentInterface.UpdateMutex) {
- Splitter splitter = instSplit.CreateInstance<Splitter> (CurrentInterface);
+ Splitter splitter = instSplit.CreateInstance<Splitter> ();
dw.Resizable = false;
dw.Left = dw.Top = 0;
Rectangle r;
if (mainStack == null) {
- mainStack = instStack.CreateInstance<GenericStack> (CurrentInterface);
+ mainStack = instStack.CreateInstance<GenericStack> ();
this.AddChild (mainStack);
this.putWidgetOnBottom (mainStack);
r = ClientRectangle;
this.ClearTemplateBinding();
if (template == null) {
- if (!Interface.DefaultTemplates.ContainsKey (this.GetType ().FullName))
+ if (!CurrentInterface.DefaultTemplates.ContainsKey (this.GetType ().FullName))
throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName));
- this.SetChild (CurrentInterface.Load (Interface.DefaultTemplates[this.GetType ().FullName]));
+ this.SetChild (CurrentInterface.Load (CurrentInterface.DefaultTemplates[this.GetType ().FullName]));
}else
this.SetChild (template);
}
}
lock (CurrentInterface.LayoutMutex) {
- g = iTemp.CreateInstance(CurrentInterface);
+ g = iTemp.CreateInstance();
page.AddChild (g);
// if (isPaged)
g.LogicalParent = this;
public Type RootType;
InstanciatorInvoker loader;
+ protected Interface iface;
internal string sourcePath;
/// <summary>
/// Initializes a new instance of the Instantiator class.
/// </summary>
- public Instantiator (string path) : this (Interface.GetStreamFromPath(path), path) {
+ public Instantiator (Interface _iface, string path) : this (_iface, Interface.GetStreamFromPath(path), path) {
}
/// <summary>
/// Initializes a new instance of the Instantiator class.
/// </summary>
- public Instantiator (Stream stream, string srcPath = null)
+ public Instantiator (Interface _iface, Stream stream, string srcPath = null)
{
+ iface = _iface;
sourcePath = srcPath;
#if DEBUG_LOAD
Stopwatch loadingTime = new Stopwatch ();
/// Initializes a new instance of the Instantiator class with an already openned xml reader
/// positionned on the start tag inside the itemTemplate
/// </summary>
- public Instantiator (XmlReader itr){
+ public Instantiator (Interface _iface, XmlReader itr){
+ iface = _iface;
parseIML (itr);
}
//TODO:check if still used
- public Instantiator (Type _root, InstanciatorInvoker _loader)
+ public Instantiator (Interface _iface, Type _root, InstanciatorInvoker _loader)
{
+ iface = _iface;
RootType = _root;
loader = _loader;
}
/// </summary>
/// <returns>A new instantiator</returns>
/// <param name="fragment">IML string</param>
- public static Instantiator CreateFromImlFragment (string fragment)
+ public static Instantiator CreateFromImlFragment (Interface _iface, string fragment)
{
try {
using (Stream s = new MemoryStream (Encoding.UTF8.GetBytes (fragment))) {
- return new Instantiator (s);
+ return new Instantiator (_iface, s);
}
} catch (Exception ex) {
throw new Exception ("Error loading IML fragment:\n" + fragment + "\n", ex);
/// </summary>
/// <returns>The new graphic object instance</returns>
/// <param name="iface">The interface to bind to</param>
- public GraphicObject CreateInstance(Interface iface){
+ public GraphicObject CreateInstance(){
return loader (iface) as GraphicObject;
}
/// <summary>
/// </summary>
/// <returns>The new T instance</returns>
/// <param name="iface">The interface to bind to</param>
- public T CreateInstance<T>(Interface iface){
+ public T CreateInstance<T>(){
return (T)loader (iface);
}
List<DynamicMethod> dsValueChangedDynMeths = new List<DynamicMethod>();
if (string.IsNullOrEmpty (path)) {
itemTmpID += Guid.NewGuid ().ToString ();
- Interface.Instantiators [itemTmpID] =
- new ItemTemplate (new MemoryStream (Encoding.UTF8.GetBytes (reader.ReadInnerXml ())), dataTest, dataType, datas);
+ iface.Instantiators [itemTmpID] =
+ new ItemTemplate (iface, new MemoryStream (Encoding.UTF8.GetBytes (reader.ReadInnerXml ())), dataTest, dataType, datas);
} else {
if (!reader.IsEmptyElement)
throw new Exception ("ItemTemplate with Path attribute set may not include sub nodes");
itemTmpID += path+dataType+datas;
- if (!Interface.Instantiators.ContainsKey (itemTmpID))
- Interface.Instantiators [itemTmpID] =
- new ItemTemplate (Interface.GetStreamFromPath (path), dataTest, dataType, datas);
+ if (!iface.Instantiators.ContainsKey (itemTmpID))
+ iface.Instantiators [itemTmpID] =
+ new ItemTemplate (iface, Interface.GetStreamFromPath (path), dataTest, dataType, datas);
}
return new string [] { dataType, itemTmpID, datas, dataTest };
}
//try to load ItemTemplate(s) from ItemTemplate attribute of TemplatedGroup
if (!string.IsNullOrEmpty (itemTemplatePath)) {
//check if it is already loaded in cache as a single itemTemplate instantiator
- if (Interface.Instantiators.ContainsKey (itemTemplatePath)) {
+ if (iface.Instantiators.ContainsKey (itemTemplatePath)) {
itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "" });
} else {
using (Stream stream = Interface.GetStreamFromPath (itemTemplatePath)) {
if (itr.NodeType == XmlNodeType.Element) {
if (itr.Name != "ItemTemplate") {
//the file contains a single template to use as default
- Interface.Instantiators [itemTemplatePath] =
- new ItemTemplate (itr);
+ iface.Instantiators [itemTemplatePath] =
+ new ItemTemplate (iface, itr);
itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "", "TypeOf" });
break;//we should be at the end of the file
}
foreach (string [] iTempId in itemTemplateIds) {
ctx.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
ctx.il.Emit (OpCodes.Ldfld, CompilerServices.fldItemTemplates);//load ItemTemplates dic field
+
+ //prepare argument to add itemTemplate to templated group dic of ItemTemplates
ctx.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key
- ctx.il.Emit (OpCodes.Ldstr, iTempId [1]);//load value
+ //load itemTemplate
+ ctx.il.Emit (OpCodes.Ldarg_1);//load currentInterface
+ ctx.il.Emit (OpCodes.Ldstr, iTempId [1]);//load path
ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miGetITemp);
ctx.il.Emit (OpCodes.Callvirt, CompilerServices.miAddITemp);
}
loadCursors ();
- findAvailableTemplates ();
FontRenderingOptions = new FontOptions ();
FontRenderingOptions.Antialias = Antialias.Subpixel;
CurrentInterface = this;
CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
loadStyling ();
+ findAvailableTemplates ();
initTooltip ();
initContextMenus ();
}
/// <summary>each IML and fragments (such as inline Templates) are compiled as a Dynamic Method stored here
/// on the first instance creation of a IML item.
/// </summary>
- public static Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>();
+ public Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>();
public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished
public DragDropEventArgs DragAndDropOperation = null;
/// Resource ID must be 'fullClassName.template' (not case sensitive)
/// Those found in application assembly have priority to the default Crow's one
/// </summary>
- public static Dictionary<string, string> DefaultTemplates = new Dictionary<string, string>();
+ public Dictionary<string, string> DefaultTemplates = new Dictionary<string, string>();
/// <summary>Finds available default templates at startup</summary>
- static void findAvailableTemplates(){
+ void findAvailableTemplates(){
searchTemplatesOnDisk ("./");
string defTemplatePath = System.IO.Path.Combine (CrowConfigRoot, "defaultTemplates");
searchTemplatesOnDisk (defTemplatePath);
searchTemplatesIn (Assembly.GetEntryAssembly ());
searchTemplatesIn (Assembly.GetExecutingAssembly ());
}
- static void searchTemplatesOnDisk (string templatePath){
+ void searchTemplatesOnDisk (string templatePath){
if (!Directory.Exists (templatePath))
return;
foreach (string f in Directory.GetFiles(templatePath, "*.template",SearchOption.AllDirectories)) {
DefaultTemplates [clsName] = f;
}
}
- static void searchTemplatesIn(Assembly assembly){
+ void searchTemplatesIn(Assembly assembly){
if (assembly == null)
return;
foreach (string resId in assembly
/// <param name="imlFragment">a valid IML string</param>
public GraphicObject LoadIMLFragment (string imlFragment) {
lock (UpdateMutex) {
- GraphicObject tmp = Instantiator.CreateFromImlFragment (imlFragment).CreateInstance(this);
+ GraphicObject tmp = Instantiator.CreateFromImlFragment (this, imlFragment).CreateInstance();
AddWidget (tmp);
return tmp;
}
public GraphicObject Load (string path)
{
//try {
- return GetInstantiator (path).CreateInstance (this);
+ return GetInstantiator (path).CreateInstance ();
//} catch (Exception ex) {
// throw new Exception ("Error loading <" + path + ">:", ex);
//}
/// </summary>
/// <returns>new Instantiator</returns>
/// <param name="path">path of the iml file to load</param>
- public static Instantiator GetInstantiator(string path){
+ public Instantiator GetInstantiator(string path){
if (!Instantiators.ContainsKey(path))
- Instantiators [path] = new Instantiator(path);
+ Instantiators [path] = new Instantiator(this, path);
return Instantiators [path];
}
/// <summary>Item templates are derived from instantiator, this function
/// try to fetch the requested one in the cache or create it.
/// They have additional properties for recursivity and
/// custom display per item type</summary>
- public static ItemTemplate GetItemTemplate(string path){
+ public ItemTemplate GetItemTemplate(string path){
if (!Instantiators.ContainsKey(path))
- Instantiators [path] = new ItemTemplate(path);
+ Instantiators [path] = new ItemTemplate(this, path);
return Instantiators [path] as ItemTemplate;
}
//TODO: .Net xml serialisation is no longer used, it has been replaced with instantiators
- public static void Save<T> (string file, T graphicObject)
+ public void Save<T> (string file, T graphicObject)
{
XmlSerializerNamespaces xn = new XmlSerializerNamespaces ();
xn.Add ("", "");
/// <param name="path">IML file to parse</param>
/// <param name="_dataType">type this item will be choosen for, or member of the data item</param>
/// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param>
- public ItemTemplate(string path, string _dataTest = "TypeOf", string _dataType = null, string _fetchDataMethod = null)
- : base(path) {
+ public ItemTemplate(Interface _iface, string path, string _dataTest = "TypeOf", string _dataType = null, string _fetchDataMethod = null)
+ : base(_iface, path) {
strDataType = _dataType;
fetchMethodName = _fetchDataMethod;
dataTest = _dataTest;
/// <param name="path">IML fragment to parse</param>
/// <param name="_dataType">type this item will be choosen for, or member of the data item</param>
/// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param>
- public ItemTemplate (Stream ImlFragment, string _dataTest, string _dataType, string _fetchDataMethod)
- :base(ImlFragment)
+ public ItemTemplate (Interface _iface, Stream ImlFragment, string _dataTest, string _dataType, string _fetchDataMethod)
+ :base(_iface, ImlFragment)
{
strDataType = _dataType;
fetchMethodName = _fetchDataMethod;
/// <param name="path">XML reader positionned before or at the root node</param>
/// <param name="_dataType">type this item will be choosen for, or member of the data item</param>
/// <param name="_fetchDataMethod">for hierarchical data, method to call for children fetching</param>
- public ItemTemplate (XmlReader reader, string _dataTest = "TypeOf" , string _dataType = null, string _fetchDataMethod = null)
- :base(reader)
+ public ItemTemplate (Interface _iface, XmlReader reader, string _dataTest = "TypeOf" , string _dataType = null, string _fetchDataMethod = null)
+ :base(_iface, reader)
{
strDataType = _dataType;
fetchMethodName = _fetchDataMethod;