summaryrefslogtreecommitdiff
path: root/NSCmpts/IgnoreProp.cpp
blob: 97692465ecde37ae86adb3f445fe288f41a71b56 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// IgnoreProp.cpp: implementation of the CIgnoreProp class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "IgnoreProp.h"

#include "resource.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


LRESULT CIgnoreProp::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Our Current Window
	CWindow wndIgnore = m_hwndIgnore;


	// Load the System Image list
	m_imgList.Load(true);


	// Set the List
	m_ctlList = wndIgnore.GetDlgItem(IDC_IGNORE_LIST);
	m_ctlList.SetImageList(m_imgList, LVSIL_SMALL);


	// Set Button Icons
	HICON hIconNew = ::LoadIcon(_Module.m_hInstResource, MAKEINTRESOURCE(IDI_NEW));
	HICON hIconDel = ::LoadIcon(_Module.m_hInstResource, MAKEINTRESOURCE(IDI_DEL));

	CButton btn = wndIgnore.GetDlgItem(IDC_NEW);
	btn.SetIcon(hIconNew);

	btn = wndIgnore.GetDlgItem(IDC_DEL);
	btn.SetIcon(hIconDel);


	// Load the Extension List
	if(m_Data.IsInitialized())
		m_Data.GetStringSet(NS_IGNORE_REG_EXT, m_asExtensions);


	UpdateData(false);

	return TRUE;
}

// Adds an extension to the List Control
int CIgnoreProp::AddExtension(string sExtension)
{
	// Get the Extension Icon
	int nIndex = m_imgList.GetTypeIndex(sExtension);
	
	LVITEM lv;
	lv.mask = LVIF_TEXT | LVIF_IMAGE;
	lv.iItem = 0;
	lv.iSubItem = 0;
	lv.pszText = sExtension.get_buffer();
	lv.iImage = nIndex;

	// Set it
	return m_ctlList.InsertItem(&lv);
}

// Updates or Saves data from Dialog
void CIgnoreProp::UpdateData(bool bSave) 
{
	if(bSave)
	{
		m_asExtensions.clear();

		// Go through List Box and take down names
		TCHAR buff[MAX_PATH];
		int nItem = 0;
		while(m_ctlList.GetItemText(nItem++, 0, buff, MAX_PATH))
			m_asExtensions.push_back(buff);
	}
	else
	{
		m_ctlList.DeleteAllItems();

		// Add everything to the List Control
		string_array::const_iterator iter = m_asExtensions.begin();
		for(; iter != m_asExtensions.end(); iter++)
			AddExtension(*iter);
	}
}

LRESULT CIgnoreProp::OnEndLabelEdit(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
	LVITEM* pItem = &((NMLVDISPINFO*)pnmh)->item;

	// Only Change if there is Text
	if(pItem->pszText)
	{
		// Make sure text is sort of valid
		// without illegal Characters
		string sTemp(pItem->pszText);
		string::size_type nPos;
		while((nPos = sTemp.find_first_of(_T("\\/:*?\"<>|."))) != string::npos)
			sTemp.erase(nPos, 1);

		// Copy it back to structure
		_tcscpy(pItem->pszText, sTemp);

		// Modify Icon
		pItem->iImage = m_imgList.GetTypeIndex(sTemp);
		pItem->mask = pItem->mask | LVIF_IMAGE;

		// Set it
		m_ctlList.SetItem(pItem);
	}

	return 0;
}

LRESULT CIgnoreProp::OnListSetFocus(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
	// Disclaimer: This is a kludge fix
	// SysListView32 wouldn't redraw itself when it had focus 
	// and app was activated 
	m_ctlList.Invalidate();
	m_ctlList.RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE);
	return 0;
}

LRESULT CIgnoreProp::OnKeyDown(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
	NMLVKEYDOWN* pLVKeyDow = (NMLVKEYDOWN*)pnmh;

	// if F2 then Edit
	if(pLVKeyDow->wVKey == VK_F2) 
	{
		m_ctlList.SetFocus(); // Needs to have the Focus in order to edit
		m_ctlList.EditLabel(m_ctlList.GetNextItem(-1, LVNI_ALL | LVNI_FOCUSED));
	}

	// If Delete then call Delete Handler
	if(pLVKeyDow->wVKey == VK_DELETE) 
	{
		OnRemove(0, 0, 0, bHandled);
	}

	return 0;
}

LRESULT CIgnoreProp::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	int iItem = -1;

	// Loop through selected items
	while((iItem = m_ctlList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED)) != -1) 
		// Take it out of List Box
		m_ctlList.DeleteItem(iItem);

	return 0;
}

/*template<class TBase>*/
LRESULT CIgnoreProp/*<TBase>*/::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	int iItem = -1;

	// Add an basic extension
	string sExt;
	sExt.load_string(IDS_BACKUP_NEWEXT);

	if((iItem = AddExtension(sExt)) != -1)
	{
		// Open for Editing
		m_ctlList.SetFocus();	// Needs to have the Focus in order to edit
		m_ctlList.EditLabel(iItem);
	}

	return 0;
}