-
Notifications
You must be signed in to change notification settings - Fork 6
/
ContentFilterDlg.cpp
116 lines (84 loc) · 2.81 KB
/
ContentFilterDlg.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "stdafx.h"
#include <algorithm>
#include "ContentFilterDlg.h"
#include "AddContentTypeDlg.h"
#include "resource.h"
CContentFilterDlg::CContentFilterDlg() : m_settings(SettingsStorage::GetStorage())
{
std::list<CString> contentTypes = m_settings.GetContentTypes();
for (std::list<CString>::const_iterator i = contentTypes.begin(); i != contentTypes.end(); ++i)
m_lstContentType.push_back(*i);
//m_psp.dwFlags |= PSP_USEICONID;
//m_psp.pszIcon = MAKEINTRESOURCE(IDI_FILTER);
//m_psp.hInstance = _Module.GetResourceInstance();
}
void CContentFilterDlg::AddContentTypeToList(LPCTSTR pszContentType, bool filterEnabled)
{
int item = m_wndList.AddItem(0, 0, "");
m_wndList.SetItemText(item, 1, pszContentType);
m_wndList.SetCheckState(item, filterEnabled);
}
BOOL CContentFilterDlg::OnInitDialog(HWND hwndFocus, LPARAM lParam)
{
CenterWindow();
m_wndList.Attach(GetDlgItem(IDC_LIST_FILTER));
m_wndList.SetExtendedListViewStyle(LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT|LVS_SINGLESEL);
m_wndList.InsertColumn ( 0, _T("Filter"), LVCFMT_LEFT, 50, 0 );
m_wndList.InsertColumn ( 1, _T("Content-Type"), LVCFMT_LEFT, 240, 1 );
PopulateList();
return 1;
}
void CContentFilterDlg::PopulateList()
{
std::list<CString> lst = m_settings.GetFilteredContentType();
for (std::list<CString>::const_iterator t = m_lstContentType.begin();
t != m_lstContentType.end(); ++t)
{
bool filtered = false;
if (lst.end() != std::find(lst.begin(), lst.end(), (*t)))
filtered = true;
AddContentTypeToList(*t, filtered);
}
}
void CContentFilterDlg::SaveSettings()
{
std::list<CString> lstFilteredContentTypes;
std::list<CString> lstContentTypes;
int items = m_wndList.GetItemCount();
for (int i = 0; i < items; ++i)
{
CString strContentType;
m_wndList.GetItemText(i, 1, strContentType);
lstContentTypes.push_back(strContentType);
if (m_wndList.GetCheckState(i))
{
lstFilteredContentTypes.push_back(strContentType);
}
}
m_settings.SetFilteredContentType(lstFilteredContentTypes);
m_settings.SetAvailableContentTypes(lstContentTypes);
}
int CContentFilterDlg::OnApply()
{
SaveSettings();
return 1;
}
LRESULT CContentFilterDlg::OnBnClickedAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAddContentTypeDlg dlg;
if (IDOK == dlg.DoModal())
{
m_lstContentType.push_back(dlg.GetContentType());
m_wndList.DeleteAllItems();
PopulateList();
}
return 0;
}
LRESULT CContentFilterDlg::OnBnClickedRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
if (m_wndList.GetSelectedCount() > 0)
{
m_wndList.DeleteItem(m_wndList.GetSelectionMark());
}
return 0;
}