Skip to content

Commit f80a34c

Browse files
committed
Add to Favorites - selection mode - add /m /-m #282
1 parent fefa347 commit f80a34c

File tree

8 files changed

+69
-12
lines changed

8 files changed

+69
-12
lines changed

src/Dialogs.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,16 @@ INT_PTR CALLBACK AddToFavDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lPa
896896
{
897897
EnableWindow(GetDlgItem(hwnd, IDC_RADIO4), FALSE);
898898
}
899-
n2e_SetCheckedRadioButton(hwnd, IDC_RADIO1, IDC_RADIO4, lpParams->cursorPosition);
899+
900+
if (n2e_IsRectangularSelection()
901+
|| !n2e_GetCurrentSelection(lpParams->pszCurrentSelection, COUNTOF(lpParams->pszCurrentSelection))
902+
|| (lstrlen(lpParams->pszCurrentSelection) == 0)
903+
|| (wcspbrk(lpParams->pszCurrentSelection, L" \t\r\n\"") != NULL))
904+
{
905+
EnableWindow(GetDlgItem(hwnd, IDC_RADIO5), FALSE);
906+
EnableWindow(GetDlgItem(hwnd, IDC_RADIO6), FALSE);
907+
}
908+
n2e_SetCheckedRadioButton(hwnd, IDC_RADIO1, IDC_RADIO6, lpParams->cursorPosition);
900909

901910
DPI_INIT();
902911
CenterDlgInParent(hwnd);
@@ -919,7 +928,7 @@ INT_PTR CALLBACK AddToFavDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lPa
919928
GetDlgItemText(hwnd, 100, lpParams->pszName,
920929
MAX_PATH - 1);
921930
// [2e]: Add to Favorites - selection mode #249
922-
lpParams->cursorPosition = (EFavoritesCursorPosition)n2e_GetCheckedRadioButton(hwnd, IDC_RADIO1, IDC_RADIO4);
931+
lpParams->cursorPosition = (EFavoritesCursorPosition)n2e_GetCheckedRadioButton(hwnd, IDC_RADIO1, IDC_RADIO6);
923932
n2e_UpdateFavLnkParams(lpParams);
924933
// [/2e]
925934
EndDialog(hwnd, IDOK);

src/Extension/EditHelper.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,17 +949,21 @@ void remove_char(char* str, char c)
949949
*pw = '\0';
950950
}
951951

