Skip to content

Commit

Permalink
Up to 1.2.3
Browse files Browse the repository at this point in the history
+ Add buttons in Edit data dialog
* Fix csv export bugs
* Fix delete bug
  • Loading branch information
little-brother committed Sep 26, 2020
1 parent c63ea64 commit 3388c10
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 125 deletions.
Binary file added resources/btn_add.bmp
Binary file not shown.
Binary file added resources/btn_delete.bmp
Binary file not shown.
Binary file added resources/btn_refresh.bmp
Binary file not shown.
Binary file modified resources/image.webp
Binary file not shown.
12 changes: 6 additions & 6 deletions sqlite-gui.depend
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
1562796420 d:\codes\sqlite-gui\sqlite3.h
<stdarg.h>

1600800646 source:d:\codes\sqlite-gui\src\resource.rc
1601110984 source:d:\codes\sqlite-gui\src\resource.rc
<windows.h>
<commctrl.h>
<richedit.h>
"resource.h"

1600700271 d:\codes\sqlite-gui\src\resource.h
1601071437 d:\codes\sqlite-gui\src\resource.h

1600772996 source:d:\codes\sqlite-gui\src\prefs.cpp
1601033071 source:d:\codes\sqlite-gui\src\prefs.cpp
<ctime>
"prefs.h"
"sqlite3.h"
Expand All @@ -43,7 +43,7 @@
1583506689 d:\codes\sqlite-gui\src\sqlite3.h
<stdarg.h>

1600861673 source:d:\codes\sqlite-gui\src\main.cpp
1601125843 source:d:\codes\sqlite-gui\src\main.cpp
"global.h"
"missing.h"
"resource.h"
Expand All @@ -69,7 +69,7 @@
<ctype.h>
"utils.h"

1600805763 source:d:\codes\sqlite-gui\src\tools.cpp
1601125122 source:d:\codes\sqlite-gui\src\tools.cpp
"global.h"
"missing.h"
"resource.h"
Expand Down Expand Up @@ -97,7 +97,7 @@
1599763781 d:\codes\sqlite-gui\src\dialogs.h
<windows.h>

1600817373 source:d:\codes\sqlite-gui\src\dialogs.cpp
1601110005 source:d:\codes\sqlite-gui\src\dialogs.cpp
"resource.h"
"global.h"
"prefs.h"
Expand Down
54 changes: 27 additions & 27 deletions sqlite-gui.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,74 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="ToDo.txt" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="463" topLine="0" />
</Cursor>
</File>
<File name="src\dialogs.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\tools.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="24217" topLine="692" />
<Cursor1 position="556" topLine="0" />
</Cursor>
</File>
<File name="src\dialogs.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\tools.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="263" topLine="0" />
<Cursor1 position="3235" topLine="54" />
</Cursor>
</File>
<File name="src\global.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\resource.rc" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2201" topLine="45" />
<Cursor1 position="4493" topLine="86" />
</Cursor>
</File>
<File name="src\main.cpp" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="src\resource.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="55264" topLine="1437" />
<Cursor1 position="6964" topLine="175" />
</Cursor>
</File>
<File name="src\missing.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\prefs.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="261" topLine="0" />
<Cursor1 position="250" topLine="0" />
</Cursor>
</File>
<File name="src\prefs.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2854" topLine="57" />
</Cursor>
</File>
<File name="src\prefs.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\missing.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="250" topLine="0" />
<Cursor1 position="261" topLine="0" />
</Cursor>
</File>
<File name="src\resource.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\main.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="6147" topLine="155" />
<Cursor1 position="6032" topLine="72" />
</Cursor>
</File>
<File name="src\resource.rc" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="11544" topLine="217" />
<Cursor1 position="263" topLine="0" />
</Cursor>
</File>
<File name="src\tools.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\dialogs.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3235" topLine="54" />
<Cursor1 position="27908" topLine="761" />
</Cursor>
</File>
<File name="src\tools.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="ToDo.txt" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="556" topLine="0" />
<Cursor1 position="588" topLine="0" />
</Cursor>
</File>
<File name="src\utils.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\global.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1901" topLine="49" />
<Cursor1 position="2201" topLine="45" />
</Cursor>
</File>
<File name="src\utils.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="287" topLine="0" />
</Cursor>
</File>
<File name="src\utils.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1901" topLine="49" />
</Cursor>
</File>
</CodeBlocks_layout_file>
113 changes: 70 additions & 43 deletions src/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace dialogs {
bool isRequireHighligth = false;
bool isRequireParenthesisHighligth = false;

HBITMAP hButtonIcons [] = {
(HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BTN_ADD), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS),
(HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BTN_DELETE), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS),
(HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDB_BTN_REFRESH), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS)
};

