51 |
|
|
52 |
|
private bool ShouldAskSave() |
53 |
|
{ |
54 |
< |
bool shouldAskSave = false; |
55 |
< |
return shouldAskSave; |
54 |
> |
return !DocumentSaved; |
55 |
|
} |
56 |
|
|
57 |
< |
|
57 |
> |
|
58 |
> |
private bool _DocumentSaved; |
59 |
> |
public bool DocumentSaved { get { return _DocumentSaved; } private set { _DocumentSaved = value; } } |
60 |
> |
|
61 |
|
private string _DocumentFilename; |
62 |
|
public string DocumentFilename { get { return _DocumentFilename; } set { _DocumentFilename = value; } } |
63 |
|
private TabPage _DocumentTab; |
65 |
|
private int _DocumentIndex; |
66 |
|
public int DocumentIndex { get { return _DocumentIndex; } set { _DocumentIndex = value; } } |
67 |
|
|
68 |
+ |
private void UpdateTabName(string name) |
69 |
+ |
{ |
70 |
+ |
this.DocumentTab.Text = name; |
71 |
+ |
} |
72 |
|
private TabControl GetParentTabControl() |
73 |
|
{ |
74 |
|
var parent = this.DocumentTab.Parent; |
123 |
|
SyntaxLanguage language = SyntaxLanguage.Text; |
124 |
|
CodeEditorSyntaxLoader.SetSyntax(txtEditor, language); |
125 |
|
txtEditor.Document.ReParse(); |
126 |
+ |
this.UpdateTabName(fi.Name); |
127 |
|
} |
128 |
|
catch (Exception ex) |
129 |
|
{ |
148 |
|
{ |
149 |
|
DialogResult result = FileSaver.ShowDialog(); |
150 |
|
if (result != DialogResult.OK) return; |
151 |
+ |
FileInfo fi = new FileInfo(FileSaver.FileName); |
152 |
+ |
try |
153 |
+ |
{ |
154 |
+ |
using (FileStream fs = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) |
155 |
+ |
{ |
156 |
+ |
try |
157 |
+ |
{ |
158 |
+ |
using (StreamWriter sw = new StreamWriter(fs)) |
159 |
+ |
{ |
160 |
+ |
try |
161 |
+ |
{ |
162 |
+ |
foreach (var t in txtEditor.Document.Lines) |
163 |
+ |
{ |
164 |
+ |
sw.WriteLine(t); |
165 |
+ |
} |
166 |
+ |
sw.Flush(); |
167 |
+ |
sw.Close(); |
168 |
+ |
this.DocumentSaved = true; |
169 |
+ |
} |
170 |
+ |
catch (Exception ex) |
171 |
+ |
{ |
172 |
+ |
throw ex; |
173 |
+ |
} |
174 |
+ |
} |
175 |
+ |
} |
176 |
+ |
catch (Exception ex) |
177 |
+ |
{ |
178 |
+ |
throw ex; |
179 |
+ |
} |
180 |
+ |
} |
181 |
+ |
} |
182 |
+ |
catch (Exception ex) |
183 |
+ |
{ |
184 |
+ |
this.DocumentSaved = false; |
185 |
+ |
MessageBox.Show(string.Format("Failed to save: '{0}'", fi.Name), "", MessageBoxButtons.OK, MessageBoxIcon.Error); |
186 |
+ |
logger.Error.WriteLine("Failed to save: '{0}'", fi.FullName); |
187 |
+ |
logger.Error.WriteLine(ex.ToString()); |
188 |
+ |
} |
189 |
|
} |
190 |
|
|
191 |
|
private void CloseDocument(bool quiting) |
201 |
|
this.DocumentClosing.Invoke(new ControlClosingEventArgs<int>(this, this.DocumentIndex)); |
202 |
|
} |
203 |
|
} |
204 |
+ |
|
205 |
+ |
private void txtEditor_TextChanged(object sender, EventArgs e) |
206 |
+ |
{ |
207 |
+ |
this.DocumentSaved = false; |
208 |
+ |
} |
209 |
|
} |
210 |
|
} |