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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 774 - (hide annotations) (download)
Thu Jun 20 22:33:04 2013 UTC (7 years, 10 months ago) by william
File size: 3567 byte(s)

1 william 767 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Linq;
7     using System.Text;
8     using System.Windows.Forms;
9     using WeifenLuo.WinFormsUI.Docking;
10 william 774 using RomCheater.Core;
11 william 767
12     namespace RomCheater.ScratchPad
13     {
14 william 769 public partial class ScratchPadDocument : UserControl
15 william 767 {
16 william 774 public event BaseEventHandler<ControlClosingEventArgs<int>> DocumentClosing;
17    
18 william 769 const string NewDocumentFilename = "New";
19     public ScratchPadDocument() : this(NewDocumentFilename, new TabPage(), 0) { }
20     public ScratchPadDocument(TabPage tp, int index) : this(NewDocumentFilename, tp, index) { }
21     public ScratchPadDocument(int index) : this(NewDocumentFilename, new TabPage(), index) { }
22     public ScratchPadDocument(string documentFilename, TabPage tp, int index)
23 william 767 {
24     InitializeComponent();
25 william 769 this.DocumentFilename = documentFilename;
26     this.DocumentIndex = index;
27     this.DocumentTab = tp;
28     this.DocumentTab.Name = string.Format("tp{0}", this.DocumentIndex);
29     this.DocumentTab.Text = string.Format("{0}{1}", this.DocumentFilename, this.DocumentIndex);
30 william 774 //this.DocumentClosing += new BaseEventHandler<ControlClosingEventArgs<int>>(ScratchPadDocument_DocumentClosing);
31     this.DocumentTab.Controls.Add(this);
32 william 769 }
33 william 767
34 william 774 //void ScratchPadDocument_DocumentClosing(ControlClosingEventArgs<int> e)
35     //{
36     // CloseDocument(this.Disposing);
37     //}
38 william 769
39 william 774
40    
41    
42 william 769 public void OnDocumentQuit()
43 william 767 {
44 william 774 CloseDocument(true);
45     }
46    
47     private void CloseDocument(bool quiting)
48     {
49     if (ShouldAskSave())
50     {
51     SaveDocument();
52     }
53 william 769 var tb = GetParentTabControl();
54 william 774 tb.TabPages.RemoveAt(this.DocumentIndex);
55     if (this.DocumentClosing != null && !quiting)
56     {
57     this.DocumentClosing.Invoke(new ControlClosingEventArgs<int>(this, this.DocumentIndex));
58     }
59 william 767 }
60    
61 william 774 private bool ShouldAskSave()
62     {
63     bool shouldAskSave = false;
64     return shouldAskSave;
65     }
66    
67     private void SaveDocument()
68     {
69     }
70    
71 william 767 private string _DocumentFilename;
72     public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } }
73 william 769 private TabPage _DocumentTab;
74     public TabPage DocumentTab { get { return _DocumentTab; } set { _DocumentTab = value; } }
75 william 767 private int _DocumentIndex;
76     public int DocumentIndex { get { return _DocumentIndex; } set { _DocumentIndex = value; } }
77 william 769
78     private TabControl GetParentTabControl()
79     {
80     var parent = this.DocumentTab.Parent;
81     TabControl tb = (parent as TabControl);
82     if (tb == null)
83     {
84     throw new ArgumentNullException("parent", string.Format("The parent of tabpage '{0}' cannot be null", DocumentTab.Name));
85     }
86     else
87     {
88     return tb;
89     }
90     }
91 william 774
92     private void mnuItemOpen_Click(object sender, EventArgs e)
93     {
94    
95     }
96    
97     private void mnuItemSave_Click(object sender, EventArgs e)
98     {
99    
100     }
101    
102     private void mnuItemClose_Click(object sender, EventArgs e)
103     {
104     CloseDocument(false);
105     }
106 william 767 }
107     }

  ViewVC Help
Powered by ViewVC 1.1.22