private IPeekResult CreatePeekResult(LocationInfo location) { IPeekResult result = null; var path = location.FilePath; if (!string.IsNullOrWhiteSpace(path)) { var fi = new FileInfo(path); var displayInfo = new PeekResultDisplayInfo(BuildLabel(location), path, BuildTitle(location), path); // TODO: the location stuff doesn't work 100% correctly. This needs to be fixed string contentType = null; var extension = Path.GetExtension(path); if (extension != null) { switch (extension.ToLower()) { case ".4gl": contentType = VSGeneroConstants.ContentType4GL; break; case ".inc": contentType = VSGeneroConstants.ContentTypeINC; break; case ".per": contentType = VSGeneroConstants.ContentTypePER; break; } } if (contentType != null) { ITextDocument textDoc = null; int line = location.Line - 1; if (line < 0) { textDoc = this._factory.TextDocumentFactoryService.CreateAndLoadTextDocument(path, this._factory.ContentTypeRegistryService.GetContentType(contentType)); line = textDoc.TextBuffer.CurrentSnapshot.GetLineNumberFromPosition(location.Index); } int character = location.Column - 1; // start index if (character < 0) { character = 0; } //EditorExtensions.EditorExtensions.GetLineAndColumnOfFile(path, location.Position, out line, out character); int endLine = line + 10; // end line int endIndex = 0; // end index int positionLine = 0; // id line int positionChar = 0; // id index bool isReadOnly = fi.IsReadOnly; // TODO: determine the stuff above. result = this._factory.PeekResultFactory.Create(displayInfo, path, line, character, endLine, endIndex, positionLine, positionChar, isReadOnly); result.Disposed += (x, y) => { if (textDoc != null) { textDoc.Dispose(); } }; } } else if (!string.IsNullOrWhiteSpace(location.DefinitionURL)) { #if DEV14_OR_LATER return(new UrlPeekResult(location.GetUrlString(_languageVersion))); #endif } return(result); }
internal static void GotoSource(this LocationInfo location, IServiceProvider serviceProvider, GeneroLanguageVersion languageVersion) { if (location.Line > 0 && location.Column > 0) { VSGeneroPackage.NavigateTo( location.FilePath, Guid.Empty, location.Line - 1, location.Column - 1); } else if (location.DefinitionURL != null) { var urlStr = location.GetUrlString(languageVersion); Uri definitionUrl; if (Uri.TryCreate(urlStr, UriKind.Absolute, out definitionUrl)) { if (serviceProvider != null) { IVsWebBrowsingService service = serviceProvider.GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService; if (service != null) { if (VSGeneroPackage.Instance.AdvancedOptions4GL.OpenExternalBrowser) { __VSCREATEWEBBROWSER createFlags = __VSCREATEWEBBROWSER.VSCWB_AutoShow; VSPREVIEWRESOLUTION resolution = VSPREVIEWRESOLUTION.PR_Default; int result = ErrorHandler.CallWithCOMConvention(() => service.CreateExternalWebBrowser((uint)createFlags, resolution, definitionUrl.AbsoluteUri)); if (ErrorHandler.Succeeded(result)) { return; } } else { IVsWindowFrame ppFrame; int result = ErrorHandler.CallWithCOMConvention(() => service.Navigate(definitionUrl.AbsoluteUri, 0, out ppFrame)); if (ErrorHandler.Succeeded(result)) { return; } } } } // Fall back to Shell Execute, but only for http or https URIs if (definitionUrl.Scheme != "http" && definitionUrl.Scheme != "https") { return; } try { Process.Start(definitionUrl.AbsoluteUri); } catch (Win32Exception) { } catch (FileNotFoundException) { } } } else { VSGeneroPackage.NavigateTo(location.FilePath, Guid.Empty, location.Index); } }