952+
int n2e_MultiByteToWideChar(LPCSTR lpMultiByteStr, const int cbMultiByte, LPWSTR lpWideCharStr, const int cchWideChar)
953+
{
954+
return MultiByteToWideChar(SciCall_GetCodePage(), 0, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar);
955+
}
956+
952957
BOOL n2e_FilteredPasteFromClipboard(const HWND hwnd)
953958
{
954959
char *pClip = EditGetClipboardText(hwndEdit);
955960
if (pClip)
956961
{
957962
remove_char(pClip, '\r');
958963
remove_char(pClip, '\n');
959-
const UINT codePage = SendMessage(hwndEdit, SCI_GETCODEPAGE, 0, 0);
960-
const int textLength = MultiByteToWideChar(codePage, 0, pClip, -1, NULL, 0);
964+
const int textLength = n2e_MultiByteToWideChar(pClip, -1, NULL, 0);
961965
LPWSTR pWideText = LocalAlloc(LPTR, textLength * 2);
962-
MultiByteToWideChar(codePage, 0, pClip, -1, pWideText, textLength);
966+
n2e_MultiByteToWideChar(pClip, -1, pWideText, textLength);
963967
SendMessage(hwnd, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)pWideText);
964968
LocalFree(pWideText);
965969
LocalFree(pClip);

src/Extension/EditHelper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ BOOL n2e_IsCheckboxChecked(const HWND hwnd, const UINT nCtrlID, const BOOL bChec
4646
void n2e_EditFindReplaceUpdateCheckboxes(const HWND hwnd, const UINT nCtrlID);
4747
void n2e_EditFindReplaceInitialUpdateCheckboxes(const HWND hwnd);
4848

49+
int n2e_MultiByteToWideChar(LPCSTR lpMultiByteStr, const int cbMultiByte, LPWSTR lpWideCharStr, const int cchWideChar);
50+
4951
BOOL n2e_CheckWindowClassName(const HWND hwnd, LPCWSTR lpwstrClassname);
5052
BOOL n2e_EnableClipboardFiltering(const HWND hwnd, const UINT idEdit);
5153
BOOL n2e_SubclassFindEditInCombo(const HWND hwnd, const UINT idCombo);

src/Extension/SciCall.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ __forceinline LRESULT SciCall_##fn(type1 var1, type2 var2) { \
7373
// Selection and information
7474
//
7575
//
76+
DeclareSciCallR0(GetCodePage, GETCODEPAGE, int);
7677
DeclareSciCallR0(GetLineCount, GETLINECOUNT, int);
7778
DeclareSciCallR0(GetLength, GETLENGTH, int);
7879
DeclareSciCallR0(GetSelectionMode, GETSELECTIONMODE, int);

src/Extension/Utils.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,26 @@ BOOL n2e_IsRectangularSelection()
478478
return SciCall_GetSelectionMode() == SC_SEL_RECTANGLE;
479479
}
480480

481+
BOOL n2e_GetCurrentSelection(LPWSTR buf, const int iCount)
482+
{
483+
BOOL res = FALSE;
484+
const int iSelStart = SciCall_GetSelStart();
485+
const int iSelEnd = SciCall_GetSelEnd();
486+
const int iSelLength = iSelEnd - iSelStart;
487+
if ((iSelLength > 0) && (iSelLength < iCount * 4))
488+
{
489+
LPSTR pSelText = LocalAlloc(LPTR, iSelLength + 1);
490+
struct TextRange tr = { { iSelStart, iSelEnd }, pSelText };
491+
if ((SciCall_GetTextRange(0, &tr) > 0)
492+
&& (n2e_MultiByteToWideChar(pSelText, -1, NULL, 0) <= iCount))
493+
{
494+
res = (n2e_MultiByteToWideChar(pSelText, -1, buf, iCount) > 0);
495+
}
496+
LocalFree(pSelText);
497+
}
498+
return res;
499+
}
500+
481501
int n2e_CompareFiles(LPCWSTR sz1, LPCWSTR sz2)
482502
{
483503
int res1, res2;
@@ -1244,6 +1264,16 @@ void n2e_UpdateFavLnkParams(TADDFAVPARAMS* lpParams)
12441264
_swprintf(lpParams->pszArguments, L"/gs %d:%d %s", SciCall_GetSelStart(), SciCall_GetSelEnd(), lpParams->pszTarget);
12451265
_swprintf(lpParams->pszTarget, L"%s", n2e_GetExePath());
12461266
break;
1267+
case FCP_FIRST_SUBSTRING:
1268+
PathQuoteSpaces(lpParams->pszTarget);
1269+
_swprintf(lpParams->pszArguments, L"/m %s %s", lpParams->pszCurrentSelection, lpParams->pszTarget);
1270+
_swprintf(lpParams->pszTarget, L"%s", n2e_GetExePath());
1271+
break;
1272+
case FCP_LAST_SUBSTRING:
1273+
PathQuoteSpaces(lpParams->pszTarget);
1274+
_swprintf(lpParams->pszArguments, L"/m- %s %s", lpParams->pszCurrentSelection, lpParams->pszTarget);
1275+
_swprintf(lpParams->pszTarget, L"%s", n2e_GetExePath());
1276+
break;
12471277
default:
12481278
break;
12491279
}

src/Extension/Utils.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ typedef enum
8383
FCP_FIRST_LINE = 0,
8484
FCP_LAST_LINE = 1,
8585
FCP_CURRENT_LINE = 2,
86-
FCP_CURRENT_SELECTION = 3
86+
FCP_CURRENT_SELECTION = 3,
87+
FCP_FIRST_SUBSTRING = 4,
88+
FCP_LAST_SUBSTRING = 5
8789
} EFavoritesCursorPosition;
8890

