def _resolveLink(self, link): """Resolves the link to a file and optional line number""" scheme = link.scheme().lower() if scheme in ['http', 'https']: QDesktopServices.openUrl(link) return None, None if scheme == '': fileName = link.path() elif scheme == 'file': if link.isValid(): fileName = link.path() else: logging.error('Invalid link: ' + link.errorString()) return None, None else: logging.error("Unsupported url scheme '" + link.scheme() + "'. Supported schemes are 'http', 'https', 'file' " "and an empty scheme for files") return None, None if not fileName: logging.error('Could not get a file name. Check the link format. ' 'Valid examples: file:./relative/fname or ' 'file:relative/fname or file:/absolute/fname or ' 'file:///absolute/fname') return None, None return resolveLinkPath(fileName, self.__parentWidget.getFileName())
def _resolveLink(self, link): """Resolves the link to a file and optional anchor/line number""" scheme = link.scheme().lower() if scheme in ['http', 'https']: QDesktopServices.openUrl(link) return None, None if scheme == '': fileName = link.path() elif scheme == 'file': if link.isValid(): fileName = link.path() else: logging.error('Invalid link: ' + link.errorString()) return None, None elif scheme == 'action': if link.isValid(): # The action is stored in the host part action = link.host() # The actions are predefined. I did not find a generic way # to find what the key is bound to if action.lower() == 'embedded-help': GlobalData().mainWindow._onEmbeddedHelp() elif action.lower() == 'f1': GlobalData().mainWindow.em.onHelp() elif action.lower() == 'project-cocumentation': GlobalData().mainWindow.projectDocClicked() else: # must be a keyboard shortcut logging.error("Unsupported action '" + link.host() + "'") return None, None else: logging.error("Unsupported url scheme '" + link.scheme() + "'. Supported schemes are 'http', 'https', 'file' " "and an empty scheme for files") return None, None if not fileName: logging.error('Could not get a file name. Check the link format. ' 'Valid examples: file:./relative/fname or ' 'file:relative/fname or file:/absolute/fname or ' 'file:///absolute/fname') return None, None fileName, anchorOrLine = resolveLinkPath( fileName, self._parentWidget.getFileName()) if anchorOrLine is None: if link.hasFragment(): return fileName, link.fragment() return fileName, anchorOrLine
def mouseClickLinkIcon(self): """Follows the link""" if self.cmlRef.link is None: return # http://... an external browser will be invoked # https://... an external browser will be invoked # [file:]absolute path # [file:]relative path. The relative is tried to the current file # and then to the project root if self.cmlRef.link.startswith('http://') or \ self.cmlRef.link.startswith('https://'): QDesktopServices.openUrl(QUrl(self.cmlRef.link)) return fileName, lineNo = resolveLinkPath(self.cmlRef.link, self._editor.getFileName()) if fileName: GlobalData().mainWindow.openFile(fileName, lineNo)