Skip to content

Commit

Permalink
Improves menu separator parsing with validity/visibility node parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
GasDauMin committed Dec 23, 2023
1 parent 4b7d8e5 commit b3ba816
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/core/ObjectFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,31 +382,70 @@ namespace shellanything
//at this step the <menu> is valid
Menu* menu = new Menu();

ElementPtrList elements; //temporary xml element containers

//parse separator
std::string menu_separator;
bool have_separator = ParseAttribute(element, "separator", true, true, menu_separator, error);
bool separator_parsed = false;
if (have_separator)
{
bool is_valid_separator = false;

//try to parse this menu separator as a boolean
bool is_horizontal_separator = false;
separator_parsed = ra::strings::Parse(menu_separator, is_horizontal_separator);
if (separator_parsed && is_horizontal_separator)
{
menu->SetSeparator(true);
return menu;
is_valid_separator = true;
}

//try to parse as a string
menu_separator = ra::strings::Lowercase(menu_separator);
if (menu_separator == "horizontal")
{
menu->SetSeparator(true);
return menu;
is_valid_separator = true;
}
else if (menu_separator == "vertical" || menu_separator == "column")
{
menu->SetColumnSeparator(true);
is_valid_separator = true;
}

//find <validity> node under <menu>
elements = GetChildNodes(element, NODE_VALIDITY);
for (size_t i = 0; i < elements.size(); i++)
{
Validator* validator = ObjectFactory::GetInstance().ParseValidator(elements[i], error);
if (validator == NULL)
{
delete menu;
return NULL;
}

//add the new validator
menu->AddValidity(validator);
}

//find <visibility> node under <menu>
elements = GetChildNodes(element, NODE_VISIBILITY);
for (size_t i = 0; i < elements.size(); i++)
{
Validator* validator = ObjectFactory::GetInstance().ParseValidator(elements[i], error);
if (validator == NULL)
{
delete menu;
return NULL;
}

//add the new validator
menu->AddVisibility(validator);
}

if (is_valid_separator)
{
return menu;
}
}
Expand Down Expand Up @@ -447,8 +486,6 @@ namespace shellanything
}
}

ElementPtrList elements; //temporary xml element containers

//find <validity> node under <menu>
elements = GetChildNodes(element, NODE_VALIDITY);
for (size_t i = 0; i < elements.size(); i++)
Expand Down

0 comments on commit b3ba816

Please sign in to comment.