diff options
-rw-r--r-- | plugins/NewStory/res/resource.rc | 5 | ||||
-rw-r--r-- | plugins/NewStory/src/history.cpp | 39 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.h | 5 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.cpp | 89 | ||||
-rw-r--r-- | plugins/NewStory/src/history_control.h | 1 | ||||
-rw-r--r-- | plugins/NewStory/src/resource.h | 1 |
6 files changed, 87 insertions, 53 deletions
diff --git a/plugins/NewStory/res/resource.rc b/plugins/NewStory/res/resource.rc index c7623316ec..82eb607d46 100644 --- a/plugins/NewStory/res/resource.rc +++ b/plugins/NewStory/res/resource.rc @@ -90,12 +90,13 @@ STYLE DS_SETFONT | DS_NOIDLEMSG | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | CAPTION "NewStory - new history for Miranda NG" FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - CONTROL "",IDC_MESSAGE,"MButtonClass",WS_TABSTOP,37,99,16,14 CONTROL "",IDC_USERINFO,"MButtonClass",WS_TABSTOP,0,99,16,14 CONTROL "",IDC_USERMENU,"MButtonClass",WS_TABSTOP,21,99,16,14 + CONTROL "",IDC_MESSAGE,"MButtonClass",WS_TABSTOP,37,99,16,14 CONTROL "",IDC_SEARCH,"MButtonClass",WS_TABSTOP,53,99,16,14 - CONTROL "",IDC_EXPORT,"MButtonClass",WS_TABSTOP,90,99,16,14 CONTROL "",IDC_COPY,"MButtonClass",WS_TABSTOP,74,99,16,14 + CONTROL "",IDC_EXPORT,"MButtonClass",WS_TABSTOP,90,99,16,14 + CONTROL "",IDC_DELETE,"MButtonClass",WS_TABSTOP,104,99,16,14 CONTROL "",IDC_FILTER,"MButtonClass",WS_TABSTOP,132,99,16,14 CONTROL "",IDC_FINDPREV,"MButtonClass",WS_TABSTOP,364,305,16,14 CONTROL "",IDC_FINDNEXT,"MButtonClass",WS_TABSTOP,337,305,16,14 diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index c01e150e54..eb29b2e624 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -72,12 +72,12 @@ enum { TBTN_USERINFO, TBTN_USERMENU, TBTN_MESSAGE, TBTN_SEARCH, TBTN_FILTER, TBTN_DATEPOPUP, - TBTN_COPY, TBTN_EXPORT, + TBTN_COPY, TBTN_DELETE, TBTN_EXPORT, TBTN_LOGOPTIONS, TBTN_COUNT }; -int tbtnSpacing[TBTN_COUNT] = { 0, 0, TBTN_SPACER, 0, 0, TBTN_SPACER, 0, -1, 0 }; +int tbtnSpacing[TBTN_COUNT] = { 0, 0, TBTN_SPACER, 0, 0, TBTN_SPACER, 0, 0, -1, 0 }; struct InfoBarEvents { @@ -198,7 +198,7 @@ class CHistoryDlg : public CDlgBase int w = rc.right - rc.left; int h = rc.bottom - rc.top; - HDWP hDwp = BeginDeferWindowPos(50); + HDWP hDwp = BeginDeferWindowPos(51); // toolbar int hToolBar = TBTN_SIZE + WND_SPACING; @@ -313,10 +313,20 @@ class CHistoryDlg : public CDlgBase EndDeferWindowPos(hDwp); } + void UpdateTitle() + { + if (m_hContact && m_hContact != INVALID_CONTACT_ID) + SetWindowText(m_hwnd, ptrW(TplFormatString(TPL_TITLE, m_hContact, 0))); + else if (m_hContact == INVALID_CONTACT_ID) + SetWindowText(m_hwnd, TranslateT("History search results")); + else + SetWindowText(m_hwnd, TranslateT("System history")); + } + CCtrlBase m_histControl; CCtrlEdit edtSearchText; CCtrlMButton btnUserInfo, btnSendMsg, btnUserMenu, btnCopy, btnOptions, btnFilter; - CCtrlMButton btnCalendar, btnSearch, btnExport, btnFindNext, btnFindPrev; + CCtrlMButton btnCalendar, btnSearch, btnExport, btnFindNext, btnFindPrev, btnDelete; CCtrlTreeView m_timeTree; public: @@ -328,6 +338,7 @@ public: edtSearchText(this, IDC_SEARCHTEXT), btnCopy(this, IDC_COPY, g_plugin.getIcon(ICO_COPY), LPGEN("Copy")), btnExport(this, IDC_EXPORT, g_plugin.getIcon(ICO_EXPORT), LPGEN("Export...")), + btnDelete(this, IDC_DELETE, Skin_LoadIcon(SKINICON_OTHER_DELETE), LPGEN("Delete...")), btnFilter(this, IDC_FILTER, g_plugin.getIcon(ICO_FILTER), LPGEN("Filter")), btnSearch(this, IDC_SEARCH, g_plugin.getIcon(ICO_SEARCH), LPGEN("Search...")), btnOptions(this, IDC_LOGOPTIONS, g_plugin.getIcon(ICO_OPTIONS), LPGEN("Options")), @@ -344,6 +355,7 @@ public: btnCopy.OnClick = Callback(this, &CHistoryDlg::onClick_Copy); btnExport.OnClick = Callback(this, &CHistoryDlg::onClick_Export); + btnDelete.OnClick = Callback(this, &CHistoryDlg::onClick_Delete); btnFilter.OnClick = Callback(this, &CHistoryDlg::onClick_Filter); btnSearch.OnClick = Callback(this, &CHistoryDlg::onClick_Search); btnOptions.OnClick = Callback(this, &CHistoryDlg::onClick_Options); @@ -389,6 +401,7 @@ public: m_hwndBtnToolbar[TBTN_SEARCH] = btnSearch.GetHwnd(); m_hwndBtnToolbar[TBTN_COPY] = btnCopy.GetHwnd(); m_hwndBtnToolbar[TBTN_EXPORT] = btnExport.GetHwnd(); + m_hwndBtnToolbar[TBTN_DELETE] = btnDelete.GetHwnd(); m_hwndBtnToolbar[TBTN_LOGOPTIONS] = btnOptions.GetHwnd(); m_hwndBtnToolbar[TBTN_FILTER] = btnFilter.GetHwnd(); m_hwndBtnToolbar[TBTN_DATEPOPUP] = btnCalendar.GetHwnd(); @@ -464,17 +477,7 @@ public: WindowList_Add(hNewstoryWindows, m_hwnd, m_hContact); - if (m_hContact && (m_hContact != INVALID_CONTACT_ID)) { - wchar_t *title = TplFormatString(TPL_TITLE, m_hContact, 0); - SetWindowText(m_hwnd, title); - mir_free(title); - } - else { - if (m_hContact == INVALID_CONTACT_ID) - SetWindowText(m_hwnd, TranslateT("History search results")); - else - SetWindowText(m_hwnd, TranslateT("System history")); - } + UpdateTitle(); ADDEVENTS tmp = { m_hContact, 0, -1 }; SendMessage(m_histControl.GetHwnd(), NSM_ADDEVENTS, WPARAM(&tmp), 0); @@ -532,6 +535,12 @@ public: m_histControl.SendMsg(NSM_COPY, 0, 0); } + void onClick_Delete(CCtrlButton *) + { + m_histControl.SendMsg(NSM_DELETE, 0, 0); + UpdateTitle(); + } + void onClick_Export(CCtrlButton *) { wchar_t FileName[MAX_PATH]; diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h index ece447676d..50e6fb1c97 100644 --- a/plugins/NewStory/src/history_array.h +++ b/plugins/NewStory/src/history_array.h @@ -135,6 +135,11 @@ public: void addChatEvent(SESSION_INFO *si, LOGINFO *pEvent); void clear(); int getCount() const; + void reset() + { + clear(); + pages.insert(new ItemBlock()); + } // bool preloadEvents(int count = 10); diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 5a7e2c8128..a7b6327a96 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -2,6 +2,8 @@ HANDLE htuLog = 0; +static wchar_t wszDelete[] = LPGENW("Are you sure to remove all events from history?"); + ///////////////////////////////////////////////////////////////////////// // Control utilities, types and constants @@ -480,13 +482,14 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { int start = min(data->items.getCount() - 1, max(0, wParam)); int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) { - start ^= end; - end ^= start; - start ^= end; + if (start > end) + std::swap(start, end); + + for (int i = start; i <= end; ++i) { + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + p->flags |= HIF_SELECTED; } - for (int i = start; i <= end; ++i) - data->items.get(i, ItemData::ELM_NOTHING)->flags |= HIF_SELECTED; + InvalidateRect(hwnd, 0, FALSE); return 0; } @@ -495,19 +498,14 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { int start = min(data->items.getCount() - 1, max(0, wParam)); int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) { - start ^= end; - end ^= start; - start ^= end; - } + if (start > end) + std::swap(start, end); + for (int i = start; i <= end; ++i) { - if (data->items.get(i, ItemData::ELM_NOTHING)->flags & HIF_SELECTED) { - data->items.get(i, ItemData::ELM_NOTHING)->flags &= ~HIF_SELECTED; - } - else { - data->items.get(i, ItemData::ELM_NOTHING)->flags |= HIF_SELECTED; - } + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + p->flags ^= HIF_SELECTED; } + InvalidateRect(hwnd, 0, FALSE); return 0; } @@ -516,20 +514,18 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { int start = min(data->items.getCount() - 1, max(0, wParam)); int end = min(data->items.getCount() - 1, max(0, lParam)); - if (start > end) { - start ^= end; - end ^= start; - start ^= end; - } + if (start > end) + std::swap(start, end); + int count = data->items.getCount(); for (int i = 0; i < count; ++i) { - if ((i >= start) && (i <= end)) { - data->items.get(i, ItemData::ELM_NOTHING)->flags |= HIF_SELECTED; - } - else { - data->items.get(i, ItemData::ELM_NOTHING)->flags &= ~((DWORD)HIF_SELECTED); - } + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + if ((i >= start) && (i <= end)) + p->flags |= HIF_SELECTED; + else + p->flags &= ~((DWORD)HIF_SELECTED); } + InvalidateRect(hwnd, 0, FALSE); return 0; } @@ -543,8 +539,11 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM end ^= start; start ^= end; } - for (int i = start; i <= end; ++i) - data->items.get(i, ItemData::ELM_NOTHING)->flags &= ~((DWORD)HIF_SELECTED); + for (int i = start; i <= end; ++i) { + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + p->flags &= ~((DWORD)HIF_SELECTED); + } + InvalidateRect(hwnd, 0, FALSE); return 0; } @@ -558,8 +557,8 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM RECT rc; GetClientRect(hwnd, &rc); int height = rc.bottom - rc.top; - DWORD count = data->items.getCount(); - DWORD current = data->scrollTopItem; + int count = data->items.getCount(); + int current = data->scrollTopItem; int top = data->scrollTopPixel; int bottom = top + LayoutItem(hwnd, &data->items, current); while (top <= height) { @@ -607,14 +606,14 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM { int eventCount = data->items.getCount(); for (int i = 0; i < eventCount; i++) { - auto *item = data->items.get(i, ItemData::ELM_NOTHING); - if (item->dbe.timestamp >= wParam) { + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + if (p->dbe.timestamp >= wParam) { SendMessage(hwnd, NSM_SELECTITEMS2, i, i); SendMessage(hwnd, NSM_SETCARET, i, TRUE); break; } - if (i == eventCount - 1) - { + + if (i == eventCount - 1) { SendMessage(hwnd, NSM_SELECTITEMS2, i, i); SendMessage(hwnd, NSM_SETCARET, i, TRUE); } @@ -626,6 +625,24 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM SendMessage(hwnd, NSM_SETCARET, data->items.getCount() - 1, 1); break; + case NSM_DELETE: + if (IDYES == MessageBoxW(hwnd, TranslateW(wszDelete), _T(MODULETITLE), MB_YESNOCANCEL | MB_ICONQUESTION)) { + db_set_safety_mode(false); + + int eventCount = data->items.getCount(); + for (int i = eventCount - 1; i >= 0; i--) { + auto *p = data->items.get(i, ItemData::ELM_NOTHING); + if (p->hEvent && p->hContact) + db_event_delete(p->hEvent); + } + db_set_safety_mode(true); + + data->items.reset(); + + InvalidateRect(hwnd, 0, FALSE); + } + break; + case NSM_COPY: { CMStringW res; diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index 0d0650aaaa..0483ac9112 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -63,6 +63,7 @@ enum // NSM_COPY, + NSM_DELETE, NSM_EXPORT, // diff --git a/plugins/NewStory/src/resource.h b/plugins/NewStory/src/resource.h index f52b7eaf74..09f898d558 100644 --- a/plugins/NewStory/src/resource.h +++ b/plugins/NewStory/src/resource.h @@ -62,6 +62,7 @@ #define IDC_ICO_URLS_IN 1031 #define IDC_ICO_URLS_OUT 1032 #define IDC_PREVIEW 1033 +#define IDC_DELETE 1034 #define IDC_TIMETREE 1035 #define IDC_PROGRESS1 1037 //!!! #define IDC_COMBO1 1038 //!!! |