Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/core/ConfigFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,24 +525,22 @@ 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, ' ');

const std::string short_string = ToShortString();
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++)
{
Menu* menu = mMenus[i];
menu->ToLongString(str, indent + 2);

str += NEW_LINE;
str += "\n";
}

str += indent_str + "}";
Expand Down
6 changes: 2 additions & 4 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,22 @@ 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, ' ');

const std::string short_string = ToShortString();
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++)
{
ConfigFile* config = mConfigurations[i];
config->ToLongString(str, indent + 2);

str += NEW_LINE;
str += "\n";
}

str += indent_str + "}";
Expand Down
1 change: 1 addition & 0 deletions src/core/IObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace shellanything

/// <summary>
/// Get a string representation of this object and its children.
/// The output string is multiple lines. Each line separated by '\n' (LF) character.
/// </summary>
/// <param name="str">The string to append this object's description to.</param>
/// <param name="indent">The indentation (spaces) to add before each line describing this object.</param>
Expand Down
1 change: 0 additions & 1 deletion src/core/Icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 6 additions & 10 deletions src/core/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,50 +516,46 @@ 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, ' ');

const std::string short_string = ToShortString();
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++)
{
Menu* submenu = mSubMenus[i];
submenu->ToLongString(str, indent + 2);

str += NEW_LINE;
str += "\n";
}

str += indent_str + "}";
Expand Down
1 change: 0 additions & 1 deletion src/core/Validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 19 additions & 7 deletions src/shellextension/CContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/shellextension/CContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/tests/TestIObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "TestIObject.h"
#include "ConfigManager.h"
#include "ConfigFile.h"
#include "LoggerHelper.h"

#include "rapidassist/strings.h"
#include "rapidassist/testing.h"
Expand Down Expand Up @@ -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";
Expand All @@ -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() << "'.";
}
Expand Down