~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields, 1840cc1
  • Date: 2012-02-05 10:49:36 UTC
  • mfrom: (10.2.12)
  • Revision ID: package-import@ubuntu.com-20120205104936-f3dutq6lnseokb6d
Tags: 2.8.6.3+dfsg-1
[1840cc1] Imported Upstream version 2.8.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
917
917
                                entry.Execute (monitor, context, IdeApp.Workspace.ActiveConfiguration);
918
918
                        } catch (Exception ex) {
919
919
                                monitor.ReportError (GettextCatalog.GetString ("Execution failed."), ex);
 
920
                                LoggingService.LogError ("Execution failed", ex);
920
921
                        } finally {
921
922
                                monitor.Dispose ();
922
923
                        }
1141
1142
                                        BuildDone (monitor, result, entry, tt); // BuildDone disposes the monitor
1142
1143
                        });
1143
1144
                }
 
1145
                
 
1146
                // Note: This must run in the main thread
 
1147
                void PromptForSave (BuildResult result)
 
1148
                {
 
1149
                        var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
 
1150
                        
 
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);
 
1157
                                                doc.Save ();
 
1158
                                                if (doc.IsDirty)
 
1159
                                                        result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
 
1160
                                        } else
 
1161
                                                break;
 
1162
                                }
 
1163
                        }
 
1164
                }
 
1165
                
 
1166
                // Note: This must run in the main thread
 
1167
                void SaveAllFiles (BuildResult result)
 
1168
                {
 
1169
                        var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
 
1170
                        
 
1171
                        foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents)) {
 
1172
                                if (doc.IsDirty && doc.Project != null) {
 
1173
                                        doc.Save ();
 
1174
                                        if (doc.IsDirty)
 
1175
                                                result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
 
1176
                                }
 
1177
                        }
 
1178
                }
1144
1179
 
1145
1180
                BuildResult DoBeforeCompileAction ()
1146
1181
                {
 
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;
1150
1184
                        
1151
1185
                        switch (action) {
1152
 
                                case BeforeCompileAction.Nothing:
1153
 
                                        break;
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);
1162
 
                                                                doc.Save ();
1163
 
                                                                if (doc.IsDirty)
1164
 
                                                                        result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1165
 
                                                        }
1166
 
                                                        else
1167
 
                                                                break;
1168
 
                                                }
1169
 
                                        }
1170
 
                                        break;
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) {
1174
 
                                                        doc.Save ();
1175
 
                                                        if (doc.IsDirty)
1176
 
                                                                result.AddError (string.Format (couldNotSaveError, Path.GetFileName (doc.FileName)), doc.FileName);
1177
 
                                                }
1178
 
                                        break;
1179
 
                                default:
1180
 
                                        System.Diagnostics.Debug.Assert(false);
1181
 
                                        break;
 
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;
1182
1190
                        }
1183
1191
                        
1184
1192
                        return result;
1429
1437
                                        
1430
1438
                                        string fileBuildAction = buildAction;
1431
1439
                                        if (string.IsNullOrEmpty (buildAction))
1432
 
                                                fileBuildAction = project.GetDefaultBuildAction (file);
 
1440
                                                fileBuildAction = project.GetDefaultBuildAction (targetPath);
1433
1441
                                        
1434
1442
                                        //files in the target directory get added directly in their current location without moving/copying
1435
1443
                                        if (file.CanonicalPath == targetPath) {
1473
1481
                                                }
1474
1482
                                                
1475
1483
                                                if (action == AddAction.Link) {
1476
 
                                                        //FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file
1477
 
                                                        ProjectFile pf;
1478
 
                                                        if (filesInProject.TryGetValue (file, out pf)) {
1479
 
                                                                var link = pf.Link;
1480
 
                                                                MessageService.ShowWarning (GettextCatalog.GetString (
1481
 
                                                                        "The link '{0}' in the project already includes the file '{1}'", link, file));
1482
 
                                                                continue;
1483
 
                                                        }
1484
 
                                                        
1485
 
                                                        pf = new ProjectFile (file, fileBuildAction) {
 
1484
                                                        ProjectFile pf = new ProjectFile (file, fileBuildAction) {
1486
1485
                                                                Link = vpath
1487
1486
                                                        };
1488
1487
                                                        vpathsInProject.Add (pf.ProjectVirtualPath);
1914
1913
                class ProviderProxy : ITextEditorDataProvider, IEditableTextFile
1915
1914
                {
1916
1915
                        TextEditorData data;
1917
 
                        public ProviderProxy (TextEditorData data)
 
1916
                        string encoding;
 
1917
                        bool bom;
 
1918
                        
 
1919
                        public ProviderProxy (TextEditorData data, string encoding, bool bom)
1918
1920
                        {
1919
1921
                                this.data = data;
 
1922
                                this.encoding = encoding;
 
1923
                                this.bom = bom;
1920
1924
                        }
1921
1925
 
1922
1926
                        public TextEditorData GetTextEditorData ()
1924
1928
                                return data;
1925
1929
                        }
1926
1930
                        
 
1931
                        void Save ()
 
1932
                        {
 
1933
                                TextFile.WriteFile (Name, Text, encoding, bom);
 
1934
                        }
 
1935
                        
1927
1936
                        #region IEditableTextFile implementation
1928
1937
                        public FilePath Name { get { return data.Document.FileName; } }
1929
1938
 
1933
1942
                        {
1934
1943
                                return data.GetTextBetween (startPosition, endPosition);
1935
1944
                        }
 
1945
                        
1936
1946
                        public char GetCharAt (int position)
1937
1947
                        {
1938
1948
                                return data.GetCharAt (position);
1953
1963
                        public int InsertText (int position, string text)
1954
1964
                        {
1955
1965
                                int result = data.Insert (position, text);
1956
 
                                File.WriteAllText (Name, Text);
 
1966
                                Save ();
 
1967
                                
1957
1968
                                return result;
1958
1969
                        }
1959
1970
                        
1960
 
                        
1961
1971
                        public void DeleteText (int position, int length)
1962
1972
                        {
1963
1973
                                data.Remove (position, length);
1964
 
                                File.WriteAllText (Name, Text);
 
1974
                                Save ();
1965
1975
                        }
1966
1976
                        
1967
1977
                        public string Text {
1970
1980
                                }
1971
1981
                                set {
1972
1982
                                        data.Text = value;
 
1983
                                        Save ();
1973
1984
                                }
1974
1985
                        }
1975
1986
                        
1985
1996
                                }
1986
1997
                        }
1987
1998
                        
 
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;
 
2003
                        
 
2004
                        return new ProviderProxy (data, file.SourceEncoding, file.HadBOM);
1992
2005
                }
1993
2006
                
1994
2007
                public TextEditorData GetTextEditorData (FilePath filePath)
2006
2019
                                }
2007
2020
                        }
2008
2021
                        
 
2022
                        TextFile file = TextFile.ReadFile (filePath);
2009
2023
                        TextEditorData data = new TextEditorData ();
2010
2024
                        data.Document.FileName = filePath;
2011
 
                        data.Text = File.ReadAllText (filePath);
 
2025
                        data.Text = file.Text;
2012
2026
                        isOpen = false;
2013
2027
                        return data;
2014
2028
                }