From f98ba5207415b8093b429b02a704bd9f5e8fc4d6 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 15 Aug 2016 16:34:17 +0200 Subject: * Crow.sln, test.crow, CrowIDE.csproj, CrowIDE.cs, imlEditor.crow, TreeView.cs, DirectoryView.cs: basic IML loading into imlVE interface * ImlVisualEditor.cs: basic IML loading into veIface * CompilerServices.cs: CurrentInterface as public * GraphicObject.cs: RegisterForRedraw as virtual --- src/GraphicObjects/TreeView.cs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/GraphicObjects/TreeView.cs') diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index ef228260..78786cd7 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -95,6 +95,8 @@ namespace Crow internal override void itemClick (object sender, MouseButtonEventArgs e) { GraphicObject tmp = sender as GraphicObject; + if (!tmp.HasFocus) + return; if (selectedItemContainer != null) { selectedItemContainer.Foreground = Color.Transparent; selectedItemContainer.Background = Color.Transparent; -- cgit v1.3.1-4-g156e From 39a9fa35ff36f8bcb3a88679e3658596d2e79b1c Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 6 Sep 2016 17:55:41 +0200 Subject: rebase master --- Templates/ComboBox.template | 2 +- Templates/ListBox.template | 2 +- Templates/ScrollingListBox.goml | 2 +- Templates/TreeView.template | 2 +- Templates/treeList.crow | 2 +- Tests/BasicTests.cs | 8 +- .../TemplatedContainer/testTreeView.crow | 2 +- .../TemplatedControl/testItemTemplateTag.crow | 2 +- appveyor.yml | 2 +- src/GraphicObjects/ListBox.cs | 208 +---------------- src/GraphicObjects/MenuItem.cs | 4 +- src/GraphicObjects/TemplatedControl.cs | 36 +-- src/GraphicObjects/TemplatedGroup.cs | 256 ++++++++++++++++++++- src/GraphicObjects/TreeView.cs | 31 +-- src/IMLReader.cs | 6 +- src/ItemTemplate.cs | 17 +- 16 files changed, 288 insertions(+), 294 deletions(-) (limited to 'src/GraphicObjects/TreeView.cs') diff --git a/Templates/ComboBox.template b/Templates/ComboBox.template index 9688721a..d28a7b91 100755 --- a/Templates/ComboBox.template +++ b/Templates/ComboBox.template @@ -22,7 +22,7 @@ HorizontalAlignment="Left" ValueChanged="../../../_scroller_ValueChanged"> diff --git a/Templates/ListBox.template b/Templates/ListBox.template index c56ec0d0..36f2f61e 100755 --- a/Templates/ListBox.template +++ b/Templates/ListBox.template @@ -4,6 +4,6 @@ Height="{./HeightPolicy}" Width="{./WidthPolicy}" ValueChanged="./_scroller_ValueChanged"> + Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/> \ No newline at end of file diff --git a/Templates/ScrollingListBox.goml b/Templates/ScrollingListBox.goml index a746cb65..54e3eb48 100644 --- a/Templates/ScrollingListBox.goml +++ b/Templates/ScrollingListBox.goml @@ -5,7 +5,7 @@ Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}" ValueChanged="./_scroller_ValueChanged"> + Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/> \ No newline at end of file + Height="Fit" Width="{../WidthPolicy}" Name="ItemsContainer"/> \ No newline at end of file diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index 62ddc567..cd9e3ba3 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -145,8 +145,12 @@ namespace Tests idx = testFiles.Length - 1; this.Title = testFiles [idx] + ". Press to cycle examples."; - GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); - obj.DataSource = this; + try { + GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]); + obj.DataSource = this; + } catch (Exception ex) { + Debug.WriteLine (ex.Message + ex.InnerException); + } } void Tv_SelectedItemChanged (object sender, SelectionChangeEventArgs e) { diff --git a/Tests/Interfaces/TemplatedContainer/testTreeView.crow b/Tests/Interfaces/TemplatedContainer/testTreeView.crow index 3a44bf34..e8e71645 100755 --- a/Tests/Interfaces/TemplatedContainer/testTreeView.crow +++ b/Tests/Interfaces/TemplatedContainer/testTreeView.crow @@ -32,7 +32,7 @@ diff --git a/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow b/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow index 5f860719..94625915 100755 --- a/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow +++ b/Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow @@ -10,7 +10,7 @@ Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}" ValueChanged="../../../_scroller_ValueChanged"> diff --git a/appveyor.yml b/appveyor.yml index dad396ef..358d2b61 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: 0.4.{build} branches: only: - - appveyor + - master clone_depth: 1 diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index f91a9836..82a4014b 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -30,218 +30,12 @@ using System.Threading; namespace Crow { - public class ListBox : TemplatedControl + public class ListBox : TemplatedGroup { #region CTOR public ListBox () : base() {} #endregion - #region events - public event EventHandler SelectedItemChanged; - #endregion - - Group _list; - GenericStack _gsList; - IList data; - int _selectedIndex; - int itemPerPage = 50; - Thread loadingThread = null; - volatile bool cancelLoading = false; - - [XmlAttributeAttribute]public IList Data { - get { - return data; - } - set { - if (value == data) - return; - - cancelLoadingThread (); - - data = value; - - NotifyValueChanged ("Data", data); - - lock (CurrentInterface.UpdateMutex) - _list.ClearChildren (); - if (_gsList.Orientation == Orientation.Horizontal) - _gsList.Width = -1; - else - _gsList.Height = -1; - - if (data == null) - return; - - loadingThread = new Thread (loading); - loadingThread.IsBackground = true; - loadingThread.Start (); - //loadPage(1); - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - } - - [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{ - get { return _selectedIndex; } - set { - if (value == _selectedIndex) - return; - - _selectedIndex = value; - - NotifyValueChanged ("SelectedIndex", _selectedIndex); - NotifyValueChanged ("SelectedItem", SelectedItem); - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - } - [XmlIgnore]public virtual object SelectedItem{ - get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } - } - protected void raiseSelectedItemChanged(){ - SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); - } - - #region TemplatedControl override - protected override void loadTemplate (GraphicObject template = null) - { - base.loadTemplate (template); - _list = this.child.FindByName ("List") as Group; - if (_list == null) - throw new Exception ("ListBox Template MUST contain a Goup widget named 'List'."); - _gsList = _list as GenericStack; - } - #endregion - - void loading(){ - if (ItemTemplates == null) - ItemTemplates = new Dictionary (); - if (!ItemTemplates.ContainsKey ("default")) - ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); - - for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { - if (cancelLoading) - return; - loadPage (i); - } - } - void cancelLoadingThread(){ - if (loadingThread == null) - return; - if (!loadingThread.IsAlive) - return; - cancelLoading = true; - loadingThread.Join (); - cancelLoading = false; - } - void loadPage(int pageNum) - { - #if DEBUG_LOAD - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - - Group page = _list.Clone () as Group; - - page.Name = "page" + pageNum; - - //reset size to fit in the dir of the stacking - //because _list total size is forced to approx size - if (_gsList.Orientation == Orientation.Horizontal) { - page.Width = Measure.Fit; - page.BindMember ("Height", "../HeightPolicy"); - } else { - page.Height = Measure.Fit; - page.BindMember ("Width", "../WidthPolicy"); - } - - for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { - if (i >= data.Count) - break; - if (cancelLoading) - return; - - loadItem (i, page); - - //g.LogicalParent = this; - } - - lock (CurrentInterface.LayoutMutex) - _list.AddChild (page); - - #if DEBUG_LOAD - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif - } - protected void loadItem(int i, Group page){ - GraphicObject g = null; - ItemTemplate iTemp = null; - Type dataType = data [i].GetType (); - - while (dataType.FullName != "System.Object") { - if (ItemTemplates.ContainsKey (dataType.FullName)) { - iTemp = ItemTemplates [dataType.FullName]; - break; - } - dataType = dataType.BaseType; - if (dataType == null) - break; - } - - if (iTemp == null) - iTemp = ItemTemplates ["default"]; - - lock (CurrentInterface.LayoutMutex) { - g = iTemp.CreateInstance(CurrentInterface); - page.AddChild (g); - g.DataSource = data [i]; - } - - registerItemClick (g); - - if (iTemp.Expand != null && g is Expandable) { - (g as Expandable).Expand += iTemp.Expand; - } - } - protected virtual void registerItemClick(GraphicObject g){ - g.MouseClick += itemClick; - } - protected void _list_LayoutChanged (object sender, LayoutingEventArgs e) - { -#if DEBUG_LAYOUTING - Debug.WriteLine("list_LayoutChanged"); -#endif - if (_gsList.Orientation == Orientation.Horizontal) { - if (e.LayoutType == LayoutingType.Width) - _gsList.Width = approxSize; - } else if (e.LayoutType == LayoutingType.Height) - _gsList.Height = approxSize; - } - int approxSize - { - get { - if (data == null) - return -1; - GenericStack page1 = _list.FindByName ("page1") as GenericStack; - if (page1 == null) - return -1; - - return page1.Orientation == Orientation.Horizontal ? - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)): - data.Count < itemPerPage ? - -1: - (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); - } - } - internal virtual void itemClick(object sender, MouseButtonEventArgs e){ - SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); - } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 60233361..78162fbb 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -101,11 +101,11 @@ namespace Crow { Execute.Raise (this, null); } - void onOpen (object sender, EventArgs e){ + protected virtual void onOpen (object sender, EventArgs e){ MenuRoot.IsOpened = true; Open.Raise (this, null); } - void onClose (object sender, EventArgs e){ + protected virtual void onClose (object sender, EventArgs e){ //MenuRoot.IsOpened = true; Close.Raise (this, null); } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index cb14dfd9..7f2e1b87 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -46,9 +46,6 @@ namespace Crow } string _template; - string _itemTemplate; - public Dictionary ItemTemplates = new Dictionary();//TODO: dont instantiate if not used - //but then i should test if null in msil gen [XmlAttributeAttribute][DefaultValue(null)] public string Template { get { return _template; } @@ -63,19 +60,7 @@ namespace Crow loadTemplate (CurrentInterface.Load (_template)); } } - [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] - public string ItemTemplate { - get { return _itemTemplate; } - set { - if (value == _itemTemplate) - return; - _itemTemplate = value; - - //TODO:reload list with new template? - NotifyValueChanged("ItemTemplate", _itemTemplate); - } - } #region GraphicObject overrides public override GraphicObject FindByName (string nameToFind) { @@ -86,7 +71,7 @@ namespace Crow { //onDraw is overrided to prevent default drawing of background, template top container //may have a binding to root background or a fixed one. - //this allow applying root background to random template component + //this allow applying root background to random template's component gr.Save (); if (ClipToClientRect) { @@ -113,6 +98,7 @@ namespace Crow this.ResolveBindings (); } + //TODO:IXmlSerializable is not used anymore #region IXmlSerializable public override System.Xml.Schema.XmlSchema GetSchema(){ return null; } public override void ReadXml(System.Xml.XmlReader reader) @@ -151,15 +137,15 @@ namespace Crow xr.MoveToElement (); itemTmp = xr.ReadInnerXml (); - if (ItemTemplates == null) - ItemTemplates = new Dictionary (); - - using (IMLReader iTmp = new IMLReader (null, itemTmp)) { - ItemTemplates [dataType] = - new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas); - } - if (!string.IsNullOrEmpty (datas)) - ItemTemplates [dataType].CreateExpandDelegate(this); +// if (ItemTemplates == null) +// ItemTemplates = new Dictionary (); +// +// using (IMLReader iTmp = new IMLReader (null, itemTmp)) { +// ItemTemplates [dataType] = +// new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas); +// } +// if (!string.IsNullOrEmpty (datas)) +// ItemTemplates [dataType].CreateExpandDelegate(this); continue; } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 0d48b9eb..500e5ea6 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -23,6 +23,9 @@ using System.Xml.Serialization; using System.Xml; using System.Reflection; using System.Collections.Generic; +using System.ComponentModel; +using System.Collections; +using System.Threading; namespace Crow { @@ -33,8 +36,127 @@ namespace Crow #endregion protected Group items; + string _itemTemplate; + + #region events + public event EventHandler SelectedItemChanged; + #endregion + + Group _list; + IList data; + int _selectedIndex; + Color selBackground, selForeground; + + int itemPerPage = 50; + Thread loadingThread = null; + volatile bool cancelLoading = false; + + #region Templating + //TODO: dont instantiate ItemTemplates if not used + //but then i should test if null in msil gen + public Dictionary ItemTemplates = new Dictionary(); + + [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] + public string ItemTemplate { + get { return _itemTemplate; } + set { + if (value == _itemTemplate) + return; + + _itemTemplate = value; + + //TODO:reload list with new template? + NotifyValueChanged("ItemTemplate", _itemTemplate); + } + } + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + + items = this.child.FindByName ("ItemsContainer") as Group; + if (items == null) + throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'"); + if (items.Children.Count == 0) + NotifyValueChanged ("HasChildren", false); + else + NotifyValueChanged ("HasChildren", true); + } + #endregion public virtual List Items{ get { return items.Children; }} + [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{ + get { return _selectedIndex; } + set { + if (value == _selectedIndex) + return; + + _selectedIndex = value; + + NotifyValueChanged ("SelectedIndex", _selectedIndex); + NotifyValueChanged ("SelectedItem", SelectedItem); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + } + [XmlIgnore]public virtual object SelectedItem{ + get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } + } + + [XmlAttributeAttribute]public IList Data { + get { return data; } + set { + if (value == data) + return; + + cancelLoadingThread (); + + data = value; + + NotifyValueChanged ("Data", data); + + lock (CurrentInterface.UpdateMutex) + ClearItems (); + + if (data == null) + return; + + loadingThread = new Thread (loading); + loadingThread.IsBackground = true; + loadingThread.Start (); + //loadPage(1); + + NotifyValueChanged ("SelectedIndex", _selectedIndex); + NotifyValueChanged ("SelectedItem", SelectedItem); + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + } + + [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen + public virtual Color SelectionBackground { + get { return selBackground; } + set { + if (value == selBackground) + return; + selBackground = value; + NotifyValueChanged ("SelectionBackground", selBackground); + RegisterForRedraw (); + } + } + [XmlAttributeAttribute][DefaultValue("White")] + public virtual Color SelectionForeground { + get { return selForeground; } + set { + if (value == selForeground) + return; + selForeground = value; + NotifyValueChanged ("SelectionForeground", selForeground); + RegisterForRedraw (); + } + } + + protected void raiseSelectedItemChanged(){ + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } + public virtual void AddItem(GraphicObject g){ items.AddChild (g); @@ -53,18 +175,6 @@ namespace Crow NotifyValueChanged ("HasChildren", false); } - protected override void loadTemplate(GraphicObject template = null) - { - base.loadTemplate (template); - - items = this.child.FindByName ("ItemsContainer") as Group; - if (items == null) - throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'"); - if (items.Children.Count == 0) - NotifyValueChanged ("HasChildren", false); - else - NotifyValueChanged ("HasChildren", true); - } #region GraphicObject overrides public override GraphicObject FindByName (string nameToFind) @@ -160,5 +270,127 @@ namespace Crow throw new NotImplementedException (); } #endregion + + void loading(){ + if (ItemTemplates == null) + ItemTemplates = new Dictionary (); + if (!ItemTemplates.ContainsKey ("default")) + ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate); + + for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) { + if (cancelLoading) + return; + loadPage (i); + } + } + void cancelLoadingThread(){ + if (loadingThread == null) + return; + if (!loadingThread.IsAlive) + return; + cancelLoading = true; + loadingThread.Join (); + cancelLoading = false; + } + void loadPage(int pageNum) + { + #if DEBUG_LOAD + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + Group page = items.Clone () as Group; + + page.Name = "page" + pageNum; + +// //reset size to fit in the dir of the stacking +// //because items total size is forced to approx size +// if (_gsList.Orientation == Orientation.Horizontal) { +// page.Width = Measure.Fit; + page.BindMember ("Height", "../HeightPolicy"); + page.BindMember ("Width", "../WidthPolicy"); +// } else { +// page.Height = Measure.Fit; +// page.BindMember ("Width", "../WidthPolicy"); +// } + + for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { + if (i >= data.Count) + break; + if (cancelLoading) + return; + + loadItem (i, page); + + //g.LogicalParent = this; + } + + lock (CurrentInterface.LayoutMutex) + items.AddChild (page); + + #if DEBUG_LOAD + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + loadingTime.ElapsedTicks, + loadingTime.ElapsedMilliseconds, this.ToString()); + #endif + } + protected void loadItem(int i, Group page){ + GraphicObject g = null; + ItemTemplate iTemp = null; + Type dataType = data [i].GetType (); + + if (ItemTemplates.ContainsKey (dataType.FullName)) + iTemp = ItemTemplates [dataType.FullName]; + else + iTemp = ItemTemplates ["default"]; + + lock (CurrentInterface.LayoutMutex) { + g = iTemp.CreateInstance(CurrentInterface); + page.AddChild (g); + g.DataSource = data [i]; + } + + registerItemClick (g); + + if (iTemp.Expand != null && g is Expandable) { + (g as Expandable).Expand += iTemp.Expand; + } + } + protected virtual void registerItemClick(GraphicObject g){ + g.MouseClick += itemClick; + } +// protected void _list_LayoutChanged (object sender, LayoutingEventArgs e) +// { +// #if DEBUG_LAYOUTING +// Debug.WriteLine("list_LayoutChanged"); +// #endif +// if (_gsList.Orientation == Orientation.Horizontal) { +// if (e.LayoutType == LayoutingType.Width) +// _gsList.Width = approxSize; +// } else if (e.LayoutType == LayoutingType.Height) +// _gsList.Height = approxSize; +// } + int approxSize + { + get { + if (data == null) + return -1; + GenericStack page1 = items.FindByName ("page1") as GenericStack; + if (page1 == null) + return -1; + + return page1.Orientation == Orientation.Horizontal ? + data.Count < itemPerPage ? + -1: + (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)): + data.Count < itemPerPage ? + -1: + (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); + } + } + internal virtual void itemClick(object sender, MouseButtonEventArgs e){ + SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); + } } } diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 78786cd7..4fa881b4 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -27,17 +27,17 @@ namespace Crow { //treeview expect expandable child (or not) //if their are expandable, some functions and events are added - public class TreeView : ListBox + public class TreeView : TemplatedGroup { GraphicObject selectedItemContainer = null; - Color selBackground; - Color selForeground; bool isRoot; - + #region CTOR public TreeView () : base() { } + #endregion + [XmlAttributeAttribute()][DefaultValue(false)] public virtual bool IsRoot { get { return isRoot; } @@ -49,29 +49,6 @@ namespace Crow } } - [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen - public virtual Color SelectionBackground { - get { return selBackground; } - set { - if (value == selBackground) - return; - selBackground = value; - NotifyValueChanged ("SelectionBackground", selBackground); - RegisterForRedraw (); - } - } - [XmlAttributeAttribute][DefaultValue("White")] - public virtual Color SelectionForeground { - get { return selForeground; } - set { - if (value == selForeground) - return; - selForeground = value; - NotifyValueChanged ("SelectionForeground", selForeground); - RegisterForRedraw (); - } - } - [XmlIgnore]public override object SelectedItem { get { return selectedItemContainer == null ? diff --git a/src/IMLReader.cs b/src/IMLReader.cs index bf6cbc49..ad4fd835 100644 --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@ -101,7 +101,7 @@ namespace Crow il.Emit (OpCodes.Ldloc_0);//save current go onto the stack if child has to be added - #region Template and TemplateItems loading + #region Template and ItemTemplates loading if (typeof(TemplatedControl).IsAssignableFrom (crowType)) { //if its a template, first read template elements using (IMLReader reader = new IMLReader (il, tmpXml)) { @@ -168,7 +168,7 @@ namespace Crow foreach (string[] iTempId in itemTemplateIds) { reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field - typeof(TemplatedControl).GetField("ItemTemplates")); + typeof(TemplatedGroup).GetField("ItemTemplates")); reader.il.Emit (OpCodes.Ldstr, iTempId[0]);//load key reader.il.Emit (OpCodes.Ldstr, iTempId[1]);//load value reader.il.Emit (OpCodes.Callvirt, @@ -181,7 +181,7 @@ namespace Crow //expand delegate creation reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field - typeof(TemplatedControl).GetField ("ItemTemplates")); + typeof(TemplatedGroup).GetField ("ItemTemplates")); reader.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key reader.il.Emit (OpCodes.Callvirt, typeof(Dictionary).GetMethod ("get_Item", diff --git a/src/ItemTemplate.cs b/src/ItemTemplate.cs index ed3459a8..a1f67786 100644 --- a/src/ItemTemplate.cs +++ b/src/ItemTemplate.cs @@ -50,12 +50,14 @@ namespace Crow } #endregion - public void CreateExpandDelegate (TemplatedControl host){ - Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method + public void CreateExpandDelegate (TemplatedGroup host){ + Type dataType = Type.GetType(strDataType); + Type tmpGrpType = typeof(TemplatedGroup); + Type hostType = tmpGrpType;//not sure is the best place to put the dyn method Type evtType = typeof(EventHandler); - Type listBoxType = typeof(ListBox); - PropertyInfo piListData = listBoxType.GetProperty ("Data"); + + PropertyInfo piData = tmpGrpType.GetProperty ("Data"); MethodInfo evtInvoke = evtType.GetMethod ("Invoke"); ParameterInfo [] evtParams = evtInvoke.GetParameters (); @@ -87,13 +89,13 @@ namespace Crow //check that 'Data' of list is not already set il.Emit (OpCodes.Ldloc_0); - il.Emit (OpCodes.Callvirt, piListData.GetGetMethod ()); + il.Emit (OpCodes.Callvirt, piData.GetGetMethod ()); il.Emit (OpCodes.Brfalse, ifDataIsNull); il.Emit (OpCodes.Br, gotoEnd); il.MarkLabel(ifDataIsNull); //copy the ref of ItemTemplates list TODO: maybe find another way to share it among the nodes? - FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates"); + FieldInfo fiTemplates = tmpGrpType.GetField("ItemTemplates"); il.Emit (OpCodes.Ldloc_0); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Ldfld, fiTemplates); @@ -105,12 +107,11 @@ namespace Crow il.Emit (OpCodes.Callvirt, typeof(GraphicObject).GetProperty("DataSource").GetGetMethod ()); if (fetchMethodName != "self"){//special keyword self allows the use of recurent list<<< - Type dataType = Type.GetType(strDataType); emitGetSubData(il, dataType); } //set 'return' from the fetch method as 'data' of the list - il.Emit (OpCodes.Callvirt, piListData.GetSetMethod ()); + il.Emit (OpCodes.Callvirt, piData.GetSetMethod ()); il.MarkLabel(gotoEnd); il.Emit (OpCodes.Ret); -- cgit v1.3.1-4-g156e From 5aea8651b674c26b9395d1b1077a287a1e885b58 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 25 Jan 2017 09:25:14 +0100 Subject: CrowThread;AlwaysOnTop win;GTree explorer; --- Crow.csproj | 1 + src/CrowThread.cs | 58 ++++++++++++++++++++++++++++++++++++ src/GraphicObjects/GenericStack.cs | 1 + src/GraphicObjects/GraphicObject.cs | 10 ++++--- src/GraphicObjects/Popper.cs | 7 +++-- src/GraphicObjects/TemplatedGroup.cs | 18 +++++------ src/GraphicObjects/TreeView.cs | 27 ++++++++++++++++- src/Interface.cs | 33 ++++++++++++++------ 8 files changed, 128 insertions(+), 27 deletions(-) create mode 100644 src/CrowThread.cs (limited to 'src/GraphicObjects/TreeView.cs') diff --git a/Crow.csproj b/Crow.csproj index 13a0a351..25e7f10d 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -153,6 +153,7 @@ + diff --git a/src/CrowThread.cs b/src/CrowThread.cs new file mode 100644 index 00000000..dfdeda00 --- /dev/null +++ b/src/CrowThread.cs @@ -0,0 +1,58 @@ +// +// CrowThread.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2017 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Threading; + +namespace Crow +{ + /// + /// Thread monitored by current interface with Finished event when state==Stopped + /// + public class CrowThread { + Thread thread; + public event EventHandler Finished; + public GraphicObject Host; + public CrowThread (GraphicObject host, ThreadStart start){ + thread = new Thread (start); + thread.IsBackground = true; + Host = host; + lock (Host.CurrentInterface.CrowThreads) + Host.CurrentInterface.CrowThreads.Add (this); + } + public void CheckState(){ + if (thread.ThreadState != ThreadState.Stopped) + return; + Finished.Raise (Host, null); + lock (Host.CurrentInterface.CrowThreads) + Host.CurrentInterface.CrowThreads.Remove (this); + } + public void Start() { thread.Start();} + public void Cancel(){ + if (thread.IsAlive){ + //cancelLoading = true; + thread.Join (); + //cancelLoading = false; + } + Host.CurrentInterface.CrowThreads.Remove (this); + } + } +} + diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index a2d78d88..0636c14e 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -29,6 +29,7 @@ namespace Crow return; _spacing = value; NotifyValueChanged ("Spacing", Spacing); + RegisterForLayouting (LayoutingType.Sizing|LayoutingType.ArrangeChildren); } } [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 070a221a..1e8bfcf9 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -507,8 +507,10 @@ namespace Crow isVisible = value; //ensure main win doesn't keep hidden childrens ref - if (!isVisible && this.Contains (CurrentInterface.HoverWidget)) - CurrentInterface.HoverWidget = null; + if (CurrentInterface.HoverWidget != null) { + if (!isVisible && this.Contains (CurrentInterface.HoverWidget)) + CurrentInterface.HoverWidget = null; + } if (isVisible) RegisterForLayouting (LayoutingType.Sizing); @@ -1200,8 +1202,8 @@ namespace Crow currentInterface.clickTimer.Restart(); CurrentInterface.eligibleForDoubleClick = null; - if (CurrentInterface.activeWidget == null) - CurrentInterface.activeWidget = this; + if (CurrentInterface.ActiveWidget == null) + CurrentInterface.ActiveWidget = this; if (this.Focusable && !Interface.FocusOnHover) { BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg; if (be.Focused == null) { diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 38621337..84088355 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -219,16 +219,17 @@ namespace Crow if (Content != null) { Content.Visible = true; if (Content.Parent == null) - CurrentInterface.AddWidget (Content); - CurrentInterface.PutOnTop (Content); + CurrentInterface.AddWidget (Content, true); + CurrentInterface.PutOnTop (Content, true); _content_LayoutChanged (this, new LayoutingEventArgs (LayoutingType.Sizing)); } Pop.Raise (this, e); } public virtual void onUnpop(object sender, EventArgs e) { - if (Content != null) + if (Content != null) { Content.Visible = false; + } Unpop.Raise (this, e); } } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index ee799fd0..a1941f06 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -40,6 +40,7 @@ namespace Crow #region events public event EventHandler SelectedItemChanged; + public event EventHandler Loaded; #endregion IList data; @@ -47,7 +48,7 @@ namespace Crow Color selBackground, selForeground; int itemPerPage = 50; - Thread loadingThread = null; + CrowThread loadingThread = null; volatile bool cancelLoading = false; #region Templating @@ -141,8 +142,8 @@ namespace Crow if (data == null) return; - loadingThread = new Thread (loading); - loadingThread.IsBackground = true; + loadingThread = new CrowThread (this, loading); + loadingThread.Finished += (object sender, EventArgs e) => (sender as TemplatedGroup).Loaded.Raise (sender, e); loadingThread.Start (); //loadPage(1); @@ -310,13 +311,8 @@ namespace Crow } } void cancelLoadingThread(){ - if (loadingThread == null) - return; - if (!loadingThread.IsAlive) - return; - cancelLoading = true; - loadingThread.Join (); - cancelLoading = false; + if (loadingThread != null) + loadingThread.Cancel (); } void loadPage(int pageNum) { @@ -374,6 +370,8 @@ namespace Crow } } protected void loadItem(int i, Group page){ + if (data [i] == null)//TODO:surely a threading sync problem + return; GraphicObject g = null; ItemTemplate iTemp = null; Type dataType = data [i].GetType (); diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 4fa881b4..d4354b65 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -48,7 +48,6 @@ namespace Crow NotifyValueChanged ("IsRoot", isRoot); } } - [XmlIgnore]public override object SelectedItem { get { return selectedItemContainer == null ? @@ -84,6 +83,32 @@ namespace Crow NotifyValueChanged ("SelectedItem", SelectedItem); raiseSelectedItemChanged (); } + + void onExpandAll_MouseClick (object sender, MouseButtonEventArgs e) + { + ExpandAll (); + } + + public void ExpandAll(){ + foreach (Group grp in items.Children) { + foreach (GraphicObject go in grp.Children) { + Expandable exp = go as Expandable; + if (exp == null) + continue; + TreeView subTV = exp.FindByName ("List") as TreeView; + if (subTV == null) + continue; + EventHandler handler = null; + handler = delegate(object sender, EventArgs e) { + TreeView tv = sender as TreeView; + tv.Loaded -= handler; + tv.ExpandAll (); + }; + subTV.Loaded += handler; + exp.IsExpanded = true; + } + } + } } } diff --git a/src/Interface.cs b/src/Interface.cs index 6b859dbe..565e6ab4 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -142,6 +142,7 @@ namespace Crow public static Dictionary Instantiators = new Dictionary(); public bool DesignMode = false; public int TopWindows = 0;//window always on top count + public List CrowThreads = new List();//used to monitor thread finished #endregion #region Private Fields @@ -302,7 +303,7 @@ namespace Crow /// Widget is focused and button is down or another perif action is occuring /// , it can not lose focus while Active - public GraphicObject activeWidget + public GraphicObject ActiveWidget { get { return _activeWidget; } set @@ -394,6 +395,13 @@ namespace Crow _focusedWidget.onKeyDown (this, lastKeyDownEvt); } } + CrowThread[] tmpThreads; + lock (CrowThreads) { + tmpThreads = new CrowThread[CrowThreads.Count]; + Array.Copy (CrowThreads.ToArray (), tmpThreads, CrowThreads.Count); + } + for (int i = 0; i < tmpThreads.Length; i++) + tmpThreads [i].CheckState (); if (!Monitor.TryEnter (UpdateMutex)) return; @@ -535,14 +543,15 @@ namespace Crow #region GraphicTree handling /// Add widget to the Graphic tree of this interface and register it for layouting - public void AddWidget(GraphicObject g) + public void AddWidget(GraphicObject g, bool topMost = false) { g.Parent = this; int ptr = TopWindows; if (g is Window) { if ((g as Window).AlwaysOnTop) ptr = 0; - } + } else if (topMost) + ptr = 0; GraphicTree.Insert (ptr, g); g.RegisteredLayoutings = LayoutingType.None; g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); @@ -554,12 +563,18 @@ namespace Crow GraphicTree.Remove (g); } /// Put widget on top of other root widgets - public void PutOnTop(GraphicObject g) + public void PutOnTop(GraphicObject g, bool topMost = false) { - if (GraphicTree.IndexOf(g) > TopWindows) + int ptr = TopWindows; + if (g is Window) { + if ((g as Window).AlwaysOnTop) + ptr = 0; + } else if (topMost) + ptr = 0; + if (GraphicTree.IndexOf(g) > ptr) { GraphicTree.Remove(g); - GraphicTree.Insert(TopWindows, g); + GraphicTree.Insert(ptr, g); EnqueueForRepaint (g); } } @@ -634,10 +649,10 @@ namespace Crow MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY); e.Mouse = Mouse; - if (activeWidget != null) { + if (ActiveWidget != null) { //TODO, ensure object is still in the graphic tree //send move evt even if mouse move outside bounds - activeWidget.onMouseMove (this, e); + ActiveWidget.onMouseMove (this, e); return true; } @@ -717,7 +732,7 @@ namespace Crow } _activeWidget.onMouseUp (_activeWidget, e); - activeWidget = null; + ActiveWidget = null; return true; } public bool ProcessMouseButtonDown(int button) -- cgit v1.3.1-4-g156e