fix bug when modifying option
This commit is contained in:
parent
f59e175aea
commit
423d54cce1
|
@ -649,7 +649,7 @@ void CDlgOptJson::to_ui(const SANEOPT& sop)
|
|||
}
|
||||
}
|
||||
}
|
||||
HTREEITEM CDlgOptJson::insert_to_tree(const SANEOPT& opt)
|
||||
HTREEITEM CDlgOptJson::insert_new_item(const SANEOPT& opt, bool sel)
|
||||
{
|
||||
HTREEITEM item = tree_.InsertItem(opt.title.c_str());
|
||||
wchar_t* name = new wchar_t[opt.name.length() + 2];
|
||||
|
@ -658,6 +658,13 @@ HTREEITEM CDlgOptJson::insert_to_tree(const SANEOPT& opt)
|
|||
if (!tree_.SetItemData(item, (DWORD_PTR)name))
|
||||
delete[] name;
|
||||
|
||||
opts_.push_back(opt);
|
||||
if (sel)
|
||||
{
|
||||
tree_.SelectItem(item);
|
||||
tree_.EnsureVisible(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
void CDlgOptJson::delete_from_tree(const wchar_t* name)
|
||||
|
@ -691,6 +698,25 @@ void CDlgOptJson::delete_from_tree(const wchar_t* name)
|
|||
tree_.DeleteAllItems();
|
||||
}
|
||||
}
|
||||
HTREEITEM CDlgOptJson::modify_tree_title(const wchar_t* name, const wchar_t* title)
|
||||
{
|
||||
HTREEITEM item = tree_.GetRootItem(), found = NULL;
|
||||
|
||||
while (item)
|
||||
{
|
||||
wchar_t* buf = (wchar_t*)tree_.GetItemData(item);
|
||||
if (buf && wcscmp(buf, name) == 0)
|
||||
{
|
||||
tree_.SetItemText(item, title);
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
|
||||
item = tree_.GetNextSiblingItem(item);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
bool CDlgOptJson::load_from_file(const wchar_t* path_file)
|
||||
{
|
||||
|
@ -776,8 +802,7 @@ bool CDlgOptJson::load_from_json_text(const wchar_t* txt, std::wstring* err_msg)
|
|||
|
||||
if (opt.from_json(child))
|
||||
{
|
||||
opts_.push_back(opt);
|
||||
insert_to_tree(opt);
|
||||
insert_new_item(opt, false);
|
||||
}
|
||||
|
||||
child->release();
|
||||
|
@ -1175,12 +1200,12 @@ void CDlgOptJson::OnBnClickedButtonModify()
|
|||
{
|
||||
sop.range = std::move(v.range);
|
||||
v = std::move(sop);
|
||||
modify_tree_title(v.name.c_str(), v.title.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
opts_.push_back(sop);
|
||||
insert_to_tree(sop);
|
||||
insert_new_item(sop);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1340,6 +1365,7 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
GotoDlgCtrl(GetDlgItem(IDC_EDIT_NAME));
|
||||
return;
|
||||
}
|
||||
opt.name = val;
|
||||
for (auto& v : opts_)
|
||||
{
|
||||
if (v.name == val)
|
||||
|
@ -1348,9 +1374,9 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
break;
|
||||
}
|
||||
}
|
||||
val = get_item_text(IDC_COMBO_DATA_TYPE);
|
||||
if (!opt.name.empty())
|
||||
{
|
||||
val = get_item_text(IDC_COMBO_DATA_TYPE);
|
||||
if (val == L"int")
|
||||
{
|
||||
dlg.init_ = std::to_wstring(*(int*)opt.def_val.c_str());
|
||||
|
@ -1423,9 +1449,8 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
from_ui(so);
|
||||
so.range = opt.range;
|
||||
so.def_val = opt.def_val;
|
||||
opts_.push_back(opt);
|
||||
insert_to_tree(opt);
|
||||
to_ui(opt);
|
||||
insert_new_item(so);
|
||||
to_ui(so);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,8 +145,9 @@ protected:
|
|||
|
||||
void from_ui(SANEOPT& sop);
|
||||
void to_ui(const SANEOPT& sop);
|
||||
HTREEITEM insert_to_tree(const SANEOPT& opt);
|
||||
HTREEITEM insert_new_item(const SANEOPT& opt, bool sel = true);
|
||||
void delete_from_tree(const wchar_t* name = NULL);
|
||||
HTREEITEM modify_tree_title(const wchar_t* name, const wchar_t* title);
|
||||
|
||||
bool load_from_file(const wchar_t* path_file);
|
||||
bool load_from_json_text(const wchar_t* txt, std::wstring* err_msg = NULL);
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue