diff --git a/src/DockingFeature/NavigateTo.rc b/src/DockingFeature/NavigateTo.rc index 3e76d66..82bd08e 100644 --- a/src/DockingFeature/NavigateTo.rc +++ b/src/DockingFeature/NavigateTo.rc @@ -29,11 +29,11 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM CAPTION "About NavigateTo" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - LTEXT "Navigate To v.1.12.2",IDC_STATIC_TEXT,7,7,124,8 - LTEXT "Author: Oleksii Maryshchenko",IDC_STATIC_TEXT,7,29,137,8 - LTEXT "young_developer@mail.ru",IDC_STATIC_TEXT,8,39,89,8 - LTEXT "2018",IDC_STATIC_TEXT,182,51,19,8 - LTEXT "omaryshchenko.info",IDC_STATIC_TEXT2,8,49,89,8 + LTEXT "Navigate To v.1.12.3",IDC_STATIC_TEXT,7,7,124,8 + LTEXT "Author: Oleksii Maryshchenko",IDC_STATIC_TEXT+1,7,29,137,8 + LTEXT "young_developer@mail.ru",IDC_STATIC_TEXT+2B,8,39,89,8 + LTEXT "2018",IDC_STATIC_TEXT+3,182,51,19,8 + LTEXT "omaryshchenko.info",IDC_STATIC_TEXT2+4,8,49,89,8 END @@ -43,8 +43,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,12,2,0 - PRODUCTVERSION 1,12,2,0 + FILEVERSION 1,12,3,0 + PRODUCTVERSION 1,12,3,0 FILEFLAGSMASK 0x37L #ifdef _DEBUG FILEFLAGS 0x21L @@ -59,15 +59,15 @@ BEGIN BEGIN BLOCK "080904b0" BEGIN - VALUE "Comments", "Latest Source available from https://github.com/young-developer/nppNavigateTo" + VALUE "Comments", "Latest Sources available - https://github.com/young-developer/nppNavigateTo" VALUE "CompanyName", "Oleksii Maryshchenko" VALUE "FileDescription", "Notepad++ File NavigateTO : a free (GPL) source code file NavigateTo" - VALUE "FileVersion", "1, 12, 2, 0" + VALUE "FileVersion", "1, 12, 3, 0" VALUE "InternalName", "NavigateTo" - VALUE "LegalCopyright", "Copyright (C) 2017 Oleksii Maryshchenko" + VALUE "LegalCopyright", "Copyright (C) 2018 Oleksii Maryshchenko" VALUE "OriginalFilename", "NavigateTo.dll" VALUE "ProductName", "NavigateTo plugin" - VALUE "ProductVersion", "1, 12, 2, 0" + VALUE "ProductVersion", "1, 12, 3, 0" VALUE "SpecialBuild", "UNICODE" END END diff --git a/src/DockingFeature/NavigateToDlg.cpp b/src/DockingFeature/NavigateToDlg.cpp index 95a45c2..ea400a9 100644 --- a/src/DockingFeature/NavigateToDlg.cpp +++ b/src/DockingFeature/NavigateToDlg.cpp @@ -65,6 +65,24 @@ LRESULT CALLBACK ComboProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); bool isDropDownOpened = false; +std::string GetErrorAsString(DWORD errorMessageID) +{ + //Get the error message, if any. + if (errorMessageID == 0) + return std::string(); //No error message has been recorded + + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); + + std::string message(messageBuffer, size); + + //Free the buffer. + LocalFree(messageBuffer); + + return message; +} + void moveSelectionUp(BOOL wrap) { @@ -428,28 +446,34 @@ INT_PTR CALLBACK NavigateToDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _winMgr.CalcLayout(_hSelf); _winMgr.SetWindowPositions(_hSelf); + if (NULL != hwndListView) + { + RECT rc; + GetClientRect(hwndListView, &rc); + LONG width = rc.right - rc.left; + LVCOLUMN LvCol; + memset(&LvCol, 0, sizeof(LvCol)); // Zero Members + LvCol.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Type of mask + LvCol.cx = static_cast(width*0.4); // width between each coloum + LvCol.pszText = TEXT("Name"); // First Header Text + ::SendMessage(hwndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, WPARAM(0), LVS_EX_FULLROWSELECT); // Set style + ::SendMessage(hwndListView, LVM_INSERTCOLUMN, NAME_COLUMN, (LPARAM)&LvCol); // Insert/Show the coloum + LvCol.pszText = TEXT("Path"); + LvCol.cx = static_cast(width*0.6); // width of column + SendMessage(hwndListView, LVM_INSERTCOLUMN, PATH_COLUMN, (LPARAM)&LvCol); // ... + + SendMessage(hwndGoLineEdit, CB_SETMINVISIBLE, 8, 0); // Visible items = 8 + //ListView_SetExtendedListViewStyle(hwndListView,LVS_EX_HEADERDRAGDROP); //now we can drag&drop headers :) + refreshResultsList(); + goToCenter(); + fitColumnsToSize(); + SetFocus(hwndListView); + } + else + { + nppManager->showMessageBox(TEXT("init dialog list is nullpointer")); + } - RECT rc; - GetClientRect(hwndListView, &rc); - LONG width = rc.right - rc.left; - - LVCOLUMN LvCol; - memset(&LvCol,0,sizeof(LvCol)); // Zero Members - LvCol.mask=LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Type of mask - LvCol.cx=static_cast(width*0.4); // width between each coloum - LvCol.pszText=TEXT("Name"); // First Header Text - ::SendMessage(hwndListView,LVM_SETEXTENDEDLISTVIEWSTYLE, WPARAM(0),LVS_EX_FULLROWSELECT); // Set style - ::SendMessage(hwndListView,LVM_INSERTCOLUMN,NAME_COLUMN,(LPARAM)&LvCol); // Insert/Show the coloum - LvCol.pszText=TEXT("Path"); - LvCol.cx=static_cast(width*0.6); // width of column - SendMessage(hwndListView,LVM_INSERTCOLUMN,PATH_COLUMN,(LPARAM)&LvCol); // ... - - SendMessage(hwndGoLineEdit,CB_SETMINVISIBLE,8,0); // Visible items = 8 - //ListView_SetExtendedListViewStyle(hwndListView,LVS_EX_HEADERDRAGDROP); //now we can drag&drop headers :) - refreshResultsList(); - goToCenter(); - fitColumnsToSize(); - SetFocus(hwndListView); return SizeableDlg::run_dlgProc(message, wParam, lParam); } break; @@ -986,9 +1010,31 @@ void NavigateToDlg::addFileToListView(const File& file) lis.iItem = 0; lis.cchTextMax = MAX_PATH; lis.iSubItem = 0; - lis.mask = LVIF_TEXT | LVIF_PARAM; + lis.mask = LVIF_PARAM; lis.lParam = (LPARAM)&fileList[file.getBufferId()]; - SendMessage(hwndListView,LVM_INSERTITEM,0,(LPARAM)&lis);// Send info to the Listview + lis.pszText = TEXT("empty"); + try + { + if (_hSelf != NULL) + { + ghwndListView = ::GetDlgItem(_hSelf, IDC_RESULTS_LIST); + if (ghwndListView == NULL) + throw GetLastError(); + int indexOfNewItem = SendMessage(ghwndListView, LVM_INSERTITEM, 0, (LPARAM)&lis);// Send info to the Listview + if (indexOfNewItem == -1) + throw GetLastError(); + } + else + throw GetLastError(); + } + catch (DWORD aCause) + { + if (!GetErrorAsString(aCause).empty()) + { + std::string error = GetErrorAsString(aCause).append(" Could not add file "); + nppManager->showMessageBox(NppManager::strToWStr(error).append(fileList[file.getBufferId()].getFileName()), TEXT("Exception")); + } + } } } @@ -1124,11 +1170,14 @@ void NavigateToDlg::updateCurrentFileStatus(FileStatus status) void NavigateToDlg::beNotified(SCNotification *notifyCode) { + if (_hSelf == NULL) + return; + switch (notifyCode->nmhdr.code) { case NPPN_FILEOPENED: case NPPN_FILERENAMED: - addFileToListView(notifyCode->nmhdr.idFrom); + addFileToListView(notifyCode->nmhdr.idFrom); if(isVisible()) refreshResultsList(false); break; diff --git a/src/NppManager.cpp b/src/NppManager.cpp index 43ead53..8b4172a 100644 --- a/src/NppManager.cpp +++ b/src/NppManager.cpp @@ -12,9 +12,9 @@ NppManager::~NppManager(void) { } -void NppManager::showMessageBox(const std::wstring& text) +void NppManager::showMessageBox(const std::wstring& text, const std::wstring &msgTitle) { - ::MessageBox(nppData._nppHandle, text.c_str() , TEXT("Info"), MB_OK); + ::MessageBox(nppData._nppHandle, text.c_str(), msgTitle.c_str(), MB_OK); } bool NppManager::switchToFile(const File* file) diff --git a/src/NppManager.h b/src/NppManager.h index 7e62a5d..39793a7 100644 --- a/src/NppManager.h +++ b/src/NppManager.h @@ -30,7 +30,7 @@ class NppManager bool switchToFile(const File* file); bool switchToFile(const int index, const int view); bool openContextMenu(const int index, const int view); - void showMessageBox(const std::wstring& text); + void showMessageBox(const std::wstring& text, const std::wstring &msgTitle = TEXT("Info")); int getBufferIdByFilePath(const std::wstring& filePath); int getIndexByFilePath(const std::wstring& filePath); HWND getCurrentHScintilla(int which);