Skip to content

Commit dadd787

Browse files
committed
0.10.0.27: Hitting Enter when highlighting a row in the grid editor now enters into edit mode on existing rows and for row insert
1 parent 090eebb commit dadd787

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/sqlite-ce-edit/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ BOOL WINAPI GetSaveFileNameW(CE_OPENFILENAME*);
8787
** Version
8888
**============================================================================*/
8989

90-
#define SQLITECEDIT_VERSION L"0.10.0.22"
90+
#define SQLITECEDIT_VERSION L"0.10.0.27"
9191

9292
/*============================================================================
9393
** Menu IDs

src/sqlite-ce-edit/grid.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ static void CopySelectedRow(void) {
9999
}
100100

101101
LRESULT CALLBACK GridProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
102+
/* Tell Windows we want Enter key */
103+
if (msg == WM_GETDLGCODE) {
104+
return DLGC_WANTALLKEYS;
105+
}
102106
/* Global shortcuts first */
103107
if (HandleGlobalKeys(msg, wParam))
104108
return 0;
@@ -143,6 +147,32 @@ LRESULT CALLBACK GridProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
143147
if (sel >= 0) StartCellEdit(sel, 0);
144148
return 0;
145149
}
150+
/* Enter - Start editing selected row, or commit if in insert mode with data */
151+
if (wParam == VK_RETURN && g_editMode && !g_hwndEditOverlay) {
152+
int sel = ListView_GetNextItem(g_hwndGrid, -1, LVNI_SELECTED);
153+
if (sel >= 0) {
154+
/* If on placeholder row with no pending data, start editing */
155+
if (sel == g_lastResultRows) {
156+
int hasData = 0, i, startCol = 0;
157+
if (g_pendingValues) {
158+
for (i = 0; i < g_colMetaCount && !hasData; i++)
159+
if (g_pendingValues[i]) hasData = 1;
160+
}
161+
if (hasData) {
162+
CommitInsert();
163+
} else {
164+
/* Find first non-autoincrement column */
165+
for (i = 0; i < g_colMetaCount; i++) {
166+
if (!g_colMeta[i].isAutoInc) { startCol = i; break; }
167+
}
168+
StartCellEdit(sel, startCol);
169+
}
170+
} else {
171+
StartCellEdit(sel, 0);
172+
}
173+
}
174+
return 0;
175+
}
146176
/* Delete - Delete selected row (only in edit mode, not placeholder) */
147177
if (wParam == VK_DELETE && g_editMode) {
148178
int sel = ListView_GetNextItem(g_hwndGrid, -1, LVNI_SELECTED);
@@ -151,11 +181,6 @@ LRESULT CALLBACK GridProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
151181
}
152182
return 0;
153183
}
154-
/* Enter - Commit new row (only in insert mode, when not in cell edit) */
155-
if (wParam == VK_RETURN && g_insertMode && !g_hwndEditOverlay) {
156-
CommitInsert();
157-
return 0;
158-
}
159184
/* Escape - Cancel insert mode if active (when not in cell edit) */
160185
if (wParam == VK_ESCAPE && g_insertMode && !g_hwndEditOverlay) {
161186
ClearInsertMode();

0 commit comments

Comments
 (0)