From 1905766918d780c8fbab0fbccc5195d72eb348ec Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Sun, 25 Aug 2024 17:33:23 -0400 Subject: [PATCH] Replaced using CRLF by LF in IObject::ToLongString() implementations. --- src/core/ConfigFile.cpp | 6 ++---- src/core/ConfigManager.cpp | 6 ++---- src/core/IObject.h | 1 + src/core/Icon.cpp | 1 - src/core/Menu.cpp | 16 ++++++---------- src/core/Validator.cpp | 1 - src/shellextension/CContextMenu.cpp | 26 +++++++++++++++++++------- src/shellextension/CContextMenu.h | 1 + src/tests/TestIObject.cpp | 5 ++++- 9 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/core/ConfigFile.cpp b/src/core/ConfigFile.cpp index 805c62f..a77afa9 100644 --- a/src/core/ConfigFile.cpp +++ b/src/core/ConfigFile.cpp @@ -525,7 +525,6 @@ namespace shellanything void ConfigFile::ToLongString(std::string& str, int indent) const { - static const char* NEW_LINE = ra::environment::GetLineSeparator(); const bool have_children = (mMenus.size() > 0); const std::string indent_str = std::string(indent, ' '); @@ -533,8 +532,7 @@ namespace shellanything str += indent_str + short_string; if (have_children) { - str += " {"; - str += NEW_LINE; + str += " {\n"; // print children for (size_t i = 0; i < mMenus.size(); i++) @@ -542,7 +540,7 @@ namespace shellanything Menu* menu = mMenus[i]; menu->ToLongString(str, indent + 2); - str += NEW_LINE; + str += "\n"; } str += indent_str + "}"; diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index aa19835..963b285 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -237,7 +237,6 @@ namespace shellanything void ConfigManager::ToLongString(std::string& str, int indent) const { - static const char* NEW_LINE = ra::environment::GetLineSeparator(); const bool have_children = (mConfigurations.size() > 0); const std::string indent_str = std::string(indent, ' '); @@ -245,8 +244,7 @@ namespace shellanything str += indent_str + short_string; if (have_children) { - str += " {"; - str += NEW_LINE; + str += " {\n"; // print config children for (size_t i = 0; i < mConfigurations.size(); i++) @@ -254,7 +252,7 @@ namespace shellanything ConfigFile* config = mConfigurations[i]; config->ToLongString(str, indent + 2); - str += NEW_LINE; + str += "\n"; } str += indent_str + "}"; diff --git a/src/core/IObject.h b/src/core/IObject.h index 31b7973..ff47ee1 100644 --- a/src/core/IObject.h +++ b/src/core/IObject.h @@ -49,6 +49,7 @@ namespace shellanything /// /// Get a string representation of this object and its children. + /// The output string is multiple lines. Each line separated by '\n' (LF) character. /// /// The string to append this object's description to. /// The indentation (spaces) to add before each line describing this object. diff --git a/src/core/Icon.cpp b/src/core/Icon.cpp index 898b93a..7b8028c 100644 --- a/src/core/Icon.cpp +++ b/src/core/Icon.cpp @@ -175,7 +175,6 @@ namespace shellanything void Icon::ToLongString(std::string& str, int indent) const { - static const char* NEW_LINE = ra::environment::GetLineSeparator(); const std::string indent_str = std::string(indent, ' '); const std::string short_string = ToShortString(); diff --git a/src/core/Menu.cpp b/src/core/Menu.cpp index a8edbe8..61a4bec 100644 --- a/src/core/Menu.cpp +++ b/src/core/Menu.cpp @@ -516,7 +516,6 @@ namespace shellanything void Menu::ToLongString(std::string& str, int indent) const { - static const char* NEW_LINE = ra::environment::GetLineSeparator(); const bool have_children = (mVisibilities.size() + mValidities.size() + mSubMenus.size() > 0); const std::string indent_str = std::string(indent, ' '); @@ -524,34 +523,31 @@ namespace shellanything str += indent_str + short_string; if (have_children) { - str += " {"; - str += NEW_LINE; + str += " {\n"; // print visibility children if (mVisibilities.size()) { - str += indent_str + " Visibilities:"; - str += NEW_LINE; + str += indent_str + " Visibilities:\n"; } for (size_t i = 0; i < mVisibilities.size(); i++) { Validator* validator = mVisibilities[i]; validator->ToLongString(str, indent + 4); - str += NEW_LINE; + str += "\n"; } // print validity children if (mValidities.size()) { - str += indent_str + " Validities:"; - str += NEW_LINE; + str += indent_str + " Validities:\n"; } for (size_t i = 0; i < mValidities.size(); i++) { Validator* validator = mValidities[i]; validator->ToLongString(str, indent + 4); - str += NEW_LINE; + str += "\n"; } // print menu children for (size_t i = 0; i < mSubMenus.size(); i++) @@ -559,7 +555,7 @@ namespace shellanything Menu* submenu = mSubMenus[i]; submenu->ToLongString(str, indent + 2); - str += NEW_LINE; + str += "\n"; } str += indent_str + "}"; diff --git a/src/core/Validator.cpp b/src/core/Validator.cpp index 26fed33..7e56f8d 100644 --- a/src/core/Validator.cpp +++ b/src/core/Validator.cpp @@ -1323,7 +1323,6 @@ namespace shellanything void Validator::ToLongString(std::string& str, int indent) const { - static const char* NEW_LINE = ra::environment::GetLineSeparator(); const std::string indent_str = std::string(indent, ' '); const std::string short_string = ToShortString(); diff --git a/src/shellextension/CContextMenu.cpp b/src/shellextension/CContextMenu.cpp index 9da433d..d75e131 100644 --- a/src/shellextension/CContextMenu.cpp +++ b/src/shellextension/CContextMenu.cpp @@ -320,6 +320,23 @@ void CContextMenu::BuildTopMenuTree(HMENU hMenu) } } +void CContextMenu::PrintVerboseMenuStructure() const +{ + if (!shellanything::LoggerHelper::IsVerboseLoggingEnabled()) + return; + + SA_DECLARE_SCOPE_LOGGER_ARGS(sli); + sli.verbose = true; + sli.instance = this; + shellanything::ScopeLogger logger(&sli); + + shellanything::ConfigManager& cmgr = shellanything::ConfigManager::GetInstance(); + + std::string menu_tree; + cmgr.ToLongString(menu_tree, 0); + SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), Menu tree:\n" << menu_tree.c_str(); +} + CContextMenu::CContextMenu() { SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), new instance " << ToHexString(this); @@ -420,13 +437,8 @@ HRESULT STDMETHODCALLTYPE CContextMenu::QueryContextMenu(HMENU hMenu, UINT menu_ UINT num_menu_items = next_command_id - first_command_id; SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), statistics: first_command_id=" << first_command_id << " menu_last_command_id=" << menu_last_command_id << " next_command_id=" << next_command_id << " num_menu_items=" << num_menu_items << ".\n"; - //debug the constructed menu tree - if (shellanything::LoggerHelper::IsVerboseLoggingEnabled()) - { - std::string menu_tree; - cmgr.ToLongString(menu_tree, 0); - SA_VERBOSE_LOG(INFO) << __FUNCTION__ "(), Menu tree:\n" << menu_tree.c_str(); - } + //debug the constructed menu tree, if required + PrintVerboseMenuStructure(); HRESULT hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, num_menu_items); return hr; diff --git a/src/shellextension/CContextMenu.h b/src/shellextension/CContextMenu.h index be22367..c5bb0a9 100644 --- a/src/shellextension/CContextMenu.h +++ b/src/shellextension/CContextMenu.h @@ -81,6 +81,7 @@ class ATL_NO_VTABLE CContextMenu : private: void BuildTopMenuTree(HMENU hMenu); void BuildSubMenuTree(HMENU hMenu, shellanything::Menu* menu, UINT& insert_pos, bool& next_menu_is_column); + void PrintVerboseMenuStructure() const; CCriticalSection m_CS; //protects class members ULONG m_refCount; diff --git a/src/tests/TestIObject.cpp b/src/tests/TestIObject.cpp index 5d91d78..eb4ad5f 100644 --- a/src/tests/TestIObject.cpp +++ b/src/tests/TestIObject.cpp @@ -25,6 +25,7 @@ #include "TestIObject.h" #include "ConfigManager.h" #include "ConfigFile.h" +#include "LoggerHelper.h" #include "rapidassist/strings.h" #include "rapidassist/testing.h" @@ -281,7 +282,6 @@ namespace shellanything //Get actual std::string longstring_actual; cmgr.ToLongString(longstring_actual, 0); - ra::strings::Replace(longstring_actual, "\r\n", "\n"); // Replace CRLF by LF to display properly in GoogleTest diff view //Get expected long string from file std::string expected_source_path = std::string("test_files") + path_separator + test_name + ".expected.txt"; @@ -300,6 +300,9 @@ namespace shellanything //Do the actual comparison ASSERT_EQ(longstring_expected, longstring_actual); + // Add to logs to show how it prints + SA_LOG(INFO) << __FUNCTION__ << "() Menu Tree:\n" << longstring_actual; + //Cleanup ASSERT_TRUE(workspace.Cleanup()) << "Failed deleting workspace directory '" << workspace.GetBaseDirectory() << "'."; }