Skip to content

Commit

Permalink
Merged revision(s) 381 from trunk:
Browse files Browse the repository at this point in the history
Made the following changes to the search dialog:
- A circular buffer is now used to store history for the filename field.
- If the filename entered already appears in the list, it will simply be swapped to the first position (rather than re-entered).
- The original search string is stored (rather than the processed string).
........
  • Loading branch information
derceg committed Oct 12, 2011
1 parent cab6edd commit a9da006
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 14 deletions.
9 changes: 9 additions & 0 deletions Documentation/History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------------
Expand Down
9 changes: 9 additions & 0 deletions Explorer++/Explorer++/DialogHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef DIALOGHELPER_INCLUDED
#define DIALOGHELPER_INCLUDED

namespace NDialogHelper
{
const int DEFAULT_HISTORY_SIZE = 20;
}

#endif
Binary file modified Explorer++/Explorer++/Explorer++.rc
Binary file not shown.
1 change: 1 addition & 0 deletions Explorer++/Explorer++/Explorer++.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
<ClInclude Include="ColorRuleDialog.h" />
<ClInclude Include="CustomizeColorsDialog.h" />
<ClInclude Include="DestroyFilesDialog.h" />
<ClInclude Include="DialogHelper.h" />
<ClInclude Include="Explorer++.h" />
<ClInclude Include="Explorer++_internal.h" />
<ClInclude Include="FilterDialog.h" />
Expand Down
3 changes: 3 additions & 0 deletions Explorer++/Explorer++/Explorer++.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
<ClInclude Include="HelpFileMissingDialog.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DialogHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Explorer++.rc">
Expand Down
85 changes: 72 additions & 13 deletions Explorer++/Explorer++/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <regex>
#include "Explorer++_internal.h"
#include "SearchDialog.h"
#include "DialogHelper.h"
#include "MainResource.h"
#include "../Helper/Helper.h"
#include "../Helper/RegistrySettings.h"
Expand Down Expand Up @@ -157,7 +158,7 @@ BOOL CSearchDialog::OnInitDialog()
hComboBox = reinterpret_cast<HWND>(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];

Expand Down Expand Up @@ -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);
Expand All @@ -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<HWND>(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<LPARAM>(&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));
Expand Down Expand Up @@ -1255,6 +1280,8 @@ CDialogSettings(SETTINGS_KEY)
StringCchCopy(m_szSearchPattern,SIZEOF_ARRAY(m_szSearchPattern),
EMPTY_STRING);

m_pSearchPatterns = new boost::circular_buffer<std::wstring>(NDialogHelper::DEFAULT_HISTORY_SIZE);

ColumnInfo_t ci;
ci.SortMode = SORT_NAME;
ci.uStringID = IDS_SEARCH_COLUMN_NAME;
Expand All @@ -1272,7 +1299,7 @@ CDialogSettings(SETTINGS_KEY)

CSearchDialogPersistentSettings::~CSearchDialogPersistentSettings()
{

delete m_pSearchPatterns;
}

CSearchDialogPersistentSettings& CSearchDialogPersistentSettings::GetInstance()
Expand All @@ -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<std::wstring> 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);
}
Expand All @@ -1312,7 +1343,11 @@ void CSearchDialogPersistentSettings::LoadExtraRegistrySettings(HKEY hKey)
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("ReadOnly"),reinterpret_cast<LPDWORD>(&m_bReadOnly));
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("System"),reinterpret_cast<LPDWORD>(&m_bSystem));
NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Directory"),m_SearchDirectories);
NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Pattern"),m_SearchPatterns);

std::list<std::wstring> SearchPatternList;
NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Pattern"),SearchPatternList);
ListToCircularBuffer(SearchPatternList,*m_pSearchPatterns);

NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortMode"),reinterpret_cast<LPDWORD>(&m_SortMode));
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortAscending"),reinterpret_cast<LPDWORD>(&m_bSortAscending));
}
Expand All @@ -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<std::wstring> 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));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -1405,4 +1444,24 @@ void CSearchDialogPersistentSettings::LoadExtraXMLSettings(BSTR bstrName,BSTR bs
{
m_bSortAscending = NXMLSettings::DecodeBoolValue(bstrValue);
}
}

template <typename T>
void CSearchDialogPersistentSettings::CircularBufferToList(const boost::circular_buffer<T> &cb,
std::list<T> &list)
{
for each(auto Item in cb)
{
list.push_back(Item);
}
}

template <typename T>
void CSearchDialogPersistentSettings::ListToCircularBuffer(const std::list<T> &list,
boost::circular_buffer<T> &cb)
{
for each(auto Item in list)
{
cb.push_back(Item);
}
}
6 changes: 5 additions & 1 deletion Explorer++/Explorer++/SearchDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <regex>
#include <unordered_map>
#include <boost/circular_buffer.hpp>
#include "../Helper/BaseDialog.h"
#include "../Helper/DialogSettings.h"
#include "../Helper/ReferenceCount.h"
Expand Down Expand Up @@ -60,9 +61,12 @@ class CSearchDialogPersistentSettings : public CDialogSettings
CSearchDialogPersistentSettings(const CSearchDialogPersistentSettings &);
CSearchDialogPersistentSettings & operator=(const CSearchDialogPersistentSettings &);

template <typename T> void CircularBufferToList(const boost::circular_buffer<T> &cb,std::list<T> &list);
template <typename T> void ListToCircularBuffer(const std::list<T> &list,boost::circular_buffer<T> &cb);

TCHAR m_szSearchPattern[MAX_PATH];
std::list<std::wstring> m_SearchDirectories;
std::list<std::wstring> m_SearchPatterns;
boost::circular_buffer<std::wstring> *m_pSearchPatterns;
BOOL m_bSearchSubFolders;
BOOL m_bUseRegularExpressions;
BOOL m_bCaseInsensitive;
Expand Down

0 comments on commit a9da006

Please sign in to comment.