BOOL CALLBACK cbDlgAddEdit (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_INITDIALOG: {
Expand Down Expand Up @@ -592,6 +598,13 @@ namespace dialogs {

SetWindowPos(hWnd, 0, prefs::get("x") + 40, prefs::get("y") + 80, prefs::get("width") - 80, prefs::get("height") - 120, SWP_NOZORDER);
ShowWindow (hWnd, prefs::get("maximized") == 1 ? SW_MAXIMIZE : SW_SHOW);

HWND hBtnWnd = GetDlgItem(hWnd, IDC_DLG_ROW_ADD);
SendMessage(hBtnWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonIcons[0]);
hBtnWnd = GetDlgItem(hWnd, IDC_DLG_ROW_DEL);
SendMessage(hBtnWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonIcons[1]);
hBtnWnd = GetDlgItem(hWnd, IDC_DLG_REFRESH);
SendMessage(hBtnWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hButtonIcons[2]);
}
break;

Expand All @@ -603,13 +616,15 @@ namespace dialogs {

case WM_SIZE: {
bool isTable = GetWindowLong(hWnd, GWL_USERDATA) == 1;
HWND hRefreshBtn = GetDlgItem(hWnd, IDC_DLG_REFRESH);
HWND hListWnd = GetDlgItem(hWnd, IDC_DLG_QUERYLIST);
HWND hFilterWnd = GetDlgItem(hWnd, IDC_DLG_QUERYFILTER);

RECT rc;
GetClientRect(hWnd, &rc);
int w = isTable ? 40 : 0;
SetWindowPos(hFilterWnd, 0, w, 0, rc.right - rc.left - 0 - w, 20, SWP_NOZORDER );
int w = isTable ? 44 : 0;
SetWindowPos(hRefreshBtn, 0, rc.right - rc.left - 21, 0, 20, 20, SWP_NOZORDER);
SetWindowPos(hFilterWnd, 0, w, 0, rc.right - rc.left - 0 - w - 22, 20, SWP_NOZORDER);
SetWindowPos(hListWnd, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top - 21, SWP_NOZORDER | SWP_NOMOVE);
}
break;
Expand Down Expand Up @@ -755,22 +770,31 @@ namespace dialogs {
case WM_COMMAND: {
WORD cmd = LOWORD(wParam);
bool isTable = GetWindowLong(hWnd, GWL_USERDATA) == 1;
HWND hListWnd = GetDlgItem(hWnd, IDC_DLG_QUERYLIST);

if (wParam == IDOK) { // User push Enter
HWND hListWnd = GetDlgItem(hWnd, IDC_DLG_QUERYLIST);
int pos = ListView_GetNextItem(hListWnd, -1, LVNI_SELECTED);
if (hListWnd == GetFocus() && pos != -1) {
currCell = {hListWnd, pos, 0};
PostMessage(hWnd, WM_COMMAND, IDM_ROW_EDIT, 0);
}
}

if (cmd == IDC_DLG_CANCEL || cmd == IDCANCEL)
SendMessage(hWnd, WM_CLOSE, 0, 0);

if (cmd == IDM_RESULT_COPY_CELL || cmd == IDM_RESULT_COPY_ROW || cmd == IDM_RESULT_EXPORT)
onListViewMenu(cmd, true);

if (cmd == IDC_DLG_ROW_ADD)
DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_ROW), hWnd, (DLGPROC)&cbDlgRow, MAKELPARAM(ROW_ADD, 0));

if (cmd == IDC_DLG_ROW_DEL)
SendMessage(hWnd, WM_COMMAND, MAKELPARAM(IDM_ROW_DELETE, 0), 0);

if (cmd == IDC_DLG_REFRESH)
SendMessage(hWnd, WMU_UPDATE_DATA, 0, 0);

if (cmd == IDM_ROW_EDIT)
DialogBoxParam(GetModuleHandle(0), MAKEINTRESOURCE(IDD_ROW), hWnd, (DLGPROC)&cbDlgRow, MAKELPARAM(isTable ? ROW_EDIT: ROW_VIEW, 0));

Expand All @@ -794,11 +818,12 @@ namespace dialogs {

sqlite3_stmt *stmt;
if (SQLITE_OK == sqlite3_prepare_v2(db, sql8, -1, &stmt, 0)) {
int colCount = Header_GetItemCount(ListView_GetHeader(hListWnd));
int pos = -1;
TCHAR buf16[64];
for (int i = 0; i < count; i++) {
pos = ListView_GetNextItem(hListWnd, pos, LVNI_SELECTED);
ListView_GetItemText(hListWnd, pos, 0, buf16, 128);
ListView_GetItemText(hListWnd, pos, colCount - 1, buf16, 128);
sqlite3_bind_int64(stmt, i + 1, _tcstol(buf16, NULL, 10));
}

Expand Down Expand Up @@ -914,9 +939,6 @@ namespace dialogs {
KillTimer(hWnd, IDT_EDIT_DATA);
SetTimer(hWnd, IDT_EDIT_DATA, 300, NULL);
}

if (cmd == IDC_DLG_CANCEL || cmd == IDCANCEL)
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
break;

Expand Down Expand Up @@ -1484,6 +1506,7 @@ namespace dialogs {

switch(msg){
case WM_KILLFOCUS: {
SendMessage(hWnd, WMU_SAVE_DATA, 0, 0);
DestroyWindow(hWnd);
}
break;
Expand All @@ -1494,54 +1517,58 @@ namespace dialogs {
if((style & ES_MULTILINE) == ES_MULTILINE && GetAsyncKeyState(VK_CONTROL))
break;

HWND hListWnd = GetParent(hWnd);
int size = GetWindowTextLength(hWnd);
TCHAR* value16 = new TCHAR[size + 1]{0};
GetWindowText(hWnd, value16, size + 1);
SendMessage(hWnd, WMU_SAVE_DATA, 0, 0);
SendMessage(hWnd, WM_CLOSE, 0, 0);
}

TCHAR column16[64];
HDITEM hdi = {0};
hdi.mask = HDI_TEXT;
hdi.pszText = column16;
hdi.cchTextMax = 64;
if (wParam == VK_ESCAPE)
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
break;

HWND hHeader = (HWND)ListView_GetHeader(hListWnd);
int data = GetWindowLong(hWnd, GWL_USERDATA);
int rowNo = LOWORD(data);
int colNo = HIWORD(data);
case WMU_SAVE_DATA: {
HWND hListWnd = GetParent(hWnd);
int size = GetWindowTextLength(hWnd);
TCHAR* value16 = new TCHAR[size + 1]{0};
GetWindowText(hWnd, value16, size + 1);

if (hHeader != NULL && Header_GetItem(hHeader, colNo, &hdi)) {
TCHAR query16[256];
_stprintf(query16, TEXT("update \"%s\" set %s = ?1 where rowid = ?2"), editTableData16, column16);
TCHAR column16[64];
HDITEM hdi = {0};
hdi.mask = HDI_TEXT;
hdi.pszText = column16;
hdi.cchTextMax = 64;

int colCount = Header_GetItemCount(hHeader);
ListView_GetItemText(hListWnd, rowNo, colCount - 1, column16, 64);
long rowid = _tcstol(column16, NULL, 10);
HWND hHeader = (HWND)ListView_GetHeader(hListWnd);
int data = GetWindowLong(hWnd, GWL_USERDATA);
int rowNo = LOWORD(data);
int colNo = HIWORD(data);

char* query8 = utils::utf16to8(query16);
char* value8 = utils::utf16to8(value16);
if (hHeader != NULL && Header_GetItem(hHeader, colNo, &hdi)) {
TCHAR query16[256];
_stprintf(query16, TEXT("update \"%s\" set %s = ?1 where rowid = ?2"), editTableData16, column16);

sqlite3_stmt *stmt;
if (SQLITE_OK == sqlite3_prepare_v2(db, query8, -1, &stmt, 0)) {
utils::sqlite3_bind_variant(stmt, 1, value8);
sqlite3_bind_int64(stmt, 2, rowid);
if (SQLITE_DONE == sqlite3_step(stmt))
ListView_SetItemText(hListWnd, rowNo, colNo, value16);
int colCount = Header_GetItemCount(hHeader);
ListView_GetItemText(hListWnd, rowNo, colCount - 1, column16, 64);
long rowid = _tcstol(column16, NULL, 10);

}
sqlite3_finalize(stmt);
char* query8 = utils::utf16to8(query16);
char* value8 = utils::utf16to8(value16);

delete [] query8;
delete [] value8;
}
sqlite3_stmt *stmt;
if (SQLITE_OK == sqlite3_prepare_v2(db, query8, -1, &stmt, 0)) {
utils::sqlite3_bind_variant(stmt, 1, value8);
sqlite3_bind_int64(stmt, 2, rowid);
if (SQLITE_DONE == sqlite3_step(stmt))
ListView_SetItemText(hListWnd, rowNo, colNo, value16);

delete [] value16;
}
sqlite3_finalize(stmt);

SendMessage(hWnd, WM_CLOSE, 0, 0);
delete [] query8;
delete [] value8;
}

if (wParam == VK_ESCAPE)
SendMessage(hWnd, WM_CLOSE, 0, 0);
delete [] value16;
}
break;
}
Expand Down
Loading

0 comments on commit 3388c10

Please sign in to comment.