Skip to content

Commit

Permalink
Merging r348 from trunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
derceg committed Aug 26, 2011
1 parent d050ced commit 19610ef
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 74 deletions.
4 changes: 4 additions & 0 deletions Documentation/32-bit Release specific/History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Note:

Version 1.3.1 (xx/xx/2011)
--------------------------
New features:
- The sort mode and direction are now saved in the search
dialog.

Bug fixes:
- The image in the about dialog would not be shown when a
translation was loaded. Fixed.
Expand Down
4 changes: 4 additions & 0 deletions Documentation/64-bit Release specific/History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Current version: 1.3

Version 1.3.1 (xx/xx/2011)
--------------------------
New features:
- The sort mode and direction are now saved in the search
dialog.

Bug fixes:
- The image in the about dialog would not be shown when a
translation was loaded. Fixed.
Expand Down
176 changes: 133 additions & 43 deletions Explorer++/Explorer++/SearchDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,13 @@ CBaseDialog(hInstance,iResource,hParent,true)

m_pexpp = pexpp;

m_bSearching = FALSE;
m_bStopSearching = FALSE;
m_bExit = FALSE;
m_bSetSearchTimer = TRUE;
m_iInternalIndex = 0;

ColumnInfo_t ci;

ci.SearchMode = SORT_NAME;
m_Columns.push_back(ci);

ci.SearchMode = SORT_PATH;
m_Columns.push_back(ci);

m_pSearch = NULL;
m_bSearching = FALSE;
m_bStopSearching = FALSE;
m_bExit = FALSE;
m_bSetSearchTimer = TRUE;
m_iInternalIndex = 0;
m_iPreviousSelectedColumn = -1;
m_pSearch = NULL;

m_sdps = &CSearchDialogPersistentSettings::GetInstance();
}
Expand Down Expand Up @@ -110,27 +102,29 @@ BOOL CSearchDialog::OnInitDialog()

SetWindowTheme(hListView,L"Explorer",NULL);

LVCOLUMN lvColumn;
TCHAR szTemp[128];
int i = 0;

for each(auto ci in m_sdps->m_Columns)
{
TCHAR szTemp[128];
LoadString(GetInstance(),ci.uStringID,szTemp,SIZEOF_ARRAY(szTemp));

LoadString(GetInstance(),IDS_SEARCH_COLUMN_NAME,
szTemp,SIZEOF_ARRAY(szTemp));
lvColumn.mask = LVCF_TEXT;
lvColumn.pszText = szTemp;
ListView_InsertColumn(hListView,0,&lvColumn);
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_TEXT;
lvColumn.pszText = szTemp;
ListView_InsertColumn(hListView,i,&lvColumn);

LoadString(GetInstance(),IDS_SEARCH_COLUMN_PATH,
szTemp,SIZEOF_ARRAY(szTemp));
lvColumn.mask = LVCF_TEXT;
lvColumn.pszText = szTemp;
ListView_InsertColumn(hListView,1,&lvColumn);
i++;
}

RECT rc;
GetClientRect(hListView,&rc);

ListView_SetColumnWidth(hListView,0,(1.0/3.0) * GetRectWidth(&rc));
ListView_SetColumnWidth(hListView,1,(1.80/3.0) * GetRectWidth(&rc));

UpdateListViewHeader();

lCheckDlgButton(m_hDlg,IDC_CHECK_ARCHIVE,m_sdps->m_bArchive);
lCheckDlgButton(m_hDlg,IDC_CHECK_HIDDEN,m_sdps->m_bHidden);
lCheckDlgButton(m_hDlg,IDC_CHECK_READONLY,m_sdps->m_bReadOnly);
Expand Down Expand Up @@ -492,6 +486,60 @@ void CSearchDialog::OnSearch()
}
}

void CSearchDialog::UpdateListViewHeader()
{
HWND hHeader = ListView_GetHeader(GetDlgItem(m_hDlg,IDC_LISTVIEW_SEARCHRESULTS));

HDITEM hdItem;

/* Remove the sort arrow from the column that was
previously selected. */
if(m_iPreviousSelectedColumn != -1)
{
hdItem.mask = HDI_FORMAT;
Header_GetItem(hHeader,m_iPreviousSelectedColumn,&hdItem);

if(hdItem.fmt & HDF_SORTUP)
{
hdItem.fmt &= ~HDF_SORTUP;
}
else if(hdItem.fmt & HDF_SORTDOWN)
{
hdItem.fmt &= ~HDF_SORTDOWN;
}

Header_SetItem(hHeader,m_iPreviousSelectedColumn,&hdItem);
}

int iColumn = 0;

for each(auto ci in m_sdps->m_Columns)
{
if(ci.SortMode == m_sdps->m_SortMode)
{
break;
}

iColumn++;
}

hdItem.mask = HDI_FORMAT;
Header_GetItem(hHeader,iColumn,&hdItem);

if(m_sdps->m_bSortAscending)
{
hdItem.fmt |= HDF_SORTUP;
}
else
{
hdItem.fmt |= HDF_SORTDOWN;
}

Header_SetItem(hHeader,iColumn,&hdItem);

m_iPreviousSelectedColumn = iColumn;
}

