Skip to content

Commit

Permalink
Add menu "URL Component Encode", issue #905.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 8, 2024
1 parent 51fe97e commit b623310
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions locale/de/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "&Malayalam nach Latein", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "&URL Codierung\tStrg+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "UR&L Decodierung\tStrg+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "&Hilfe"
Expand Down
1 change: 1 addition & 0 deletions locale/fr/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "&Malayalam à Latin", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "Encodage des &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "Décodage des UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "Aide"
Expand Down
1 change: 1 addition & 0 deletions locale/it/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "&Malayalam a Latino", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "Codifica &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "Decodifica UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "&Aiuto"
Expand Down
1 change: 1 addition & 0 deletions locale/ja/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "マラヤーラム語を(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "URLエンコード(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "URLデコード(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "ヘルプ(&H)"
Expand Down
1 change: 1 addition & 0 deletions locale/ko/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "말라얄람 문자를 라틴 문자로(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "URL 인코드(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "URL 디코드(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "도움말(&H)"
Expand Down
1 change: 1 addition & 0 deletions locale/pt-BR/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "&Malayalam to Latin", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "&URL Encode\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "UR&L Decode\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "&Help"
Expand Down
1 change: 1 addition & 0 deletions locale/ru/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ BEGIN
MENUITEM "Из &малаялам в латинский", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "Закодировать в &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "Декодировать из UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "&Справка"
Expand Down
1 change: 1 addition & 0 deletions locale/zh-Hans/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "马拉雅拉姆语转拉丁语(&M)",IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "URL 编码(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL 组件编码", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "URL 解码(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "帮助(&H)"
Expand Down
1 change: 1 addition & 0 deletions locale/zh-Hant/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ BEGIN
MENUITEM "馬拉雅拉姆語轉拉丁語(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "URL 編碼(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL 元件編碼", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "URL 解碼(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "說明(&H)"
Expand Down
18 changes: 9 additions & 9 deletions src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,12 +1683,15 @@ void EditMapTextCase(int menu) noexcept {
#ifndef URL_UNESCAPE_AS_UTF8 // NTDDI_VERSION >= NTDDI_WIN8
#define URL_UNESCAPE_AS_UTF8 URL_ESCAPE_AS_UTF8
#endif
#ifndef URL_ESCAPE_ASCII_URI_COMPONENT // NTDDI_VERSION >= NTDDI_WIN8
#define URL_ESCAPE_ASCII_URI_COMPONENT 0x00080000
#endif

//=============================================================================
//
// EditURLEncode()
//
LPWSTR EditURLEncodeSelection(int *pcchEscaped) noexcept {
LPWSTR EditURLEncodeSelection(int *pcchEscaped, bool component) noexcept {
*pcchEscaped = 0;
const Sci_Position iSelCount = SciCall_GetSelTextLength();
if (iSelCount == 0) {
Expand All @@ -1713,18 +1716,15 @@ LPWSTR EditURLEncodeSelection(int *pcchEscaped) noexcept {
LPWSTR pszEscapedW = static_cast<LPWSTR>(NP2HeapAlloc(NP2HeapSize(pszTextW) * kMaxMultiByteCount * 3)); // '&', H1, H0

DWORD cchEscapedW = static_cast<DWORD>(NP2HeapSize(pszEscapedW) / sizeof(WCHAR));
UrlEscape(pszTextW, pszEscapedW, &cchEscapedW, URL_ESCAPE_AS_UTF8);
if (!IsWin7AndAbove()) {
// TODO: encode some URL parts as UTF-8 then percent escape these UTF-8 bytes.
//ParseURL(pszEscapedW, &ppu);
}
const DWORD flags = component ? (URL_ESCAPE_AS_UTF8 | URL_ESCAPE_ASCII_URI_COMPONENT | URL_ESCAPE_SEGMENT_ONLY) : URL_ESCAPE_AS_UTF8;
UrlEscape(pszTextW, pszEscapedW, &cchEscapedW, flags);

NP2HeapFree(pszTextW);
*pcchEscaped = cchEscapedW;
return pszEscapedW;
}

void EditURLEncode() noexcept {
void EditURLEncode(bool component) noexcept {
const Sci_Position iSelCount = SciCall_GetSelTextLength();
if (iSelCount == 0) {
return;
Expand All @@ -1735,7 +1735,7 @@ void EditURLEncode() noexcept {
}

int cchEscapedW;
LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW);
LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW, component);
if (pszEscapedW == nullptr) {
return;
}
Expand Down Expand Up @@ -6893,7 +6893,7 @@ void EditSelectionAction(int action) noexcept {
}

int cchEscapedW;
LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW);
LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW, false);
if (pszEscapedW == nullptr) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool EditSaveFile(HWND hwnd, LPCWSTR pszFile, int saveFlag, EditFileIOStatus &st
void EditReplaceMainSelection(Sci_Position cchText, LPCSTR pszText) noexcept;
void EditMapTextCase(int menu) noexcept;

void EditURLEncode() noexcept;
void EditURLEncode(bool component) noexcept;
void EditURLDecode() noexcept;
void EditEscapeCChars(HWND hwnd) noexcept;
void EditUnescapeCChars(HWND hwnd) noexcept;
Expand Down
8 changes: 3 additions & 5 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) noexcept {
IDM_EDIT_SPLITLINES,
IDM_EDIT_TITLECASE,
IDM_EDIT_UNESCAPECCHARS,
IDM_EDIT_URLCOMPONENTENCODE,
IDM_EDIT_URLDECODE,
IDM_EDIT_URLENCODE,
IDM_EDIT_XHTML_ESCAPE_CHAR,
Expand Down Expand Up @@ -3564,15 +3565,12 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) {
break;

case IDM_EDIT_URLENCODE:
BeginWaitCursor();
EditURLEncode();
EndWaitCursor();
case IDM_EDIT_URLCOMPONENTENCODE:
EditURLEncode(LOWORD(wParam) == IDM_EDIT_URLCOMPONENTENCODE);
break;

case IDM_EDIT_URLDECODE:
BeginWaitCursor();
EditURLDecode();
EndWaitCursor();
break;

case IDM_EDIT_ESCAPECCHARS:
Expand Down
1 change: 1 addition & 0 deletions src/Notepad4.rc
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ BEGIN
MENUITEM "&Malayalam to Latin", IDM_EDIT_MAP_MALAYALAM_LATIN
END
MENUITEM "&URL Encode\tCtrl+Shift+E", IDM_EDIT_URLENCODE
MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE
MENUITEM "UR&L Decode\tCtrl+Shift+R", IDM_EDIT_URLDECODE
END
POPUP "&Help"
Expand Down
4 changes: 2 additions & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@
#define IDM_EDIT_CONVERTLOWERCASE 40340 // Ctrl+U
#define IDM_EDIT_MERGEDUPLICATELINE 40341
#define IDM_EDIT_REMOVEDUPLICATELINE 40342

#define IDM_EDIT_URLDECODE 40343 // Ctrl+Shift+R
#define IDM_EDIT_CONVERTTABS 40344 // Ctrl+Shift+S
#define IDM_EDIT_CONVERTSPACES 40345 // Ctrl+Shift+T
#define IDM_EDIT_CONVERTTABS2 40346 // Ctrl+Alt+S
Expand All @@ -588,7 +588,7 @@
#define IDM_EDIT_LINECOMMENT 40354 // Ctrl+/
#define IDM_EDIT_STREAMCOMMENT 40355 // Ctrl+Q
#define IDM_EDIT_URLENCODE 40356 // Ctrl+Shift+E
#define IDM_EDIT_URLDECODE 40357 // Ctrl+Shift+R
#define IDM_EDIT_URLCOMPONENTENCODE 40357
#define IDM_EDIT_ESCAPECCHARS 40358 // Ctrl+Alt+E
#define IDM_EDIT_UNESCAPECCHARS 40359 // Ctrl+Alt+R
#define IDM_EDIT_CHAR2HEX 40360 // Ctrl+Alt+X
Expand Down

0 comments on commit b623310

Please sign in to comment.