internal Task <Document> OpenDocument(FilePath fileName, WorkspaceObject project, int line, int column, OpenDocumentOptions options, Encoding encoding, DocumentControllerDescription binding) { var openFileInfo = new FileOpenInformation(fileName, project) { Options = options, Line = line, Column = column, DocumentControllerDescription = binding, Encoding = encoding }; return(documentManager.OpenDocument(openFileInfo)); }
public StartupInfo(IEnumerable <string> args) { foreach (string arg in args) { string a = arg; Match fileMatch = FileExpression.Match(a); // this does not yet work with relative paths if (a[0] == '~') { a = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), a.Substring(1)); } if (fileMatch != null && fileMatch.Success) { string filename = fileMatch.Groups["filename"].Value; if (File.Exists(filename)) { int line = 1, column = 1; filename = Path.GetFullPath(filename); if (fileMatch.Groups["line"].Success) { int.TryParse(fileMatch.Groups["line"].Value, out line); } if (fileMatch.Groups["column"].Success) { int.TryParse(fileMatch.Groups["column"].Value, out column); } line = Math.Max(1, line); column = Math.Max(1, column); var file = new FileOpenInformation(filename, line, column, true); requestedFileList.Add(file); } } else if (a[0] == '-' || a[0] == '/') { int markerLength = 1; if (a.Length >= 2 && a[0] == '-' && a[1] == '-') { markerLength = 2; } parameterList.Add(a.Substring(markerLength)); } } }
IViewContent BatchOpenDocument(IProgressMonitor monitor, FilePath fileName, int line, int column) { if (string.IsNullOrEmpty(fileName)) { return(null); } using (Counters.OpenDocumentTimer.BeginTiming("Batch opening file " + fileName)) { var openFileInfo = new FileOpenInformation() { FileName = fileName, Options = OpenDocumentOptions.OnlyInternalViewer, Line = line, Column = column, }; RealOpenFile(monitor, openFileInfo); return(openFileInfo.NewContent); } }
public virtual Task Load(FileOpenInformation fileOpenInformation) { return(Task.FromResult(true)); }
public Task <Document> OpenDocument(FileOpenInformation info) { return(documentManager.OpenDocument(info)); }
public override void Load(FileOpenInformation fileOpenInformation) { }
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)); } } } }
internal Document OpenDocument(FilePath fileName, int line, int column, OpenDocumentOptions options, string encoding, IViewDisplayBinding binding) { if (string.IsNullOrEmpty(fileName)) { return(null); } using (Counters.OpenDocumentTimer.BeginTiming("Opening file " + fileName)) { NavigationHistoryService.LogActiveDocument(); Counters.OpenDocumentTimer.Trace("Look for open document"); foreach (Document doc in Documents) { IBaseViewContent vcFound = null; int vcIndex = 0; //search all ViewContents to see if they can "re-use" this filename if (doc.Window.ViewContent.CanReuseView(fileName)) { vcFound = doc.Window.ViewContent; } //old method as fallback if ((vcFound == null) && (doc.FileName == fileName)) { vcFound = doc.Window.ViewContent; } //if found, select window and jump to line if (vcFound != null) { IEditableTextBuffer ipos = vcFound.GetContent <IEditableTextBuffer> (); if (line >= 1 && ipos != null) { ipos.SetCaretTo(line, column >= 1 ? column : 1, options.HasFlag(OpenDocumentOptions.HighlightCaretLine)); } if (options.HasFlag(OpenDocumentOptions.BringToFront)) { doc.Select(); doc.Window.SwitchView(vcIndex); doc.Window.SelectWindow(); NavigationHistoryService.LogActiveDocument(); Present(); } return(doc); } } Counters.OpenDocumentTimer.Trace("Initializing monitor"); IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor(GettextCatalog.GetString("Opening {0}", fileName), Stock.OpenFileIcon, true); var openFileInfo = new FileOpenInformation() { ProgressMonitor = pm, FileName = fileName, Options = options, Line = line, Column = column, DisplayBinding = binding, Encoding = encoding }; RealOpenFile(openFileInfo); if (!pm.AsyncOperation.Success) { return(null); } if (openFileInfo.NewContent != null) { Counters.OpenDocumentTimer.Trace("Wrapping document"); Document doc = WrapDocument(openFileInfo.NewContent.WorkbenchWindow); if (options.HasFlag(OpenDocumentOptions.BringToFront)) { Present(); doc.RunWhenLoaded(() => doc.Window.SelectWindow()); } return(doc); } else { return(null); } } }
public LoadFileWrapper(DefaultWorkbench workbench, IViewDisplayBinding binding, Project project, FileOpenInformation fileInfo) : this(workbench, binding, fileInfo) { this.project = project; }
public LoadFileWrapper(DefaultWorkbench workbench, IViewDisplayBinding binding, FileOpenInformation fileInfo) { this.workbench = workbench; this.fileInfo = fileInfo; this.binding = binding; }
public LoadFileWrapper(IProgressMonitor monitor, DefaultWorkbench workbench, IViewDisplayBinding binding, FileOpenInformation fileInfo) { this.monitor = monitor; this.workbench = workbench; this.fileInfo = fileInfo; this.binding = binding; }
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 abstract void Load(FileOpenInformation fileOpenInformation);