// These are usually analyzers which would crash the process. public void ShowDetailedErrorInfo(Exception exception) { LoggingService.LogError("Roslyn reported an exception to the user", exception); var logFile = (string)typeof(LoggingService).InvokeMember("logFile", BindingFlags.GetField | BindingFlags.Static | BindingFlags.NonPublic, null, null, null); // If the output is redirected, open the log file, otherwise do not do anything. if (logFile != null) { DesktopService.OpenFile(logFile); } }
async Task <(bool Success, Document Content)> RealOpenFile(ProgressMonitor monitor, FileOpenInformation openFileInfo) { FilePath fileName; await InitDesktopService(); Counters.OpenDocumentTimer.Trace("Checking file"); string origName = openFileInfo.FileName; if (origName == null) { monitor.ReportError(GettextCatalog.GetString("Invalid file name"), null); return(false, null); } fileName = openFileInfo.FileName; if (!origName.StartsWith("http://", StringComparison.Ordinal)) { fileName = fileName.FullPath; } //Debug.Assert(FileService.IsValidPath(fileName)); if (FileService.IsDirectory(fileName)) { monitor.ReportError(GettextCatalog.GetString("{0} is a directory", fileName), null); return(false, null); } // test, if file fileName exists if (!origName.StartsWith("http://", StringComparison.Ordinal)) { // test, if an untitled file should be opened if (!Path.IsPathRooted(origName)) { foreach (Document doc in Documents) { if (doc.IsNewDocument && doc.FilePath == origName) { doc.Select(); ScrollToRequestedCaretLocation(doc, openFileInfo); return(true, doc); } } } if (!File.Exists(fileName)) { monitor.ReportError(GettextCatalog.GetString("File not found: {0}", fileName), null); return(false, null); } } Counters.OpenDocumentTimer.Trace("Looking for binding"); var documentControllerService = await ServiceProvider.GetService <DocumentControllerService> (); IExternalDisplayBinding externalBinding = null; DocumentControllerDescription internalBinding = null; WorkspaceObject project = null; if (openFileInfo.Owner == null) { var workspace = await ServiceProvider.GetService <RootWorkspace> (); // Set the project if one can be found. The project on the FileOpenInformation // is used to add project metadata to the OpenDocumentTimer counter. project = workspace.GetProjectContainingFile(fileName); // In some cases, the file may be a symlinked file. We cannot find the resolved symlink path // in the project, so we should try looking up the original file. if (project == null) { project = workspace.GetProjectContainingFile(openFileInfo.OriginalFileName); } openFileInfo.Owner = project; } else { project = openFileInfo.Owner; } var displayBindingService = await ServiceProvider.GetService <DisplayBindingService> (); var fileDescriptor = new FileDescriptor(fileName, null, project); var internalViewers = await documentControllerService.GetSupportedControllers(fileDescriptor); var externalViewers = displayBindingService.GetDisplayBindings(fileName, null, project as Project).OfType <IExternalDisplayBinding> ().ToList(); if (openFileInfo.DocumentControllerDescription != null) { internalBinding = openFileInfo.DocumentControllerDescription; } else { var bindings = displayBindingService.GetDisplayBindings(fileName, null, project as Project).ToList(); if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer)) { internalBinding = internalViewers.FirstOrDefault(d => d.CanUseAsDefault) ?? internalViewers.FirstOrDefault(); } else if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyExternalViewer)) { externalBinding = externalViewers.FirstOrDefault(d => d.CanUseAsDefault) ?? externalViewers.FirstOrDefault(); } else { internalBinding = internalViewers.FirstOrDefault(d => d.CanUseAsDefault); if (internalBinding == null) { externalBinding = externalViewers.FirstOrDefault(d => d.CanUseAsDefault); if (externalBinding == null) { internalBinding = internalViewers.FirstOrDefault(); if (internalBinding == null) { externalBinding = externalViewers.FirstOrDefault(); } } } } } Document newContent = null; try { if (internalBinding != null) { newContent = await LoadFile(fileName, monitor, internalBinding, project, openFileInfo); } else if (externalBinding != null) { var extBinding = (IExternalDisplayBinding)externalBinding; var app = extBinding.GetApplication(fileName, null, project as Project); app.Launch(fileName); } else if (!openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer)) { try { Counters.OpenDocumentTimer.Trace("Showing in browser"); desktopService.OpenFile(fileName); } catch (Exception ex) { LoggingService.LogError("Error opening file: " + fileName, ex); MessageService.ShowError(GettextCatalog.GetString("File '{0}' could not be opened", fileName)); return(false, null); } } Counters.OpenDocumentTimer.Trace("Adding to recent files"); desktopService.RecentFiles.AddFile(fileName, project); } catch (Exception ex) { monitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), ex); return(false, null); } return(true, newContent); }
void RealOpenFile(FileOpenInformation openFileInfo) { FilePath fileName; IProgressMonitor monitor = openFileInfo.ProgressMonitor; using (monitor) { Counters.OpenDocumentTimer.Trace("Checking file"); string origName = openFileInfo.FileName; if (origName == null) { monitor.ReportError(GettextCatalog.GetString("Invalid file name"), null); return; } if (origName.StartsWith("file://")) { fileName = new Uri(origName).LocalPath; } else { fileName = origName; } if (!origName.StartsWith("http://")) { fileName = fileName.FullPath; } //Debug.Assert(FileService.IsValidPath(fileName)); if (FileService.IsDirectory(fileName)) { monitor.ReportError(GettextCatalog.GetString("{0} is a directory", fileName), null); return; } // test, if file fileName exists if (!origName.StartsWith("http://")) { // test, if an untitled file should be opened if (!System.IO.Path.IsPathRooted(origName)) { foreach (Document doc in Documents) { if (doc.Window.ViewContent.IsUntitled && doc.Window.ViewContent.UntitledName == origName) { doc.Select(); openFileInfo.NewContent = doc.Window.ViewContent; return; } } } if (!File.Exists(fileName)) { monitor.ReportError(GettextCatalog.GetString("File not found: {0}", fileName), null); return; } } foreach (Document doc in Documents) { if (doc.FileName == fileName) { if (openFileInfo.Options.HasFlag(OpenDocumentOptions.BringToFront)) { doc.Select(); doc.RunWhenLoaded(delegate { IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> (); if (openFileInfo.Line > 0 && ipos != null) { ipos.SetCaretTo(openFileInfo.Line, Math.Max(1, openFileInfo.Column), openFileInfo.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine)); } }); } openFileInfo.NewContent = doc.Window.ViewContent; return; } } Counters.OpenDocumentTimer.Trace("Looking for binding"); IDisplayBinding binding = null; IViewDisplayBinding viewBinding = null; Project project = GetProjectContainingFile(fileName); if (openFileInfo.DisplayBinding != null) { binding = viewBinding = openFileInfo.DisplayBinding; } else { var bindings = DisplayBindingService.GetDisplayBindings(fileName, null, project).Where(d => d.CanUseAsDefault); if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer)) { binding = bindings.OfType <IViewDisplayBinding>().FirstOrDefault(); viewBinding = (IViewDisplayBinding)binding; } else if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyExternalViewer)) { binding = bindings.OfType <IExternalDisplayBinding>().FirstOrDefault(); viewBinding = null; } else { binding = bindings.FirstOrDefault(); viewBinding = binding as IViewDisplayBinding; } } if (binding != null) { if (viewBinding != null) { var fw = new LoadFileWrapper(workbench, viewBinding, project, openFileInfo); fw.Invoke(fileName); } else { var extBinding = (IExternalDisplayBinding)binding; var app = extBinding.GetApplication(fileName, null, project); app.Launch(fileName); } Counters.OpenDocumentTimer.Trace("Adding to recent files"); DesktopService.RecentFiles.AddFile(fileName, project); } else if (!openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer)) { try { Counters.OpenDocumentTimer.Trace("Showing in browser"); DesktopService.OpenFile(fileName); } catch (Exception ex) { LoggingService.LogError("Error opening file: " + fileName, ex); MessageService.ShowError(GettextCatalog.GetString("File '{0}' could not be opened", fileName)); } } } }
void RealOpenFile(FileOpenInformation openFileInfo) { FilePath fileName; IProgressMonitor monitor = openFileInfo.ProgressMonitor; using (monitor) { Counters.OpenDocumentTimer.Trace("Checking file"); string origName = openFileInfo.FileName; if (origName == null) { monitor.ReportError(GettextCatalog.GetString("Invalid file name"), null); return; } if (origName.StartsWith("file://")) { fileName = new Uri(origName).LocalPath; } else { fileName = origName; } if (!origName.StartsWith("http://")) { fileName = fileName.FullPath; } //Debug.Assert(FileService.IsValidPath(fileName)); if (FileService.IsDirectory(fileName)) { monitor.ReportError(GettextCatalog.GetString("{0} is a directory", fileName), null); return; } // test, if file fileName exists if (!origName.StartsWith("http://")) { // test, if an untitled file should be opened if (!System.IO.Path.IsPathRooted(origName)) { foreach (Document doc in Documents) { if (doc.Window.ViewContent.IsUntitled && doc.Window.ViewContent.UntitledName == origName) { doc.Select(); openFileInfo.NewContent = doc.Window.ViewContent; return; } } } if (!File.Exists(fileName)) { monitor.ReportError(GettextCatalog.GetString("File not found: {0}", fileName), null); return; } } foreach (Document doc in Documents) { if (doc.FileName == fileName) { if (openFileInfo.BringToFront) { doc.Select(); IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> (); if (openFileInfo.Line != -1 && ipos != null) { ipos.SetCaretTo(openFileInfo.Line, openFileInfo.Column != -1 ? openFileInfo.Column : 0, openFileInfo.HighlightCaretLine); } } openFileInfo.NewContent = doc.Window.ViewContent; return; } } Counters.OpenDocumentTimer.Trace("Looking for binding"); IDisplayBinding binding; if (openFileInfo.DisplayBinding != null) { binding = openFileInfo.DisplayBinding; } else { binding = DisplayBindingService.GetDefaultBinding(fileName, DesktopService.GetMimeTypeForUri(fileName)); } if (binding != null) { // When looking for the project to which the file belongs, look first // in the active project, then the active solution, and so on Project project = null; if (IdeApp.ProjectOperations.CurrentSelectedProject != null) { if (IdeApp.ProjectOperations.CurrentSelectedProject.Files.GetFile(fileName) != null) { project = IdeApp.ProjectOperations.CurrentSelectedProject; } } if (project == null && IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null) { project = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetProjectContainingFile(fileName); if (project == null) { WorkspaceItem it = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.ParentWorkspace; while (it != null && project == null) { project = it.GetProjectContainingFile(fileName); it = it.ParentWorkspace; } } } if (project == null) { project = IdeApp.Workspace.GetProjectContainingFile(fileName); } LoadFileWrapper fw = new LoadFileWrapper(workbench, binding, project, openFileInfo); fw.Invoke(fileName); Counters.OpenDocumentTimer.Trace("Adding to recent files"); DesktopService.RecentFiles.AddFile(fileName, project); } else { try { Counters.OpenDocumentTimer.Trace("Showing in browser"); DesktopService.OpenFile(fileName); } catch (Exception ex) { LoggingService.LogError("Error opening file: " + fileName, ex); MessageService.ShowError(GettextCatalog.GetString("File '{0}' could not be opened", fileName)); } } } }
public void Navigate(string url) { DesktopService.OpenFile(url); }
public AboutMonoDevelopTabPage() { BorderWidth = 0; var aboutFile = BrandingService.GetFile(AboutDialogImage.Name); if (aboutFile != null) { imageSep = Xwt.Drawing.Image.FromFile(aboutFile); } else { imageSep = Xwt.Drawing.Image.FromResource(AboutDialogImage.Name); } PackStart(new ImageView(imageSep), false, false, 0); Xwt.VBox infoBox = new Xwt.VBox(); Xwt.FrameBox mbox = new Xwt.FrameBox(infoBox); infoBox.Spacing = 6; infoBox.Margin = 12; PackStart(mbox.ToGtkWidget(), false, false, 0); infoBox.PackStart(new Xwt.Label() { Markup = string.Format("<b>{0}</b>", GettextCatalog.GetString("Version")), MarginTop = 6, }); infoBox.PackStart(new Xwt.Label() { Text = IdeVersionInfo.MonoDevelopVersion, MarginLeft = 12 }); infoBox.PackStart(new Xwt.Label() { Markup = string.Format("<b>{0}</b>", GettextCatalog.GetString("License")), MarginTop = 6, }); var cbox = new Xwt.HBox() { Spacing = 0, MarginLeft = 12 }; var linkLabel = new Xwt.Label { Markup = "<span underline='true'>License Terms</span>", Cursor = Xwt.CursorType.Hand, }; if (IdeTheme.UserInterfaceTheme == Theme.Light) { linkLabel.Markup = string.Format("<span color='#5C2D91'>{0}</span>", linkLabel.Markup); } linkLabel.ButtonReleased += (sender, e) => { var binDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); string licensePath = System.IO.Path.Combine(binDir, "branding", "License.txt"); if (Platform.IsMac) { var appDir = System.IO.Path.GetFullPath(System.IO.Path.Combine(binDir, "..", "..", "..", "..", "..")); if (appDir.EndsWith(".app", StringComparison.Ordinal)) { licensePath = System.IO.Path.Combine(appDir, "Contents", "License.txt"); } } if (!File.Exists(licensePath)) { MessageService.ShowError("License file is missing"); } else { DesktopService.OpenFile(licensePath); } }; cbox.PackStart(linkLabel); infoBox.PackStart(cbox); linkLabel = new Xwt.Label { Markup = string.Format("<span underline='true'>{0}</span>", GettextCatalog.GetString("Privacy Statement")), Cursor = Xwt.CursorType.Hand, MarginLeft = 12 }; //TODO: factor out const string PRIVACY_URL = "https://go.microsoft.com/fwlink/?LinkID=824704"; if (IdeTheme.UserInterfaceTheme == Theme.Light) { linkLabel.Markup = string.Format("<span color='#5C2D91'>{0}</span>", linkLabel.Markup); } linkLabel.ButtonReleased += (sender, e) => DesktopService.ShowUrl(PRIVACY_URL); infoBox.PackStart(linkLabel); infoBox.PackStart(new Xwt.Label() { Markup = string.Format("<b>{0}</b>", GettextCatalog.GetString("Copyright")), MarginTop = 6, }); infoBox.PackStart(new Xwt.Label() { Text = (DateTime.Now.Year == 2016 ? "© 2016" : "© 2016–" + DateTime.Now.Year) + " Microsoft Corp.", MarginLeft = 12 }); infoBox.PackStart(new Xwt.Label() { Text = "© 2004–" + DateTime.Now.Year + " Xamarin Inc.", MarginLeft = 12 }); infoBox.PackStart(new Xwt.Label() { Text = "© 2004–" + DateTime.Now.Year + " MonoDevelop contributors", MarginLeft = 12 }); this.ShowAll(); }