ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.ScratchPad/ScratchPadDocument.cs
(Generate patch)

Comparing trunk/RomCheater.ScratchPad/ScratchPadDocument.cs (file contents):
Revision 767 by william, Thu Jun 20 20:43:46 2013 UTC vs.
Revision 769 by william, Thu Jun 20 21:34:48 2013 UTC

--- trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 20:43:46	767
+++ trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 21:34:48	769
@@ -10,26 +10,47 @@ using WeifenLuo.WinFormsUI.Docking;
 
 namespace RomCheater.ScratchPad
 {
-    public partial class ScratchPadDocument : DockContent
+    public partial class ScratchPadDocument : UserControl
     {
-       
-        public ScratchPadDocument()
+        const string NewDocumentFilename = "New";
+        public ScratchPadDocument() : this(NewDocumentFilename, new TabPage(), 0) { }
+        public ScratchPadDocument(TabPage tp, int index) : this(NewDocumentFilename, tp, index) { }
+        public ScratchPadDocument(int index) : this(NewDocumentFilename, new TabPage(), index) { }
+        public ScratchPadDocument(string documentFilename, TabPage tp, int index)
         {
             InitializeComponent();
-
-            this.DocumentFilename = "New1";
-            this.DocumentIndex = 0;
-        }
-        public ScratchPadDocument(string documentFilename, int documentInex) : this()
-        {
             this.DocumentFilename = documentFilename;
-            this.DocumentIndex = documentInex;
+            this.DocumentIndex = index;
+            this.DocumentTab = tp;
+            this.DocumentTab.Name = string.Format("tp{0}", this.DocumentIndex);
+            this.DocumentTab.Text = string.Format("{0}{1}", this.DocumentFilename, this.DocumentIndex);
         }
 
 
+        public void OnDocumentQuit()
+        {
+            var tb = GetParentTabControl();
+        }
+
         private string _DocumentFilename;
         public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } }
+        private TabPage _DocumentTab;
+        public TabPage DocumentTab { get { return _DocumentTab; } set { _DocumentTab = value; } }
         private int _DocumentIndex;
         public int DocumentIndex { get { return _DocumentIndex; } set { _DocumentIndex = value; } }
+
+        private TabControl GetParentTabControl()
+        {
+            var parent = this.DocumentTab.Parent;
+            TabControl tb = (parent as TabControl);
+            if (tb == null)
+            {
+                throw new ArgumentNullException("parent", string.Format("The parent of tabpage '{0}' cannot be null", DocumentTab.Name));
+            }
+            else
+            {
+                return tb;
+            }
+        }
     }
 }