Ignore:
Timestamp:
Sep 2, 2010, 4:38:18 PM (11 years ago)
Author:
kopal
Message:
  • removed Parent because it did not work well (have to implement new Parent concept)
  • TextModels (RichTextBox) data is now saved/loaded
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Model/TextModel.cs

    r1892 r1895  
    33using System.Linq;
    44using System.Text;
     5using System.IO;
     6using System.Windows.Documents;
     7using System.Windows.Controls;
    58
    69namespace WorkspaceManager.Model
     
    1215    public class TextModel : VisualElementModel
    1316    {
    14         private string text = null;
     17        private byte[] data = null;
    1518
    1619        /// <summary>
     
    1922        public TextModel()
    2023        {
    21             this.text = "";
     24           
    2225        }
    2326
     
    2629        /// </summary>
    2730        /// <param name="text"></param>
    28         public TextModel(string text)
     31        public TextModel(byte[] data)
    2932        {
    30             this.text = text;
     33            this.data = data;
    3134        }
    3235
    3336        /// <summary>
    34         /// Get/Set the text
     37        /// The WorkspaceModel of this TextModel
    3538        /// </summary>
    36         public string Text
    37         {
    38             get { return this.text; }
    39             set { this.text = value; }
     39        public WorkspaceModel WorkspaceModel { get; set; }
     40
     41        /// <summary>
     42        /// Loads the Content of this TextModel to the given RichtTextBox
     43        /// </summary>
     44        /// <param name="rtb"></param>
     45        public void loadRTB(RichTextBox rtb){
     46           
     47            if (data == null)
     48            {
     49                return;
     50            }
     51
     52            MemoryStream memoryStream = new MemoryStream(data);
     53            FlowDocument flowDocument = new FlowDocument();
     54            TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
     55            textRange.Load(memoryStream, System.Windows.DataFormats.XamlPackage);
     56            rtb.Document = flowDocument;           
     57        }
     58
     59        /// <summary>
     60        /// Save the Content of the given RichTextBox to this TextModel
     61        /// </summary>
     62        /// <param name="rtb"></param>
     63        public void saveRTB(RichTextBox rtb){
     64
     65            if (rtb.Document.Blocks.Count == 0)
     66            {
     67                return;
     68            }
     69
     70            MemoryStream memoryStream = new MemoryStream();
     71            TextRange textRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
     72            textRange.Save(memoryStream, System.Windows.DataFormats.XamlPackage);
     73
     74            data = new byte[memoryStream.Length];
     75            data = memoryStream.ToArray();
     76            memoryStream.Close();
     77           
    4078        }
    4179
Note: See TracChangeset for help on using the changeset viewer.