管理员JSON测试配置添加描述项

This commit is contained in:
gb 2022-12-14 17:59:02 +08:00
parent 5311342f1f
commit d68c3a7fc5
8 changed files with 59 additions and 10 deletions

View File

@ -5,6 +5,7 @@
#include "scanner-check.h" #include "scanner-check.h"
#include "CDlgItemMgr.h" #include "CDlgItemMgr.h"
#include "afxdialogex.h" #include "afxdialogex.h"
#include "CDlgInput.h"
#include <file/file_util.h> #include <file/file_util.h>
#include <coding/coding.h> #include <coding/coding.h>
@ -56,6 +57,7 @@ BOOL CDlgItemMgr::OnInitDialog()
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u540D\u79F0"), 0, 102); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u540D\u79F0"), 0, 102);
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5FC5\u987B\u8054\u673A\u6D4B\u8BD5"), 0, 87); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u5FC5\u987B\u8054\u673A\u6D4B\u8BD5"), 0, 87);
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u4E0D\u901A\u8FC7\u5219\u505C\u6B62"), 0, 87); list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u4E0D\u901A\u8FC7\u5219\u505C\u6B62"), 0, 87);
list_.InsertColumn(list_.GetHeaderCtrl()->GetItemCount(), TEXT("\u63CF\u8FF0"), 0, 120);
list_.SetExtendedStyle((list_.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES) & (~LVS_EX_CHECKBOXES)); list_.SetExtendedStyle((list_.GetExStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES) & (~LVS_EX_CHECKBOXES));
list_.ModifyStyle(0, LVS_SINGLESEL); list_.ModifyStyle(0, LVS_SINGLESEL);
load_stored_config(); load_stored_config();
@ -76,14 +78,17 @@ END_MESSAGE_MAP()
void CDlgItemMgr::OnBnClickedButtonAdd() void CDlgItemMgr::OnBnClickedButtonAdd()
{ {
// TODO: 在此添加控件通知处理程序代码 // TODO: 在此添加控件通知处理程序代码
wchar_t text[128] = { 0 }, name[128] = { 0 }; wchar_t text[128] = { 0 }, name[128] = { 0 }, desc[128] = { 0 };
bool online = is_checked(this, IDC_CHECK_ONLINE), fatal = is_checked(this, IDC_CHECK_FATAL); bool online = is_checked(this, IDC_CHECK_ONLINE), fatal = is_checked(this, IDC_CHECK_FATAL);
int ind = -1; int ind = -1;
if (::GetWindowTextW(GetDlgItem(IDC_EDIT_TITLE)->m_hWnd, text, _countof(text) - 1) == 0 || if (::GetWindowTextW(GetDlgItem(IDC_EDIT_TITLE)->m_hWnd, text, _countof(text) - 1) == 0 ||
::GetWindowTextW(GetDlgItem(IDC_EDIT_NAME)->m_hWnd, name, _countof(name) - 1) == 0) ::GetWindowTextW(GetDlgItem(IDC_EDIT_NAME)->m_hWnd, name, _countof(name) - 1) == 0)
return; return;
if (::GetWindowTextW(GetDlgItem(IDC_EDIT_DESC)->m_hWnd, name, _countof(name) - 1) == 0)
{
wcscpy(desc, text);
}
for (int i = 0; i < list_.GetItemCount(); ++i) for (int i = 0; i < list_.GetItemCount(); ++i)
{ {
wchar_t val[128] = { 0 }; wchar_t val[128] = { 0 };
@ -106,6 +111,7 @@ void CDlgItemMgr::OnBnClickedButtonAdd()
list_.SetItemText(ind, 2, text); list_.SetItemText(ind, 2, text);
list_.SetItemText(ind, 3, online ? L"true" : L"false"); list_.SetItemText(ind, 3, online ? L"true" : L"false");
list_.SetItemText(ind, 4, fatal ? L"true" : L"false"); list_.SetItemText(ind, 4, fatal ? L"true" : L"false");
list_.SetItemText(ind, 5, desc);
list_.SetItemState(ind, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED); list_.SetItemState(ind, LVNI_FOCUSED | LVIS_SELECTED, LVNI_FOCUSED | LVIS_SELECTED);
item_changed(); item_changed();
} }
@ -122,7 +128,7 @@ void CDlgItemMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
if (r.left != -1) if (r.left != -1)
{ {
std::vector<int> width; std::vector<int> width;
int ind = r.left; int ind = r.left, hpos = list_.GetScrollPos(SB_HORZ);
for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i) for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i)
{ {
@ -130,6 +136,7 @@ void CDlgItemMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
list_.GetHeaderCtrl()->GetItemRect(i, &r); list_.GetHeaderCtrl()->GetItemRect(i, &r);
width.push_back(r.right - r.left); width.push_back(r.right - r.left);
} }
pos.x += hpos;
for (int i = 0; i < width.size(); ++i) for (int i = 0; i < width.size(); ++i)
{ {
if (pos.x <= width[i]) if (pos.x <= width[i])
@ -152,7 +159,7 @@ void CDlgItemMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
} }
} }
} }
else else if(i < 5)
{ {
list_.GetItemText(ind, i, text, _countof(text) - 1); list_.GetItemText(ind, i, text, _countof(text) - 1);
if (wcscmp(text, L"true")) if (wcscmp(text, L"true"))
@ -160,6 +167,25 @@ void CDlgItemMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
else else
list_.SetItemText(ind, i, L"false"); list_.SetItemText(ind, i, L"false");
} }
else
{
CDlgInput input;
wchar_t val[128] = { 0 };
std::wstring def(L"");
list_.GetItemText(ind, 2, val, _countof(val) - 1);
def = val;
input.set_title((std::wstring(L"\u4FEE\u6539 ") + val + L" \u63CF\u8FF0").c_str());
list_.GetItemText(ind, 5, val, _countof(val) - 1);
input.val_ = val;
if (input.DoModal() == IDOK)
{
if(input.val_.empty())
list_.SetItemText(ind, 5, def.c_str());
else
list_.SetItemText(ind, 5, input.val_.c_str());
}
}
break; break;
} }
@ -199,6 +225,8 @@ void CDlgItemMgr::get_item(int ind, page_config::ITEM* item)
item->man = wcscmp(text, L"false") == 0; item->man = wcscmp(text, L"false") == 0;
list_.GetItemText(ind, 4, text, _countof(text) - 1); list_.GetItemText(ind, 4, text, _countof(text) - 1);
item->fatal = wcscmp(text, L"true") == 0; item->fatal = wcscmp(text, L"true") == 0;
list_.GetItemText(ind, 5, text, _countof(text) - 1);
item->desc = text;
} }
void CDlgItemMgr::load_from_file(const wchar_t* file) void CDlgItemMgr::load_from_file(const wchar_t* file)
{ {
@ -207,7 +235,8 @@ void CDlgItemMgr::load_from_file(const wchar_t* file)
*n = sn + 40, *n = sn + 40,
*t = n + 40, *t = n + 40,
*m = t + 40, *m = t + 40,
*f = m + 40; *f = m + 40,
*d = f + 40;
size_t pos = 0; size_t pos = 0;
std::string bom(""); std::string bom("");
std::wstring cont(L""); std::wstring cont(L"");
@ -218,7 +247,7 @@ void CDlgItemMgr::load_from_file(const wchar_t* file)
cont += L"\r\n"; cont += L"\r\n";
while ((pos = cont.find(L"\r\n")) != std::wstring::npos) while ((pos = cont.find(L"\r\n")) != std::wstring::npos)
{ {
int cnt = swscanf(cont.substr(0, pos).c_str(), L"%s %s %s %s", n, t, m, f); int cnt = swscanf(cont.substr(0, pos).c_str(), L"%s %s %s %s %s", n, t, m, f, d);
if (cnt >= 2) if (cnt >= 2)
{ {
bool man = false, fatal = true; bool man = false, fatal = true;
@ -233,7 +262,12 @@ void CDlgItemMgr::load_from_file(const wchar_t* file)
list_.SetItemText(cnt, 2, t); list_.SetItemText(cnt, 2, t);
list_.SetItemText(cnt, 3, man ? L"false" : L"true"); list_.SetItemText(cnt, 3, man ? L"false" : L"true");
list_.SetItemText(cnt, 4, f ? L"true" : L"false"); list_.SetItemText(cnt, 4, f ? L"true" : L"false");
if(*d)
list_.SetItemText(cnt, 5, d);
else
list_.SetItemText(cnt, 5, t);
} }
memset(path, 0, sizeof(path));
cont.erase(0, pos + 2); cont.erase(0, pos + 2);
} }
@ -256,7 +290,8 @@ void CDlgItemMgr::item_changed(void)
{ {
text += items[i].name + L" " + items[i].title + L" "; text += items[i].name + L" " + items[i].title + L" ";
text += items[i].man ? L"false " : L"true "; text += items[i].man ? L"false " : L"true ";
text += items[i].fatal ? L"true\r\n" : L"false\r\n"; text += items[i].fatal ? L"true " : L"false ";
text += items[i].desc + L"\r\n";
} }
coding_util::bom::from_unicode(text.c_str(), text.length() * 2, got_str, &bom); coding_util::bom::from_unicode(text.c_str(), text.length() * 2, got_str, &bom);
file_util::save_2_file(bom.c_str(), bom.length(), get_stored_config_file().c_str()); file_util::save_2_file(bom.c_str(), bom.length(), get_stored_config_file().c_str());

View File

@ -330,7 +330,7 @@ void CDlgMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
if (r.left != -1) if (r.left != -1)
{ {
std::vector<int> width; std::vector<int> width;
int ind = r.left; int ind = r.left, hpos = list_.GetScrollPos(SB_HORZ);
for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i) for (int i = 0; i < list_.GetHeaderCtrl()->GetItemCount(); ++i)
{ {
@ -338,6 +338,7 @@ void CDlgMgr::OnNMDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
list_.GetHeaderCtrl()->GetItemRect(i, &r); list_.GetHeaderCtrl()->GetItemRect(i, &r);
width.push_back(r.right - r.left); width.push_back(r.right - r.left);
} }
pos.x += hpos;
for (int i = 0; i < width.size(); ++i) for (int i = 0; i < width.size(); ++i)
{ {
if (pos.x <= width[i]) if (pos.x <= width[i])
@ -512,6 +513,7 @@ std::wstring CDlgMgr::export_config(bool *ok, bool used_in_code, int code_ver)
child->set_value(L"man", wcscmp(text, L"false") == 0); child->set_value(L"man", wcscmp(text, L"false") == 0);
list_.GetItemText(i, 3, text, _countof(text) - 1); list_.GetItemText(i, 3, text, _countof(text) - 1);
child->set_value(L"err-level", wcscmp(text, L"true") == 0 ? L"fatal" : L"warning"); child->set_value(L"err-level", wcscmp(text, L"true") == 0 ? L"fatal" : L"warning");
child->set_value(L"desc", item.desc.c_str());
} }
else else
{ {

View File

@ -24,6 +24,7 @@ public:
{ {
std::wstring name; std::wstring name;
std::wstring title; std::wstring title;
std::wstring desc;
bool man; bool man;
bool fatal; bool fatal;

View File

@ -9,6 +9,7 @@
#define IDD_MANAGER 130 #define IDD_MANAGER 130
#define IDD_TEST_ITEM 131 #define IDD_TEST_ITEM 131
#define IDR_MENU1 133 #define IDR_MENU1 133
#define IDD_INPUT 134
#define IDC_TAB1 1000 #define IDC_TAB1 1000
#define IDC_STATIC_RECT 1001 #define IDC_STATIC_RECT 1001
#define IDC_EDIT_VID_SRC 1002 #define IDC_EDIT_VID_SRC 1002
@ -33,6 +34,8 @@
#define IDC_EDIT_VER 1018 #define IDC_EDIT_VER 1018
#define IDC_EDIT_NAME 1019 #define IDC_EDIT_NAME 1019
#define IDC_EDIT_TITLE 1020 #define IDC_EDIT_TITLE 1020
#define IDC_EDIT1 1020
#define IDC_EDIT_DESC 1021
#define ID_LIST_32771 32771 #define ID_LIST_32771 32771
#define ID_LIST_PASTE_CLIPBOARD 32772 #define ID_LIST_PASTE_CLIPBOARD 32772
#define ID_LIST_32773 32773 #define ID_LIST_32773 32773
@ -42,9 +45,9 @@
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 134 #define _APS_NEXT_RESOURCE_VALUE 136
#define _APS_NEXT_COMMAND_VALUE 32775 #define _APS_NEXT_COMMAND_VALUE 32775
#define _APS_NEXT_CONTROL_VALUE 1020 #define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#endif #endif
#endif #endif

View File

@ -189,6 +189,7 @@
</ResourceCompile> </ResourceCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CDlgInput.h" />
<ClInclude Include="CDlgItemMgr.h" /> <ClInclude Include="CDlgItemMgr.h" />
<ClInclude Include="CDlgMgr.h" /> <ClInclude Include="CDlgMgr.h" />
<ClInclude Include="framework.h" /> <ClInclude Include="framework.h" />
@ -200,6 +201,7 @@
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CDlgInput.cpp" />
<ClCompile Include="CDlgItemMgr.cpp" /> <ClCompile Include="CDlgItemMgr.cpp" />
<ClCompile Include="CDlgMgr.cpp" /> <ClCompile Include="CDlgMgr.cpp" />
<ClCompile Include="pch.cpp"> <ClCompile Include="pch.cpp">

View File

@ -42,6 +42,9 @@
<ClInclude Include="CDlgItemMgr.h"> <ClInclude Include="CDlgItemMgr.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CDlgInput.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="scanner-check.cpp"> <ClCompile Include="scanner-check.cpp">
@ -59,6 +62,9 @@
<ClCompile Include="CDlgItemMgr.cpp"> <ClCompile Include="CDlgItemMgr.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="CDlgInput.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="scannercheck.rc"> <ResourceCompile Include="scannercheck.rc">