]> O.S.I.I.S - jp/crow.git/commitdiff
IMLStream
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 3 Aug 2016 10:37:04 +0000 (12:37 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 3 Aug 2016 10:37:04 +0000 (12:37 +0200)
Crow.csproj
src/GraphicObjects/ListBox.cs
src/IMLStream.cs [new file with mode: 0644]
src/Interface.cs

index ad8ce32f97bbb2d61f2cd7d039cef17292e4d02c..611ad9189ed5447652af1997b9c74086d737c660 100644 (file)
     <Compile Include="src\CompilerServices\MemberReference.cs" />
     <Compile Include="src\CompilerServices\Bindings.cs" />
     <Compile Include="src\StyleReader.cs" />
+    <Compile Include="src\IMLStream.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
index 0543a0b2e8277301034f5bd39b01bc563e054825..e7a1c3304f25fe9d29fa821c4794a774d2e280b6 100644 (file)
@@ -22,7 +22,6 @@ using System;
 using System.Collections;
 using System.Xml.Serialization;
 using System.ComponentModel;
-//TODO: implement ItemTemplate node in xml
 using System.IO;
 using System.Diagnostics;
 using System.Xml;
@@ -47,12 +46,12 @@ namespace Crow
                IList data;
                int _selectedIndex;
                string _itemTemplate;
-               int itemPerPage = 20;
-               MemoryStream templateStream = null;
-               Type templateBaseType = null;
+               int itemPerPage = 50;
                Thread loadingThread = null;
                volatile bool cancelLoading = false;
 
+               IMLStream templateStream = null;
+
                [XmlAttributeAttribute]public IList Data {
                        get {
                                return data;
@@ -133,12 +132,7 @@ namespace Crow
                }
                #endregion
                void loading(){                 
-                       lock (Interface.CurrentInterface.UpdateMutex) {
-                               templateStream = new MemoryStream ();
-                               using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
-                                       stream.CopyTo (templateStream);
-                               templateBaseType = Interface.GetTopContainerOfXMLStream (templateStream);
-                       }
+                       templateStream = new IMLStream (ItemTemplate);
                        for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
                                if (cancelLoading)
                                        return;
@@ -180,8 +174,8 @@ namespace Crow
                                        break;
                                if (cancelLoading)
                                        return;
-                               templateStream.Seek (0, SeekOrigin.Begin);
-                               GraphicObject g = Interface.Load (templateStream, templateBaseType);
+
+                               GraphicObject g = Interface.Load (templateStream);
                                g.MouseClick += itemClick;
 
                                lock (Interface.CurrentInterface.UpdateMutex)
diff --git a/src/IMLStream.cs b/src/IMLStream.cs
new file mode 100644 (file)
index 0000000..6935779
--- /dev/null
@@ -0,0 +1,35 @@
+//
+//  IMLStream.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2016 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.IO;
+
+namespace Crow
+{
+       public class IMLStream : MemoryStream {
+               public Type RootType;
+               public IMLStream(string path) : base (){                        
+                       using (Stream stream = Interface.GetStreamFromPath (path))
+                               stream.CopyTo (this);
+                       RootType = Interface.GetTopContainerOfXMLStream (this);
+               }
+       }
+}
+
index 607044d9c6e471a264ec25d5b467efb113ba0ddf..208bd2a4adb3165613c3e6db08d726870874f6df 100644 (file)
@@ -232,6 +232,10 @@ namespace Crow
 
                        return tmp;
                }
+               internal static GraphicObject Load (IMLStream stream, object hostClass = null){
+                       stream.Seek (0, SeekOrigin.Begin);
+                       return Load(stream, stream.RootType, hostClass);
+               }
                internal static GraphicObject Load (Stream stream, Type type, object hostClass = null)
                {
                        #if DEBUG_LOAD