Skip to content

Commit

Permalink
directvt#86 WIP: Fix config variables expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 23, 2024
1 parent 6ef5c35 commit c1882e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ namespace netxs::app::shared
{
item.views.push_back(
{
.label = label->take_value(),
.label = config.expand(label),
.tooltip = label->take(menu::attr::tooltip, defs.tooltip),
.data = label->take(menu::attr::data, defs.data),
});
Expand Down Expand Up @@ -741,7 +741,7 @@ namespace netxs::app::shared
for (auto& f : recs)
{
//todo implement 'fonts/font/file' - font file path/url
gui_config.fontlist.push_back(f->take_value());
gui_config.fontlist.push_back(config.expand(f));
}
gui_config.hotkeys = ui::pro::keybd::load(config, "gui");
return gui_config;
Expand Down
6 changes: 3 additions & 3 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2238,21 +2238,21 @@ namespace netxs::ui
auto keybinds = config.list(path);
for (auto keybind_ptr : keybinds)
{
auto chord = keybind_ptr->take_value();
auto chord = config.expand(keybind_ptr);
auto preview = keybind_ptr->take("preview", faux);
auto action_ptr_list = keybind_ptr->list("action");
bindings.push_back({ .chord = chord, .preview = preview });
auto& rec = bindings.back();
//if constexpr (debugmode) log("chord=%% preview=%%", chord, preview);
for (auto action_ptr : action_ptr_list)
{
rec.actions.push_back({ .action = action_ptr->take_value() });
rec.actions.push_back({ .action = config.expand(action_ptr) });
auto& action = rec.actions.back();
//if constexpr (debugmode) log(" action=", action.action);
auto arg_ptr_list = action_ptr->list("data");
for (auto arg_ptr : arg_ptr_list)
{
action.args.push_back(arg_ptr->take_value());
action.args.push_back(config.expand(arg_ptr));
//if constexpr (debugmode) log(" data=", action.args.back());
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/netxs/desktopio/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,17 @@ namespace netxs::xml
if (is_like_variable()) return take<Quiet>(crop.front() == '/' ? crop : "/config/set/" + crop, defval, primary_value - 1);
else return defval;
}
auto expand(document::sptr item_ptr, si32 primary_value = 3)
{
auto crop = item_ptr->take_value();
auto is_quoted = item_ptr->is_quoted();
auto is_like_variable = !is_quoted && primary_value && crop.size() && (crop.front() == '/' || crop.size() < 128);
if (is_like_variable) // Try to find variable if it is not quoted and its len < 128.
{
return take<true>(crop.front() == '/' ? crop : "/config/set/" + crop, crop, primary_value - 1);
}
return crop;
}
template<class T>
auto take(text frompath, T defval, std::unordered_map<text, T> const& dict)
{
Expand Down

0 comments on commit c1882e6

Please sign in to comment.