From 9e4927ece5448c94bc3f46f7be019c0ffe14a686 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 11 Oct 2012 17:29:04 -0400 Subject: Make LLTransUtil::parseStrings() merge all relevant strings.xml files. Until now, adding a xui/en/strings.xml file in any non-default skin meant you had to clone the entire file, editing only the particular entries you wanted to override. With this change, we load strings.xml file(s) from the default skin before loading the specified skin -- so a non-default skin can now provide a strings.xml file containing only the specific entries it wants to override. --- indra/llui/lltransutil.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'indra/llui/lltransutil.cpp') diff --git a/indra/llui/lltransutil.cpp b/indra/llui/lltransutil.cpp index 58fa8a0828..97a72b55e1 100644 --- a/indra/llui/lltransutil.cpp +++ b/indra/llui/lltransutil.cpp @@ -31,15 +31,27 @@ #include "lltrans.h" #include "lluictrlfactory.h" #include "llxmlnode.h" - +#include "lldir.h" bool LLTransUtil::parseStrings(const std::string& xml_filename, const std::set& default_args) { + // LLUICtrlFactory::getLayeredXMLNode() just calls + // gDirUtilp->findSkinnedFilenames(merge=false) and then passes the + // resulting paths to LLXMLNode::getLayeredXMLNode(). Bypass that and call + // LLXMLNode::getLayeredXMLNode() directly: we want merge=true. + std::vector paths = + gDirUtilp->findSkinnedFilenames(LLDir::XUI, xml_filename, true); + if (paths.empty()) + { + // xml_filename not found at all in any skin -- check whether entire + // path was passed (but I hope we no longer have callers who do that) + paths.push_back(xml_filename); + } LLXMLNodePtr root; - BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root); + bool success = LLXMLNode::getLayeredXMLNode(root, paths); if (!success) { - llerrs << "Couldn't load string table" << llendl; + llerrs << "Couldn't load string table " << xml_filename << llendl; return false; } @@ -54,7 +66,7 @@ bool LLTransUtil::parseLanguageStrings(const std::string& xml_filename) if (!success) { - llerrs << "Couldn't load string table " << xml_filename << llendl; + llerrs << "Couldn't load localization table " << xml_filename << llendl; return false; } -- cgit v1.3 From 730d13a76a4b06e6dbdd4bd5829a90bcb98b52b3 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 11 Oct 2012 19:51:07 -0400 Subject: Change LLDir::findSkinnedFilenames() to use enum instead of bool. At Richard's suggestion, changed the bool merge parameter to new enum ESkinConstraint with values CURRENT_SKIN and ALL_SKINS. This clarifies what we're requesting at the point of the call. --- indra/llui/llnotifications.cpp | 7 ++++--- indra/llui/lltransutil.cpp | 9 +++++---- indra/llui/lluicolortable.cpp | 5 +++-- indra/llvfs/lldir.cpp | 19 ++++++++++--------- indra/llvfs/lldir.h | 22 ++++++++++++---------- indra/llvfs/tests/lldir_test.cpp | 14 +++++++------- indra/newview/llviewertexturelist.cpp | 7 ++++--- 7 files changed, 45 insertions(+), 38 deletions(-) (limited to 'indra/llui/lltransutil.cpp') diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp index 4fbee8cd80..210a320f41 100644 --- a/indra/llui/llnotifications.cpp +++ b/indra/llui/llnotifications.cpp @@ -1424,10 +1424,11 @@ void addPathIfExists(const std::string& new_path, std::vector& path bool LLNotifications::loadTemplates() { llinfos << "Reading notifications template" << llendl; - // Passing findSkinnedFilenames(merge=true) makes it output all relevant - // pathnames instead of just the ones from the most specific skin. + // Passing findSkinnedFilenames(constraint=LLDir::ALL_SKINS) makes it + // output all relevant pathnames instead of just the ones from the most + // specific skin. std::vector search_paths = - gDirUtilp->findSkinnedFilenames(LLDir::XUI, "notifications.xml", true); + gDirUtilp->findSkinnedFilenames(LLDir::XUI, "notifications.xml", LLDir::ALL_SKINS); std::string base_filename = search_paths.front(); LLXMLNodePtr root; diff --git a/indra/llui/lltransutil.cpp b/indra/llui/lltransutil.cpp index 97a72b55e1..3b7e737dea 100644 --- a/indra/llui/lltransutil.cpp +++ b/indra/llui/lltransutil.cpp @@ -36,11 +36,12 @@ bool LLTransUtil::parseStrings(const std::string& xml_filename, const std::set& default_args) { // LLUICtrlFactory::getLayeredXMLNode() just calls - // gDirUtilp->findSkinnedFilenames(merge=false) and then passes the - // resulting paths to LLXMLNode::getLayeredXMLNode(). Bypass that and call - // LLXMLNode::getLayeredXMLNode() directly: we want merge=true. + // gDirUtilp->findSkinnedFilenames(constraint=LLDir::CURRENT_SKIN) and + // then passes the resulting paths to LLXMLNode::getLayeredXMLNode(). + // Bypass that and call LLXMLNode::getLayeredXMLNode() directly: we want + // constraint=LLDir::ALL_SKINS. std::vector paths = - gDirUtilp->findSkinnedFilenames(LLDir::XUI, xml_filename, true); + gDirUtilp->findSkinnedFilenames(LLDir::XUI, xml_filename, LLDir::ALL_SKINS); if (paths.empty()) { // xml_filename not found at all in any skin -- check whether entire diff --git a/indra/llui/lluicolortable.cpp b/indra/llui/lluicolortable.cpp index 2717445396..ffeff15968 100644 --- a/indra/llui/lluicolortable.cpp +++ b/indra/llui/lluicolortable.cpp @@ -207,9 +207,10 @@ bool LLUIColorTable::loadFromSettings() { bool result = false; - // pass merge=true because we want colors.xml from every skin dir + // pass constraint=LLDir::ALL_SKINS because we want colors.xml from every + // skin dir BOOST_FOREACH(std::string colors_path, - gDirUtilp->findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", true)) + gDirUtilp->findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS)) { result |= loadFromFilename(colors_path, mLoadedColors); } diff --git a/indra/llvfs/lldir.cpp b/indra/llvfs/lldir.cpp index a7d12476a4..2d0adf14e6 100644 --- a/indra/llvfs/lldir.cpp +++ b/indra/llvfs/lldir.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #if LL_WINDOWS #include "lldir_win32.h" @@ -544,10 +543,10 @@ std::string LLDir::getExtension(const std::string& filepath) const std::string LLDir::findSkinnedFilenameBaseLang(const std::string &subdir, const std::string &filename, - bool merge) const + ESkinConstraint constraint) const { // This implementation is basically just as described in the declaration comments. - std::vector found(findSkinnedFilenames(subdir, filename, merge)); + std::vector found(findSkinnedFilenames(subdir, filename, constraint)); if (found.empty()) { return ""; @@ -557,10 +556,10 @@ std::string LLDir::findSkinnedFilenameBaseLang(const std::string &subdir, std::string LLDir::findSkinnedFilename(const std::string &subdir, const std::string &filename, - bool merge) const + ESkinConstraint constraint) const { // This implementation is basically just as described in the declaration comments. - std::vector found(findSkinnedFilenames(subdir, filename, merge)); + std::vector found(findSkinnedFilenames(subdir, filename, constraint)); if (found.empty()) { return ""; @@ -570,7 +569,7 @@ std::string LLDir::findSkinnedFilename(const std::string &subdir, std::vector LLDir::findSkinnedFilenames(const std::string& subdir, const std::string& filename, - bool merge) const + ESkinConstraint constraint) const { // Recognize subdirs that have no localization. static const char* sUnlocalizedData[] = @@ -582,7 +581,9 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, boost::end(sUnlocalizedData)); LL_DEBUGS("LLDir") << "subdir '" << subdir << "', filename '" << filename - << "', merge " << std::boolalpha << merge << LL_ENDL; + << "', constraint " + << ((constraint == CURRENT_SKIN)? "CURRENT_SKIN" : "ALL_SKINS") + << LL_ENDL; // Cache the default language directory for each subdir we've encountered. // A cache entry whose value is the empty string means "not localized, @@ -672,8 +673,8 @@ std::vector LLDir::findSkinnedFilenames(const std::string& subdir, // Here the desired filename exists in the first subsubdir. That means // this is a skindir we want to record in results. But if the caller - // passed merge=false, we must discard all previous skindirs. - if (! merge) + // passed constraint=CURRENT_SKIN, we must discard all previous skindirs. + if (constraint == CURRENT_SKIN) { results.clear(); } diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index a242802979..ffa2676838 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -119,6 +119,8 @@ class LLDir // these methods search the various skin paths for the specified file in the following order: // getUserSkinDir(), getUserDefaultSkinDir(), getSkinDir(), getDefaultSkinDir() + /// param value for findSkinnedFilenames(), explained below + enum ESkinConstraint { CURRENT_SKIN, ALL_SKINS }; /** * Given a filename within skin, return an ordered sequence of paths to * search. Nonexistent files will be filtered out -- which means that the @@ -130,25 +132,25 @@ class LLDir * level of skin subdirectory). * @param filename Desired filename within subdir within skin, e.g. * "panel_login.xml". DO NOT prepend (e.g.) "xui" or the desired language. - * @param merge Callers perform two different kinds of processing. When - * fetching a XUI file, for instance, the existence of @a filename in the - * specified skin completely supercedes any @a filename in the default - * skin. For that case, leave the default @a merge=false. The returned - * vector will contain only + * @param constraint Callers perform two different kinds of processing. + * When fetching a XUI file, for instance, the existence of @a filename in + * the specified skin completely supercedes any @a filename in the default + * skin. For that case, leave the default @a constraint=CURRENT_SKIN. The + * returned vector will contain only * ".../current_skin/xui/en/filename", * ".../current_skin/xui/current_language/filename". * But for (e.g.) "strings.xml", we want a given skin to be able to * override only specific entries from the default skin. Any string not * defined in the specified skin will be sought in the default skin. For - * that case, pass @a merge=true. The returned vector will contain at - * least ".../default/xui/en/strings.xml", + * that case, pass @a constraint=ALL_SKINS. The returned vector will + * contain at least ".../default/xui/en/strings.xml", * ".../default/xui/current_language/strings.xml", * ".../current_skin/xui/en/strings.xml", * ".../current_skin/xui/current_language/strings.xml". */ std::vector findSkinnedFilenames(const std::string& subdir, const std::string& filename, - bool merge=false) const; + ESkinConstraint constraint=CURRENT_SKIN) const; /// Values for findSkinnedFilenames(subdir) parameter static const char *XUI, *TEXTURES, *SKINBASE; /** @@ -160,7 +162,7 @@ class LLDir */ std::string findSkinnedFilenameBaseLang(const std::string &subdir, const std::string &filename, - bool merge=false) const; + ESkinConstraint constraint=CURRENT_SKIN) const; /** * Return the "most localized" pathname from findSkinnedFilenames(), or * the empty string if no such file exists. Parameters are identical to @@ -170,7 +172,7 @@ class LLDir */ std::string findSkinnedFilename(const std::string &subdir, const std::string &filename, - bool merge=false) const; + ESkinConstraint constraint=CURRENT_SKIN) const; // random filename in common temporary directory std::string getTempFilename() const; diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index a00fc8684c..15a5b6d4f3 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -584,7 +584,7 @@ namespace tut ensure_equals(lldir.getLanguage(), "en"); // top-level directory of a skin isn't localized - ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS), vec(list_of("install/skins/default/colors.xml") ("user/skins/default/colors.xml"))); // We should not have needed to check for skins/default/en. We should @@ -599,13 +599,13 @@ namespace tut StringVec expected(vec(list_of("install/skins/default/xui/en/strings.xml") ("user/skins/default/xui/en/strings.xml"))); - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), expected); // The first time, we had to probe to find out whether xui was localized. lldir.ensure_checked("install/skins/default/xui/en"); lldir.clear_checked(); // Now make the same call again -- should return same result -- - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), expected); // but this time it should remember that xui is localized. lldir.ensure_not_checked("install/skins/default/xui/en"); @@ -648,7 +648,7 @@ namespace tut ensure_equals(lldir.getLanguage(), "fr"); // pass merge=true to request this filename in all relevant skins - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), vec(list_of ("install/skins/default/xui/en/strings.xml") ("install/skins/default/xui/fr/strings.xml") @@ -691,7 +691,7 @@ namespace tut /*------------------------- "steam", "en" --------------------------*/ lldir.setSkinFolder("steam", "en"); - ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::SKINBASE, "colors.xml", LLDir::ALL_SKINS), vec(list_of ("install/skins/default/colors.xml") ("install/skins/steam/colors.xml") @@ -715,7 +715,7 @@ namespace tut vec(list_of("user/skins/steam/xui/en/strings.xml"))); // pass merge=true to request this filename in all relevant skins - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), vec(list_of ("install/skins/default/xui/en/strings.xml") ("install/skins/steam/xui/en/strings.xml") @@ -732,7 +732,7 @@ namespace tut ("user/skins/steam/xui/fr/strings.xml"))); // pass merge=true to request this filename in all relevant skins - ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", true), + ensure_equals(lldir.findSkinnedFilenames(LLDir::XUI, "strings.xml", LLDir::ALL_SKINS), vec(list_of ("install/skins/default/xui/en/strings.xml") ("install/skins/default/xui/fr/strings.xml") diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index 7eb1a202a0..edc43534dd 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -1583,10 +1583,11 @@ struct UIImageDeclarations : public LLInitParam::Block bool LLUIImageList::initFromFile() { - // Look for textures.xml in all the right places. Pass merge=true because - // we want to overlay textures.xml from all the skins directories. + // Look for textures.xml in all the right places. Pass + // constraint=LLDir::ALL_SKINS because we want to overlay textures.xml + // from all the skins directories. std::vector textures_paths = - gDirUtilp->findSkinnedFilenames(LLDir::TEXTURES, "textures.xml", true); + gDirUtilp->findSkinnedFilenames(LLDir::TEXTURES, "textures.xml", LLDir::ALL_SKINS); std::vector::const_iterator pi(textures_paths.begin()), pend(textures_paths.end()); if (pi == pend) { -- cgit v1.3 From 6ca37068080e3b26e5cb163dfd874bc0e2f4c837 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 12 Oct 2012 08:42:18 -0400 Subject: LLUICtrlFactory::getLayeredXMLNode() gets LLDir::ESkinConstraint. At this point, LLUICtrlFactory::getLayeredXMLNode() is a pretty thin wrapper around LLDir::findSkinnedFilenames() and LLXMLNode::getLayeredXMLNode(). Until now, LLUICtrlFactory::getLayeredXMLNode() passed (by default) LLDir::CURRENT_SKIN to LLDir::findSkinnedFilenames(). But that meant that a caller such as LLTransUtil::parseStrings() that wants almost the same functionality, but with LLDir::ALL_SKINS instead, had to clone the logic from LLUICtrlFactory::getLayeredXMLNode(). Allowing its caller to pass the desired LLDir::ESkinConstraint enum value eliminates the need to clone its logic. Remove cloned logic from LLTransUtil::parseStrings(). --- indra/llui/lltransutil.cpp | 20 ++++++-------------- indra/llui/lluictrlfactory.cpp | 5 +++-- indra/llui/lluictrlfactory.h | 4 +++- 3 files changed, 12 insertions(+), 17 deletions(-) (limited to 'indra/llui/lltransutil.cpp') diff --git a/indra/llui/lltransutil.cpp b/indra/llui/lltransutil.cpp index 3b7e737dea..80d079cbc8 100644 --- a/indra/llui/lltransutil.cpp +++ b/indra/llui/lltransutil.cpp @@ -35,21 +35,13 @@ bool LLTransUtil::parseStrings(const std::string& xml_filename, const std::set& default_args) { - // LLUICtrlFactory::getLayeredXMLNode() just calls - // gDirUtilp->findSkinnedFilenames(constraint=LLDir::CURRENT_SKIN) and - // then passes the resulting paths to LLXMLNode::getLayeredXMLNode(). - // Bypass that and call LLXMLNode::getLayeredXMLNode() directly: we want - // constraint=LLDir::ALL_SKINS. - std::vector paths = - gDirUtilp->findSkinnedFilenames(LLDir::XUI, xml_filename, LLDir::ALL_SKINS); - if (paths.empty()) - { - // xml_filename not found at all in any skin -- check whether entire - // path was passed (but I hope we no longer have callers who do that) - paths.push_back(xml_filename); - } LLXMLNodePtr root; - bool success = LLXMLNode::getLayeredXMLNode(root, paths); + // Pass LLDir::ALL_SKINS to load a composite of all the individual string + // definitions in the default skin and the current skin. This means an + // individual skin can provide an xml_filename that overrides only a + // subset of the available string definitions; any string definition not + // overridden by that skin will be sought in the default skin. + bool success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root, LLDir::ALL_SKINS); if (!success) { llerrs << "Couldn't load string table " << xml_filename << llendl; diff --git a/indra/llui/lluictrlfactory.cpp b/indra/llui/lluictrlfactory.cpp index 2b317b46e3..f7307cd076 100644 --- a/indra/llui/lluictrlfactory.cpp +++ b/indra/llui/lluictrlfactory.cpp @@ -151,11 +151,12 @@ static LLFastTimer::DeclareTimer FTM_XML_PARSE("XML Reading/Parsing"); //----------------------------------------------------------------------------- // getLayeredXMLNode() //----------------------------------------------------------------------------- -bool LLUICtrlFactory::getLayeredXMLNode(const std::string &xui_filename, LLXMLNodePtr& root) +bool LLUICtrlFactory::getLayeredXMLNode(const std::string &xui_filename, LLXMLNodePtr& root, + LLDir::ESkinConstraint constraint) { LLFastTimer timer(FTM_XML_PARSE); std::vector paths = - gDirUtilp->findSkinnedFilenames(LLDir::XUI, xui_filename); + gDirUtilp->findSkinnedFilenames(LLDir::XUI, xui_filename, constraint); if (paths.empty()) { diff --git a/indra/llui/lluictrlfactory.h b/indra/llui/lluictrlfactory.h index 56e5f3eb7b..1acfd24112 100644 --- a/indra/llui/lluictrlfactory.h +++ b/indra/llui/lluictrlfactory.h @@ -31,6 +31,7 @@ #include "llinitparam.h" #include "llregistry.h" #include "llxuiparser.h" +#include "lldir.h" class LLView; @@ -212,7 +213,8 @@ fail: static void createChildren(LLView* viewp, LLXMLNodePtr node, const widget_registry_t&, LLXMLNodePtr output_node = NULL); - static bool getLayeredXMLNode(const std::string &filename, LLXMLNodePtr& root); + static bool getLayeredXMLNode(const std::string &filename, LLXMLNodePtr& root, + LLDir::ESkinConstraint constraint=LLDir::CURRENT_SKIN); private: //NOTE: both friend declarations are necessary to keep both gcc and msvc happy -- cgit v1.3