Skip to content

Commit 83d1888

Browse files
author
Oleksii Maryshchenko
authored
Merge pull request #6 from young-developer/develop
Fix loading crash. New version 1.12.3
2 parents 9354fee + f2f2040 commit 83d1888

File tree

4 files changed

+87
-38
lines changed

4 files changed

+87
-38
lines changed

src/DockingFeature/NavigateTo.rc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
2929
CAPTION "About NavigateTo"
3030
FONT 8, "MS Shell Dlg", 400, 0, 0x1
3131
BEGIN
32-
LTEXT "Navigate To v.1.12.2",IDC_STATIC_TEXT,7,7,124,8
33-
LTEXT "Author: Oleksii Maryshchenko",IDC_STATIC_TEXT,7,29,137,8
34-
LTEXT "[email protected]",IDC_STATIC_TEXT,8,39,89,8
35-
LTEXT "2018",IDC_STATIC_TEXT,182,51,19,8
36-
LTEXT "omaryshchenko.info",IDC_STATIC_TEXT2,8,49,89,8
32+
LTEXT "Navigate To v.1.12.3",IDC_STATIC_TEXT,7,7,124,8
33+
LTEXT "Author: Oleksii Maryshchenko",IDC_STATIC_TEXT+1,7,29,137,8
34+
LTEXT "[email protected]",IDC_STATIC_TEXT+2B,8,39,89,8
35+
LTEXT "2018",IDC_STATIC_TEXT+3,182,51,19,8
36+
LTEXT "omaryshchenko.info",IDC_STATIC_TEXT2+4,8,49,89,8
3737
END
3838

3939

@@ -43,8 +43,8 @@ END
4343
//
4444

4545
VS_VERSION_INFO VERSIONINFO
46-
FILEVERSION 1,12,2,0
47-
PRODUCTVERSION 1,12,2,0
46+
FILEVERSION 1,12,3,0
47+
PRODUCTVERSION 1,12,3,0
4848
FILEFLAGSMASK 0x37L
4949
#ifdef _DEBUG
5050
FILEFLAGS 0x21L
@@ -59,15 +59,15 @@ BEGIN
5959
BEGIN
6060
BLOCK "080904b0"
6161
BEGIN
62-
VALUE "Comments", "Latest Source available from https://github.com/young-developer/nppNavigateTo"
62+
VALUE "Comments", "Latest Sources available - https://github.com/young-developer/nppNavigateTo"
6363
VALUE "CompanyName", "Oleksii Maryshchenko"
6464
VALUE "FileDescription", "Notepad++ File NavigateTO : a free (GPL) source code file NavigateTo"
65-
VALUE "FileVersion", "1, 12, 2, 0"
65+
VALUE "FileVersion", "1, 12, 3, 0"
6666
VALUE "InternalName", "NavigateTo"
67-
VALUE "LegalCopyright", "Copyright (C) 2017 Oleksii Maryshchenko"
67+
VALUE "LegalCopyright", "Copyright (C) 2018 Oleksii Maryshchenko"
6868
VALUE "OriginalFilename", "NavigateTo.dll"
6969
VALUE "ProductName", "NavigateTo plugin"
70-
VALUE "ProductVersion", "1, 12, 2, 0"
70+
VALUE "ProductVersion", "1, 12, 3, 0"
7171
VALUE "SpecialBuild", "UNICODE"
7272
END
7373
END

src/DockingFeature/NavigateToDlg.cpp

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,24 @@ LRESULT CALLBACK ComboProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
6565

6666
bool 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+
6886
void 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

11251171
void 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;

src/NppManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ NppManager::~NppManager(void)
1212
{
1313
}
1414

15-
void NppManager::showMessageBox(const std::wstring& text)
15+
void NppManager::showMessageBox(const std::wstring& text, const std::wstring &msgTitle)
1616
{
17-
::MessageBox(nppData._nppHandle, text.c_str() , TEXT("Info"), MB_OK);
17+
::MessageBox(nppData._nppHandle, text.c_str(), msgTitle.c_str(), MB_OK);
1818
}
1919

2020
bool NppManager::switchToFile(const File* file)

src/NppManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class NppManager
3030
bool switchToFile(const File* file);
3131
bool switchToFile(const int index, const int view);
3232
bool openContextMenu(const int index, const int view);
33-
void showMessageBox(const std::wstring& text);
33+
void showMessageBox(const std::wstring& text, const std::wstring &msgTitle = TEXT("Info"));
3434
int getBufferIdByFilePath(const std::wstring& filePath);
3535
int getIndexByFilePath(const std::wstring& filePath);
3636
HWND getCurrentHScintilla(int which);

0 commit comments

Comments
 (0)