From 773397d6eab4bd59ea7104796936d9d52456c228 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 6 Dec 2015 23:20:14 +0100 Subject: [PATCH] Add Debug Info feature --- .../MISC/PluginsManager/PluginsManager.cpp | 11 ++ .../src/MISC/PluginsManager/PluginsManager.h | 31 +++--- PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/Notepad_plus.h | 1 + PowerEditor/src/Notepad_plus.rc | 13 +++ PowerEditor/src/NppCommands.cpp | 6 + PowerEditor/src/Parameters.cpp | 22 ++++ PowerEditor/src/Parameters.h | 3 +- .../src/ScitillaComponent/FindReplaceDlg.cpp | 2 +- .../src/WinControls/AboutDlg/AboutDlg.cpp | 103 +++++++++++++++++- .../src/WinControls/AboutDlg/AboutDlg.h | 30 ++++- PowerEditor/src/menuCmdID.h | 1 + PowerEditor/src/resource.h | 5 + 13 files changed, 209 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index 2a5cd463a..679128e27 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -541,3 +541,14 @@ bool PluginsManager::allocateMarker(int numberRequired, int *start) return retVal; } +generic_string PluginsManager::getLoadedPluginNames() const +{ + generic_string pluginPaths; + for (size_t i = 0; i < _loadedDlls.size(); ++i) + { + pluginPaths += _loadedDlls[i]; + pluginPaths += TEXT(" "); + } + return pluginPaths; +} + diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index b8c456ee8..eaef46dcd 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -57,9 +57,7 @@ struct PluginCommand struct PluginInfo { - PluginInfo() :_hLib(NULL), _pluginMenu(NULL), _pFuncSetInfo(NULL),\ - _pFuncGetFuncsArray(NULL), _pFuncGetName(NULL), _funcItems(NULL),\ - _nbFuncItem(0){} + PluginInfo() {} ~PluginInfo() { if (_pluginMenu) @@ -69,25 +67,25 @@ struct PluginInfo ::FreeLibrary(_hLib); } - HINSTANCE _hLib; - HMENU _pluginMenu; + HINSTANCE _hLib = NULL; + HMENU _pluginMenu = NULL; - PFUNCSETINFO _pFuncSetInfo; - PFUNCGETNAME _pFuncGetName; - PBENOTIFIED _pBeNotified; - PFUNCGETFUNCSARRAY _pFuncGetFuncsArray; - PMESSAGEPROC _pMessageProc; - PFUNCISUNICODE _pFuncIsUnicode; + PFUNCSETINFO _pFuncSetInfo = NULL; + PFUNCGETNAME _pFuncGetName = NULL; + PBENOTIFIED _pBeNotified = NULL; + PFUNCGETFUNCSARRAY _pFuncGetFuncsArray = NULL; + PMESSAGEPROC _pMessageProc = NULL; + PFUNCISUNICODE _pFuncIsUnicode = NULL; - FuncItem *_funcItems; - int _nbFuncItem; + FuncItem *_funcItems = NULL; + int _nbFuncItem = 0; generic_string _moduleName; }; class PluginsManager { public: - PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false), _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT), + PluginsManager() : _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT), _markerAlloc(MARKER_PLUGINS, MARKER_PLUGINS_LIMIT) {} ~PluginsManager() { @@ -128,15 +126,16 @@ public: bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); } bool allocateMarker(int numberRequired, int *start); + generic_string getLoadedPluginNames() const; private: NppData _nppData; - HMENU _hPluginsMenu; + HMENU _hPluginsMenu = NULL; std::vector _pluginInfos; std::vector _pluginsCommands; std::vector _loadedDlls; - bool _isDisabled; + bool _isDisabled = false; IDAllocator _dynamicIDAlloc; IDAllocator _markerAlloc; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index dd5e5f479..05d73ef04 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -616,6 +616,7 @@ LRESULT Notepad_plus::init(HWND hwnd) _findCharsInRangeDlg.init(_pPublicInterface->getHinst(), hwnd, &_pEditView); _colEditorDlg.init(_pPublicInterface->getHinst(), hwnd, &_pEditView); _aboutDlg.init(_pPublicInterface->getHinst(), hwnd); + _debugInfoDlg.init(_pPublicInterface->getHinst(), hwnd, _isAdministrator, _pluginsManager.getLoadedPluginNames()); _runDlg.init(_pPublicInterface->getHinst(), hwnd); _runMacroDlg.init(_pPublicInterface->getHinst(), hwnd); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index ac26d9ddd..4626b757b 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -341,6 +341,7 @@ private: FindReplaceDlg _findReplaceDlg; FindIncrementDlg _incrementFindDlg; AboutDlg _aboutDlg; + DebugInfoDlg _debugInfoDlg; RunDlg _runDlg; GoToLineDlg _goToLineDlg; ColumnEditorDlg _colEditorDlg; diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 84a0265f9..de216873d 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -855,6 +855,7 @@ BEGIN MENUITEM "Update Notepad++", IDM_UPDATE_NPP MENUITEM "Set Updater Proxy...", IDM_CONFUPDATERPROXY MENUITEM SEPARATOR + MENUITEM "Debug Info", IDM_DEBUGINFO MENUITEM "About Notepad++", IDM_ABOUT END @@ -894,6 +895,18 @@ BEGIN EDITTEXT IDC_LICENCE_EDIT,31,99,209,96,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL END +IDD_DEBUGINFOBOX DIALOGEX 0, 0, 271, 200 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE +CAPTION "Debug Info" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + EDITTEXT IDC_DEBUGINFO_EDIT,31,20,220,96,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL + LTEXT "Copy debug info into clipboard",IDC_DEBUGINFO_COPYLINK,31,120,126,8 + DEFPUSHBUTTON "OK",IDOK,106,160,50,14,BS_FLAT,WS_EX_STATICEDGE +END + + IDD_GOLINE DIALOGEX 26, 41, 261, 88 STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 79e79e2d6..9c2ed9cd3 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -2196,6 +2196,12 @@ void Notepad_plus::command(int id) break; } + case IDM_DEBUGINFO: + { + _debugInfoDlg.doDialog(); + break; + } + case IDM_ABOUT: { bool doAboutDlg = false; diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index f03d8978a..126a38d19 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -6040,6 +6040,28 @@ int NppParameters::langTypeToCommandID(LangType lt) const return id; } +generic_string NppParameters:: getWinVersionStr() const +{ + switch (_winVersion) + { + case WV_WIN32S: return TEXT("Windows 3.1"); + case WV_95: return TEXT("Windows 95"); + case WV_98: return TEXT("Windows 98"); + case WV_ME: return TEXT("Windows Millennium Edition"); + case WV_NT: return TEXT("Windows NT"); + case WV_W2K: return TEXT("Windows 2000"); + case WV_XP: return TEXT("Windows XP"); + case WV_S2003: return TEXT("Windows Server 2003"); + case WV_XPX64: return TEXT("Windows XP 64 bits"); + case WV_VISTA: return TEXT("Windows Vista"); + case WV_WIN7: return TEXT("Windows 7"); + case WV_WIN8: return TEXT("Windows 8"); + case WV_WIN81: return TEXT("Windows 8.1"); + case WV_WIN10: return TEXT("Windows 10"); + default: /*case WV_UNKNOWN:*/ return TEXT("Windows unknown version"); + } +} + void NppParameters::writeStyles(LexerStylerArray & lexersStylers, StyleArray & globalStylers) { TiXmlNode *lexersRoot = (_pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("LexerStyles")); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index d992e4fe2..84bfd5717 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1495,7 +1495,8 @@ public: bool getContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU pluginsMenu); bool reloadContextMenuFromXmlTree(HMENU mainMenuHadle, HMENU pluginsMenu); - winVer getWinVersion() { return _winVersion;}; + winVer getWinVersion() const {return _winVersion;}; + generic_string getWinVersionStr() const; FindHistory & getFindHistory() {return _findHistory;}; bool _isFindReplacing; // an on the fly variable for find/replace functions void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index c47d46a69..a2198af9b 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -2566,7 +2566,7 @@ void Finder::copy() const generic_string toClipboard = stringJoin(lines, TEXT("\r\n")); if (!toClipboard.empty()) { - if (!str2Clipboard(toClipboard.c_str(), _hSelf)) + if (!str2Clipboard(toClipboard, _hSelf)) { assert(false); ::MessageBox(NULL, TEXT("Error placing text in clipboard."), TEXT("Notepad++"), MB_ICONINFORMATION); diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index c1a2472b2..5f52f2a95 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -111,5 +111,106 @@ void AboutDlg::doDialog() // Adjust the position of AboutBox goToCenter(); -}; +} + + +INT_PTR CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/) +{ + switch (message) + { + case WM_INITDIALOG: + { + // Notepad++ version + _debugInfoStr = NOTEPAD_PLUS_VERSION; + _debugInfoStr += TEXT("\r\n"); + + // Build time + _debugInfoStr += TEXT("Build time : "); + generic_string buildTime; + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + buildTime += wmc->char2wchar(__DATE__, CP_ACP); + buildTime += TEXT(" - "); + buildTime += wmc->char2wchar(__TIME__, CP_ACP); + _debugInfoStr += buildTime; + _debugInfoStr += TEXT("\r\n"); + + // Binary path + _debugInfoStr += TEXT("Path : "); + TCHAR nppFullPath[MAX_PATH]; + ::GetModuleFileName(NULL, nppFullPath, MAX_PATH); + _debugInfoStr += nppFullPath; + _debugInfoStr += TEXT("\r\n"); + + // Administrator mode + _debugInfoStr += TEXT("Admin mode : "); + _debugInfoStr += (_isAdmin ? TEXT("ON") : TEXT("OFF")); + _debugInfoStr += TEXT("\r\n"); + + // local conf + _debugInfoStr += TEXT("Local Conf mode : "); + bool doLocalConf = (NppParameters::getInstance())->isLocal(); + _debugInfoStr += (doLocalConf ? TEXT("ON") : TEXT("OFF")); + _debugInfoStr += TEXT("\r\n"); + + // OS version + _debugInfoStr += TEXT("OS : "); + _debugInfoStr += (NppParameters::getInstance())->getWinVersionStr(); + _debugInfoStr += TEXT("\r\n"); + + // Plugins + _debugInfoStr += TEXT("Plugins : "); + _debugInfoStr += _loadedPlugins; + _debugInfoStr += TEXT("\r\n"); + + ::SetDlgItemText(_hSelf, IDC_DEBUGINFO_EDIT, _debugInfoStr.c_str()); + + _copyToClipboardLink.init(_hInst, _hSelf); + _copyToClipboardLink.create(::GetDlgItem(_hSelf, IDC_DEBUGINFO_COPYLINK), IDC_DEBUGINFO_COPYLINK); + + getClientRect(_rc); + return TRUE; + } + + case WM_COMMAND: + { + switch (wParam) + { + case IDCANCEL: + case IDOK: + display(false); + return TRUE; + + case IDC_DEBUGINFO_COPYLINK: + { + if ((GetKeyState(VK_LBUTTON) & 0x100) != 0) + { + // Visual effect + ::SendDlgItemMessage(_hSelf, IDC_DEBUGINFO_EDIT, EM_SETSEL, 0, _debugInfoStr.length() - 1); + + // Copy to clipboard + str2Clipboard(_debugInfoStr, _hSelf); + } + return TRUE; + } + default: + break; + } + } + + case WM_DESTROY: + { + return TRUE; + } + } + return FALSE; +} + +void DebugInfoDlg::doDialog() +{ + if (!isCreated()) + create(IDD_DEBUGINFOBOX); + + // Adjust the position of AboutBox + goToCenter(); +} diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h index 44aff6fb1..55b59148c 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h @@ -55,7 +55,6 @@ along with this program; if not, write to the Free Software \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.") - class AboutDlg : public StaticDialog { public : @@ -76,4 +75,33 @@ private : URLCtrl _pageLink; }; + +class DebugInfoDlg : public StaticDialog +{ +public: + DebugInfoDlg() : StaticDialog() {}; + + void init(HINSTANCE hInst, HWND parent, bool isAdmin, generic_string loadedPlugins) { + _isAdmin = isAdmin; + _loadedPlugins = loadedPlugins; + Window::init(hInst, parent); + }; + + void doDialog(); + + virtual void destroy() { + _copyToClipboardLink.destroy(); + }; + +protected: + virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private: + generic_string _debugInfoStr; + bool _isAdmin = false; + generic_string _loadedPlugins; + URLCtrl _copyToClipboardLink; +}; + + #endif //ABOUT_DLG_H diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index f4bd257f3..61e240655 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -487,6 +487,7 @@ #define IDM_CONFUPDATERPROXY (IDM_ABOUT + 9) #define IDM_CMDLINEARGUMENTS (IDM_ABOUT + 10) #define IDM_ONLINESUPPORT (IDM_ABOUT + 11) + #define IDM_DEBUGINFO (IDM_ABOUT + 12) #define IDM_SETTING (IDM + 8000) diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 4f3376c23..a0270e1a0 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -277,6 +277,11 @@ #define IDC_ONLINEHELP_ADDR 1704 #define IDC_AUTHOR_NAME 1705 #define IDC_BUILD_DATETIME 1706 //LS: CompileDateInAboutDialog: Automatically insert compile date as additional version info in About-dialog! + +#define IDD_DEBUGINFOBOX 1750 +#define IDC_DEBUGINFO_EDIT 1751 +#define IDC_DEBUGINFO_COPYLINK 1752 + //#define IDD_USER_DEFINE_BOX 1800 //#define IDD_RUN_DLG 1900