From: jpbruyere Date: Wed, 3 Aug 2016 10:37:04 +0000 (+0200) Subject: IMLStream X-Git-Tag: v0.4~18^2~13 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=5e7f9ad632b4c42bee7f111c0155b869e3ae4f18;p=jp%2Fcrow.git IMLStream --- diff --git a/Crow.csproj b/Crow.csproj index ad8ce32f..611ad918 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -134,6 +134,7 @@ + diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 0543a0b2..e7a1c330 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -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 index 00000000..69357791 --- /dev/null +++ b/src/IMLStream.cs @@ -0,0 +1,35 @@ +// +// IMLStream.cs +// +// Author: +// Jean-Philippe Bruyère +// +// 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 . +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); + } + } +} + diff --git a/src/Interface.cs b/src/Interface.cs index 607044d9..208bd2a4 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -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