int CALLBACK NSearchDialog::SortResultsStub(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort)
{
assert(lParamSort != NULL);
Expand All @@ -505,18 +553,18 @@ int CALLBACK CSearchDialog::SortResults(LPARAM lParam1,LPARAM lParam2)
{
int iRes = 0;

switch(m_SortMode)
switch(m_sdps->m_SortMode)
{
case SORT_NAME:
case CSearchDialogPersistentSettings::SORT_NAME:
iRes = SortResultsByName(lParam1,lParam2);
break;

case SORT_PATH:
case CSearchDialogPersistentSettings::SORT_PATH:
iRes = SortResultsByPath(lParam1,lParam2);
break;
}

if(!m_bSortAscending)
if(!m_sdps->m_bSortAscending)
{
iRes = -iRes;
}
Expand Down Expand Up @@ -740,17 +788,20 @@ BOOL CSearchDialog::OnNotify(NMHDR *pnmhdr)

/* If the column clicked matches the current sort mode,
flip the sort direction, else switch to that sort mode. */
if(m_Columns[pnmlv->iSubItem].SearchMode == m_SortMode)
if(m_sdps->m_Columns[pnmlv->iSubItem].SortMode == m_sdps->m_SortMode)
{
m_bSortAscending = !m_bSortAscending;
m_sdps->m_bSortAscending = !m_sdps->m_bSortAscending;
}
else
{
m_SortMode = m_Columns[pnmlv->iSubItem].SearchMode;
m_sdps->m_SortMode = m_sdps->m_Columns[pnmlv->iSubItem].SortMode;
m_sdps->m_bSortAscending = m_sdps->m_Columns[pnmlv->iSubItem].bSortAscending;
}

ListView_SortItems(GetDlgItem(m_hDlg,IDC_LISTVIEW_SEARCHRESULTS),
NSearchDialog::SortResultsStub,reinterpret_cast<LPARAM>(this));

UpdateListViewHeader();
}
break;
}
Expand Down Expand Up @@ -1191,18 +1242,32 @@ void CSearchDialog::SaveState()
CSearchDialogPersistentSettings::CSearchDialogPersistentSettings() :
CDialogSettings(SETTINGS_KEY)
{
m_bSearchSubFolders = TRUE;
m_bUseRegularExpressions = FALSE;
m_bCaseInsensitive = FALSE;
m_bArchive = FALSE;
m_bHidden = FALSE;
m_bReadOnly = FALSE;
m_bSystem = FALSE;
m_iColumnWidth1 = -1;
m_iColumnWidth1 = -1;
m_bSearchSubFolders = TRUE;
m_bUseRegularExpressions = FALSE;
m_bCaseInsensitive = FALSE;
m_bArchive = FALSE;
m_bHidden = FALSE;
m_bReadOnly = FALSE;
m_bSystem = FALSE;
m_iColumnWidth1 = -1;
m_iColumnWidth2 = -1;

StringCchCopy(m_szSearchPattern,SIZEOF_ARRAY(m_szSearchPattern),
EMPTY_STRING);

ColumnInfo_t ci;
ci.SortMode = SORT_NAME;
ci.uStringID = IDS_SEARCH_COLUMN_NAME;
ci.bSortAscending = true;
m_Columns.push_back(ci);

ci.SortMode = SORT_PATH;
ci.uStringID = IDS_SEARCH_COLUMN_PATH;
ci.bSortAscending = true;
m_Columns.push_back(ci);

m_SortMode = m_Columns.front().SortMode;
m_bSortAscending = m_Columns.front().bSortAscending;
}

CSearchDialogPersistentSettings::~CSearchDialogPersistentSettings()
Expand Down Expand Up @@ -1230,6 +1295,8 @@ void CSearchDialogPersistentSettings::SaveExtraRegistrySettings(HKEY hKey)
NRegistrySettings::SaveDwordToRegistry(hKey,_T("System"),m_bSystem);
NRegistrySettings::SaveStringListToRegistry(hKey,_T("Directory"),m_SearchDirectories);
NRegistrySettings::SaveStringListToRegistry(hKey,_T("Pattern"),m_SearchPatterns);
NRegistrySettings::SaveDwordToRegistry(hKey,_T("SortMode"),m_SortMode);
NRegistrySettings::SaveDwordToRegistry(hKey,_T("SortAscending"),m_bSortAscending);
}

void CSearchDialogPersistentSettings::LoadExtraRegistrySettings(HKEY hKey)
Expand All @@ -1246,6 +1313,8 @@ void CSearchDialogPersistentSettings::LoadExtraRegistrySettings(HKEY hKey)
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("System"),reinterpret_cast<LPDWORD>(&m_bSystem));
NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Directory"),m_SearchDirectories);
NRegistrySettings::ReadStringListFromRegistry(hKey,_T("Pattern"),m_SearchPatterns);
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortMode"),reinterpret_cast<LPDWORD>(&m_SortMode));
NRegistrySettings::ReadDwordFromRegistry(hKey,_T("SortAscending"),reinterpret_cast<LPDWORD>(&m_bSortAscending));
}

