Skip to content

Commit

Permalink
Add "Inconsistent Line Endings" warning dialog, finish issue #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 3, 2018
1 parent 7e373b2 commit 8c35b70
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 12 deletions.
2 changes: 1 addition & 1 deletion metapath/src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void OpenContainingFolder(HWND hwnd, LPCWSTR pszFile, BOOL bSelect) {
sei.hwnd = hwnd;
//sei.lpVerb = L"explore";
sei.lpVerb = L"open";
sei.lpIDList = pidl;
sei.lpIDList = (void *)pidl;
sei.nShow = SW_SHOW;

const BOOL result = ShellExecuteEx(&sei);
Expand Down
63 changes: 62 additions & 1 deletion src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ static INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd, UINT umsg, WPARAM
// Load options
WCHAR wch[128];
for (int i = 0; i < 3; i++) {
GetString(IDS_EOLMODENAME0 + i, wch, COUNTOF(wch));
GetString(IDS_EOLMODENAME_CRLF + i, wch, COUNTOF(wch));
SendDlgItemMessage(hwnd, IDC_EOLMODELIST, CB_ADDSTRING, 0, (LPARAM)wch);
}

Expand Down Expand Up @@ -1907,6 +1907,67 @@ BOOL SelectDefLineEndingDlg(HWND hwnd, int *iOption) {
return iResult == IDOK;
}

static INT_PTR CALLBACK WarnLineEndingDlgDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
EditFileIOStatus *status = (EditFileIOStatus *)lParam;
int iEOLMode = status->iEOLMode;
iEOLMode = (iEOLMode == SC_EOL_CRLF) ? 0 : (iEOLMode == SC_EOL_LF) ? 1 : 2;

// Load options
WCHAR wch[128];
for (int i = 0; i < 3; i++) {
GetString(IDS_EOLMODENAME_CRLF + i, wch, COUNTOF(wch));
SendDlgItemMessage(hwnd, IDC_EOLMODELIST, CB_ADDSTRING, 0, (LPARAM)wch);
}

SendDlgItemMessage(hwnd, IDC_EOLMODELIST, CB_SETCURSEL, iEOLMode, 0);
SendDlgItemMessage(hwnd, IDC_EOLMODELIST, CB_SETEXTENDEDUI, TRUE, 0);

WCHAR tchFmt[128];
for (int i = 0; i < 3; i++) {
WCHAR tchLn[32];
wsprintf(tchLn, L"%u", status->linesCount[i]);
FormatNumberStr(tchLn);
GetDlgItemText(hwnd, IDC_EOL_SUM_CRLF + i, tchFmt, COUNTOF(tchFmt));
wsprintf(wch, tchFmt, tchLn);
SetDlgItemText(hwnd, IDC_EOL_SUM_CRLF + i, wch);
}

if (bWarnLineEndings) {
CheckDlgButton(hwnd, IDC_WARNINCONSISTENTEOLS, BST_CHECKED);
}

CenterDlgInParent(hwnd);
}
return TRUE;

case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK: {
EditFileIOStatus *status = (EditFileIOStatus *)GetWindowLongPtr(hwnd, DWLP_USER);
const int iEOLMode = (int)SendDlgItemMessage(hwnd, IDC_EOLMODELIST, CB_GETCURSEL, 0, 0);
status->iEOLMode = iEOLMode;
bWarnLineEndings = IsButtonChecked(hwnd, IDC_WARNINCONSISTENTEOLS);
EndDialog(hwnd, IDOK);
}
break;

case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
return TRUE;
}
return FALSE;
}

BOOL WarnLineEndingDlg(HWND hwnd, struct EditFileIOStatus *status) {
const INT_PTR iResult = ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_WARNLINEENDS), hwnd, WarnLineEndingDlgDlgProc, (LPARAM)status);
return iResult == IDOK;
}

//=============================================================================
//
// InfoBoxDlgProc()
Expand Down
3 changes: 3 additions & 0 deletions src/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ BOOL SelectDefEncodingDlg(HWND hwnd, int *pidREncoding);
BOOL SelectEncodingDlg(HWND hwnd, int *pidREncoding);
BOOL RecodeDlg(HWND hwnd, int *pidREncoding);
BOOL SelectDefLineEndingDlg(HWND hwnd, int *iOption);

struct EditFileIOStatus;
BOOL WarnLineEndingDlg(HWND hwnd, struct EditFileIOStatus *status);
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, int uidMessage, ...);

#endif // NOTEPAD2_DIALOGS_H_
Expand Down
3 changes: 0 additions & 3 deletions src/Edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ void EditShowCallTips(HWND hwnd, Sci_Position position);
#define CPI_UTF8SIGN 7
#define CPI_UTF7 8

#define IDS_ENCODINGNAME0 61000
#define IDS_EOLMODENAME0 62000

#define MAX_ENCODING_LABEL_SIZE 32

