Skip to content

Commit

Permalink
Up to 1.0.5
Browse files Browse the repository at this point in the history
* Column reordering
* Bug fixes
  • Loading branch information
little-brother committed Mar 22, 2023
1 parent f177eff commit 0d7db4f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
42 changes: 34 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#define MAX_COLUMN_COUNT 128
#define MAX_COLUMN_LENGTH 2000
#define APP_NAME TEXT("jsontab")
#define APP_VERSION TEXT("1.0.4")
#define APP_VERSION TEXT("1.0.5")

#define CP_UTF16LE 1200
#define CP_UTF16BE 1201
Expand Down Expand Up @@ -378,7 +378,7 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) {
205, 0, 100, 100, hTabWnd, (HMENU)IDC_GRID, GetModuleHandle(0), NULL);

int noLines = getStoredValue(TEXT("disable-grid-lines"), 0);
ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP);
ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP | LVS_EX_HEADERDRAGDROP);
SetProp(hGridWnd, TEXT("WNDPROC"), (HANDLE)SetWindowLongPtr(hGridWnd, GWLP_WNDPROC, (LONG_PTR)cbHotKey));

HWND hHeader = ListView_GetHeader(hGridWnd);
Expand Down Expand Up @@ -728,8 +728,13 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (cmd == IDM_COPY_ROWS) {
int pos = 0;
int rowNo = ListView_GetNextItem(hGridWnd, -1, LVNI_SELECTED);

int* colOrder = calloc(colCount, sizeof(int));
Header_GetOrderArray(hHeader, colCount, colOrder);

while (rowNo != -1) {
for (int colNo = 0; colNo < colCount; colNo++) {
for (int idx = 0; idx < colCount; idx++) {
int colNo = colOrder[idx];
if (ListView_GetColumnWidth(hGridWnd, colNo)) {
int len = _tcslen(cache[resultset[rowNo]][colNo]);
_tcsncpy(buf + pos, cache[resultset[rowNo]][colNo], len);
Expand All @@ -742,6 +747,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
rowNo = ListView_GetNextItem(hGridWnd, rowNo, LVNI_SELECTED);
}
buf[pos - 1] = 0; // remove last \n

free(colOrder);
}

if (cmd == IDM_COPY_COLUMN) {
Expand Down Expand Up @@ -784,7 +791,13 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
while (rowNo != -1) {
if (gridType == 0) {
JSON_Value* json2 = json_value_init_object();
for (int colNo = 0; colNo < colCount; colNo++) {

int* colOrder = calloc(colCount, sizeof(int));
Header_GetOrderArray(hHeader, colCount, colOrder);

for (int idx = 0; idx < colCount; idx++) {
int colNo = colOrder[idx];

if (ListView_GetColumnWidth(hGridWnd, colNo)) {
TCHAR* value16 = cache[resultset[rowNo]][colNo];
char* value8 = utf16to8(value16);
Expand All @@ -802,6 +815,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
}
json_array_append_value(json_value_get_array(json), json2);

free(colOrder);
}

if (gridType == 1) {
Expand Down Expand Up @@ -1007,8 +1022,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
}

if (pHdr->code == HDN_ITEMCHANGED && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(GetDlgItem(hWnd, IDC_TAB), IDC_GRID)))
SendMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0);
if ((pHdr->code == HDN_ITEMCHANGED || pHdr->code == HDN_ENDDRAG) && pHdr->hwndFrom == ListView_GetHeader(GetDlgItem(GetDlgItem(hWnd, IDC_TAB), IDC_GRID)))
PostMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0);

if (pHdr->code == (UINT)NM_SETFOCUS)
SetProp(hWnd, TEXT("LASTFOCUS"), pHdr->hwndFrom);
Expand Down Expand Up @@ -1430,12 +1445,18 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
HWND hHeader = ListView_GetHeader(hGridWnd);
int colCount = Header_GetItemCount(hHeader);
SendMessage(hHeader, WM_SIZE, 0, 0);
for (int colNo = 0; colNo < colCount; colNo++) {
int* colOrder = calloc(colCount, sizeof(int));
Header_GetOrderArray(hHeader, colCount, colOrder);

for (int idx = 0; idx < colCount; idx++) {
int colNo = colOrder[idx];
RECT rc;
Header_GetItemRect(hHeader, colNo, &rc);
int h2 = round((rc.bottom - rc.top) / 2);
SetWindowPos(GetDlgItem(hHeader, IDC_HEADER_EDIT + colNo), 0, rc.left, h2, rc.right - rc.left, h2 + 1, SWP_NOZORDER);
}

free(colOrder);
}
break;

Expand Down Expand Up @@ -1718,11 +1739,16 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

case WMU_HOT_CHARS: {
BOOL isCtrl = HIWORD(GetKeyState(VK_CONTROL));

unsigned char scancode = ((unsigned char*)&lParam)[2];
UINT key = MapVirtualKey(scancode,MAPVK_VSC_TO_VK);

return !_istprint(wParam) && (
wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F1 ||
wParam == VK_F3 || wParam == VK_F5 || wParam == VK_F7) ||
wParam == VK_TAB || wParam == VK_RETURN ||
isCtrl && (wParam == 0x46 || wParam == 0x20);
isCtrl && key == 0x46 || // Ctrl + F
getStoredValue(TEXT("exit-by-q"), 0) && key == 0x51 && GetDlgCtrlID(GetFocus()) / 100 * 100 != IDC_HEADER_EDIT; // Q
}
break;
}
Expand Down
9 changes: 2 additions & 7 deletions parson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,13 +1468,8 @@ JSON_Value * parse_value_v2(const char **string, int mode, int* isMalformed) {
json_value_free(roots);
res = NULL;
} else if (cnt == 1) {
res = json_array_get_value(array, 0);

// Replace by null and erase array
JSON_Value* value = json_value_init_null();
value->parent = json_array_get_wrapping_value(array);
array->items[0] = value;
json_value_free(roots);
res = json_value_deep_copy(json_array_get_value(array, 0));
json_value_free(roots);
} else {
if (isMalformed)
*isMalformed = 1;
Expand Down

0 comments on commit 0d7db4f

Please sign in to comment.