-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory_oplog.cpp
More file actions
100 lines (68 loc) · 2.21 KB
/
Copy pathhistory_oplog.cpp
File metadata and controls
100 lines (68 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "stdafx.h"
#include "utils_db.h"
#include "history_oplog.h"
bool history_oplog::init(bool enabled, size_t max_items) {
if (m_enabled == enabled && m_max_items == max_items) return false;
m_enabled = enabled;
m_max_items = max_items;
zap_vhistory();
sqldb db;
std::map<oplog_type, vppair*> out_history = {
{oplog_type::release, &m_vres_release_history},
{oplog_type::artist, &m_vres_artist_history},
{oplog_type::filter, &m_vres_filter_history}
};
size_t inc = db.recharge_history(kcmdHistoryWashup, max_items, out_history);
return inc != pfc_infinite;
}
//serves config dialog
void history_oplog::zap_vhistory() {
m_vres_release_history.clear();
m_vres_artist_history.clear();
m_vres_filter_history.clear();
}
bool history_oplog::add_history_row(oplog_type optype, rppair row) {
if (!get_row_key(optype, row).get_length()) return false;
vppair& vh = get_history(optype);
vppair::iterator fit;
fit = std::find_if(vh.begin(), vh.end(),
[=](const rppair& w) {
return get_row_key(optype, w).equals(get_row_key(optype, row));
});
if (!vh.size() || fit == vh.end()) {
vh.insert(vh.begin(), row);
return true;
}
else {
std::iter_swap(vh.begin(), fit);
}
return false;
}
bool history_oplog::do_history_menu(oplog_type optype, HWND hwndCtrl, pfc::string8 &out) {
vppair& vophistory = get_history(optype);
if (!vophistory.size()) return false;
CRect clientRect;
::GetWindowRect(hwndCtrl, &clientRect);
POINT pt;
pt.x = clientRect.left;
pt.y = clientRect.bottom;
//build menu
enum { MENU_FIRST_ITEM = 1 };
HMENU hMenu = CreatePopupMenu();
for (auto walk_it = vophistory.begin(); walk_it != vophistory.end(); ++walk_it) {
const pfc::string8 label = get_menu_label(optype, walk_it._Ptr);
const pfc::stringcvt::string_os_from_utf8 os_str(label);
size_t item_id = MENU_FIRST_ITEM + std::distance(vophistory.begin(), walk_it);
AppendMenu(hMenu, MF_STRING, item_id, os_str);
}
//display menu
int cmd = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD, pt.x, pt.y, 0, hwndCtrl, NULL);
DestroyMenu(hMenu);
//return value
if (cmd) {
rppair row_h = vophistory.at(--cmd);
out = get_row_val(optype, row_h);
return out.get_length();
}
return false;
}