Automatically size and sort the Default Columns in the dialog

Share any ideas you have on improving Explorer++
Post Reply
Edgar5
Posts: 63
Joined: Sun Apr 02, 2017 7:22 am

Automatically size and sort the Default Columns in the dialog

Post by Edgar5 »

On the Options > Default Settings tab the "Default columns" button brings up a new dialog which offers a large
number of possible columns (specifically under the General Folder option).
There's one bug/enhancement that is easy to fix/improve; the fixed width of the column checkbox items was far
narrower than the containing window and so narrow that at least one of the item's text was truncated. In file:
\Explorer++\SetDefaultColumnsDialog.cpp
at or near line #109:
lvColumn.cx = 180;//efm5 "parental rating reason" was truncated: "parental rating r…"
There is at least 386 pixels after the slightly indented checkbox and an examination of the similar code for the
non-global version (menu View > Select Columns…) uses the Windows API to autosize the column; following

the same process resolves the problem:
at or near line #109-114:
//lvColumn.cx = 180;//efm5 use auto-sizing
ListView_InsertColumn(hListView,0,&lvColumn);

SetupFolderColumns(m_psdcdps->m_FolderType);
ListView_SetColumnWidth(hListView, 0, LVSCW_AUTOSIZE);//efm5

SetFocus(hListView);
comment out the line or remove it; add the new line after:
SetupFolderColumns(m_psdcdps->m_FolderType);
ListView_SetColumnWidth(hListView, 0, LVSCW_AUTOSIZE);//efm5
so that the column will be automatically sized based on text length (and we get font awareness for free).

While I was playing with this dialog I decided to add some enhancements. The first was to turn on automatic
alphabetical sorting of the column items. In file:
\Explorer++\Explorer++.rc
at or near line #390+
the first thing to do is add sorting ( | LVS_SORTASCENDING):
CONTROL "", IDC_DEFAULTCOLUMNS_LISTVIEW, "SysListView32", LVS_REPORT |

LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT |
LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP | LVS_SORTASCENDING,
//efm5 sort column items
6, 56, 137, 174
While you're in the vicinity add another pushbutton:
PUSHBUTTON "Move To &Top", IDC_DEFAULTCOLUMNS_MOVETOP, 148, 88, 48, 14,

WS_CLIPSIBLINGS//efm5
note the accelerator key - and speaking of accelerators:
DEFPUSHBUTTON "&OK",IDOK,95,272,50,14,WS_CLIPSIBLINGS
PUSHBUTTON "&Cancel",IDCANCEL,148,272,50,14,WS_CLIPSIBLINGS
I added accelerator keys for these buttons.
Now we need to implement the new button. In file:
\Explorer++\SetDefaultColumnsDialog.h
at or near line #81, add new function declaration:
void OnMoveColumnToTop();
In file:
\Explorer++\SetDefaultColumnsDialog.cpp
at or near line #400 (it doesn't really matter where you put it but there's similar code here), define the function:
void CSetDefaultColumnsDialog::OnMoveColumnToTop() {
HWND hListView = GetDlgItem(m_hDlg, IDC_COLUMNS_LISTVIEW);
int iSelected = ListView_GetNextItem(hListView, -1, LVNI_SELECTED);

if (iSelected != -1) {
do {
NListView::ListView_SwapItems(hListView, iSelected, iSelected - 1);
iSelected--;
}
while (iSelected != -1);
}
}
next, we will need to exercise the new function. In file:
\Explorer++\SetDefaultColumnsDialog.cpp
at or near line #200, add a new case:
case IDC_DEFAULTCOLUMNS_MOVETOP:
OnMoveColumnToTop();
break;
Give this a try, pick some item well down the list (it need not be checked) and click the new button. It's a tough
call whether after moving the item to the top the list itself should be scrolled all the way to the top but I suspect
that this code:
NListView::ListView_SelectItem(hListView,0,TRUE);
would probably do the trick (I prefer it not to move me away from where I'm working).

The new function: OnMoveColumnToTop seemed like it might be a candidate for another trick. When Windows
presents this kind of list, the items that are checked when the list is initialized are automatically moved to the top
after the alpha-numeric sorting. In file:
\Explorer++\SetDefaultColumnsDialog.cpp
at or near line #312 you will find the function:
void CSetDefaultColumnsDialog::SetupFolderColumns(FolderType_t FolderType)
almost at the very end of the function at these few lines:
ListView_SetCheckState(hListView,iItem,Column.bChecked);//existing code

iItem++;//existing code
}//existing code
//efm5 start automatically move all checked items to top
iItem = 0;
for each(auto Column in *pColumnList) {
NListView::ListView_SelectItem(hListView, iItem, TRUE);
if (Column.bChecked)
OnMoveColumnToTop();
iItem++;
}
//efm5 end
NListView::ListView_SelectItem(hListView,0,TRUE);//existing code
}//existing code
Have fun!

One thing I noticed, when an item is checked it does not get selected (the reverse is also true simply selecting
does not check in item - I think this one is right). For my personal use case I would prefer that checking in item
also select it so that it is immediately ready to be moved-to-top.
Post Reply