@@ -221,6 +221,86 @@ void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode)
221
221
CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), nodePath);
222
222
}
223
223
224
+ void JsonViewDlg::SearchInTree ()
225
+ {
226
+ std::wstring itemToSearch = CUtility::GetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_SEARCH));
227
+ CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), STR_SRCH_SEARCHING + itemToSearch);
228
+ m_hTreeView->SetSelection (nullptr );
229
+
230
+ static int foundCount = 0 ;
231
+ static std::wstring previousSearch;
232
+ static HTREEITEM nextNode = m_hTreeView->NextItem (m_hTreeView->GetRoot ());
233
+
234
+ // New search, hence search from begining
235
+ if (previousSearch != itemToSearch)
236
+ {
237
+ previousSearch = itemToSearch;
238
+ nextNode = m_hTreeView->NextItem (m_hTreeView->GetRoot ());
239
+ foundCount = 0 ;
240
+ }
241
+ else
242
+ {
243
+ nextNode = m_hTreeView->NextItem (nextNode);
244
+ if (nextNode == m_hTreeView->GetRoot ())
245
+ {
246
+ nextNode = m_hTreeView->NextItem (nextNode);
247
+ foundCount = 0 ;
248
+ }
249
+ }
250
+
251
+ // Check if this is an empty json
252
+ std::wstring nodeText = m_hTreeView->GetNodeName (nextNode);
253
+ if (nodeText.empty () || wcscmp (nodeText.c_str (), JSON_ERR_PARSE) == 0 )
254
+ {
255
+ CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), STR_SRCH_NOTFOUND + itemToSearch);
256
+ }
257
+ else
258
+ {
259
+ bool bFound = false ;
260
+ while (!bFound && nextNode)
261
+ {
262
+ nodeText = m_hTreeView->GetNodeName (nextNode);
263
+ auto nodeKey = m_hTreeView->GetNodeKey (nextNode);
264
+ auto nodeVal = m_hTreeView->GetNodeValue (nextNode);
265
+
266
+ // Search in node value
267
+ if (nodeKey != nodeVal)
268
+ bFound = StringHelper::Contains (nodeVal, itemToSearch);
269
+
270
+ // If both are euaal, but not all three
271
+ // { "[i]": "[i]"} => Search for '[i]'
272
+ //
273
+ if (!bFound && nodeKey == nodeVal && nodeKey != nodeText)
274
+ bFound = StringHelper::Contains (nodeVal, itemToSearch);
275
+
276
+ // If all three are same, then key does not start with '[' and end with ']'
277
+ // "num": [12.148681171238422,42.835353759876654] => Search for 'num'
278
+ //
279
+ if (!bFound && nodeKey == nodeVal && nodeKey == nodeText && !nodeKey.starts_with (L" [" ) && !nodeKey.ends_with (L" ]" ))
280
+ bFound = StringHelper::Contains (nodeText, itemToSearch);
281
+
282
+ if (bFound)
283
+ break ;
284
+
285
+ nextNode = m_hTreeView->NextItem (nextNode);
286
+ }
287
+
288
+ if (bFound)
289
+ {
290
+ UpdateNodePath (nextNode);
291
+ m_hTreeView->SetSelection (nextNode);
292
+ ++foundCount;
293
+ }
294
+ else
295
+ {
296
+ if (foundCount)
297
+ CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), STR_SRCH_NOMOREFOUND + itemToSearch);
298
+ else
299
+ CUtility::SetEditCtrlText (::GetDlgItem (_hSelf, IDC_EDT_NODEPATH), STR_SRCH_NOTFOUND + itemToSearch);
300
+ }
301
+ }
302
+ }
303
+
224
304
void JsonViewDlg::PrepareButtons ()
225
305
{
226
306
// Refresh Button
@@ -651,7 +731,7 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
651
731
break ;
652
732
653
733
case IDC_BTN_SEARCH:
654
- ShowMessage ( L" OK " , L" IDC_BTN_SEARCH " , MB_OK );
734
+ SearchInTree ( );
655
735
break ;
656
736
657
737
// Handle context menu entries
@@ -702,9 +782,6 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
702
782
}
703
783
704
784
default :
705
- // TODO: Temporarily hide controls which are not implemented
706
- std::vector<DWORD> toHide = {IDC_BTN_SEARCH, IDC_EDT_SEARCH};
707
- ShowControls (toHide, false );
708
785
return DockingDlgInterface::run_dlgProc (message, wParam, lParam);
709
786
}
710
787
}
0 commit comments