Add new explorer context menu entry "Edit with Notepad++" for W11

Windows 11 has its new interface for its explorer context menu. It makes the old "Edit with Notepad++" command hardly accessible. This commit improves the accessibility and also fix issue of run as an administrator (Properties set in Compatibility) in the new context menu command.
It fixes also the context menu command issue under ARM64 architecture (fixed only under Windows 11).

The localization of "Edit with Notepad++" is also possible in this commit.

Note that if the command place of "Edit with Notepad++" context menu command is taken by other application ("\HKEY_CLASSES_ROOT*\shell\pintohome"), the new context menu "Edit with Notepad++" won't be installed. User should install it him/herself.

Fix #10320, fix #10565, fix #4368, fix #8786, fix #10320, fix #10640, fix #10856, fix #10653, fix #7747, fix #6169, fix #92, close #13170
This commit is contained in:
Don Ho 2023-02-18 17:43:24 +01:00
parent b077c58b5d
commit a0031159cd
5 changed files with 95 additions and 35 deletions

View File

@ -261,7 +261,39 @@ FunctionEnd
!include "nsisInclude\themes.nsh"
!include "StrFunc.nsh"
${Using:StrFunc} StrStr
Var muiVerbStr
Var nppSubStrRes
Var editWithNppLocalStr
${MementoSection} "Context Menu Entry" explorerContextMenu
${If} $WinVer == "11"
ReadRegStr $muiVerbStr HKLM "SOFTWARE\Classes\*\shell\pintohome" MUIVerb
${StrStr} $nppSubStrRes $muiVerbStr "Notepad++"
;MessageBox MB_OK "entry value: $muiVerbStr"
;MessageBox MB_OK "result: $nppSubStrRes"
; Make sure there's no entry before creating it, so we won't override other application if present
${If} $muiVerbStr == ""
${OrIf} $nppSubStrRes != "" ; it contains "Notepad++"
ReadINIStr $editWithNppLocalStr "$PLUGINSDIR\nppLocalization\explorerContextMenuEntryLocal.ini" $(langFileName) "Edit_with_Notepad++"
${If} $editWithNppLocalStr == ""
StrCpy $editWithNppLocalStr "Edit with Notepad++"
MessageBox MB_OK "translation: $editWithNppLocalStr"
${EndIf}
WriteRegStr HKLM "SOFTWARE\Classes\*\shell\pintohome" 'MUIVerb' $editWithNppLocalStr
WriteRegStr HKLM "SOFTWARE\Classes\*\shell\pintohome\command" "" '"$INSTDIR\notepad++.exe" "%1"'
${EndIf}
${EndIf}
SetOverwrite try
SetOutPath "$INSTDIR\"
@ -281,6 +313,8 @@ ${MementoSection} "Context Menu Entry" explorerContextMenu
${EndIf}
!endif
Exec 'regsvr32 /s "$INSTDIR\NppShell_06.dll"'
${MementoSectionEnd}
${MementoSectionDone}

View File

@ -115,7 +115,7 @@ Function copyCommonFiles
SetOutPath "$INSTDIR\localization\"
File ".\nativeLang\english.xml"
; Copy all the language files to the temp directory
; Copy all the Notepad++ localization files to the temp directory
; than make them installed via option
SetOutPath "$PLUGINSDIR\nppLocalization\"
File ".\nativeLang\"
@ -131,6 +131,7 @@ Function copyCommonFiles
CopyFiles "$PLUGINSDIR\nppLocalization\$(langFileName)" "$INSTDIR\localization\$(langFileName)"
IfFileExists "$PLUGINSDIR\gupLocalization\$(langFileName)" 0 +2
CopyFiles "$PLUGINSDIR\gupLocalization\$(langFileName)" "$INSTDIR\updater\nativeLang.xml"
FunctionEnd
; Source from: https://nsis.sourceforge.io/VersionCompare

View File

