48
48
using MonoDevelop.Core.Instrumentation;
49
49
using Mono.TextEditor;
50
50
using System.Diagnostics;
51
using ICSharpCode.NRefactory.TypeSystem;
52
51
using ICSharpCode.NRefactory.Documentation;
52
using ICSharpCode.NRefactory.TypeSystem.Implementation;
54
55
namespace MonoDevelop.Ide
157
158
public IAsyncOperation CurrentRunOperation {
158
159
get { return currentRunOperation; }
159
set { currentRunOperation = value ?? NullAsyncOperation.Success; }
161
currentRunOperation = value ?? NullAsyncOperation.Success;
162
OnCurrentRunOperationChanged (EventArgs.Empty);
162
166
public bool IsBuilding (IBuildTarget target)
164
168
return !currentBuildOperation.IsCompleted && ContainsTarget (target, currentBuildOperationOwner);
213
217
return (GetDeclaredFile(item) != null);
216
public bool CanJumpToDeclaration (INamedElement element)
220
public bool CanJumpToDeclaration (object element)
218
var entity = element as IEntity;
219
if (entity == null && element is IType)
220
entity = ((IType)element).GetDefinition ();
222
if (element is ICSharpCode.NRefactory.TypeSystem.IVariable)
224
var entity = element as ICSharpCode.NRefactory.TypeSystem.IEntity;
225
if (entity == null && element is ICSharpCode.NRefactory.TypeSystem.IType)
226
entity = ((ICSharpCode.NRefactory.TypeSystem.IType)element).GetDefinition ();
221
227
if (entity == null)
224
229
if (entity.Region.IsEmpty) {
225
return !string.IsNullOrEmpty (entity.ParentAssembly.UnresolvedAssembly.Location);
230
var parentAssembly = entity.ParentAssembly;
231
if (parentAssembly == null)
233
return !string.IsNullOrEmpty (parentAssembly.UnresolvedAssembly.Location);
231
static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult (IUnresolvedTypeDefinition part)
238
static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult (ICSharpCode.NRefactory.TypeSystem.IUnresolvedTypeDefinition part)
233
240
var provider = new MonoDevelop.Ide.FindInFiles.FileProvider (part.Region.FileName);
234
241
var doc = new Mono.TextEditor.TextDocument ();
242
249
return new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length);
245
public void JumpToDeclaration (INamedElement visitable, bool askIfMultipleLocations = true)
252
public void JumpToDeclaration (ICSharpCode.NRefactory.TypeSystem.INamedElement visitable, bool askIfMultipleLocations = true)
247
254
if (askIfMultipleLocations) {
248
var type = visitable as IType;
255
var type = visitable as ICSharpCode.NRefactory.TypeSystem.IType;
249
256
if (type != null && type.GetDefinition () != null && type.GetDefinition ().Parts.Count > 1) {
250
257
using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) {
251
258
foreach (var part in type.GetDefinition ().Parts)
258
265
JumpToDeclaration (visitable);
261
void JumpToDeclaration (INamedElement element)
268
void JumpToDeclaration (ICSharpCode.NRefactory.TypeSystem.INamedElement element)
263
IEntity entity = element as IEntity;
265
if (entity == null && element is IType)
266
entity = ((IType)element).GetDefinition ();
270
var entity = element as ICSharpCode.NRefactory.TypeSystem.IEntity;
272
if (entity == null && element is ICSharpCode.NRefactory.TypeSystem.IType)
273
entity = ((ICSharpCode.NRefactory.TypeSystem.IType)element).GetDefinition ();
274
if (entity is SpecializedMember)
275
entity = ((SpecializedMember)entity).MemberDefinition;
267
277
if (entity == null) {
268
278
LoggingService.LogError ("Unknown element:" + element);
282
292
if (isCecilProjectContent && doc != null) {
283
293
doc.RunWhenLoaded (delegate {
284
MonoDevelop.Ide.Gui.Content.IUrlHandler handler = doc.ActiveView as MonoDevelop.Ide.Gui.Content.IUrlHandler;
294
var handler = doc.PrimaryView.GetContent<MonoDevelop.Ide.Gui.Content.IUrlHandler> ();
285
295
if (handler != null)
286
296
handler.Open (entity.GetIdString ());
291
public void JumpToDeclaration (IVariable entity)
301
public void JumpToDeclaration (ICSharpCode.NRefactory.TypeSystem.IVariable entity)
293
303
if (entity == null)
294
304
throw new ArgumentNullException ("entity");
295
305
string fileName = entity.Region.FileName;
296
var doc = IdeApp.Workbench.OpenDocument (fileName, entity.Region.BeginLine, entity.Region.BeginColumn);
306
IdeApp.Workbench.OpenDocument (fileName, entity.Region.BeginLine, entity.Region.BeginColumn);
299
309
public void RenameItem (IWorkspaceFileObject item, string newName)
465
475
bool AllowSave (IWorkspaceFileObject item)
467
if (HasChanged (item))
477
if (HasChanged (item)) {
468
478
return MessageService.Confirm (
469
GettextCatalog.GetString ("Some project files have been changed from outside MonoDevelop. Do you want to overwrite them?"),
470
GettextCatalog.GetString ("Changes done in those files will be overwritten by MonoDevelop."),
471
AlertButton.OverwriteFile);
479
GettextCatalog.GetString (
480
"Some project files have been changed from outside {0}. Do you want to overwrite them?",
481
BrandingService.ApplicationName
483
GettextCatalog.GetString (
484
"Changes done in those files will be overwritten by {0}.",
485
BrandingService.ApplicationName
487
AlertButton.OverwriteFile);
476
493
bool HasChanged (IWorkspaceFileObject item)
734
751
if (MessageService.RunCustomDialog (selDialog) == (int)Gtk.ResponseType.Ok) {
735
752
var newRefs = selDialog.ReferenceInformations;
737
ArrayList toDelete = new ArrayList ();
754
var editEventArgs = new EditReferencesEventArgs (project);
738
755
foreach (ProjectReference refInfo in project.References)
739
756
if (!newRefs.Contains (refInfo))
740
toDelete.Add (refInfo);
742
foreach (ProjectReference refInfo in toDelete)
743
project.References.Remove (refInfo);
757
editEventArgs.ReferencesToRemove.Add (refInfo);
745
759
foreach (ProjectReference refInfo in selDialog.ReferenceInformations)
746
760
if (!project.References.Contains (refInfo))
747
project.References.Add(refInfo);
761
editEventArgs.ReferencesToAdd.Add(refInfo);
763
if (BeforeEditReferences != null)
764
BeforeEditReferences (this, editEventArgs);
766
foreach (var reference in editEventArgs.ReferencesToRemove)
767
project.References.Remove (reference);
769
foreach (var reference in editEventArgs.ReferencesToAdd)
770
project.References.Add (reference);
772
return editEventArgs.ReferencesToAdd.Count > 0 || editEventArgs.ReferencesToRemove.Count > 0;
840
863
public bool CanExecute (IBuildTarget entry)
842
ExecutionContext context = new ExecutionContext (Runtime.ProcessService.DefaultExecutionHandler, IdeApp.Workbench.ProgressMonitors);
865
ExecutionContext context = new ExecutionContext (Runtime.ProcessService.DefaultExecutionHandler, IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget);
843
866
return CanExecute (entry, context);
846
869
public bool CanExecute (IBuildTarget entry, IExecutionHandler handler)
848
ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors);
871
ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget);
849
872
return entry.CanExecute (context, IdeApp.Workspace.ActiveConfiguration);
862
885
public IAsyncOperation Execute (IBuildTarget entry, IExecutionHandler handler)
864
ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors);
887
ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors, IdeApp.Workspace.ActiveExecutionTarget);
865
888
return Execute (entry, context);
874
897
DispatchService.ThreadDispatch (delegate {
875
898
ExecuteSolutionItemAsync (monitor, entry, context);
877
currentRunOperation = monitor.AsyncOperation;
900
CurrentRunOperation = monitor.AsyncOperation;
878
901
currentRunOperationOwner = entry;
879
902
currentRunOperation.Completed += delegate {
880
903
DispatchService.GuiDispatch (() => {
1213
1241
string errorString = GettextCatalog.GetPluralString("{0} error", "{0} errors", result.ErrorCount, result.ErrorCount);
1214
1242
string warningString = GettextCatalog.GetPluralString("{0} warning", "{0} warnings", result.WarningCount, result.WarningCount);
1216
if (result.ErrorCount == 0 && result.WarningCount == 0 && lastResult.FailedBuildCount == 0) {
1244
if (monitor.IsCancelRequested) {
1245
monitor.ReportError (GettextCatalog.GetString ("Build canceled."), null);
1246
} else if (result.ErrorCount == 0 && result.WarningCount == 0 && lastResult.FailedBuildCount == 0) {
1217
1247
monitor.ReportSuccess (GettextCatalog.GetString ("Build successful."));
1218
1248
} else if (result.ErrorCount == 0 && result.WarningCount > 0) {
1219
1249
monitor.ReportWarning(GettextCatalog.GetString("Build: ") + errorString + ", " + warningString);
1313
1343
if (folder.IsRoot) {
1314
1344
// Don't allow adding files to the root folder. VS doesn't allow it
1315
1345
// If there is no existing folder, create one
1316
var itemsFolder = (SolutionFolder) folder.Items.Where (item => item.Name == "Solution Items").FirstOrDefault ();
1317
if (itemsFolder == null) {
1318
itemsFolder = new SolutionFolder ();
1319
itemsFolder.Name = "Solution Items";
1320
folder.AddItem (itemsFolder);
1322
folder = itemsFolder;
1346
folder = folder.ParentSolution.DefaultSolutionFolder;
1325
1349
if (!fp.IsChildPathOf (folder.BaseDirectory)) {
1617
1641
ProjectFile sourceParent = null;
1618
1642
if (filesToMove.Count == 1 && sourceProject != null) {
1619
1643
var pf = filesToMove[0];
1620
if (pf != null && pf.HasChildren)
1621
foreach (ProjectFile child in pf.DependentChildren)
1644
if (pf != null && pf.HasChildren) {
1645
foreach (ProjectFile child in pf.DependentChildren) {
1646
filesToRemove.Add (child);
1622
1647
filesToMove.Add (child);
1623
1650
sourceParent = pf;
1649
monitor.BeginTask (GettextCatalog.GetString ("Copying files..."), filesToMove.Count);
1676
if (removeFromSource)
1677
monitor.BeginTask (GettextCatalog.GetString ("Moving files..."), filesToMove.Count);
1679
monitor.BeginTask (GettextCatalog.GetString ("Copying files..."), filesToMove.Count);
1651
1681
ProjectFile targetParent = null;
1652
1682
foreach (ProjectFile file in filesToMove) {
1671
1701
FilePath fileDir = newFile.ParentDirectory;
1672
1702
if (!Directory.Exists (fileDir) && !file.IsLink)
1673
1703
FileService.CreateDirectory (fileDir);
1674
if (removeFromSource)
1704
if (removeFromSource) {
1705
// File.Move() does not have an overwrite argument and will fail if the destFile path exists, however, the user
1706
// has already chosen to overwrite the destination file.
1707
if (File.Exists (newFile))
1708
File.Delete (newFile);
1675
1710
FileService.MoveFile (sourceFile, newFile);
1677
1712
FileService.CopyFile (sourceFile, newFile);
1678
1713
} catch (Exception ex) {
1679
monitor.ReportError (GettextCatalog.GetString ("File '{0}' could not be created.", newFile), ex);
1714
if (removeFromSource)
1715
monitor.ReportError (GettextCatalog.GetString ("File '{0}' could not be moved.", sourceFile), ex);
1717
monitor.ReportError (GettextCatalog.GetString ("File '{0}' could not be copied.", sourceFile), ex);
1680
1718
monitor.Step (1);
1715
1753
// Remove all files and directories under 'sourcePath'
1716
1754
foreach (var v in filesToRemove)
1717
1755
sourceProject.Files.Remove (v);
1757
// Moving an empty folder. A new folder object has to be added to the project.
1758
if (movingFolder && !sourceProject.Files.GetFilesInVirtualPath (targetPath).Any ()) {
1759
var folderFile = new ProjectFile (targetPath) { Subtype = Subtype.Directory };
1760
sourceProject.Files.Add (folderFile);
1720
1764
var pfolder = sourcePath.ParentDirectory;
1896
1940
// Fired just before an entry is added to a combine
1897
1941
public event AddEntryEventHandler AddingEntryToCombine;
1943
public event EventHandler CurrentRunOperationChanged;
1944
public event EventHandler<EditReferencesEventArgs> BeforeEditReferences;
1945
protected virtual void OnCurrentRunOperationChanged (EventArgs e)
1947
var handler = CurrentRunOperationChanged;
1948
if (handler != null)
1900
1953
class ParseProgressMonitorFactory: IProgressMonitorFactory
2012
2065
return new ProviderProxy (data, file.SourceEncoding, file.HadBOM);
2069
/// Performs an edit operation on a text file regardless of it's open in the IDE or not.
2071
/// <returns><c>true</c>, if file operation was saved, <c>false</c> otherwise.</returns>
2072
/// <param name="filePath">File path.</param>
2073
/// <param name="operation">The operation.</param>
2074
public bool EditFile (FilePath filePath, Action<TextEditorData> operation)
2076
if (operation == null)
2077
throw new ArgumentNullException ("operation");
2081
var data = GetTextEditorData (filePath, out hadBom, out encoding, out isOpen);
2085
Mono.TextEditor.Utils.TextFileUtility.WriteText (filePath, data.Text, encoding, hadBom);
2086
} catch (Exception e) {
2087
LoggingService.LogError ("Error while saving changes to : " + filePath, e);
2015
2094
public TextEditorData GetTextEditorData (FilePath filePath)
2018
2097
return GetTextEditorData (filePath, out isOpen);
2100
public TextEditorData GetReadOnlyTextEditorData (FilePath filePath)
2102
foreach (var doc in IdeApp.Workbench.Documents) {
2103
if (doc.FileName == filePath) {
2109
var text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (filePath, out hadBom, out encoding);
2110
var data = new TextEditorData (TextDocument.CreateImmutableDocument (text));
2111
data.Document.MimeType = DesktopService.GetMimeTypeForUri (filePath);
2112
data.Document.FileName = filePath;
2021
2117
public TextEditorData GetTextEditorData (FilePath filePath, out bool isOpen)
2121
return GetTextEditorData (filePath, out hadBom, out encoding, out isOpen);
2124
public TextEditorData GetTextEditorData (FilePath filePath, out bool hadBom, out Encoding encoding, out bool isOpen)
2023
2126
foreach (var doc in IdeApp.Workbench.Documents) {
2024
2127
if (doc.FileName == filePath) {
2130
encoding = Encoding.Default;
2026
2131
return doc.Editor;
2030
TextFile file = TextFile.ReadFile (filePath);
2135
var text = Mono.TextEditor.Utils.TextFileUtility.ReadAllText (filePath, out hadBom, out encoding);
2031
2136
TextEditorData data = new TextEditorData ();
2137
data.Document.SuppressHighlightUpdate = true;
2138
data.Document.MimeType = DesktopService.GetMimeTypeForUri (filePath);
2032
2139
data.Document.FileName = filePath;
2033
data.Text = file.Text;
2034
2141
isOpen = false;