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 773 by william, Thu Jun 20 21:34:48 2013 UTC vs.
Revision 774 by william, Thu Jun 20 22:33:04 2013 UTC

--- trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 22:03:10	773
+++ trunk/RomCheater.ScratchPad/ScratchPadDocument.cs	2013/06/20 22:33:04	774
@@ -7,11 +7,14 @@ using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using WeifenLuo.WinFormsUI.Docking;
+using RomCheater.Core;
 
 namespace RomCheater.ScratchPad
 {
     public partial class ScratchPadDocument : UserControl
     {
+        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) { }
@@ -24,12 +27,45 @@ namespace RomCheater.ScratchPad
             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);
+        }
+
+        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));
+            }
+        }
+
+        private bool ShouldAskSave()
+        {
+            bool shouldAskSave = false;
+            return shouldAskSave;
+        }
+
+        private void SaveDocument()
+        {
         }
 
         private string _DocumentFilename;
@@ -52,5 +88,20 @@ namespace RomCheater.ScratchPad
                 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);
+        }
     }
 }