Skip to content

Commit e825cd7

Browse files
committed
0.8.0.51: Implemented shortcut entry for the current directory ('[.]') in file picker list view, implemented manual sorting to place working/parent directory shortcuts at the top of the list, then subdirectories, then files, sorted alphabetically.
1 parent c05744a commit e825cd7

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

src/sqlite-ce-edit/filepicker.c

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,58 @@ static void GetFilterExt(const wchar_t *filter, wchar_t *ext, int maxLen) {
5151
** Populate file list for current directory
5252
**============================================================================*/
5353

54+
#define MAX_ENTRIES 256
55+
56+
static void SortAndAdd(wchar_t entries[][MAX_PATH], int count, int bracket) {
57+
int i, j;
58+
wchar_t temp[MAX_PATH];
59+
/* Simple insertion sort */
60+
for (i = 1; i < count; i++) {
61+
lstrcpyW(temp, entries[i]);
62+
j = i - 1;
63+
while (j >= 0 && lstrcmpiW(entries[j], temp) > 0) {
64+
lstrcpyW(entries[j + 1], entries[j]);
65+
j--;
66+
}
67+
lstrcpyW(entries[j + 1], temp);
68+
}
69+
/* Add to listbox */
70+
for (i = 0; i < count; i++) {
71+
if (bracket) {
72+
wchar_t item[MAX_PATH];
73+
wsprintfW(item, L"[%s]", entries[i]);
74+
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)item);
75+
} else {
76+
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)entries[i]);
77+
}
78+
}
79+
}
80+
5481
static void PopulateFileList(void) {
5582
WIN32_FIND_DATAW fd;
5683
HANDLE hFind;
5784
wchar_t pattern[MAX_PATH];
5885
wchar_t ext[32];
5986
int atRoot;
87+
static wchar_t entries[MAX_ENTRIES][MAX_PATH];
88+
int count;
6089

6190
SendMessageW(g_hwndList, LB_RESETCONTENT, 0, 0);
6291

6392
atRoot = (lstrcmpW(g_pickerDir, L"\\") == 0);
6493

94+
/* Add [.] for save mode - confirms with current filename */
95+
if (g_pickerSaveMode) {
96+
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)L"[.]");
97+
}
98+
6599
/* Add parent directory entry if not at root */
66100
if (!atRoot) {
67101
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)L"[..]");
68102
}
69103

70-
/* Add subdirectories */
104+
/* Collect subdirectories */
105+
count = 0;
71106
if (atRoot) {
72107
lstrcpyW(pattern, L"\\*");
73108
} else {
@@ -77,16 +112,16 @@ static void PopulateFileList(void) {
77112
if (hFind != INVALID_HANDLE_VALUE) {
78113
do {
79114
if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
80-
fd.cFileName[0] != '.') {
81-
wchar_t item[MAX_PATH];
82-
wsprintfW(item, L"[%s]", fd.cFileName);
83-
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)item);
115+
fd.cFileName[0] != '.' && count < MAX_ENTRIES) {
116+
lstrcpyW(entries[count++], fd.cFileName);
84117
}
85118
} while (FindNextFileW(hFind, &fd));
86119
FindClose(hFind);
87120
}
121+
SortAndAdd(entries, count, 1);
88122

89-
/* Add files matching filter */
123+
/* Collect files matching filter */
124+
count = 0;
90125
GetFilterExt(g_pickerFilter, ext, 32);
91126
if (atRoot) {
92127
if (ext[0]) {
@@ -105,12 +140,13 @@ static void PopulateFileList(void) {
105140
hFind = FindFirstFileW(pattern, &fd);
106141
if (hFind != INVALID_HANDLE_VALUE) {
107142
do {
108-
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
109-
SendMessageW(g_hwndList, LB_ADDSTRING, 0, (LPARAM)fd.cFileName);
143+
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && count < MAX_ENTRIES) {
144+
lstrcpyW(entries[count++], fd.cFileName);
110145
}
111146
} while (FindNextFileW(hFind, &fd));
112147
FindClose(hFind);
113148
}
149+
SortAndAdd(entries, count, 0);
114150

115151
/* Update path display */
116152
SetWindowTextW(g_hwndPath, g_pickerDir);
@@ -136,7 +172,12 @@ static void OnItemActivate(void) {
136172
SendMessageW(g_hwndList, LB_GETTEXT, sel, (LPARAM)item);
137173

138174
if (item[0] == '[') {
139-
/* Directory - navigate into it */
175+
/* Special entries */
176+
if (lstrcmpW(item, L"[.]") == 0) {
177+
/* Save to current directory - simulate OK button */
178+
SendMessageW(g_hwndPicker, WM_COMMAND, IDOK, 0);
179+
return;
180+
}
140181
if (lstrcmpW(item, L"[..]") == 0) {
141182
/* Go up one level */
142183
wchar_t *p = g_pickerDir + lstrlenW(g_pickerDir) - 1;
@@ -430,7 +471,7 @@ int CustomFilePicker(HWND hwndOwner, wchar_t *filePath, int maxPath,
430471

431472
/* File listbox */
432473
g_hwndList = CreateWindowW(L"LISTBOX", NULL,
433-
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_NOTIFY | LBS_SORT,
474+
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | LBS_NOTIFY,
434475
10, 34, dlgW - 20, 80, g_hwndPicker, (HMENU)101, g_hInst, NULL);
435476

436477
/* Subclass listbox */

src/sqlite-ce-edit/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ BOOL WINAPI GetSaveFileNameW(CE_OPENFILENAME*);
8282
** Version
8383
**============================================================================*/
8484

85-
#define SQLITECEDIT_VERSION L"0.8.0.48"
85+
#define SQLITECEDIT_VERSION L"0.8.0.51"
8686

8787
/*============================================================================
8888
** Menu IDs

0 commit comments

Comments
 (0)