/[RomCheater]/trunk/RomCheater.ScratchPad/ScratchPadDocument.cs
ViewVC logotype

Diff of /trunk/RomCheater.ScratchPad/ScratchPadDocument.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 20:43:46	767
+++ trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 22:33:04	774
@@ -7,29 +7,101 @@
 using System.Text;
 using System.Windows.Forms;
 using WeifenLuo.WinFormsUI.Docking;
+using RomCheater.Core;
 
 namespace RomCheater.ScratchPad
 {
-    public partial class ScratchPadDocument : DockContent
+    public partial class ScratchPadDocument : UserControl
     {
-       
-        public ScratchPadDocument()
+        public event BaseEventHandler<ControlClosingEventArgs<int>> DocumentClosing;
+
+        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 = documentFilename;
+            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);
+            //this.DocumentClosing += new BaseEventHandler<ControlClosingEventArgs<int>>(ScratchPadDocument_DocumentClosing);
+            this.DocumentTab.Controls.Add(this);
+        }
+
+        //void ScratchPadDocument_DocumentClosing(ControlClosingEventArgs<int> e)
+        //{
+        //    CloseDocument(this.Disposing);
+        //}
+
+
+        
+
+        public void OnDocumentQuit()
+        {
+            CloseDocument(true);
+        }
 
-            this.DocumentFilename = "New1";
-            this.DocumentIndex = 0;
+        private void CloseDocument(bool quiting)
+        {
+            if (ShouldAskSave())
+            {
+                SaveDocument();
+            }
+            var tb = GetParentTabControl();
+            tb.TabPages.RemoveAt(this.DocumentIndex);
+            if (this.DocumentClosing != null && !quiting)
+            {
+                this.DocumentClosing.Invoke(new ControlClosingEventArgs<int>(this, this.DocumentIndex));
+            }
         }
-        public ScratchPadDocument(string documentFilename, int documentInex) : this()
+
+        private bool ShouldAskSave()
         {
-            this.DocumentFilename = documentFilename;
-            this.DocumentIndex = documentInex;
+            bool shouldAskSave = false;
+            return shouldAskSave;
         }
 
+        private void SaveDocument()
+        {
+        }
 
         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;
+            }
+        }
+
+        private void mnuItemOpen_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private void mnuItemSave_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private void mnuItemClose_Click(object sender, EventArgs e)
+        {
+            CloseDocument(false);
+        }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22