-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmru.hpp
79 lines (70 loc) · 1.35 KB
/
mru.hpp
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
#pragma once
class MRUList
{
public:
char * list[10];
char section[256];
Properties &props;
MRUList(Properties &_props, char* section) : props(_props)
{
char prop[6] = "item0";
for (int i=0; i<10; i++)
{
list[i] = new char[256];
prop[4] = '0' + i;
props.GetString(section, prop, list[i], 256);
}
strncpy(this->section, section, 255);
}
~MRUList()
{
for (int i=0; i<10; i++)
{
delete [] list[i];
list[i] = 0;
}
}
void MakeCombo(CComboBox &combo)
{
combo.ResetContent();
for (int i=0; i<10; i++)
if (list[i][0] != 0)
combo.AddString(list[i]);
combo.SetCurSel(0);
}
void UpdateAndSave(CComboBox &combo)
{
char str[256];
combo.GetWindowText(str, 256);
Update(str);
Save(props);
}
void Update(char *latest)
{
int foundat = 9;
for (int i=0; i<10; i++)
{
if (strncmp(list[i], latest, 256) == 0)
{
foundat = i;
break;
}
}
// rotate by one (up to the one to move to front)
char *oldest = list[foundat];
for (int i=foundat-1; i>=0; --i)
list[i+1] = list[i];
list[0] = oldest;
// update first one
strncpy(list[0], latest, 256);
}
void Save(Properties &props)
{
char prop[6] = "item0";
for (int i=0; i<10; i++)
{
prop[4] = '0' + i;
props.SetString(section, prop, list[i]);
}
}
};