1141
1142
BuildDone (monitor, result, entry, tt); // BuildDone disposes the monitor
1146
// Note: This must run in the main thread
1147
void PromptForSave (BuildResult result)
1149
var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
1151
foreach (var doc in IdeApp.Workbench.Documents) {
1152
if (doc.IsDirty && doc.Project != null) {
1153
if (MessageService.AskQuestion (GettextCatalog.GetString ("Save changed documents before building?"),
1154
GettextCatalog.GetString ("Some of the open documents have unsaved changes."),
1155
AlertButton.BuildWithoutSave, AlertButton.Save) == AlertButton.Save) {
1156
MarkFileDirty (doc.FileName);
1159
result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1166
// Note: This must run in the main thread
1167
void SaveAllFiles (BuildResult result)
1169
var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
1171
foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents)) {
1172
if (doc.IsDirty && doc.Project != null) {
1175
result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1145
1180
BuildResult DoBeforeCompileAction ()
1182
BeforeCompileAction action = IdeApp.Preferences.BeforeBuildSaveAction;
1147
1183
var result = new BuildResult ();
1148
var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
1149
BeforeCompileAction action = IdeApp.Preferences.BeforeBuildSaveAction;
1151
1185
switch (action) {
1152
case BeforeCompileAction.Nothing:
1154
case BeforeCompileAction.PromptForSave:
1155
foreach (var doc in IdeApp.Workbench.Documents) {
1156
if (doc.IsDirty && doc.Project != null) {
1157
if (MessageService.AskQuestion (
1158
GettextCatalog.GetString ("Save changed documents before building?"),
1159
GettextCatalog.GetString ("Some of the open documents have unsaved changes."),
1160
AlertButton.BuildWithoutSave, AlertButton.Save) == AlertButton.Save) {
1161
MarkFileDirty (doc.FileName);
1164
result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1171
case BeforeCompileAction.SaveAllFiles:
1172
foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents))
1173
if (doc.IsDirty && doc.Project != null) {
1176
result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1180
System.Diagnostics.Debug.Assert(false);
1186
case BeforeCompileAction.Nothing: break;
1187
case BeforeCompileAction.PromptForSave: DispatchService.GuiDispatch (delegate { PromptForSave (result); }); break;
1188
case BeforeCompileAction.SaveAllFiles: DispatchService.GuiDispatch (delegate { SaveAllFiles (result); }); break;
1189
default: System.Diagnostics.Debug.Assert (false); break;
1475
1483
if (action == AddAction.Link) {
1476
//FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file
1478
if (filesInProject.TryGetValue (file, out pf)) {
1480
MessageService.ShowWarning (GettextCatalog.GetString (
1481
"The link '{0}' in the project already includes the file '{1}'", link, file));
1485
pf = new ProjectFile (file, fileBuildAction) {
1484
ProjectFile pf = new ProjectFile (file, fileBuildAction) {
1488
1487
vpathsInProject.Add (pf.ProjectVirtualPath);
1953
1963
public int InsertText (int position, string text)
1955
1965
int result = data.Insert (position, text);
1956
File.WriteAllText (Name, Text);
1961
1971
public void DeleteText (int position, int length)
1963
1973
data.Remove (position, length);
1964
File.WriteAllText (Name, Text);
1967
1977
public string Text {
1999
TextFile file = TextFile.ReadFile (filePath);
1988
2000
TextEditorData data = new TextEditorData ();
1989
2001
data.Document.FileName = filePath;
1990
data.Text = File.ReadAllText (filePath);
1991
return new ProviderProxy (data);
2002
data.Text = file.Text;
2004
return new ProviderProxy (data, file.SourceEncoding, file.HadBOM);
1994
2007
public TextEditorData GetTextEditorData (FilePath filePath)