ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.ScratchPad/ScratchPadDocument.cs
Revision: 774
Committed: Thu Jun 20 22:33:04 2013 UTC (10 years, 3 months ago) by william
File size: 3567 byte(s)
Log Message:

File Contents

# Content
1 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 using RomCheater.Core;
11
12 namespace RomCheater.ScratchPad
13 {
14 public partial class ScratchPadDocument : UserControl
15 {
16 public event BaseEventHandler<ControlClosingEventArgs<int>> DocumentClosing;
17
18 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 {
24 InitializeComponent();
25 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 //this.DocumentClosing += new BaseEventHandler<ControlClosingEventArgs<int>>(ScratchPadDocument_DocumentClosing);
31 this.DocumentTab.Controls.Add(this);
32 }
33
34 //void ScratchPadDocument_DocumentClosing(ControlClosingEventArgs<int> e)
35 //{
36 // CloseDocument(this.Disposing);
37 //}
38
39
40
41
42 public void OnDocumentQuit()
43 {
44 CloseDocument(true);
45 }
46
47 private void CloseDocument(bool quiting)
48 {
49 if (ShouldAskSave())
50 {
51 SaveDocument();
52 }
53 var tb = GetParentTabControl();
54 tb.TabPages.RemoveAt(this.DocumentIndex);
55 if (this.DocumentClosing != null && !quiting)
56 {
57 this.DocumentClosing.Invoke(new ControlClosingEventArgs<int>(this, this.DocumentIndex));
58 }
59 }
60
61 private bool ShouldAskSave()
62 {
63 bool shouldAskSave = false;
64 return shouldAskSave;
65 }
66
67 private void SaveDocument()
68 {
69 }
70
71 private string _DocumentFilename;
72 public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } }
73 private TabPage _DocumentTab;
74 public TabPage DocumentTab { get { return _DocumentTab; } set { _DocumentTab = value; } }
75 private int _DocumentIndex;
76 public int DocumentIndex { get { return _DocumentIndex; } set { _DocumentIndex = value; } }
77
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
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 }
107 }