diff options
Diffstat (limited to 'NSCmpts/IgnoreProp.cpp')
-rw-r--r-- | NSCmpts/IgnoreProp.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/NSCmpts/IgnoreProp.cpp b/NSCmpts/IgnoreProp.cpp new file mode 100644 index 0000000..9769246 --- /dev/null +++ b/NSCmpts/IgnoreProp.cpp @@ -0,0 +1,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; +}
\ No newline at end of file |