From 863c4e90c1808b823ffcbadc32f067e69a6377cb Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 22 Aug 2016 00:52:26 +0200 Subject: [PATCH] Add open file on selection & open container on selection commands --- PowerEditor/installer/packageAll.bat | 2 +- .../MISC/PluginsManager/Notepad_plus_msgs.h | 3 + PowerEditor/src/Notepad_plus.rc | 8 +++ PowerEditor/src/NppBigSwitch.cpp | 56 +++++++++-------- PowerEditor/src/NppCommands.cpp | 63 ++++++++++++++++++- .../StaticDialog/RunDlg/RunDlg.cpp | 2 + .../WinControls/StaticDialog/RunDlg/RunDlg.h | 1 + PowerEditor/src/menuCmdID.h | 5 ++ PowerEditor/src/shortcuts.xml | 3 +- 9 files changed, 112 insertions(+), 31 deletions(-) diff --git a/PowerEditor/installer/packageAll.bat b/PowerEditor/installer/packageAll.bat index 22a8373c9..a7a7ccea1 100644 --- a/PowerEditor/installer/packageAll.bat +++ b/PowerEditor/installer/packageAll.bat @@ -29,7 +29,7 @@ If ErrorLevel 1 goto End signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\NppShell_06.dll If ErrorLevel 1 goto End signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin\NppShell64_06.dll -signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\NppShell64_06.dll +rem signtool.exe sign /f %NPP_CERT% /p %NPP_CERT_PWD% /d "Notepad++" /du https://notepad-plus-plus.org/ /t http://timestamp.digicert.com/ ..\bin64\NppShell64_06.dll If ErrorLevel 1 goto End sign them manuelly as they are updated diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 95269afd0..794323f18 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -440,6 +440,8 @@ enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, W // INT NPPM_GETCURRENTCOLUMN(0, 0) // return the caret current position column + #define NPPM_GETNPPFULLFILEPATH (RUNCOMMAND_USER + NPP_FULL_FILE_PATH) + #define VAR_NOT_RECOGNIZED 0 #define FULL_CURRENT_PATH 1 #define CURRENT_DIRECTORY 2 @@ -450,6 +452,7 @@ enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, W #define NPP_DIRECTORY 7 #define CURRENT_LINE 8 #define CURRENT_COLUMN 9 + #define NPP_FULL_FILE_PATH 10 // Notification code diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc index 831644e9e..350468b6b 100644 --- a/PowerEditor/src/Notepad_plus.rc +++ b/PowerEditor/src/Notepad_plus.rc @@ -347,6 +347,14 @@ BEGIN MENUITEM "Cut Binary Content", IDM_EDIT_CUT_BINARY MENUITEM "Paste Binary Content", IDM_EDIT_PASTE_BINARY END + POPUP "On Selection" + BEGIN + MENUITEM "Open as file", IDM_EDIT_OPENASFILE + MENUITEM "Open in folder", IDM_EDIT_OPENINFOLDER + //MENUITEM SEPARATOR + //MENUITEM "Search on Internet", IDM_EDIT_SEARCHONINTERNET + //MENUITEM "Change Search Engin...", IDM_EDIT_CHANGESEARCHENGIN + END MENUITEM SEPARATOR MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP MENUITEM "Column Editor...", IDM_EDIT_COLUMNMODE diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index c932436a9..04b769fb2 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -71,12 +71,12 @@ struct SortTaskListPred final }; -LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if (hwnd == NULL) return FALSE; - switch(Message) + switch(message) { case WM_NCCREATE: { @@ -90,15 +90,15 @@ LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message, default: { - return (reinterpret_cast(::GetWindowLongPtr(hwnd, GWLP_USERDATA))->runProc(hwnd, Message, wParam, lParam)); + return (reinterpret_cast(::GetWindowLongPtr(hwnd, GWLP_USERDATA))->runProc(hwnd, message, wParam, lParam)); } } } -LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (Message) + switch (message) { case WM_CREATE: { @@ -117,25 +117,25 @@ LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPA default: { if (this) - return _notepad_plus_plus_core.process(hwnd, Message, wParam, lParam); + return _notepad_plus_plus_core.process(hwnd, message, wParam, lParam); } } return FALSE; } -LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT result = FALSE; NppParameters *pNppParam = NppParameters::getInstance(); - switch (Message) + switch (message) { case WM_NCACTIVATE: { // Note: lParam is -1 to prevent endless loops of calls ::SendMessage(_dockingManager.getHSelf(), WM_NCACTIVATE, wParam, -1); - return ::DefWindowProc(hwnd, Message, wParam, lParam); + return ::DefWindowProc(hwnd, message, wParam, lParam); } case WM_DRAWITEM: @@ -646,16 +646,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa // par defaut : NPPM_GETCURRENTDIRECTORY TCHAR *fileStr = lstrcpy(str, _pEditView->getCurrentBuffer()->getFullPathName()); - if (Message == NPPM_GETCURRENTDIRECTORY) + if (message == NPPM_GETCURRENTDIRECTORY) PathRemoveFileSpec(str); - else if (Message == NPPM_GETFILENAME) + else if (message == NPPM_GETFILENAME) fileStr = PathFindFileName(str); - else if (Message == NPPM_GETNAMEPART) + else if (message == NPPM_GETNAMEPART) { fileStr = PathFindFileName(str); PathRemoveExtension(fileStr); } - else if (Message == NPPM_GETEXTPART) + else if (message == NPPM_GETEXTPART) fileStr = PathFindExtension(str); // For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough. @@ -699,13 +699,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_GETNPPFULLFILEPATH: case NPPM_GETNPPDIRECTORY: { const int strSize = MAX_PATH; TCHAR str[strSize]; ::GetModuleFileName(NULL, str, strSize); - PathRemoveFileSpec(str); + + if (message == NPPM_GETNPPDIRECTORY) + PathRemoveFileSpec(str); // For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough. // otherwise we check if the generic_string buffer size is enough for the generic_string to copy. @@ -779,7 +782,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa size_t nbFileNames = static_cast(lParam); size_t j = 0; - if (Message != NPPM_GETOPENFILENAMESSECOND) + if (message != NPPM_GETOPENFILENAMESSECOND) { for (size_t i = 0; i < _mainDocTab.nbItem() && j < nbFileNames; ++i) { @@ -789,7 +792,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } } - if (Message != NPPM_GETOPENFILENAMESPRIMARY) + if (message != NPPM_GETOPENFILENAMESPRIMARY) { for (size_t i = 0; i < _subDocTab.nbItem() && j < nbFileNames; ++i) { @@ -871,7 +874,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa break; } } - return ::DefWindowProc(hwnd, Message, wParam, lParam); + return ::DefWindowProc(hwnd, message, wParam, lParam); } case NPPM_GETNBSESSIONFILES: @@ -999,7 +1002,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa switchEditViewTo(whichView); activateDoc(index); - if (Message == NPPM_TRIGGERTABBARCONTEXTMENU) + if (message == NPPM_TRIGGERTABBARCONTEXTMENU) { // open here tab menu NMHDR nmhdr; @@ -1318,7 +1321,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return TRUE; } - case NPPM_INTERNAL_SCROLLBEYONDLASTLINE: { const bool endAtLastLine = not (pNppParam->getSVP())._scrollBeyondLastLine; @@ -1407,7 +1409,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa } } - return ::DefWindowProc(hwnd, Message, wParam, lParam); + return ::DefWindowProc(hwnd, message, wParam, lParam); } case WM_NOTIFY: @@ -1727,7 +1729,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa ::LockWindowUpdate(NULL); //Sends WM_DESTROY, Notepad++ will end - if (Message == WM_CLOSE) + if (message == WM_CLOSE) ::DestroyWindow(hwnd); } return TRUE; @@ -1770,7 +1772,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _sysMenuEntering = true; } - return ::DefWindowProc(hwnd, Message, wParam, lParam); + return ::DefWindowProc(hwnd, message, wParam, lParam); } case WM_LBUTTONDBLCLK: @@ -1936,7 +1938,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_MSGTOPLUGIN : { - return _pluginsManager.relayPluginMessages(Message, wParam, lParam); + return _pluginsManager.relayPluginMessages(message, wParam, lParam); } case NPPM_ALLOCATESUPPORTED: @@ -2132,7 +2134,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR: case NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR: { - return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR + return (message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR ?(NppParameters::getInstance())->getCurrentDefaultFgColor() :(NppParameters::getInstance())->getCurrentDefaultBgColor()); } @@ -2240,7 +2242,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa default: { - if (Message == WDN_NOTIFY) + if (message == WDN_NOTIFY) { NMWINDLG* nmdlg = reinterpret_cast(lParam); switch (nmdlg->type) @@ -2310,11 +2312,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return TRUE; } - return ::DefWindowProc(hwnd, Message, wParam, lParam); + return ::DefWindowProc(hwnd, message, wParam, lParam); } } - _pluginsManager.relayNppMessages(Message, wParam, lParam); + _pluginsManager.relayNppMessages(message, wParam, lParam); return result; } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 4cc483777..518f82861 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -342,7 +342,6 @@ void Notepad_plus::command(int id) } else { - _pEditView->execute(SCI_REPLACESEL, 0, reinterpret_cast(lpchar)); } GlobalUnlock(hglb); @@ -353,6 +352,68 @@ void Notepad_plus::command(int id) } break; + case IDM_EDIT_OPENINFOLDER: + case IDM_EDIT_OPENASFILE: + { + if (_pEditView->execute(SCI_GETSELECTIONS) != 1) // Multi-Selection || Column mode || no selection + return; + + HWND hwnd = _pPublicInterface->getHSelf(); + TCHAR curentWord[CURRENTWORD_MAXLENGTH]; + ::SendMessage(hwnd, NPPM_GETCURRENTWORD, CURRENTWORD_MAXLENGTH, reinterpret_cast(curentWord)); + + TCHAR cmd2Exec[CURRENTWORD_MAXLENGTH]; + if (id == IDM_EDIT_OPENINFOLDER) + { + lstrcpy(cmd2Exec, TEXT("explorer")); + } + else + { + ::SendMessage(hwnd, NPPM_GETNPPFULLFILEPATH, CURRENTWORD_MAXLENGTH, reinterpret_cast(cmd2Exec)); + } + + if (::PathFileExists(curentWord)) + { + generic_string fullFilePath = id == IDM_EDIT_OPENINFOLDER ? TEXT("/select,") : TEXT(""); + fullFilePath += TEXT("\""); + fullFilePath += curentWord; + fullFilePath += TEXT("\""); + + if (id == IDM_EDIT_OPENINFOLDER || + (id == IDM_EDIT_OPENASFILE && not ::PathIsDirectory(curentWord))) + ::ShellExecute(hwnd, TEXT("open"), cmd2Exec, fullFilePath.c_str(), TEXT("."), SW_SHOW); + } + else + { + TCHAR currentDir[CURRENTWORD_MAXLENGTH]; + ::SendMessage(hwnd, NPPM_GETCURRENTDIRECTORY, CURRENTWORD_MAXLENGTH, reinterpret_cast(currentDir)); + + generic_string fullFilePath = id == IDM_EDIT_OPENINFOLDER ? TEXT("/select,") : TEXT(""); + fullFilePath += TEXT("\""); + fullFilePath += currentDir; + fullFilePath += TEXT("\\"); + fullFilePath += curentWord; + if ((id == IDM_EDIT_OPENASFILE && + (not::PathFileExists(fullFilePath.c_str() + 1) || ::PathIsDirectory(fullFilePath.c_str() + 1)))) + return; + fullFilePath += TEXT("\""); + ::ShellExecute(hwnd, TEXT("open"), cmd2Exec, fullFilePath.c_str(), TEXT("."), SW_SHOW); + } + } + break; + + case IDM_EDIT_SEARCHONINTERNET: + { + + } + break; + + case IDM_EDIT_CHANGESEARCHENGIN: + { + + } + break; + case IDM_EDIT_PASTE_AS_RTF: case IDM_EDIT_PASTE_AS_HTML: { diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp index 9a2204341..2a64a7c7f 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp @@ -79,6 +79,8 @@ int whichVar(TCHAR *str) return CURRENT_WORD; else if (!lstrcmp(nppDir, str)) return NPP_DIRECTORY; + else if (!lstrcmp(nppFullFilePath, str)) + return NPP_FULL_FILE_PATH; else if (!lstrcmp(currentLine, str)) return CURRENT_LINE; else if (!lstrcmp(currentColumn, str)) diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h index 4503af719..69fdbb0ba 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h @@ -34,6 +34,7 @@ const TCHAR fileNamePart[] = TEXT("NAME_PART"); const TCHAR fileExtPart[] = TEXT("EXT_PART"); const TCHAR currentWord[] = TEXT("CURRENT_WORD"); const TCHAR nppDir[] = TEXT("NPP_DIRECTORY"); +const TCHAR nppFullFilePath[] = TEXT("NPP_FULL_FILE_PATH"); const TCHAR currentLine[] = TEXT("CURRENT_LINE"); const TCHAR currentColumn[] = TEXT("CURRENT_COLUMN"); diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h index 07122586a..50add7235 100644 --- a/PowerEditor/src/menuCmdID.h +++ b/PowerEditor/src/menuCmdID.h @@ -128,6 +128,11 @@ #define IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING (IDM_EDIT + 65) #define IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING (IDM_EDIT + 66) + #define IDM_EDIT_OPENASFILE (IDM_EDIT + 73) + #define IDM_EDIT_OPENINFOLDER (IDM_EDIT + 74) + #define IDM_EDIT_SEARCHONINTERNET (IDM_EDIT + 75) + #define IDM_EDIT_CHANGESEARCHENGIN (IDM_EDIT + 76) + // Menu macro #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18) #define IDM_MACRO_STOPRECORDINGMACRO (IDM_EDIT + 19) diff --git a/PowerEditor/src/shortcuts.xml b/PowerEditor/src/shortcuts.xml index f7cb0e980..08f55bc6f 100644 --- a/PowerEditor/src/shortcuts.xml +++ b/PowerEditor/src/shortcuts.xml @@ -14,8 +14,7 @@ http://www.php.net/$(CURRENT_WORD) https://www.google.com/search?q=$(CURRENT_WORD) https://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD) - $(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) - $(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) -nosession -multiInst + $(NPP_FULL_FILE_PATH) $(CURRENT_WORD) -nosession -multiInst outlook /a "$(FULL_CURRENT_PATH)"