[feat]: +/- page next/prev
This commit is contained in:
1 parent
0ef2b27c8a
commit
f9d6911b4f
3 files changed
+72
-16
No files matched your search
@@ -59,27 +59,24 @@ void WorkerThread()
|
||||
//
|
||||
Global::CandidateWordList.clear();
|
||||
Global::SelectedCandidateString = L"";
|
||||
int cnt = 0;
|
||||
for (const auto &[pinyin, word, weight] : Global::CandidateList)
|
||||
Global::PageIndex = 0;
|
||||
Global::ItemTotalCount = Global::CandidateList.size();
|
||||
int loop = Global::ItemTotalCount > Global::CountOfOnePage //
|
||||
? Global::CountOfOnePage //
|
||||
: Global::ItemTotalCount;
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
if (cnt == 0)
|
||||
auto &[pinyin, word, weight] = Global::CandidateList[i];
|
||||
if (i == 0)
|
||||
{
|
||||
Global::SelectedCandidateString = string_to_wstring(word);
|
||||
}
|
||||
if (cnt < 8)
|
||||
{
|
||||
candidate_string += std::to_string(cnt + 1) + ". " + word;
|
||||
Global::CandidateWordList.push_back(string_to_wstring(word));
|
||||
cnt++;
|
||||
}
|
||||
if (cnt < 7)
|
||||
candidate_string += std::to_string(i + 1) + ". " + word;
|
||||
Global::CandidateWordList.push_back(string_to_wstring(word));
|
||||
if (i < Global::CountOfOnePage - 1)
|
||||
{
|
||||
candidate_string += ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
::WriteDataToSharedMemory(string_to_wstring(candidate_string), true);
|
||||
PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0);
|
||||
@@ -110,6 +107,61 @@ void WorkerThread()
|
||||
::SendImeInputs(Global::CandidateWordList[Global::Keycode - '1']);
|
||||
}
|
||||
}
|
||||
else if (Global::Keycode == VK_OEM_MINUS) // Page previous
|
||||
{
|
||||
if (Global::PageIndex > 0)
|
||||
{
|
||||
std::string candidate_string;
|
||||
Global::PageIndex--;
|
||||
int loop = Global::CountOfOnePage;
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
auto &[pinyin, word, weight] =
|
||||
Global::CandidateList[i + Global::PageIndex * Global::CountOfOnePage];
|
||||
if (i == 0)
|
||||
{
|
||||
Global::SelectedCandidateString = string_to_wstring(word);
|
||||
}
|
||||
candidate_string += std::to_string(i + 1) + ". " + word;
|
||||
Global::CandidateWordList.push_back(string_to_wstring(word));
|
||||
if (i < loop - 1)
|
||||
{
|
||||
candidate_string += ",";
|
||||
}
|
||||
}
|
||||
::WriteDataToSharedMemory(string_to_wstring(candidate_string), true);
|
||||
PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0);
|
||||
}
|
||||
}
|
||||
else if (Global::Keycode == VK_OEM_PLUS) // Page next
|
||||
{
|
||||
if (Global::PageIndex < (Global::ItemTotalCount - 1) / Global::CountOfOnePage)
|
||||
{
|
||||
std::string candidate_string;
|
||||
Global::PageIndex++;
|
||||
int loop =
|
||||
Global::ItemTotalCount - Global::PageIndex * Global::CountOfOnePage > Global::CountOfOnePage
|
||||
? Global::CountOfOnePage
|
||||
: Global::ItemTotalCount - Global::PageIndex * Global::CountOfOnePage;
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
auto &[pinyin, word, weight] =
|
||||
Global::CandidateList[i + Global::PageIndex * Global::CountOfOnePage];
|
||||
if (i == 0)
|
||||
{
|
||||
Global::SelectedCandidateString = string_to_wstring(word);
|
||||
}
|
||||
candidate_string += std::to_string(i + 1) + ". " + word;
|
||||
Global::CandidateWordList.push_back(string_to_wstring(word));
|
||||
if (i < loop - 1)
|
||||
{
|
||||
candidate_string += ",";
|
||||
}
|
||||
}
|
||||
::WriteDataToSharedMemory(string_to_wstring(candidate_string), true);
|
||||
PostMessage(::global_hwnd, WM_SHOW_MAIN_WINDOW, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +57,8 @@ inline std::wstring CandidateString = L"";
|
||||
inline std::vector<DictionaryUlPb::WordItem> CandidateList;
|
||||
inline std::vector<std::wstring> CandidateWordList;
|
||||
inline std::wstring SelectedCandidateString = L"";
|
||||
|
||||
inline int CountOfOnePage = 8;
|
||||
inline int PageIndex = 0;
|
||||
inline int ItemTotalCount = 0;
|
||||
} // namespace Global
|
||||
@@ -143,10 +143,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
ShowWindow(hWnd, SW_SHOWNOACTIVATE);
|
||||
::ReadDataFromSharedMemory(0b100000);
|
||||
Global::PinyinString = string_to_wstring( //
|
||||
std::wstring embeded_pinyin = string_to_wstring( //
|
||||
PinyinUtil::pinyin_segmentation(wstring_to_string(Global::PinyinString)) //
|
||||
);
|
||||
std::wstring str = Global::PinyinString + L"," + Global::CandidateString;
|
||||
std::wstring str = embeded_pinyin + L"," + Global::CandidateString;
|
||||
InflateCandidateWindow(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user