typedef struct _np2encoding {
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ void OpenContainingFolder(HWND hwnd, LPCWSTR pszFile, BOOL bSelect) {
sei.hwnd = hwnd;
//sei.lpVerb = L"explore";
sei.lpVerb = L"open";
sei.lpIDList = pidl;
sei.lpIDList = (void *)pidl;
sei.nShow = SW_SHOW;

const BOOL result = ShellExecuteEx(&sei);
Expand Down
4 changes: 4 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7030,6 +7030,10 @@ BOOL FileLoad(BOOL bDontSave, BOOL bNew, BOOL bReload, BOOL bNoEncDetect, LPCWST
}
// Show inconsistent line endings warning
if (status.bInconsistent && bWarnLineEndings) {
if (WarnLineEndingDlg(hwndMain, &status)) {
const int iNewEOLMode = iLineEndings[status.iEOLMode];
ConvertLineEndings(iNewEOLMode);
}
}
} else if (!status.bFileTooBig) {
MsgBox(MBWARN, IDS_ERR_LOADFILE, szFileName);
Expand Down
29 changes: 23 additions & 6 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,23 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,139,24,50,14
END

IDD_WARNLINEENDS DIALOGEX 0, 0, 196, 100
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Inconsistent Line Endings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "The line endings in this file is not consistent:",IDC_STATIC,7,7,180,8
LTEXT "CR+LF: %s line(s).",IDC_EOL_SUM_CRLF,22,18,164,8
LTEXT "LF: %s line(s).",IDC_EOL_SUM_LF,36,28,154,8
LTEXT "CR: %s line(s).",IDC_EOL_SUM_CR,34,38,152,8
LTEXT "&Do you want to normalize the line ending?",IDC_STATIC,7,52,180,8
COMBOBOX IDC_EOLMODELIST,7,64,118,81,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Yes",IDOK,138,63,50,14
PUSHBUTTON "&No",IDCANCEL,138,80,50,14
CONTROL "&Always show this dialog.",IDC_WARNINCONSISTENTEOLS,
"Button",BS_AUTOCHECKBOX | BS_VCENTER | WS_TABSTOP,7,82,118,10
END

IDD_LINENUM DIALOGEX 0, 0, 166, 70
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Goto"
Expand Down Expand Up @@ -1757,9 +1774,9 @@ END

STRINGTABLE
BEGIN
IDS_GOOGLE_SEARCH_URL "https://www.google.com/search?q=%s"
IDS_BING_SEARCH_URL "https://www.bing.com/search?q=%s"
IDS_WIKI_SEARCH_URL "https://en.wikipedia.org/wiki/Special:Search?search=%s"
IDS_GOOGLE_SEARCH_URL "https://www.google.com/search?q=%s"
IDS_BING_SEARCH_URL "https://www.bing.com/search?q=%s"
IDS_WIKI_SEARCH_URL "https://en.wikipedia.org/wiki/Special:Search?search=%s"
END

STRINGTABLE
Expand Down Expand Up @@ -1840,9 +1857,9 @@ END

STRINGTABLE
BEGIN
62000 "Windows (CR+LF)"
62001 "Unix/Mac (LF)"
62002 "Old Mac (CR)"
IDS_EOLMODENAME_CRLF "Windows (CR+LF)"
IDS_EOLMODENAME_LF "Unix/Mac (LF)"
IDS_EOLMODENAME_CR "Old Mac (CR)"
END


Expand Down
7 changes: 7 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define IDI_STYLES 102
#define IDC_ASCIIASUTF8 102
#define IDC_LINE_RANGE 102
#define IDC_EOL_SUM_CRLF 102
#define IDD_DEFENCODING 103
#define IDC_FINDWORD 103
#define IDC_RESIZEGRIP3 103
Expand All @@ -54,6 +55,8 @@
#define IDC_AUTOSTRIPBLANKS 103
#define IDC_ENCODINGFROMFILEVARS 103
#define IDC_EMPTY_MRU 103
#define IDC_EOL_SUM_LF 103
#define IDC_EOL_SUM_CR 104

#define IDD_ABOUT 100
#define IDC_VERSION 100
Expand Down Expand Up @@ -119,6 +122,7 @@
#define IDD_INFOBOX 126
#define IDD_INFOBOX2 127
#define IDD_INFOBOX3 128
#define IDD_WARNLINEENDS 129
#define IDC_BACKSLASHHELP 151
#define IDC_REGEXPHELP 152
#define IDC_WILDCARDHELP 153
Expand Down Expand Up @@ -604,6 +608,9 @@
#define IDS_SETTINGSNOTSAVED 50039
#define IDS_EXPORT_FAIL 50040
#define IDS_CMDLINEHELP 60000
#define IDS_EOLMODENAME_CRLF 62000
#define IDS_EOLMODENAME_LF 62001
#define IDS_EOLMODENAME_CR 62002

// Next default values for new objects
//
Expand Down

0 comments on commit 8c35b70

Please sign in to comment.