8 |
using System.Windows.Forms; |
using System.Windows.Forms; |
9 |
using WeifenLuo.WinFormsUI.Docking; |
using WeifenLuo.WinFormsUI.Docking; |
10 |
using RomCheater.Core; |
using RomCheater.Core; |
11 |
|
using System.IO; |
12 |
|
using RomCheater.Logging; |
13 |
|
using Fireball.CodeEditor.SyntaxFiles; |
14 |
|
|
15 |
namespace RomCheater.ScratchPad |
namespace RomCheater.ScratchPad |
16 |
{ |
{ |
47 |
CloseDocument(true); |
CloseDocument(true); |
48 |
} |
} |
49 |
|
|
50 |
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)); |
|
|
} |
|
|
} |
|
51 |
|
|
52 |
private bool ShouldAskSave() |
private bool ShouldAskSave() |
53 |
{ |
{ |
55 |
return shouldAskSave; |
return shouldAskSave; |
56 |
} |
} |
57 |
|
|
58 |
private void SaveDocument() |
|
|
{ |
|
|
} |
|
|
|
|
59 |
private string _DocumentFilename; |
private string _DocumentFilename; |
60 |
public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } } |
public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } } |
61 |
private TabPage _DocumentTab; |
private TabPage _DocumentTab; |
79 |
|
|
80 |
private void mnuItemOpen_Click(object sender, EventArgs e) |
private void mnuItemOpen_Click(object sender, EventArgs e) |
81 |
{ |
{ |
82 |
|
OpenDocument(); |
83 |
} |
} |
84 |
|
|
85 |
private void mnuItemSave_Click(object sender, EventArgs e) |
private void mnuItemSave_Click(object sender, EventArgs e) |
86 |
{ |
{ |
87 |
|
SaveDocument(); |
88 |
} |
} |
89 |
|
|
90 |
private void mnuItemClose_Click(object sender, EventArgs e) |
private void mnuItemClose_Click(object sender, EventArgs e) |
91 |
{ |
{ |
92 |
CloseDocument(false); |
CloseDocument(false); |
93 |
} |
} |
94 |
|
|
95 |
|
|
96 |
|
private void OpenDocument() |
97 |
|
{ |
98 |
|
DialogResult result = FileLoader.ShowDialog(); |
99 |
|
if (result != DialogResult.OK) return; |
100 |
|
FileInfo fi = new FileInfo(FileLoader.FileName); |
101 |
|
try |
102 |
|
{ |
103 |
|
|
104 |
|
using (FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) |
105 |
|
{ |
106 |
|
try |
107 |
|
{ |
108 |
|
using (StreamReader sr = new StreamReader(fs)) |
109 |
|
{ |
110 |
|
try |
111 |
|
{ |
112 |
|
var text = sr.ReadToEnd(); |
113 |
|
sr.Close(); |
114 |
|
|
115 |
|
txtEditor.Document = new Fireball.Syntax.SyntaxDocument(); |
116 |
|
txtEditor.Document.Text = text; |
117 |
|
SyntaxLanguage language = SyntaxLanguage.Text; |
118 |
|
CodeEditorSyntaxLoader.SetSyntax(txtEditor, language); |
119 |
|
txtEditor.Document.ReParse(); |
120 |
|
} |
121 |
|
catch (Exception ex) |
122 |
|
{ |
123 |
|
throw ex; |
124 |
|
} |
125 |
|
} |
126 |
|
} |
127 |
|
catch (Exception ex) |
128 |
|
{ |
129 |
|
throw ex; |
130 |
|
} |
131 |
|
} |
132 |
|
} |
133 |
|
catch (Exception ex) |
134 |
|
{ |
135 |
|
MessageBox.Show(string.Format("Failed to open: '{0}'", fi.Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error); |
136 |
|
logger.Error.WriteLine("Failed to open: '{0}'", fi.FullName); |
137 |
|
logger.Error.WriteLine(ex.ToString()); |
138 |
|
} |
139 |
|
} |
140 |
|
private void SaveDocument() |
141 |
|
{ |
142 |
|
DialogResult result = FileSaver.ShowDialog(); |
143 |
|
if (result != DialogResult.OK) return; |
144 |
|
} |
145 |
|
|
146 |
|
private void CloseDocument(bool quiting) |
147 |
|
{ |
148 |
|
if (ShouldAskSave()) |
149 |
|
{ |
150 |
|
SaveDocument(); |
151 |
|
} |
152 |
|
var tb = GetParentTabControl(); |
153 |
|
tb.TabPages.RemoveAt(this.DocumentIndex); |
154 |
|
if (this.DocumentClosing != null && !quiting) |
155 |
|
{ |
156 |
|
this.DocumentClosing.Invoke(new ControlClosingEventArgs<int>(this, this.DocumentIndex)); |
157 |
|
} |
158 |
|
} |
159 |
} |
} |
160 |
} |
} |