8991
typedef struct TAddToFavoritesParams
9092
{
9193
WCHAR pszName[MAX_PATH];
9294
WCHAR pszTarget[MAX_PATH];
9395
WCHAR pszArguments[MAX_PATH];
96+
WCHAR pszCurrentSelection[MAX_PATH];
9497
EFavoritesCursorPosition cursorPosition;
9598
} TADDFAVPARAMS, *PTADDFAVPARAMS;
9699

@@ -118,6 +121,7 @@ void n2e_Reload_Settings();
118121
BOOL n2e_CanSaveINISection(const BOOL bCheckSaveSettingsMode, const ESaveSettingsMode modeRequired);
119122
BOOL n2e_IsTextEmpty(LPCWSTR txt);
120123
BOOL n2e_IsRectangularSelection();
124+
BOOL n2e_GetCurrentSelection(LPWSTR buf, const int iCount);
121125
BOOL n2e_OpenMRULast(LPWSTR fn);
122126
void n2e_GetLastDir(LPTSTR out);
123127
LPCWSTR n2e_GetExePath();

src/Notepad2.rc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,20 +939,22 @@ BEGIN
939939
SCROLLBAR IDC_RESIZEGRIP3,7,112,10,10
940940
END
941941

942-
IDD_ADDTOFAV DIALOGEX 0, 0, 172, 143
942+
IDD_ADDTOFAV DIALOGEX 0, 0, 172, 173
943943
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
944944
CAPTION "Add to Favorites"
945945
FONT 8, "MS Shell Dlg", 400, 0, 0x1
946946
BEGIN
947947
LTEXT "Enter the name for the new favorites item:",IDC_STATIC,7,7,158,8
948948
EDITTEXT 100,7,22,158,14,ES_AUTOHSCROLL
949-
GROUPBOX "Cursor position",IDC_STATIC,7,41,158,75
950-
CONTROL "&First line",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP,15,54,43,10
949+
GROUPBOX "Cursor position",IDC_STATIC,7,41,158,105
950+
CONTROL "&First line",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,15,54,43,10
951951
CONTROL "L&ast line",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,15,68,42,10
952952
CONTROL "&Current line",IDC_RADIO3,"Button",BS_AUTORADIOBUTTON,15,83,53,10
953953
CONTROL "Current &selection",IDC_RADIO4,"Button",BS_AUTORADIOBUTTON,15,98,71,10
954-
DEFPUSHBUTTON "OK",IDOK,60,122,50,14,WS_DISABLED
955-
PUSHBUTTON "Cancel",IDCANCEL,116,122,50,14
954+
CONTROL "Fi&rst substring",IDC_RADIO5,"Button",BS_AUTORADIOBUTTON,15,113,60,10
955+
CONTROL "Las&t substring",IDC_RADIO6,"Button",BS_AUTORADIOBUTTON,15,128,71,10
956+
DEFPUSHBUTTON "OK",IDOK,59,152,50,14,WS_DISABLED
957+
PUSHBUTTON "Cancel",IDCANCEL,115,152,50,14
956958
END
957959

958960
IDD_COLUMNWRAP DIALOGEX 0, 0, 130, 47
@@ -1264,7 +1266,10 @@ BEGIN
12641266
LEFTMARGIN, 7
12651267
RIGHTMARGIN, 165
12661268
TOPMARGIN, 7
1267-
BOTTOMMARGIN, 136
1269+
BOTTOMMARGIN, 166
1270+
HORZGUIDE, 41
1271+
HORZGUIDE, 146
1272+
HORZGUIDE, 152
12681273
END
12691274

12701275
IDD_COLUMNWRAP, DIALOG

src/resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@
140140
#define IDD_STYLESELECT 120
141141
#define IDC_RADIO4 120
142142
#define IDD_STYLECONFIG 121
143+
#define IDC_RADIO5 121
143144
#define IDD_WORDWRAP 122
145+
#define IDC_RADIO6 122
144146
#define IDD_LONGLINES 123
145147
#define IDD_TABSETTINGS 124
146148
#define IDD_PAGESETUP 125

0 commit comments

Comments
 (0)