14 #include "xitemnode.h"
16 XItemNodeBase::XItemNodeBase(
const char *name,
bool runtime,
bool auto_set_any) :
20 m_lsnTryAutoSet = tr[ *
this].onListChanged().connect( *
this,
21 &XItemNodeBase::onTryAutoSet);
26 XItemNodeBase::onTryAutoSet(
const Snapshot &shot,
const Payload::ListChangeEvent &e) {
27 if( !autoSetAny())
return;
28 XString var = shot[ *
this].to_str();
29 if(var.length())
return;
30 auto items = itemStrings(e.shot_of_list);
32 trans( *this).str(items.front().label);
37 xpointeritemnode_throwConversionError_() {
38 throw XKameError(i18n_noncontext(
"No item."), __FILE__, __LINE__);
41 XComboNode::XComboNode(
const char *name,
bool runtime,
bool auto_set_any)
51 XComboNode::Payload::operator=(
const XString &var) {
54 for(i = 0; i < m_strings->size(); ++i) {
55 if(m_strings->at(i) == var) {
60 if(i == m_strings->size())
62 m_var = std::pair<XString, int>(var, i);
63 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>( &node()));
68 XComboNode::Payload::operator=(
int t) {
69 if((t >= 0) && (t < (
int)m_strings->size()))
70 m_var = std::pair<XString, int>(m_strings->at(t), t);
72 m_var = std::pair<XString, int>(
"", -1);
73 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>( &node()));
78 XComboNode::Payload::add(
const XString &str) {
79 m_strings = std::make_shared<std::deque<XString>>( *m_strings);
80 m_strings->push_back(str);
81 ListChangeEvent e(tr(), static_cast<XItemNodeBase*>( &node()));
82 tr().mark(onListChanged(), std::move(e));
83 if(str == m_var.first) {
84 m_var.second = m_strings->size() - 1;
85 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>( &node()));
90 XComboNode::Payload::clear() {
91 m_strings = std::make_shared<std::deque<XString>>();
92 ListChangeEvent e(tr(), static_cast<XItemNodeBase*>( &node()));
93 tr().mark(onListChanged(), std::move(e));
94 if(m_var.second >= 0) {
96 tr().mark(onValueChanged(), static_cast<XValueNodeBase*>( &node()));
100 std::vector<XItemNodeBase::Item> XComboNode::Payload::itemStrings()
const {
101 std::vector<XItemNodeBase::Item> items;
102 for(
auto it = m_strings->begin(); it != m_strings->end(); it++) {
106 items.push_back(std::move(item));
108 assert(m_strings->size() || (m_var.second < 0));
109 if(m_var.second < 0) {
111 item.name = m_var.first;
112 if(item.name.length()) {
113 item.label = formatString(
"(%s)", item.name.c_str());
114 items.push_back(std::move(item));