void CSearchDialogPersistentSettings::SaveExtraXMLSettings(
Expand All @@ -1263,6 +1332,8 @@ void CSearchDialogPersistentSettings::SaveExtraXMLSettings(
NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("Hidden"),NXMLSettings::EncodeBoolValue(m_bHidden));
NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("ReadOnly"),NXMLSettings::EncodeBoolValue(m_bReadOnly));
NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("System"),NXMLSettings::EncodeBoolValue(m_bSystem));
NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("SortMode"),NXMLSettings::EncodeIntValue(m_SortMode));
NXMLSettings::AddAttributeToNode(pXMLDom,pParentNode,_T("SortAscending"),NXMLSettings::EncodeBoolValue(m_bSortAscending));
}

void CSearchDialogPersistentSettings::LoadExtraXMLSettings(BSTR bstrName,BSTR bstrValue)
Expand Down Expand Up @@ -1315,4 +1386,23 @@ void CSearchDialogPersistentSettings::LoadExtraXMLSettings(BSTR bstrName,BSTR bs
{
m_bSystem = NXMLSettings::DecodeBoolValue(bstrValue);
}
else if(lstrcmpi(bstrName,_T("SortMode")) == 0)
{
int SortMode = NXMLSettings::DecodeIntValue(bstrValue);

switch(SortMode)
{
case SORT_NAME:
m_SortMode = SORT_NAME;
break;

case SORT_PATH:
m_SortMode = SORT_PATH;
break;
}
}
else if(lstrcmpi(bstrName,_T("SortAscending")) == 0)
{
m_bSortAscending = NXMLSettings::DecodeBoolValue(bstrValue);
}
}
68 changes: 37 additions & 31 deletions Explorer++/Explorer++/SearchDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,45 @@ class CSearchDialogPersistentSettings : public CDialogSettings

static const TCHAR SETTINGS_KEY[];

enum SortMode_t
{
SORT_NAME = 1,
SORT_PATH = 2
};

struct ColumnInfo_t
{
SortMode_t SortMode;
UINT uStringID;

/* Indicates whether the sort direction
for this column should be ascending by
default. */
bool bSortAscending;
};

CSearchDialogPersistentSettings();

CSearchDialogPersistentSettings(const CSearchDialogPersistentSettings &);
CSearchDialogPersistentSettings & operator=(const CSearchDialogPersistentSettings &);

TCHAR m_szSearchPattern[MAX_PATH];
std::list<std::wstring> m_SearchDirectories;
std::list<std::wstring> m_SearchPatterns;
BOOL m_bSearchSubFolders;
BOOL m_bUseRegularExpressions;
BOOL m_bCaseInsensitive;
BOOL m_bArchive;
BOOL m_bHidden;
BOOL m_bReadOnly;
BOOL m_bSystem;

/* Control size properties. */
int m_iColumnWidth1;
int m_iColumnWidth2;
TCHAR m_szSearchPattern[MAX_PATH];
std::list<std::wstring> m_SearchDirectories;
std::list<std::wstring> m_SearchPatterns;
BOOL m_bSearchSubFolders;
BOOL m_bUseRegularExpressions;
BOOL m_bCaseInsensitive;
BOOL m_bArchive;
BOOL m_bHidden;
BOOL m_bReadOnly;
BOOL m_bSystem;

std::vector<ColumnInfo_t> m_Columns;
SortMode_t m_SortMode;
BOOL m_bSortAscending;

int m_iColumnWidth1;
int m_iColumnWidth2;
};

class CSearch : public CReferenceCount
Expand Down Expand Up @@ -135,19 +155,8 @@ class CSearchDialog : public CBaseDialog, public IFileContextMenuExternal

static const int MENU_ID_OPEN_FILE_LOCATION = (MAX_SHELL_MENU_ID + 1);

/* Available search modes. */
enum SortMode_t
{
SORT_NAME,
SORT_PATH
};

struct ColumnInfo_t
{
SortMode_t SearchMode;
};

void OnSearch();
void OnSearch();
void UpdateListViewHeader();

TCHAR m_szSearchDirectory[MAX_PATH];
HICON m_hDialogIcon;
Expand All @@ -157,16 +166,13 @@ class CSearchDialog : public CBaseDialog, public IFileContextMenuExternal
TCHAR m_szSearchButton[32];
BOOL m_bExit;

/* Search data. */
CSearch *m_pSearch;

/* Listview item information. */
std::list<LPITEMIDLIST> m_AwaitingSearchItems;
std::unordered_map<int,std::wstring> m_SearchItemsMapInternal;
int m_iInternalIndex;
std::vector<ColumnInfo_t> m_Columns;
SortMode_t m_SortMode;
BOOL m_bSortAscending;
int m_iPreviousSelectedColumn;

BOOL m_bSetSearchTimer;

Expand Down

0 comments on commit 19610ef

Please sign in to comment.