]> O.S.I.I.S - jp/crow.git/commitdiff
CrowThread;AlwaysOnTop win;GTree explorer;
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 25 Jan 2017 08:25:14 +0000 (09:25 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 25 Jan 2017 08:25:14 +0000 (09:25 +0100)
Crow.csproj
src/CrowThread.cs [new file with mode: 0644]
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Popper.cs
src/GraphicObjects/TemplatedGroup.cs
src/GraphicObjects/TreeView.cs
src/Interface.cs

index 13a0a351d2624fba7418dd6d9316cf542d5f9c8b..25e7f10dc4d5e609580ed87d9f5bc277400c67ce 100644 (file)
     <Compile Include="src\IML\EventBinding.cs" />
     <Compile Include="src\PerformanceMeasure.cs" />
     <Compile Include="src\IML\BindingMember.cs" />
+    <Compile Include="src\CrowThread.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
diff --git a/src/CrowThread.cs b/src/CrowThread.cs
new file mode 100644 (file)
index 0000000..dfdeda0
--- /dev/null
@@ -0,0 +1,58 @@
+//
+//  CrowThread.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  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 <http://www.gnu.org/licenses/>.
+using System;
+using System.Threading;
+
+namespace Crow
+{
+       /// <summary>
+       /// Thread monitored by current interface with Finished event when state==Stopped
+       /// </summary>
+       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);
+               }
+       }
+}
+
index a2d78d88be345453e5bc766c01be9e189732b210..0636c14e457a90773f41c70cccb04292132534a4 100644 (file)
@@ -29,6 +29,7 @@ namespace Crow
                                        return;
                                _spacing = value; 
                                NotifyValueChanged ("Spacing", Spacing);
+                               RegisterForLayouting (LayoutingType.Sizing|LayoutingType.ArrangeChildren);
                        }
         }
         [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
index 070a221a6abb711fd2cdc1102b62f3f985d4cc2e..1e8bfcf99fd8380253de77d87a9fbfd28823834d 100644 (file)
@@ -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) {
index 3862133710b95208d0994a21ab1eb050ee1b7b42..84088355e767bae43f18e0931c0ee3e4027f3b0d 100644 (file)
@@ -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);
                }
        }
index ee799fd02fc732dfcf87e47d531b7a286943cc46..a1941f06b10c84cb351f98fe0a1fad04b78ce7f3 100644 (file)
@@ -40,6 +40,7 @@ namespace Crow
 
                #region events
                public event EventHandler<SelectionChangeEventArgs> 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 ();
index 4fa881b4e0e3c08bc73308f6e724e919776e5faa..d4354b65b97fdf7b323ea7a198904f8163da42c2 100644 (file)
@@ -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;
+                               }
+                       }
+               }
        }
 }
 
index 6b859dbedda4df1e8ce03398407489cfe68d68a6..565e6ab4985635582e6755cb8d4817fc09b7da6e 100644 (file)
@@ -142,6 +142,7 @@ namespace Crow
                public static Dictionary<String, Instantiator> Instantiators = new Dictionary<string, Instantiator>();
                public bool DesignMode = false;
                public int TopWindows = 0;//window always on top count
+               public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished
                #endregion
 
                #region Private Fields
@@ -302,7 +303,7 @@ namespace Crow
 
                /// <summary>Widget is focused and button is down or another perif action is occuring
                /// , it can not lose focus while Active</summary>
-               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
                /// <summary>Add widget to the Graphic tree of this interface and register it for layouting</summary>
-               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);
                }
                /// <summary> Put widget on top of other root widgets</summary>
-               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)