|
2 | 2 |
|
3 | 3 | #include <stdexcept> |
4 | 4 | #include <wayfire/config/option.hpp> |
| 5 | +#include <wayfire/config/section.hpp> |
5 | 6 | #include <wayfire/config/compound-option.hpp> |
6 | 7 |
|
7 | 8 | namespace wf |
@@ -77,25 +78,12 @@ class base_option_wrapper_t |
77 | 78 | */ |
78 | 79 | void load_option(const std::string& name) |
79 | 80 | { |
80 | | - if (raw_option) |
81 | | - { |
82 | | - throw std::logic_error( |
83 | | - "Loading an option into option wrapper twice!"); |
84 | | - } |
85 | | - |
86 | | - auto untyped_option = load_raw_option(name); |
87 | | - if (untyped_option == nullptr) |
88 | | - { |
89 | | - throw std::runtime_error("No such option: " + std::string(name)); |
90 | | - } |
91 | | - |
92 | | - raw_option = std::dynamic_pointer_cast<OptionType>(untyped_option); |
93 | | - if (raw_option == nullptr) |
94 | | - { |
95 | | - throw std::runtime_error("Bad option type: " + std::string(name)); |
96 | | - } |
| 81 | + _load_option(load_raw_option(name), name); |
| 82 | + } |
97 | 83 |
|
98 | | - raw_option->add_updated_handler(&option_update_listener); |
| 84 | + void load_option(std::shared_ptr<wf::config::section_t> section, const std::string& name) |
| 85 | + { |
| 86 | + _load_option(section->get_option_or(name), section->get_name() + "/" + name); |
99 | 87 | } |
100 | 88 |
|
101 | 89 | virtual ~base_option_wrapper_t() |
@@ -162,5 +150,27 @@ class base_option_wrapper_t |
162 | 150 | */ |
163 | 151 | virtual std::shared_ptr<wf::config::option_base_t> load_raw_option( |
164 | 152 | const std::string& name) = 0; |
| 153 | + |
| 154 | + void _load_option(std::shared_ptr<wf::config::option_base_t> _option, const std::string& name) |
| 155 | + { |
| 156 | + if (raw_option) |
| 157 | + { |
| 158 | + throw std::logic_error( |
| 159 | + "Loading an option into option wrapper twice!"); |
| 160 | + } |
| 161 | + |
| 162 | + if (_option == nullptr) |
| 163 | + { |
| 164 | + throw std::runtime_error("No such option: " + std::string(name)); |
| 165 | + } |
| 166 | + |
| 167 | + raw_option = std::dynamic_pointer_cast<OptionType>(_option); |
| 168 | + if (raw_option == nullptr) |
| 169 | + { |
| 170 | + throw std::runtime_error("Bad option type: " + name); |
| 171 | + } |
| 172 | + |
| 173 | + raw_option->add_updated_handler(&option_update_listener); |
| 174 | + } |
165 | 175 | }; |
166 | 176 | } |
0 commit comments