From 5168bdb7c5395821e458aaf20297cb7e8c76ef02 Mon Sep 17 00:00:00 2001 From: Udo Hoffmann Date: Sun, 22 Nov 2020 00:06:28 +0100 Subject: [PATCH] Allow custom URL schemes Fix #9155, close #9190 --- PowerEditor/src/Notepad_plus.cpp | 15 +++++++++++++-- PowerEditor/src/Parameters.cpp | 17 +++++++++++++++++ PowerEditor/src/Parameters.h | 1 + 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 9b50f923..4bea1272 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -2628,7 +2628,7 @@ bool isUrlQueryDelimiter(TCHAR const c) return false; } -bool isUrlSchemeSupported(INTERNET_SCHEME s) +bool isUrlSchemeSupported(INTERNET_SCHEME s, TCHAR *url) { switch (s) { @@ -2639,6 +2639,17 @@ bool isUrlSchemeSupported(INTERNET_SCHEME s) case INTERNET_SCHEME_FILE: return true; } + generic_string const mySchemes = (NppParameters::getInstance()).getNppGUI()._customizedShemes + TEXT(" "); + TCHAR *p = (TCHAR *)mySchemes.c_str(); + while (*p) + { + int i = 0; + while (p [i] && (p [i] != ' ')) i++; + if (i == 0) return false; + if (generic_strnicmp (url, p, i) == 0) return true; + p += i; + while (*p == ' ') p++; + } return false; } @@ -2863,7 +2874,7 @@ bool isUrl(TCHAR * text, int textLen, int start, int* segmentLen) URL_COMPONENTS url; memset (& url, 0, sizeof(url)); url.dwStructSize = sizeof(url); - bool r = InternetCrackUrl(& text [start], len, 0, & url) && isUrlSchemeSupported(url.nScheme); + bool r = InternetCrackUrl(& text [start], len, 0, & url) && isUrlSchemeSupported(url.nScheme, & text [start]); if (r) { while (removeUnwantedTrailingCharFromUrl (& text [start], & len)); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 99fbf787..fb8e0dd4 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -4442,6 +4442,17 @@ void NppParameters::feedGUIParameters(TiXmlNode *node) } } + else if (!lstrcmp(nm, TEXT("URL customized schemes"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + const TCHAR* val = n->Value(); + if (val) + _nppGUI._customizedShemes = val; + } + } + else if (!lstrcmp(nm, TEXT("CheckHistoryFiles"))) { TiXmlNode *n = childNode->FirstChild(); @@ -5998,6 +6009,12 @@ void NppParameters::createXmlTreeFromGUIParams() GUIConfigElement->InsertEndChild(TiXmlText(szStr)); } + // svn:// + { + TiXmlElement *GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("URL customized schemes")); + GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._customizedShemes.c_str())); + } // { TiXmlElement *GUIConfigElement = (newGUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index d7f6e17a..670baabb 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -849,6 +849,7 @@ struct NppGUI final bool _isWordCharDefault = true; std::string _customWordChars; urlMode _styleURL = urlUnderLineFg; + generic_string _customizedShemes = TEXT(""); NewDocDefaultSettings _newDocDefaultSettings;