diff --git a/Documentation/History.txt b/Documentation/History.txt index 8e1842a921..af469f3346 100644 --- a/Documentation/History.txt +++ b/Documentation/History.txt @@ -8,6 +8,15 @@ Version 1.3.3 (xx/xx/2011) Bug fixes: - The media duration column was previously showing times in 100-nanosecond units. Updated to hh:mm:ss. +- The processed search string (rather than original search + string) was been stored in the search dialog. Fixed. + +Misc: +- When searching using the search dialog, if the filename + entered already appears in the history list, it will simply + be swapped to the first position (rather than been re-entered). +- The number of history entries stored for the filename field + in the search dialog is now capped at 20. Version 1.3.2 (11/10/2011) -------------------------- diff --git a/Explorer++/Explorer++/DialogHelper.h b/Explorer++/Explorer++/DialogHelper.h new file mode 100644 index 0000000000..ab42c49ef8 --- /dev/null +++ b/Explorer++/Explorer++/DialogHelper.h @@ -0,0 +1,9 @@ +#ifndef DIALOGHELPER_INCLUDED +#define DIALOGHELPER_INCLUDED + +namespace NDialogHelper +{ + const int DEFAULT_HISTORY_SIZE = 20; +} + +#endif \ No newline at end of file diff --git a/Explorer++/Explorer++/Explorer++.rc b/Explorer++/Explorer++/Explorer++.rc index 70ae6e1728..484ab367fa 100644 Binary files a/Explorer++/Explorer++/Explorer++.rc and b/Explorer++/Explorer++/Explorer++.rc differ diff --git a/Explorer++/Explorer++/Explorer++.vcxproj b/Explorer++/Explorer++/Explorer++.vcxproj index 7ca790c8a6..042c72c833 100644 --- a/Explorer++/Explorer++/Explorer++.vcxproj +++ b/Explorer++/Explorer++/Explorer++.vcxproj @@ -324,6 +324,7 @@ + diff --git a/Explorer++/Explorer++/Explorer++.vcxproj.filters b/Explorer++/Explorer++/Explorer++.vcxproj.filters index 1fe71cfd21..740d6b5696 100644 --- a/Explorer++/Explorer++/Explorer++.vcxproj.filters +++ b/Explorer++/Explorer++/Explorer++.vcxproj.filters @@ -219,6 +219,9 @@ Header Files + + Header Files + diff --git a/Explorer++/Explorer++/SearchDialog.cpp b/Explorer++/Explorer++/SearchDialog.cpp index 466d54e52f..f12f08855f 100644 --- a/Explorer++/Explorer++/SearchDialog.cpp +++ b/Explorer++/Explorer++/SearchDialog.cpp @@ -15,6 +15,7 @@ #include #include "Explorer++_internal.h" #include "SearchDialog.h" +#include "DialogHelper.h" #include "MainResource.h" #include "../Helper/Helper.h" #include "../Helper/RegistrySettings.h" @@ -157,7 +158,7 @@ BOOL CSearchDialog::OnInitDialog() hComboBox = reinterpret_cast(SendMessage(hComboBoxEx,CBEM_GETCOMBOCONTROL,0,0)); iItem = 0; - for each(auto strPattern in m_sdps->m_SearchPatterns) + for each(auto strPattern in *m_sdps->m_pSearchPatterns) { TCHAR szPattern[MAX_PATH]; @@ -423,6 +424,7 @@ void CSearchDialog::OnSearch() if(bSaveEntry) { + /* TODO: Switch to circular buffer. */ m_sdps->m_SearchDirectories.push_front(szBaseDirectory); HWND hComboBoxEx = GetDlgItem(m_hDlg,IDC_COMBO_DIRECTORY); @@ -439,26 +441,49 @@ void CSearchDialog::OnSearch() bSaveEntry = FALSE; - if(m_sdps->m_SearchPatterns.empty() || - lstrcmp(szSearchPattern,m_sdps->m_SearchPatterns.begin()->c_str()) != 0) + if(m_sdps->m_pSearchPatterns->empty() || + lstrcmp(szSearchPattern,m_sdps->m_pSearchPatterns->begin()->c_str()) != 0) { bSaveEntry = TRUE; } if(bSaveEntry) { - m_sdps->m_SearchPatterns.push_front(szSearchPattern); + TCHAR szSearchPatternOriginal[MAX_PATH]; + GetDlgItemText(m_hDlg,IDC_COMBO_NAME,szSearchPatternOriginal, + SIZEOF_ARRAY(szSearchPatternOriginal)); + + std::wstring strSearchPatternOriginal(szSearchPatternOriginal); + auto itr = std::find_if(m_sdps->m_pSearchPatterns->begin(),m_sdps->m_pSearchPatterns->end(), + [strSearchPatternOriginal](const std::wstring Pattern){return Pattern.compare(strSearchPatternOriginal) == 0;}); HWND hComboBoxEx = GetDlgItem(m_hDlg,IDC_COMBO_NAME); - HWND hComboBox = (HWND)SendMessage(hComboBoxEx,CBEM_GETCOMBOCONTROL,0,0); + HWND hComboBox = reinterpret_cast(SendMessage(hComboBoxEx,CBEM_GETCOMBOCONTROL,0,0)); + + ComboBox_SetCurSel(hComboBox,-1); + + /* Remove the current element from both the list and the + combo box. It will be reinserted at the front of both below. */ + if(itr != m_sdps->m_pSearchPatterns->end()) + { + auto index = std::distance(m_sdps->m_pSearchPatterns->begin(),itr); + SendMessage(hComboBoxEx,CBEM_DELETEITEM,index,0); + + m_sdps->m_pSearchPatterns->erase(itr); + } + + m_sdps->m_pSearchPatterns->push_front(szSearchPatternOriginal); COMBOBOXEXITEM cbi; cbi.mask = CBEIF_TEXT; cbi.iItem = 0; - cbi.pszText = szSearchPattern; - SendMessage(hComboBoxEx,CBEM_INSERTITEM,0,(LPARAM)&cbi); + cbi.pszText = szSearchPatternOriginal; + SendMessage(hComboBoxEx,CBEM_INSERTITEM,0,reinterpret_cast(&cbi)); - ComboBox_SetCurSel(hComboBox,0); + if(ComboBox_GetCount(hComboBox) > m_sdps->m_pSearchPatterns->capacity()) + { + SendMessage(hComboBoxEx,CBEM_DELETEITEM,ComboBox_GetCount(hComboBox) - 1,0); + } } GetDlgItemText(m_hDlg,IDSEARCH,m_szSearchButton,SIZEOF_ARRAY(m_szSearchButton)); @@ -1255,6 +1280,8 @@ CDialogSettings(SETTINGS_KEY) StringCchCopy(m_szSearchPattern,SIZEOF_ARRAY(m_szSearchPattern), EMPTY_STRING); + m_pSearchPatterns = new boost::circular_buffer(NDialogHelper::DEFAULT_HISTORY_SIZE); + ColumnInfo_t ci; ci.SortMode = SORT_NAME; ci.uStringID = IDS_SEARCH_COLUMN_NAME; @@ -1272,7 +1299,7 @@ CDialogSettings(SETTINGS_KEY) CSearchDialogPersistentSettings::~CSearchDialogPersistentSettings() { - + delete m_pSearchPatterns; } CSearchDialogPersistentSettings& CSearchDialogPersistentSettings::GetInstance() @@ -1294,7 +1321,11 @@ void CSearchDialogPersistentSettings::SaveExtraRegistrySettings(HKEY hKey) NRegistrySettings::SaveDwordToRegistry(hKey,_T("ReadOnly"),m_bReadOnly); NRegistrySettings::SaveDwordToRegistry(hKey,_T("System"),m_bSystem); NRegistrySettings::SaveStringListToRegistry(hKey,_T("Directory"),m_SearchDirectories); - NRegistrySettings::SaveStringListToRegistry(hKey,_T("Pattern"),m_SearchPatterns); + + std::list SearchPatternList; + CircularBufferToList(*m_pSearchPatterns,SearchPatternList); + NRegistrySettings::SaveStringListToRegistry(hKey,_T("Pattern"),SearchPatternList); + NRegistrySettings::SaveDwordToRegistry(hKey,_T("SortMode"),m_SortMode); NRegistrySettings::SaveDwordToRegistry(hKey,_T("SortAscending"),m_bSortAscending); } @@ -1312,7 +1343,11 @@ void CSearchDialogPersistentSettings::LoadExtraRegistrySettings(HKEY hKey) NRegistrySettings::ReadDwordFromRegistry(hKey,_T("ReadOnly"),reinterpret_cast(&m_bReadOnly)); NRegistrySettings::ReadDwordFromRegistry(hKey,_T("System"),reinterpret_cast(&m_bSystem)); NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Directory"),m_SearchDirectories); - NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Pattern"),m_SearchPatterns); + + std::list SearchPatternList; + NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Pattern"),SearchPatternList); + ListToCircularBuffer(SearchPatternList,*m_pSearchPatterns); + NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortMode"),reinterpret_cast(&m_SortMode)); NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortAscending"),reinterpret_cast(&m_bSortAscending)); } @@ -1323,7 +1358,11 @@ void CSearchDialogPersistentSettings::SaveExtraXMLSettings( NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("ColumnWidth1"),NXMLSettings::EncodeIntValue(m_iColumnWidth1)); NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("ColumnWidth2"),NXMLSettings::EncodeIntValue(m_iColumnWidth2)); NXMLSettings::AddStringListToNode(pXMLDom,pParentNode,_T("Directory"),m_SearchDirectories); - NXMLSettings::AddStringListToNode(pXMLDom,pParentNode,_T("Pattern"),m_SearchPatterns); + + std::list SearchPatternList; + CircularBufferToList(*m_pSearchPatterns,SearchPatternList); + NXMLSettings::AddStringListToNode(pXMLDom,pParentNode,_T("Pattern"),SearchPatternList); + NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("SearchDirectoryText"),m_szSearchPattern); NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("SearchSubFolders"),NXMLSettings::EncodeBoolValue(m_bSearchSubFolders)); NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("UseRegularExpressions"),NXMLSettings::EncodeBoolValue(m_bUseRegularExpressions)); @@ -1352,7 +1391,7 @@ void CSearchDialogPersistentSettings::LoadExtraXMLSettings(BSTR bstrName,BSTR bs } else if(CheckWildcardMatch(_T("Pattern*"),bstrName,TRUE)) { - m_SearchPatterns.push_back(bstrValue); + m_pSearchPatterns->push_back(bstrValue); } else if(lstrcmpi(bstrName,_T("SearchDirectoryText")) == 0) { @@ -1405,4 +1444,24 @@ void CSearchDialogPersistentSettings::LoadExtraXMLSettings(BSTR bstrName,BSTR bs { m_bSortAscending = NXMLSettings::DecodeBoolValue(bstrValue); } +} + +template +void CSearchDialogPersistentSettings::CircularBufferToList(const boost::circular_buffer &cb, + std::list &list) +{ + for each(auto Item in cb) + { + list.push_back(Item); + } +} + +template +void CSearchDialogPersistentSettings::ListToCircularBuffer(const std::list &list, + boost::circular_buffer &cb) +{ + for each(auto Item in list) + { + cb.push_back(Item); + } } \ No newline at end of file diff --git a/Explorer++/Explorer++/SearchDialog.h b/Explorer++/Explorer++/SearchDialog.h index ae8f4e2818..87ec8974d5 100644 --- a/Explorer++/Explorer++/SearchDialog.h +++ b/Explorer++/Explorer++/SearchDialog.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "../Helper/BaseDialog.h" #include "../Helper/DialogSettings.h" #include "../Helper/ReferenceCount.h" @@ -60,9 +61,12 @@ class CSearchDialogPersistentSettings : public CDialogSettings CSearchDialogPersistentSettings(const CSearchDialogPersistentSettings &); CSearchDialogPersistentSettings & operator=(const CSearchDialogPersistentSettings &); + template void CircularBufferToList(const boost::circular_buffer &cb,std::list &list); + template void ListToCircularBuffer(const std::list &list,boost::circular_buffer &cb); + TCHAR m_szSearchPattern[MAX_PATH]; std::list m_SearchDirectories; - std::list m_SearchPatterns; + boost::circular_buffer *m_pSearchPatterns; BOOL m_bSearchSubFolders; BOOL m_bUseRegularExpressions; BOOL m_bCaseInsensitive;