From 05e3493346665d745f57399771a2a4078992e1fe Mon Sep 17 00:00:00 2001 From: Salomon CHUNG Date: Mon, 18 Jan 2021 15:56:26 +0100 Subject: [PATCH] bt_spn #20401: TApplication: Reference URL can be set - TApplication::set_url() added. - This method sets .help metacommand URL. --- core/base/inc/TApplication.h | 6 ++++++ core/base/src/TApplication.cxx | 32 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/core/base/inc/TApplication.h b/core/base/inc/TApplication.h index 7f6f7c5673..e4a5bdb3bf 100644 --- a/core/base/inc/TApplication.h +++ b/core/base/inc/TApplication.h @@ -31,6 +31,8 @@ #include "TApplicationImp.h" +#include + class TObjArray; class TTimer; class TSignalHandler; @@ -77,6 +79,8 @@ private: TApplication(const TApplication&); // not implemented TApplication& operator=(const TApplication&); // not implemented + std::string _url_base {"https://root.cern/doc/"}; // Reference guide URL base + protected: TApplication *fAppRemote; //Current remote application, if defined @@ -160,6 +164,8 @@ public: static void CreateApplication(); static void NeedGraphicsLibs(); + void set_url(std::string url_base); + ClassDef(TApplication,0) //GUI application singleton }; diff --git a/core/base/src/TApplication.cxx b/core/base/src/TApplication.cxx index bd1952085a..bc65541d89 100644 --- a/core/base/src/TApplication.cxx +++ b/core/base/src/TApplication.cxx @@ -677,10 +677,10 @@ enum EUrl { kURLforClass, kURLforNameSpace, kURLforStruct }; /// \param[in] scopeName the name of the class or the namespace /// \param[in] scopeType the enumerator for class or namespace -static TString UrlGenerator(TString scopeName, EUrl scopeType) +static TString UrlGenerator(const std::string& url_base, TString scopeName, EUrl scopeType) { // We start the URL with a static part, the same for all scopes and members. - TString url = "https://root.cern/doc/"; + TString url = url_base; // Then we check the ROOT version used. TPRegexp re4(R"(.*/v(\d)-(\d\d)-00-patches)"); const char *branchName = gROOT->GetGitBranch(); @@ -815,7 +815,7 @@ namespace { /// \param[in] scopeType enumerator to the scope type static TString -GetUrlForDataMember(const TString &scopeName, const TString &dataMemberName, TDataMember *dataMember, EUrl scopeType) +GetUrlForDataMember(const std::string& url_base, const TString &scopeName, const TString &dataMemberName, TDataMember *dataMember, EUrl scopeType) { // We first check if the data member is not enumerator. if (!dataMember->IsEnum()) { @@ -831,7 +831,7 @@ GetUrlForDataMember(const TString &scopeName, const TString &dataMemberName, TDa md5DataMember.Append(dataMemberName); md5DataMember.Append(dataMemberName); // We call UrlGenerator for the scopeName. - TString urlForDataMember = UrlGenerator(scopeName, scopeType); + TString urlForDataMember = UrlGenerator(url_base, scopeName, scopeType); // Then we append "#a" and the hashed text. urlForDataMember.Append("#a"); urlForDataMember.Append(md5DataMember.MD5()); @@ -862,7 +862,7 @@ GetUrlForDataMember(const TString &scopeName, const TString &dataMemberName, TDa md5Enumerator.Append(dataMemberName); md5Enumerator.Append(dataMemberName); // We make the URL for the "scopeName". - TString url = UrlGenerator(scopeName, scopeType); + TString url = UrlGenerator(url_base, scopeName, scopeType); // Then we have to append the hashed text for the enumerator. url.Append("#a"); url.Append(md5EnumClass.MD5()); @@ -882,7 +882,7 @@ namespace { /// \param[in] enumeration the name of the enumeration /// \param[in] scopeType enumerator for class/namespace/struct -static TString GetUrlForEnumeration(TString scopeName, const TString &enumeration, EUrl scopeType) +static TString GetUrlForEnumeration(const std::string& url_base, TString scopeName, const TString &enumeration, EUrl scopeType) { // The URL consists of URL for the "scopeName", "#a" and hashed as MD5 text. // The text is "Class::EnumerationEnumeration. @@ -891,7 +891,7 @@ static TString GetUrlForEnumeration(TString scopeName, const TString &enumeratio md5Enumeration.Append(enumeration); md5Enumeration.Append(enumeration); // We make the URL for the scope "scopeName". - TString url(UrlGenerator(scopeName, scopeType)); + TString url(UrlGenerator(url_base, scopeName, scopeType)); // Then we have to append "#a" and the hashed text. url.Append("#a"); url.Append(md5Enumeration.MD5()); @@ -915,7 +915,7 @@ enum EMethodKind { kURLforMethod, kURLforStructor }; /// \param[in] methodType enumerator for method or constructor /// \param[in] scopeType enumerator for class/namespace/struct -static TString GetUrlForMethod(const TString &scopeName, const TString &methodName, TFunction *func, +static TString GetUrlForMethod(const std::string& url_base, const TString &scopeName, const TString &methodName, TFunction *func, EMethodKind methodType, EUrl scopeType) { TString md5Text; @@ -939,7 +939,7 @@ static TString GetUrlForMethod(const TString &scopeName, const TString &methodNa // We use "FormatMethodArgsForDoxygen" to modify the arguments of Method with respect of Doxygen. md5Text.Append(FormatMethodArgsForDoxygen(scopeName, func)); // We generate the URL for the class/namespace/struct. - TString url = UrlGenerator(scopeName, scopeType); + TString url = UrlGenerator(url_base, scopeName, scopeType); url.Append("#a"); // We append the hashed text. url.Append(md5Text.MD5()); @@ -971,7 +971,7 @@ void TApplication::OpenReferenceGuideFor(const TString &strippedClass) scopeType = kURLforClass; } // If the user search directly for a scope we open the URL for him with OpenInBrowser. - OpenInBrowser(UrlGenerator(strippedClass, scopeType)); + OpenInBrowser(UrlGenerator(_url_base, strippedClass, scopeType)); return; } // Else we subtract the name of the method and remove it from the command. @@ -1025,14 +1025,14 @@ void TApplication::OpenReferenceGuideFor(const TString &strippedClass) methodType = kURLforMethod; } // We call "GetUrlForMethod" for the correct class and scope. - OpenInBrowser(GetUrlForMethod(baseClName, memberName, func, methodType, scopeType)); + OpenInBrowser(GetUrlForMethod(_url_base, baseClName, memberName, func, methodType, scopeType)); return; } // We check if "memberName" is an enumeration. if (cl->GetListOfEnums()->FindObject(memberName)) { // If so with OpenInBrowser we open the URL generated with GetUrlForEnumeration // with respect to the "scopeType". - OpenInBrowser(GetUrlForEnumeration(scopeName, memberName, scopeType)); + OpenInBrowser(GetUrlForEnumeration(_url_base, scopeName, memberName, scopeType)); return; } @@ -1040,14 +1040,14 @@ void TApplication::OpenReferenceGuideFor(const TString &strippedClass) if (auto enumerator = (TDataMember *)cl->GetListOfAllPublicDataMembers()->FindObject(memberName)) { // We find the actual scope (might be in a base) and open the URL in a browser. TString baseClName = ((TMethod *)enumerator->GetClass())->GetName(); - OpenInBrowser(GetUrlForDataMember(baseClName, memberName, enumerator, scopeType)); + OpenInBrowser(GetUrlForDataMember(_url_base, baseClName, memberName, enumerator, scopeType)); return; } // Warning message will appear if the user types the function name incorrectly // or the function is not a member function of "cl" or any of its base classes. Warning("Help", "cannot find \"%s\" as member of %s or its base classes! Check %s\n", memberName.Data(), - scopeName.Data(), UrlGenerator(scopeName, scopeType).Data()); + scopeName.Data(), UrlGenerator(_url_base, scopeName, scopeType).Data()); } //////////////////////////////////////////////////////////////////////////////// @@ -1859,6 +1859,10 @@ void TApplication::ls(Option_t *opt) const } } +void TApplication::set_url(std::string url_base) { + _url_base = url_base; +} + //////////////////////////////////////////////////////////////////////////////// /// Static method returning the list of available applications -- 2.21.0