source: trunk/CrypPlugins/WorkspaceManager/Model/TextModel.cs @ 1895

Last change on this file since 1895 was 1895, checked in by kopal, 11 years ago
  • removed Parent because it did not work well (have to implement new Parent concept)
  • TextModels (RichTextBox) data is now saved/loaded
File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using System.Windows.Documents;
7using System.Windows.Controls;
8
9namespace WorkspaceManager.Model
10{
11    /// <summary>
12    /// This class wraps a text which can be put to the workspace
13    /// </summary>
14    [Serializable]
15    public class TextModel : VisualElementModel
16    {
17        private byte[] data = null;
18
19        /// <summary>
20        /// Instantiate a new TextModel
21        /// </summary> 
22        public TextModel()
23        {
24           
25        }
26
27        /// <summary>
28        /// Instantiate a new TextModel
29        /// </summary>
30        /// <param name="text"></param>
31        public TextModel(byte[] data)
32        {
33            this.data = data;
34        }
35
36        /// <summary>
37        /// The WorkspaceModel of this TextModel
38        /// </summary>
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           
78        }
79
80        /// <summary>
81        /// is the image enabled ?
82        /// </summary>
83        private bool isEnabled = true;
84        public bool IsEnabled { get { return isEnabled; } set { isEnabled = value; } }
85    }
86}
Note: See TracBrowser for help on using the repository browser.