@ -50,6 +50,12 @@ Function un.onUninstSuccess
FunctionEnd
!include "StrFunc.nsh"
${Using:StrFunc} UnStrStr
Var muiVerbStrUn
Var nppSubStrUn
Section un.explorerContextMenu
Exec 'regsvr32 /u /s "$INSTDIR\NppShell_01.dll"'
Exec 'regsvr32 /u /s "$INSTDIR\NppShell_02.dll"'
@ -63,6 +69,17 @@ Section un.explorerContextMenu
Delete "$INSTDIR\NppShell_04.dll"
Delete "$INSTDIR\NppShell_05.dll"
Delete "$INSTDIR\NppShell_06.dll"
ReadRegStr $muiVerbStrUn HKLM "SOFTWARE\Classes\*\shell\pintohome" MUIVerb
${UnStrStr} $nppSubStrUn $muiVerbStrUn "Notepad++"
; Make sure there's an entry, and the entry belong to Notepad++ before deleting it
${If} $muiVerbStrUn != ""
${AndIf} $nppSubStrUn != "" ; it contains "Notepad++"
DeleteRegKey HKLM "SOFTWARE\Classes\*\shell\pintohome"
${EndIf}
SectionEnd
Section un.UnregisterFileExt

View File

@ -42,14 +42,12 @@ Function GetWindowsVersion
ClearErrors
; check if Windows NT family
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
IfErrors 0 lbl_winnt
; we are not NT
ReadRegStr $R0 HKLM \
"SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
StrCpy $R1 $R0 1
StrCmp $R1 '4' 0 lbl_error
@ -59,19 +57,19 @@ Function GetWindowsVersion
StrCmp $R1 '4.0' lbl_win32_95
StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98
lbl_win32_95:
StrCpy $R0 '95'
lbl_win32_95:
StrCpy $R0 '95'
Goto lbl_done
lbl_win32_98:
StrCpy $R0 '98'
lbl_win32_98:
StrCpy $R0 '98'
Goto lbl_done
lbl_win32_ME:
StrCpy $R0 'ME'
lbl_win32_ME:
StrCpy $R0 'ME'
Goto lbl_done
lbl_winnt:
lbl_winnt:
StrCpy $R1 $R0 1
@ -94,46 +92,56 @@ Function GetWindowsVersion
StrCmp $R1 '10.0' lbl_winnt_10
Goto lbl_error
lbl_winnt_x:
StrCpy $R0 "NT $R0" 6
lbl_winnt_x:
StrCpy $R0 "NT $R0" 6
Goto lbl_done
lbl_winnt_2000:
Strcpy $R0 '2000'
lbl_winnt_2000:
Strcpy $R0 '2000'
Goto lbl_done
lbl_winnt_XP:
Strcpy $R0 'XP'
lbl_winnt_XP:
Strcpy $R0 'XP'
Goto lbl_done
lbl_winnt_2003:
Strcpy $R0 '2003'
lbl_winnt_2003:
Strcpy $R0 '2003'
Goto lbl_done
lbl_winnt_vista:
Strcpy $R0 'Vista'
lbl_winnt_vista:
Strcpy $R0 'Vista'
Goto lbl_done
lbl_winnt_7:
Strcpy $R0 '7'
lbl_winnt_7:
Strcpy $R0 '7'
Goto lbl_done
lbl_winnt_8:
Strcpy $R0 '8'
lbl_winnt_8:
Strcpy $R0 '8'
Goto lbl_done
lbl_winnt_81:
lbl_winnt_81:
lbl_winnt_10:
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentBuildNumber
${If} $R0 >= 17763 ; Windows 10 or later
${If} $R0 >= 22000 ; Windows 11 or later
Strcpy $R0 '11'
Goto lbl_done
${Else}
Strcpy $R0 '10'
Goto lbl_done
${EndIf}
${Else}
Strcpy $R0 '8.1'
Goto lbl_done
${EndIf}
Goto lbl_done
lbl_winnt_10:
Strcpy $R0 '10.0'
Goto lbl_done
lbl_error:
Strcpy $R0 ''
lbl_done:
lbl_error:
Strcpy $R0 ''
lbl_done:
Pop $R1
Exch $R0