@@ -65,6 +65,24 @@ LRESULT CALLBACK ComboProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
6565
6666bool isDropDownOpened = false ;
6767
68+ std::string GetErrorAsString (DWORD errorMessageID)
69+ {
70+ // Get the error message, if any.
71+ if (errorMessageID == 0 )
72+ return std::string (); // No error message has been recorded
73+
74+ LPSTR messageBuffer = nullptr ;
75+ size_t size = FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
76+ NULL , errorMessageID, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0 , NULL );
77+
78+ std::string message (messageBuffer, size);
79+
80+ // Free the buffer.
81+ LocalFree (messageBuffer);
82+
83+ return message;
84+ }
85+
6886void moveSelectionUp (BOOL wrap)
6987{
7088
@@ -428,28 +446,34 @@ INT_PTR CALLBACK NavigateToDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
428446
429447 _winMgr.CalcLayout (_hSelf);
430448 _winMgr.SetWindowPositions (_hSelf);
449+ if (NULL != hwndListView)
450+ {
451+ RECT rc;
452+ GetClientRect (hwndListView, &rc);
453+ LONG width = rc.right - rc.left ;
454+ LVCOLUMN LvCol;
455+ memset (&LvCol, 0 , sizeof (LvCol)); // Zero Members
456+ LvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Type of mask
457+ LvCol.cx = static_cast <LONG>(width*0.4 ); // width between each coloum
458+ LvCol.pszText = TEXT (" Name" ); // First Header Text
459+ ::SendMessage (hwndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, WPARAM(0 ), LVS_EX_FULLROWSELECT); // Set style
460+ ::SendMessage (hwndListView, LVM_INSERTCOLUMN, NAME_COLUMN, (LPARAM)&LvCol); // Insert/Show the coloum
461+ LvCol.pszText = TEXT (" Path" );
462+ LvCol.cx = static_cast <LONG>(width*0.6 ); // width of column
463+ SendMessage (hwndListView, LVM_INSERTCOLUMN, PATH_COLUMN, (LPARAM)&LvCol); // ...
464+
465+ SendMessage (hwndGoLineEdit, CB_SETMINVISIBLE, 8 , 0 ); // Visible items = 8
466+ // ListView_SetExtendedListViewStyle(hwndListView,LVS_EX_HEADERDRAGDROP); //now we can drag&drop headers :)
467+ refreshResultsList ();
468+ goToCenter ();
469+ fitColumnsToSize ();
470+ SetFocus (hwndListView);
471+ }
472+ else
473+ {
474+ nppManager->showMessageBox (TEXT (" init dialog list is nullpointer" ));
475+ }
431476
432- RECT rc;
433- GetClientRect (hwndListView, &rc);
434- LONG width = rc.right - rc.left ;
435-
436- LVCOLUMN LvCol;
437- memset (&LvCol,0 ,sizeof (LvCol)); // Zero Members
438- LvCol.mask =LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Type of mask
439- LvCol.cx =static_cast <LONG>(width*0.4 ); // width between each coloum
440- LvCol.pszText =TEXT (" Name" ); // First Header Text
441- ::SendMessage (hwndListView,LVM_SETEXTENDEDLISTVIEWSTYLE, WPARAM(0 ),LVS_EX_FULLROWSELECT); // Set style
442- ::SendMessage (hwndListView,LVM_INSERTCOLUMN,NAME_COLUMN,(LPARAM)&LvCol); // Insert/Show the coloum
443- LvCol.pszText =TEXT (" Path" );
444- LvCol.cx =static_cast <LONG>(width*0.6 ); // width of column
445- SendMessage (hwndListView,LVM_INSERTCOLUMN,PATH_COLUMN,(LPARAM)&LvCol); // ...
446-
447- SendMessage (hwndGoLineEdit,CB_SETMINVISIBLE,8 ,0 ); // Visible items = 8
448- // ListView_SetExtendedListViewStyle(hwndListView,LVS_EX_HEADERDRAGDROP); //now we can drag&drop headers :)
449- refreshResultsList ();
450- goToCenter ();
451- fitColumnsToSize ();
452- SetFocus (hwndListView);
453477 return SizeableDlg::run_dlgProc (message, wParam, lParam);
454478 }
455479 break ;
@@ -986,9 +1010,31 @@ void NavigateToDlg::addFileToListView(const File& file)
9861010 lis.iItem = 0 ;
9871011 lis.cchTextMax = MAX_PATH;
9881012 lis.iSubItem = 0 ;
989- lis.mask = LVIF_TEXT | LVIF_PARAM;
1013+ lis.mask = LVIF_PARAM;
9901014 lis.lParam = (LPARAM)&fileList[file.getBufferId ()];
991- SendMessage (hwndListView,LVM_INSERTITEM,0 ,(LPARAM)&lis);// Send info to the Listview
1015+ lis.pszText = TEXT (" empty" );
1016+ try
1017+ {
1018+ if (_hSelf != NULL )
1019+ {
1020+ ghwndListView = ::GetDlgItem (_hSelf, IDC_RESULTS_LIST);
1021+ if (ghwndListView == NULL )
1022+ throw GetLastError ();
1023+ int indexOfNewItem = SendMessage (ghwndListView, LVM_INSERTITEM, 0 , (LPARAM)&lis);// Send info to the Listview
1024+ if (indexOfNewItem == -1 )
1025+ throw GetLastError ();
1026+ }
1027+ else
1028+ throw GetLastError ();
1029+ }
1030+ catch (DWORD aCause)
1031+ {
1032+ if (!GetErrorAsString (aCause).empty ())
1033+ {
1034+ std::string error = GetErrorAsString (aCause).append (" Could not add file " );
1035+ nppManager->showMessageBox (NppManager::strToWStr (error).append (fileList[file.getBufferId ()].getFileName ()), TEXT (" Exception" ));
1036+ }
1037+ }
9921038 }
9931039}
9941040
@@ -1124,11 +1170,14 @@ void NavigateToDlg::updateCurrentFileStatus(FileStatus status)
11241170
11251171void NavigateToDlg::beNotified (SCNotification *notifyCode)
11261172{
1173+ if (_hSelf == NULL )
1174+ return ;
1175+
11271176 switch (notifyCode->nmhdr .code )
11281177 {
11291178 case NPPN_FILEOPENED:
11301179 case NPPN_FILERENAMED:
1131- addFileToListView (notifyCode->nmhdr .idFrom );
1180+ addFileToListView (notifyCode->nmhdr .idFrom );
11321181 if (isVisible ())
11331182 refreshResultsList (false );
11341183 break ;
0 commit comments