From da2abe891163fd8694734cfd2e09d2dd5b000906 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 6 Feb 2020 09:57:29 +0000 Subject: [PATCH] ide: Context goto now able to detect files / links git-svn-id: svn://ultimatepp.org/upp/trunk@13969 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/ContextGoto.cpp | 25 ++++++++++++++++++++++++- uppsrc/ide/ide.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/uppsrc/ide/ContextGoto.cpp b/uppsrc/ide/ContextGoto.cpp index 570f6067d..22ff63d95 100644 --- a/uppsrc/ide/ContextGoto.cpp +++ b/uppsrc/ide/ContextGoto.cpp @@ -91,12 +91,35 @@ String RemoveTemplateParams(const String& s) return ParseTemplatedType(s, dummy); } +bool Ide::OpenLink(const String& s, int pos) +{ // try to find link at cursor, either http, https or file + auto IsLinkChar = [](int c) { return findarg(c, '\'', '\"', '\t', ' ', '\0') < 0; }; + int b = pos; + while(b > 0 && IsLinkChar(s[b - 1])) + b--; + int e = pos; + while(IsLinkChar(s[e])) + e++; + String link = s.Mid(b, e - b); + if(link.StartsWith("http://") || link.StartsWith("https://")) + LaunchWebBrowser(link); + else + if(FileExists(link)) + EditFile(link); + else + return false; + return true; +} + void Ide::ContextGoto0(int pos) { if(designer) return; - int li = editor.GetLine(pos); + int lp = pos; + int li = editor.GetLinePos(lp); String l = editor.GetUtf8Line(li); + if(OpenLink(l, lp)) + return; if(IsPif(l) || IsPelse(l)) { int lvl = 0; while(li + 1 < editor.GetLineCount()) { diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 1f85ba92a..f803e282d 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -939,6 +939,7 @@ public: bool SwapSIf(const char *cref); void SwapS(); void FindId(const String& id); + bool OpenLink(const String& s, int pos); void ContextGoto0(int pos); void ContextGoto(); void GoToLine();