UI: explain dangerous operations, screen modes and host filtering
Four items from a user-side review of the master. The common thread: the UI
now says what it is about to do instead of leaving the user to guess.
Confirm boxes. Logout, restart, shutdown, delete host and uninstall client
all asked "are you sure" without naming the action or the hosts, so a
multi-selection could not be checked. DescribeTargetHosts() lists
"note (or computer name) (ip)" capped at five lines, and the default button
is No. The preview is dropped before the modal box and targets are
re-resolved after it, since the list can reshuffle in between.
Screen modes. High Speed / Ultra Speed became High Quality (DXGI +
differential: lossless, bandwidth hungry) and Smooth (GDI + H264: lossy,
cheap). TranslateMenu looks menus up by displayed text, so the .rc entries,
the FeatureLimitsDlg item names and the language pack keys changed together.
Host filter. The Ctrl+F bar was find-next; it now filters as you type over
IP, location, note, OS and version, and Esc clears the filter. The status
line reads "filtered: N / M total" while active. Commands still resolve by
clientID and m_FilteredIndices still maps row to m_HostList index, so no
command path changes. SearchBarDlg drops from 446 to 312 lines.
Quality changes. The adaptive level now shows its reason for twenty seconds
("Good (high latency)") instead of silently changing. The full-screen info
bar was a fixed 170px, so that reason was clipped; the width is now measured
from the text with the same font that paints it, 170 becoming the floor and
16px quantisation so changing digits do not jitter the window. Cosmetic
only: no threshold, hysteresis, cooldown or lock-out logic is touched.
Verified: debug server build, 0 errors; new strings present in .res and in
the exe. UI not exercised - the debug master would fight the running release
master for the listening port in Bin/settings.ini.
This commit is contained in:
1 parent
a190c21217
commit
6b87a31c6f
12 files changed
+364
-220
No files matched your search
@@ -8,7 +8,6 @@ IMPLEMENT_DYNAMIC(CSearchBarDlg, CDialogEx)
|
||||
CSearchBarDlg::CSearchBarDlg(CMy2015RemoteDlg* pParent)
|
||||
: CDialogLangEx(IDD_SEARCH_BAR, pParent)
|
||||
, m_pParent(pParent)
|
||||
, m_nCurrentIndex(-1)
|
||||
{
|
||||
m_brushEdit.CreateSolidBrush(RGB(60, 60, 60));
|
||||
m_brushStatic.CreateSolidBrush(RGB(40, 40, 40));
|
||||
@@ -153,6 +152,15 @@ void CSearchBarDlg::Hide()
|
||||
{
|
||||
KillTimer(TIMER_SEARCH); // 清理定时器
|
||||
ShowWindow(SW_HIDE);
|
||||
|
||||
// 关掉搜索栏就撤掉筛选。否则列表停在被筛过的状态,用户看到“少了很多机器”
|
||||
// 却找不到原因 —— 筛选条已经关掉了,没有任何地方提示当前处于筛选状态。
|
||||
if (m_pParent && !m_strLastSearch.IsEmpty()) {
|
||||
m_strLastSearch.Empty();
|
||||
m_editSearch.SetWindowText(_T(""));
|
||||
m_pParent->SetHostFilter(CString());
|
||||
}
|
||||
|
||||
// 将焦点还给主窗口列表
|
||||
if (m_pParent) {
|
||||
m_pParent->SetFocus();
|
||||
@@ -164,20 +172,10 @@ void CSearchBarDlg::InvalidateCache()
|
||||
// 杀掉 pending 的搜索定时器,避免竞争条件
|
||||
KillTimer(TIMER_SEARCH);
|
||||
|
||||
// 清空搜索缓存
|
||||
m_strLastSearch.Empty();
|
||||
m_Results.clear();
|
||||
m_nCurrentIndex = -1;
|
||||
|
||||
// 如果搜索栏存在且可见,立即重新搜索并更新界面
|
||||
// 筛选本身由主窗口的 RebuildFilteredIndices 维护(切分组、主机上下线都会重建),
|
||||
// 这里只需要把计数刷新一下。
|
||||
if (GetSafeHwnd() && IsWindowVisible()) {
|
||||
CString searchText;
|
||||
m_editSearch.GetWindowText(searchText);
|
||||
if (!searchText.IsEmpty()) {
|
||||
DoSearch();
|
||||
} else {
|
||||
UpdateCountText();
|
||||
}
|
||||
UpdateCountText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,98 +216,28 @@ void CSearchBarDlg::DoSearch()
|
||||
{
|
||||
CString searchText;
|
||||
m_editSearch.GetWindowText(searchText);
|
||||
searchText.Trim();
|
||||
|
||||
// 空文本时清空结果
|
||||
if (searchText.IsEmpty()) {
|
||||
m_Results.clear();
|
||||
m_nCurrentIndex = -1;
|
||||
m_strLastSearch.Empty();
|
||||
UpdateCountText();
|
||||
return;
|
||||
}
|
||||
|
||||
// 相同文本不重复搜索(注意:Tab 切换时 m_strLastSearch 会被清空,强制重新搜索)
|
||||
if (searchText == m_strLastSearch && !m_Results.empty()) {
|
||||
return;
|
||||
}
|
||||
if (searchText == m_strLastSearch) return;
|
||||
m_strLastSearch = searchText;
|
||||
|
||||
// 大小写不敏感
|
||||
searchText.MakeLower();
|
||||
m_Results.clear();
|
||||
|
||||
if (!m_pParent) return;
|
||||
|
||||
// 获取当前选中项的 clientID,用于确定搜索起始位置
|
||||
uint64_t selectedClientID = 0;
|
||||
POSITION pos = m_pParent->m_CList_Online.GetFirstSelectedItemPosition();
|
||||
if (pos) {
|
||||
int nSelectedItem = m_pParent->m_CList_Online.GetNextSelectedItem(pos);
|
||||
EnterCriticalSection(&m_pParent->m_cs);
|
||||
context* selCtx = m_pParent->GetContextByListIndex(nSelectedItem);
|
||||
if (selCtx) selectedClientID = selCtx->GetClientID();
|
||||
LeaveCriticalSection(&m_pParent->m_cs);
|
||||
}
|
||||
// 交给主窗口按文本重建过滤索引:命中的主机才留在列表里。
|
||||
// 原来的实现是“在列表里找下一个匹配项并跳过去”,机器一多(几千台)就没法用:
|
||||
// 用户想的是“把带 LEVI 的都列出来”,而不是一条条按 F3 翻。
|
||||
m_pParent->SetHostFilter(searchText);
|
||||
|
||||
// 加锁保护:访问 m_FilteredIndices, m_HostList, context
|
||||
EnterCriticalSection(&m_pParent->m_cs);
|
||||
|
||||
// 遍历过滤后的列表,存储匹配项的 clientID(而非索引)
|
||||
int count = (int)m_pParent->m_FilteredIndices.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
context* ctx = m_pParent->GetContextByListIndex(i);
|
||||
if (!ctx) continue;
|
||||
|
||||
bool matched = false;
|
||||
|
||||
// 搜索各列:IP(0), 地理位置(2), 计算机名/备注(3), 操作系统(4), 版本(8)
|
||||
int cols[] = { 0, 2, 3, 4, 8 };
|
||||
for (int col : cols) {
|
||||
CString colText;
|
||||
|
||||
// 备注列特殊处理
|
||||
if (col == 3) { // ONLINELIST_COMPUTER_NAME
|
||||
colText = m_pParent->m_ClientMap->GetClientMapData(ctx->GetClientID(), MAP_NOTE);
|
||||
if (colText.IsEmpty()) {
|
||||
colText = ctx->GetClientData(col);
|
||||
}
|
||||
} else {
|
||||
colText = ctx->GetClientData(col);
|
||||
}
|
||||
|
||||
// 地理位置列已统一按 UTF-8 存储(见 AddList),而搜索输入是 CP_ACP;
|
||||
// 转回 CP_ACP 再比对,否则按中文位置搜索会因编码不一致而失配。
|
||||
if (col == ONLINELIST_LOCATION) {
|
||||
colText = CString(Utf8ToAnsi(std::string(colText.GetString())).c_str());
|
||||
}
|
||||
|
||||
colText.MakeLower();
|
||||
if (colText.Find(searchText) >= 0) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
// 列表已经被筛过,把选中项放到第一行,键盘可以直接接着操作
|
||||
CListCtrl& list = m_pParent->m_CList_Online;
|
||||
const int count = list.GetItemCount();
|
||||
if (count > 0) {
|
||||
int sel = -1;
|
||||
while ((sel = list.GetNextItem(sel, LVNI_SELECTED)) != -1) {
|
||||
list.SetItemState(sel, 0, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
m_Results.push_back(ctx->GetClientID());
|
||||
}
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&m_pParent->m_cs);
|
||||
|
||||
// 定位到最接近当前选中项的结果
|
||||
m_nCurrentIndex = -1;
|
||||
if (!m_Results.empty()) {
|
||||
m_nCurrentIndex = 0;
|
||||
if (selectedClientID != 0) {
|
||||
for (int i = 0; i < (int)m_Results.size(); i++) {
|
||||
if (m_Results[i] == selectedClientID) {
|
||||
m_nCurrentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
GotoResult(m_nCurrentIndex);
|
||||
list.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
list.EnsureVisible(0, FALSE);
|
||||
}
|
||||
|
||||
UpdateCountText();
|
||||
@@ -317,113 +245,52 @@ void CSearchBarDlg::DoSearch()
|
||||
|
||||
void CSearchBarDlg::GotoPrev()
|
||||
{
|
||||
if (m_Results.empty()) return;
|
||||
|
||||
m_nCurrentIndex--;
|
||||
if (m_nCurrentIndex < 0) {
|
||||
m_nCurrentIndex = (int)m_Results.size() - 1; // 循环
|
||||
}
|
||||
GotoResult(m_nCurrentIndex);
|
||||
UpdateCountText();
|
||||
MoveSelection(-1);
|
||||
}
|
||||
|
||||
void CSearchBarDlg::GotoNext()
|
||||
{
|
||||
if (m_Results.empty()) return;
|
||||
|
||||
m_nCurrentIndex++;
|
||||
if (m_nCurrentIndex >= (int)m_Results.size()) {
|
||||
m_nCurrentIndex = 0; // 循环
|
||||
}
|
||||
GotoResult(m_nCurrentIndex);
|
||||
UpdateCountText();
|
||||
MoveSelection(+1);
|
||||
}
|
||||
|
||||
int CSearchBarDlg::FindListIndexByClientID(uint64_t clientID)
|
||||
{
|
||||
if (!m_pParent || clientID == 0) return -1;
|
||||
|
||||
// 加锁查找
|
||||
EnterCriticalSection(&m_pParent->m_cs);
|
||||
int count = (int)m_pParent->m_FilteredIndices.size();
|
||||
for (int i = 0; i < count; i++) {
|
||||
context* ctx = m_pParent->GetContextByListIndex(i);
|
||||
if (ctx && ctx->GetClientID() == clientID) {
|
||||
LeaveCriticalSection(&m_pParent->m_cs);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_pParent->m_cs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CSearchBarDlg::GotoResult(int index)
|
||||
// 在(已经筛选过的)列表里上下移动选中项。列表本身就是结果集,
|
||||
// 所以这里不再需要维护 clientID → 行号的映射表。
|
||||
void CSearchBarDlg::MoveSelection(int delta)
|
||||
{
|
||||
if (!m_pParent) return;
|
||||
|
||||
// 循环查找有效结果(避免递归导致栈溢出)
|
||||
int attempts = 0;
|
||||
int maxAttempts = (int)m_Results.size();
|
||||
CListCtrl& list = m_pParent->m_CList_Online;
|
||||
const int count = list.GetItemCount();
|
||||
if (count <= 0) return;
|
||||
|
||||
while (attempts < maxAttempts) {
|
||||
if (index < 0 || index >= (int)m_Results.size()) {
|
||||
m_nCurrentIndex = -1;
|
||||
UpdateCountText();
|
||||
return;
|
||||
}
|
||||
const int cur = list.GetNextItem(-1, LVNI_SELECTED);
|
||||
int next = (cur < 0) ? 0 : cur + delta;
|
||||
if (next < 0) next = count - 1; // 循环
|
||||
if (next >= count) next = 0; // 循环
|
||||
|
||||
uint64_t clientID = m_Results[index];
|
||||
int listIndex = FindListIndexByClientID(clientID);
|
||||
|
||||
if (listIndex >= 0) {
|
||||
// 找到有效结果
|
||||
m_nCurrentIndex = index;
|
||||
|
||||
// 取消所有选中
|
||||
int nItem = -1;
|
||||
while ((nItem = m_pParent->m_CList_Online.GetNextItem(-1, LVNI_SELECTED)) != -1) {
|
||||
m_pParent->m_CList_Online.SetItemState(nItem, 0, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
}
|
||||
|
||||
// 选中并滚动到目标项
|
||||
m_pParent->m_CList_Online.SetItemState(listIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
m_pParent->m_CList_Online.EnsureVisible(listIndex, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
// 该主机不在当前列表中,移除并尝试下一个
|
||||
m_Results.erase(m_Results.begin() + index);
|
||||
if (m_Results.empty()) {
|
||||
m_nCurrentIndex = -1;
|
||||
UpdateCountText();
|
||||
return;
|
||||
}
|
||||
|
||||
// 调整索引继续查找
|
||||
if (index >= (int)m_Results.size()) {
|
||||
index = 0;
|
||||
}
|
||||
attempts++;
|
||||
if (cur >= 0) {
|
||||
list.SetItemState(cur, 0, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
}
|
||||
|
||||
// 所有结果都失效
|
||||
m_Results.clear();
|
||||
m_nCurrentIndex = -1;
|
||||
UpdateCountText();
|
||||
list.SetItemState(next, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
|
||||
list.EnsureVisible(next, FALSE);
|
||||
}
|
||||
|
||||
void CSearchBarDlg::UpdateCountText()
|
||||
{
|
||||
CString text;
|
||||
if (m_Results.empty()) {
|
||||
CString searchText;
|
||||
m_editSearch.GetWindowText(searchText);
|
||||
if (!searchText.IsEmpty()) {
|
||||
text = _T("Not found");
|
||||
CString searchText;
|
||||
m_editSearch.GetWindowText(searchText);
|
||||
searchText.Trim();
|
||||
|
||||
if (!searchText.IsEmpty() && m_pParent) {
|
||||
const int count = m_pParent->m_CList_Online.GetItemCount();
|
||||
if (count > 0) {
|
||||
text.Format(_T("%d"), count); // 匹配台数(列表里就这么多行)
|
||||
} else {
|
||||
text = _TR("无匹配");
|
||||
}
|
||||
} else {
|
||||
text.Format(_T("%d/%d"), m_nCurrentIndex + 1, (int)m_Results.size());
|
||||
}
|
||||
|
||||
m_staticCount.SetWindowText(text);
|
||||
m_staticCount.Invalidate();
|
||||
m_staticCount.UpdateWindow();
|
||||
|
||||
Reference in new issue
Block a user