diff options
author | George Hazan <george.hazan@gmail.com> | 2023-08-24 19:41:26 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-08-24 19:41:26 +0300 |
commit | d2426dcc2c146b6f953d3cd517c4887d4e203cd4 (patch) | |
tree | 9da44d5c9e256735fbba3ae9b56b3772aa2cfee2 /plugins | |
parent | 2c05db5b281148d00bfd55ccadd9c307ade2b73d (diff) |
code cleaning
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 93 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 14 | ||||
-rw-r--r-- | plugins/NewStory/src/history_dlg.cpp | 8 | ||||
-rw-r--r-- | plugins/NewStory/src/history_menus.cpp | 48 |
4 files changed, 76 insertions, 87 deletions
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 7dfc1ae9f3..bb358dd161 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -220,6 +220,41 @@ void NewstoryListData::ClearSelection(int iFirst, int iLast) InvalidateRect(hwnd, 0, FALSE); } +void NewstoryListData::Copy(bool bTextOnly) +{ + CMStringW res; + + int eventCount = totalCount; + for (int i = 0; i < eventCount; i++) { + ItemData *p = GetItem(i); + if (!p->m_bSelected) + continue; + + if (p->m_bOfflineFile) { + DB::EventInfo dbei(p->hEvent); + DB::FILE_BLOB blob(dbei); + if (p->m_bOfflineDownloaded) + res.Append(blob.getLocalName()); + else + res.Append(_A2T(blob.getUrl())); + res.Append(L"\r\n"); + } + else { + if (bTextOnly) { + res.Append(p->wtext); + res.Append(L"\r\n"); + } + else { // copy text only + ptrW wszText(TplFormatString(p->getCopyTemplate(), p->hContact, p)); + RemoveBbcodes(wszText); + res.Append(wszText); + } + } + } + + Utils_ClipboardCopy(res); +} + void NewstoryListData::DeleteItems(void) { if (IDYES != MessageBoxW(hwnd, TranslateT("Are you sure to remove selected event(s)?"), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) @@ -246,6 +281,12 @@ void NewstoryListData::DeleteItems(void) } } +void NewstoryListData::Download(int options) +{ + if (auto *p = LoadItem(caret)) + Srmm_DownloadOfflineFile(p->hContact, p->hEvent, options); +} + void NewstoryListData::EndEditItem(bool bAccept) { if (hwndEditBox == nullptr) @@ -733,19 +774,10 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; // History list control messages - case NSM_GETARRAY: - return (LRESULT)&data->items; - - case NSM_GETCOUNT: - return data->totalCount; - case NSM_SELECTITEMS: data->AddSelection(wParam, lParam); return 0; - case NSM_GETCARET: - return data->caret; - case NSM_SEEKTIME: { int eventCount = data->totalCount; @@ -765,47 +797,6 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } return TRUE; - case NSM_COPY: - { - CMStringW res; - - int eventCount = data->totalCount; - for (int i = 0; i < eventCount; i++) { - ItemData *p = data->GetItem(i); - if (!p->m_bSelected) - continue; - - if (p->m_bOfflineFile) { - DB::EventInfo dbei(p->hEvent); - DB::FILE_BLOB blob(dbei); - if (p->m_bOfflineDownloaded) - res.Append(blob.getLocalName()); - else - res.Append(_A2T(blob.getUrl())); - res.Append(L"\r\n"); - } - else { - if (wParam == 0) { - ptrW wszText(TplFormatString(p->getCopyTemplate(), p->hContact, p)); - RemoveBbcodes(wszText); - res.Append(wszText); - } - else { // copy text only - res.Append(p->wtext); - res.Append(L"\r\n"); - } - } - } - - Utils_ClipboardCopy(res); - } - break; - - case NSM_DOWNLOAD: - if (auto *p = data->LoadItem(data->caret)) - Srmm_DownloadOfflineFile(p->hContact, p->hEvent, lParam); - break; - case NSM_SET_OPTIONS: data->bSortAscending = g_plugin.bSortAscending; InvalidateRect(hwnd, 0, FALSE); @@ -993,7 +984,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case VK_INSERT: case 'C': if (isCtrl) - PostMessage(hwnd, NSM_COPY, 0, 0); + data->Copy(); break; case 'A': diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 9081dfdd4c..c80f8be547 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -12,18 +12,6 @@ enum // result = number of total selected items NSM_SELECTITEMS = NSM_FIRST, - // result = id - NSM_GETCARET, - - // - NSM_COPY, - NSM_EXPORT, - NSM_DOWNLOAD, - - // - NSM_GETCOUNT, - NSM_GETARRAY, - // NSM_SEEKTIME, @@ -74,7 +62,9 @@ struct NewstoryListData : public MZeroedObject void BeginEditItem(int index, bool bReadOnly); void Clear(); void ClearSelection(int iFirst, int iLast); + void Copy(bool bTextOnly = false); void DeleteItems(void); + void Download(int iOptions); void EndEditItem(bool bAccept); void EnsureVisible(int item); int FindNext(const wchar_t *pwszText); diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp index b06f408865..0de4d1f494 100644 --- a/plugins/NewStory/src/history_dlg.cpp +++ b/plugins/NewStory/src/history_dlg.cpp @@ -275,13 +275,13 @@ class CHistoryDlg : public CDlgBase return; m_timeTree.DeleteAllItems(); - auto *pArray = (HistoryArray *)m_histWindow.SendMsg(NSM_GETARRAY, 0, 0); - int numItems = pArray->getCount(); + auto &pArray = m_histCtrl->items; + int numItems = pArray.getCount(); int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1; HTREEITEM hCurYear = 0, hCurMonth = 0, hCurDay = 0; for (int i = 0; i < numItems; i++) { - auto *pItem = pArray->get(i, true); + auto *pItem = pArray.get(i, true); if (pItem->dbe.timestamp == 0) continue; @@ -717,7 +717,7 @@ public: void onClick_Copy(CCtrlButton *) { - m_histWindow.SendMsg(NSM_COPY, 0, 0); + m_histCtrl->Copy(); } void onClick_Delete(CCtrlButton *) diff --git a/plugins/NewStory/src/history_menus.cpp b/plugins/NewStory/src/history_menus.cpp index abc6598282..0643758aad 100644 --- a/plugins/NewStory/src/history_menus.cpp +++ b/plugins/NewStory/src/history_menus.cpp @@ -1,5 +1,13 @@ #include "stdafx.h" +enum +{ + MENU_COPY, MENU_COPYTEXT, + MENU_SAVEAS, MENU_DOWNLOAD, + MENU_EDIT, MENU_DELETE, + MENU_SELECTALL, MENU_BOOKMARK, +}; + static int hMenuObject; static HANDLE hEventPreBuildMenu; static HGENMENU hmiHistory, hmiCopy, hmiSaveAs, hmiDownload; @@ -33,35 +41,35 @@ static INT_PTR NSMenuHelper(WPARAM wParam, LPARAM lParam) auto *pData = (NewstoryListData *)lParam; switch (wParam) { - case 1: - SendMessage(pData->hwnd, NSM_COPY, 0, 0); + case MENU_COPY: + pData->Copy(false); break; - case 8: - SendMessage(pData->hwnd, NSM_COPY, 1, 0); + case MENU_COPYTEXT: + pData->Copy(true); break; - case 2: + case MENU_EDIT: pData->BeginEditItem(pData->caret, false); break; - case 3: + case MENU_DELETE: pData->DeleteItems(); break; - case 4: + case MENU_SELECTALL: SendMessage(pData->hwnd, NSM_SELECTITEMS, 0, pData->totalCount - 1); break; - case 5: - SendMessage(pData->hwnd, NSM_DOWNLOAD, 0, OFD_SAVEAS | OFD_RUN); + case MENU_SAVEAS: + pData->Download(OFD_SAVEAS | OFD_RUN); break; - case 6: - SendMessage(pData->hwnd, NSM_DOWNLOAD, 0, OFD_DOWNLOAD); + case MENU_DOWNLOAD: + pData->Download(OFD_DOWNLOAD); break; - case 7: + case MENU_BOOKMARK: pData->ToggleBookmark(); break; @@ -161,33 +169,33 @@ void InitMenus() mi.position = 100000; mi.name.a = LPGEN("Copy"); - hmiCopy = Menu_AddNewStoryMenuItem(&mi, 1); + hmiCopy = Menu_AddNewStoryMenuItem(&mi, MENU_COPY); mi.position = 100001; mi.name.a = LPGEN("Copy text"); - hmiCopy = Menu_AddNewStoryMenuItem(&mi, 8); + hmiCopy = Menu_AddNewStoryMenuItem(&mi, MENU_COPYTEXT); mi.position = 100002; mi.name.a = LPGEN("Save as"); - hmiSaveAs = Menu_AddNewStoryMenuItem(&mi, 5); + hmiSaveAs = Menu_AddNewStoryMenuItem(&mi, MENU_SAVEAS); mi.position = 100003; mi.name.a = LPGEN("Download"); - hmiDownload = Menu_AddNewStoryMenuItem(&mi, 6); + hmiDownload = Menu_AddNewStoryMenuItem(&mi, MENU_DOWNLOAD); mi.position = 200000; mi.name.a = LPGEN("Edit"); - Menu_AddNewStoryMenuItem(&mi, 2); + Menu_AddNewStoryMenuItem(&mi, MENU_EDIT); mi.position = 200001; mi.name.a = LPGEN("Delete"); - Menu_AddNewStoryMenuItem(&mi, 3); + Menu_AddNewStoryMenuItem(&mi, MENU_DELETE); mi.position = 200002; mi.name.a = LPGEN("Toggle bookmark"); - Menu_AddNewStoryMenuItem(&mi, 7); + Menu_AddNewStoryMenuItem(&mi, MENU_BOOKMARK); mi.position = 300000; mi.name.a = LPGEN("Select all"); - Menu_AddNewStoryMenuItem(&mi, 4); + Menu_AddNewStoryMenuItem(&mi, MENU_SELECTALL); } |