diff --git a/language/common_res.h b/language/common_res.h index 32c546383..38c8be2bc 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -70,6 +70,7 @@ #define IDS_MUI_ERR_ADMINEXE 13011 #define IDS_MUI_WARN_LOAD_BIG_FILE 13012 #define IDS_MUI_WARN_UNKNOWN_EXT 13013 +#define IDS_MUI_WARN_INCONSIST_EOLS 13014 #define IDS_MUI_SELRECT 14000 #define IDS_MUI_BUFFERTOOSMALL 14001 @@ -218,61 +219,63 @@ #define IDC_ASCIIASUTF8 18033 #define IDC_NFOASOEM 18034 #define IDC_ENCODINGFROMFILEVARS 18035 -#define IDC_CONSISTENTEOLS 18036 -#define IDC_AUTOSTRIPBLANKS 18037 -#define IDC_LINENUM 18038 -#define IDC_COLNUM 18039 -#define IDC_FILEMRU 18040 -#define IDC_PRESERVECARET 18041 -#define IDC_SAVEMRU 18042 -#define IDC_REMOVE 18043 -#define IDC_RESIZEGRIP 18044 -#define IDC_REMEMBERSEARCHPATTERN 18045 -#define IDC_STYLELIST 18046 -#define IDC_DEFAULTSCHEME 18047 -#define IDC_AUTOSELECT 18048 -#define IDC_STYLELABEL_ROOT 18049 -#define IDC_STYLEEDIT_ROOT 18050 -#define IDC_STYLELABEL 18051 -#define IDC_STYLEFORE 18052 -#define IDC_STYLEBACK 18053 -#define IDC_STYLEFONT 18054 -#define IDC_PREVIEW 18055 -#define IDC_STYLEDEFAULT 18056 -#define IDC_PREVSTYLE 18057 -#define IDC_NEXTSTYLE 18058 -#define IDC_IMPORT 18059 -#define IDC_EXPORT 18060 -#define IDC_TITLE 18061 -#define IDC_STYLEEDIT 18062 -#define IDC_PRINTER 18063 -#define IDC_FAVORITESDIR 18064 -#define IDC_GETFAVORITESDIR 18065 -#define IDC_FAVORITESDESCR 18066 -#define IDC_PWD_EDIT1 18067 -#define IDC_PWD_EDIT2 18068 -#define IDC_PWD_EDIT3 18069 -#define IDC_PWD_CHECK1 18070 -#define IDC_PWD_CHECK2 18071 -#define IDC_PWD_CHECK3 18072 -#define IDC_PWD_CHECK4 18073 -#define IDC_PWD_STATMPW 18074 -#define IDC_COLUMNWRAP 18075 -#define IDC_INFOBOXTEXT 18076 -#define IDC_INFOBOXCHECK 18077 -#define IDC_INFOBOXICON 18078 -#define IDC_RESIZEGRIP4 18079 -#define IDC_VERSION 18080 -#define IDC_SCI_VERSION 18081 -#define IDC_COMPILER 18082 -#define IDC_COPYRIGHT 18083 -#define IDC_WEBPAGE2 18084 -#define IDC_WEBPAGE 18085 -#define IDR_RIZBITMAP 18086 -#define IDC_RIZONEBMP 18087 -#define IDC_COPYVERSTRG 18088 -#define IDC_RICHEDITABOUT 18089 -#define IDC_TRANSL_AUTH 18090 +#define IDC_EOLMODELIST 18036 +#define IDC_WARNINCONSISTENTEOLS 18037 +#define IDC_CONSISTENTEOLS 18038 +#define IDC_AUTOSTRIPBLANKS 18039 +#define IDC_LINENUM 18040 +#define IDC_COLNUM 18041 +#define IDC_FILEMRU 18042 +#define IDC_PRESERVECARET 18043 +#define IDC_SAVEMRU 18044 +#define IDC_REMOVE 18045 +#define IDC_RESIZEGRIP 18046 +#define IDC_REMEMBERSEARCHPATTERN 18047 +#define IDC_STYLELIST 18048 +#define IDC_DEFAULTSCHEME 18049 +#define IDC_AUTOSELECT 18050 +#define IDC_STYLELABEL_ROOT 18051 +#define IDC_STYLEEDIT_ROOT 18052 +#define IDC_STYLELABEL 18053 +#define IDC_STYLEFORE 18054 +#define IDC_STYLEBACK 18055 +#define IDC_STYLEFONT 18056 +#define IDC_PREVIEW 18057 +#define IDC_STYLEDEFAULT 18058 +#define IDC_PREVSTYLE 18059 +#define IDC_NEXTSTYLE 18060 +#define IDC_IMPORT 18061 +#define IDC_EXPORT 18062 +#define IDC_TITLE 18063 +#define IDC_STYLEEDIT 18064 +#define IDC_PRINTER 18065 +#define IDC_FAVORITESDIR 18066 +#define IDC_GETFAVORITESDIR 18067 +#define IDC_FAVORITESDESCR 18068 +#define IDC_PWD_EDIT1 18069 +#define IDC_PWD_EDIT2 18070 +#define IDC_PWD_EDIT3 18071 +#define IDC_PWD_CHECK1 18072 +#define IDC_PWD_CHECK2 18073 +#define IDC_PWD_CHECK3 18074 +#define IDC_PWD_CHECK4 18075 +#define IDC_PWD_STATMPW 18076 +#define IDC_COLUMNWRAP 18077 +#define IDC_INFOBOXTEXT 18078 +#define IDC_INFOBOXCHECK 18079 +#define IDC_INFOBOXICON 18080 +#define IDC_RESIZEGRIP4 18081 +#define IDC_VERSION 18082 +#define IDC_SCI_VERSION 18083 +#define IDC_COMPILER 18084 +#define IDC_COPYRIGHT 18085 +#define IDC_WEBPAGE2 18086 +#define IDC_WEBPAGE 18087 +#define IDR_RIZBITMAP 18088 +#define IDC_RIZONEBMP 18089 +#define IDC_COPYVERSTRG 18090 +#define IDC_RICHEDITABOUT 18091 +#define IDC_TRANSL_AUTH 18092 #define CMD_ESCAPE 20000 #define CMD_SHIFTESC 20001 @@ -390,7 +393,6 @@ #define IDM_EDIT_MOVELINEUP 40313 #define IDM_EDIT_MOVELINEDOWN 40314 #define IDM_EDIT_DUPLINEORSELECTION 40315 -//#define IDM_EDIT_SELECTIONDUPLICATE 40329 #define IDM_EDIT_LINETRANSPOSE 40316 #define IDM_EDIT_CUTLINE 40317 #define IDM_EDIT_COPYLINE 40318 diff --git a/language/np3_af_za/dialogs_af_za.rc b/language/np3_af_za/dialogs_af_za.rc index fb3846f58..95a8550b3 100644 Binary files a/language/np3_af_za/dialogs_af_za.rc and b/language/np3_af_za/dialogs_af_za.rc differ diff --git a/language/np3_af_za/strings_af_za.rc b/language/np3_af_za/strings_af_za.rc index 3cd4dd737..7ab756338 100644 Binary files a/language/np3_af_za/strings_af_za.rc and b/language/np3_af_za/strings_af_za.rc differ diff --git a/language/np3_de_de/dialogs_de_de.rc b/language/np3_de_de/dialogs_de_de.rc index eace6a0c4..ba8b4420c 100644 Binary files a/language/np3_de_de/dialogs_de_de.rc and b/language/np3_de_de/dialogs_de_de.rc differ diff --git a/language/np3_de_de/strings_de_de.rc b/language/np3_de_de/strings_de_de.rc index 0d77ee7cc..45511ff09 100644 Binary files a/language/np3_de_de/strings_de_de.rc and b/language/np3_de_de/strings_de_de.rc differ diff --git a/language/np3_en_gb/dialogs_en_gb.rc b/language/np3_en_gb/dialogs_en_gb.rc index 73566709a..d880cb7b7 100644 Binary files a/language/np3_en_gb/dialogs_en_gb.rc and b/language/np3_en_gb/dialogs_en_gb.rc differ diff --git a/language/np3_en_gb/strings_en_gb.rc b/language/np3_en_gb/strings_en_gb.rc index 1d664fd99..928bd6a1a 100644 Binary files a/language/np3_en_gb/strings_en_gb.rc and b/language/np3_en_gb/strings_en_gb.rc differ diff --git a/language/np3_en_us/dialogs_en_us.rc b/language/np3_en_us/dialogs_en_us.rc index d20f05778..ef31d673c 100644 Binary files a/language/np3_en_us/dialogs_en_us.rc and b/language/np3_en_us/dialogs_en_us.rc differ diff --git a/language/np3_en_us/strings_en_us.rc b/language/np3_en_us/strings_en_us.rc index af6ac5682..d36c2fc1b 100644 Binary files a/language/np3_en_us/strings_en_us.rc and b/language/np3_en_us/strings_en_us.rc differ diff --git a/language/np3_es_es/dialogs_es_es.rc b/language/np3_es_es/dialogs_es_es.rc index 995f3960b..422ea1588 100644 Binary files a/language/np3_es_es/dialogs_es_es.rc and b/language/np3_es_es/dialogs_es_es.rc differ diff --git a/language/np3_es_es/strings_es_es.rc b/language/np3_es_es/strings_es_es.rc index 404e034a5..629895aa2 100644 Binary files a/language/np3_es_es/strings_es_es.rc and b/language/np3_es_es/strings_es_es.rc differ diff --git a/language/np3_fr_fr/dialogs_fr_fr.rc b/language/np3_fr_fr/dialogs_fr_fr.rc index add0429be..a38a59a4c 100644 Binary files a/language/np3_fr_fr/dialogs_fr_fr.rc and b/language/np3_fr_fr/dialogs_fr_fr.rc differ diff --git a/language/np3_fr_fr/strings_fr_fr.rc b/language/np3_fr_fr/strings_fr_fr.rc index 8695b9ff9..2cc2d93ad 100644 Binary files a/language/np3_fr_fr/strings_fr_fr.rc and b/language/np3_fr_fr/strings_fr_fr.rc differ diff --git a/language/np3_ja_jp/dialogs_ja_jp.rc b/language/np3_ja_jp/dialogs_ja_jp.rc index 1c11c7f36..d343028d3 100644 Binary files a/language/np3_ja_jp/dialogs_ja_jp.rc and b/language/np3_ja_jp/dialogs_ja_jp.rc differ diff --git a/language/np3_ja_jp/strings_ja_jp.rc b/language/np3_ja_jp/strings_ja_jp.rc index 88bd24ca7..ba1fd8932 100644 Binary files a/language/np3_ja_jp/strings_ja_jp.rc and b/language/np3_ja_jp/strings_ja_jp.rc differ diff --git a/language/np3_nl_nl/dialogs_nl_nl.rc b/language/np3_nl_nl/dialogs_nl_nl.rc index 18507f6f2..1789dff4c 100644 Binary files a/language/np3_nl_nl/dialogs_nl_nl.rc and b/language/np3_nl_nl/dialogs_nl_nl.rc differ diff --git a/language/np3_nl_nl/strings_nl_nl.rc b/language/np3_nl_nl/strings_nl_nl.rc index a99542821..100bb28ef 100644 Binary files a/language/np3_nl_nl/strings_nl_nl.rc and b/language/np3_nl_nl/strings_nl_nl.rc differ diff --git a/language/np3_zh_cn/dialogs_zh_cn.rc b/language/np3_zh_cn/dialogs_zh_cn.rc index 399ef1538..a4890cc1b 100644 Binary files a/language/np3_zh_cn/dialogs_zh_cn.rc and b/language/np3_zh_cn/dialogs_zh_cn.rc differ diff --git a/language/np3_zh_cn/strings_zh_cn.rc b/language/np3_zh_cn/strings_zh_cn.rc index da04bbbbd..b7cece689 100644 Binary files a/language/np3_zh_cn/strings_zh_cn.rc and b/language/np3_zh_cn/strings_zh_cn.rc differ diff --git a/src/AccelKeys.c b/src/AccelKeys.c new file mode 100644 index 000000000..96e4d299b --- /dev/null +++ b/src/AccelKeys.c @@ -0,0 +1,285 @@ +/****************************************************************************** +* * +* * +* Notepad3 * +* * +* AccelKeys.c * +* Load Accelerator Keys at Runtime * +* * +* * +* (c) Rizonesoft 2015-2018 * +* https://rizonesoft.com * +* * +*******************************************************************************/ + +// https://docs.microsoft.com/en-us/windows/desktop/menurc/using-keyboard-accelerators + +// ============================================================================ + +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ +#endif +#define VC_EXTRALEAN 1 +#define WIN32_LEAN_AND_MEAN 1 +#include + +#include "resource.h" + +#include "AccelKeys.h" + +// ============================================================================ + +// typedef struct tagACCEL { +// BYTE fVirt; // FVIRTKEY (else ASCII code) | FNOINVERT | FCONTROL | FALT | FSHIFT +// WORD key; // ASCII character code or a virtual-key code +// WORD cmd; +// } ACCEL, *LPACCEL; + +typedef struct _CMDNAMEIDMAP +{ + char* pCmdName; + int ridStrgTbl; + ACCEL accel; +} +CMD_NAME_ID_MAP, *LP_CMD_NAME_ID_MAP; + + +// ============================================================================ + +CMD_NAME_ID_MAP NP3_ACCEL_KEY_MAP[] = { + { "CMD_DUPLINEORSEL", 0, { (FVIRTKEY | FNOINVERT), 0 , IDM_EDIT_DUPLINEORSELECTION } } + ,{ "CMD_TRANSPLINES", 0, { (FVIRTKEY | FNOINVERT), 0 , IDM_EDIT_LINETRANSPOSE } } +}; + + + + + +// ============================================================================ +// VKey Lookup Support +// ---------------------------------------------------------------------------- + +#define MAXKEYS 25 + +typedef struct _VKEYS +{ + char *pKeyName; + char *pKeyString; +} VKEYS; + +VKEYS vkeys[MAXKEYS] = { + "BkSp", "Back Space", + "PgUp", "Page Up", + "PgDn", "Page Down", + "End", "End", + "Home", "Home", + "Lft", "Left", + "Up", "Up", + "Rgt", "Right", + "Dn", "Down", + "Ins", "Insert", + "Del", "Delete", + "Mult", "Multiply", + "Add", "Add", + "Sub", "Subtract", + "DecPt", "Decimal Point", + "Div", "Divide", + "F2", "F2", + "F3", "F3", + "F5", "F5", + "F6", "F6", + "F7", "F7", + "F8", "F8", + "F9", "F9", + "F11", "F11", + "F12", "F12" +}; +// ============================================================================ + + +// ============================================================================ +// ============================================================================ +// Constant value Description +// ---------------------------------------------- - +// VK_LBUTTON 0x01 Left mouse button +// VK_RBUTTON 0x02 Right mouse button +// VK_CANCEL 0x03 Control - break processing +// VK_MBUTTON 0x04 Middle mouse button(three - button mouse) +// VK_XBUTTON1 0x05 X1 mouse button +// VK_XBUTTON2 0x06 X2 mouse button +// - 0x07 Undefined +// VK_BACK 0x08 BACKSPACE key +// VK_TAB 0x09 TAB key +// - 0x0A-0B Reserved +// VK_CLEAR 0x0C CLEAR key +// VK_RETURN 0x0D ENTER key +// - 0x0E - 0F Undefined +// VK_SHIFT 0x10 SHIFT key +// VK_CONTROL 0x11 CTRL key +// VK_MENU 0x12 ALT key +// VK_PAUSE 0x13 PAUSE key +// VK_CAPITAL 0x14 CAPS LOCK key +// VK_KANA 0x15 IME Kana mode +// VK_HANGUEL 0x15 IME Hanguel mode(maintained for compatibility; use VK_HANGUL) +// VK_HANGUL 0x15 IME Hangul mode +// - 0x16 Undefined +// VK_JUNJA 0x17 IME Junja mode +// VK_FINAL 0x18 IME final mode +// VK_HANJA 0x19 IME Hanja mode +// VK_KANJI 0x19 IME Kanji mode +// - 0x1A Undefined +// VK_ESCAPE 0x1B ESC key +// VK_CONVERT 0x1C IME convert +// VK_NONCONVERT 0x1D IME nonconvert +// VK_ACCEPT 0x1E IME accept +// VK_MODECHANGE 0x1F IME mode change request +// VK_SPACE 0x20 SPACEBAR +// VK_PRIOR 0x21 PAGE UP key +// VK_NEXT 0x22 PAGE DOWN key +// VK_END 0x23 END key +// VK_HOME 0x24 HOME key +// VK_LEFT 0x25 LEFT ARROW key +// VK_UP 0x26 UP ARROW key +// VK_RIGHT 0x27 RIGHT ARROW key +// VK_DOWN 0x28 DOWN ARROW key +// VK_SELECT 0x29 SELECT key +// VK_PRINT 0x2A PRINT key +// VK_EXECUTE 0x2B EXECUTE key +// VK_SNAPSHOT 0x2C PRINT SCREEN key +// VK_INSERT 0x2D INS key +// VK_DELETE 0x2E DEL key +// VK_HELP 0x2F HELP key +// - 0x30 Undefined +// - 0x30 - 39 0 - 9 key +// - 0x3A - 40 Undefined +// - 0x41 - 5A A - Z key +// VK_LWIN 0x5B Left Windows key(Natural keyboard) +// VK_RWIN 0x5C Right Windows key(Natural keyboard) +// VK_APPS 0x5D Applications key(Natural keyboard) +// - 0x5E Reserved +// VK_SLEEP 0x5F Computer Sleep key +// VK_NUMPAD0 0x60 Numeric keypad 0 key +// VK_NUMPAD1 0x61 Numeric keypad 1 key +// VK_NUMPAD2 0x62 Numeric keypad 2 key +// VK_NUMPAD3 0x63 Numeric keypad 3 key +// VK_NUMPAD4 0x64 Numeric keypad 4 key +// VK_NUMPAD5 0x65 Numeric keypad 5 key +// VK_NUMPAD6 0x66 Numeric keypad 6 key +// VK_NUMPAD7 0x67 Numeric keypad 7 key +// VK_NUMPAD8 0x68 Numeric keypad 8 key +// VK_NUMPAD9 0x69 Numeric keypad 9 key +// VK_MULTIPLY 0x6A Multiply key +// VK_ADD 0x6B Add key +// VK_SEPARATOR 0x6C Separator key +// VK_SUBTRACT 0x6D Subtract key +// VK_DECIMAL 0x6E Decimal key +// VK_DIVIDE 0x6F Divide key +// VK_F1 0x70 F1 key +// VK_F2 0x71 F2 key +// VK_F3 0x72 F3 key +// VK_F4 0x73 F4 key +// VK_F5 0x74 F5 key +// VK_F6 0x75 F6 key +// VK_F7 0x76 F7 key +// VK_F8 0x77 F8 key +// VK_F9 0x78 F9 key +// VK_F10 0x79 F10 key +// VK_F11 0x7A F11 key +// VK_F12 0x7B F12 key +// VK_F13 0x7C F13 key +// VK_F14 0x7D F14 key +// VK_F15 0x7E F15 key +// VK_F16 0x7F F16 key +// VK_F17 0x80 F17 key +// VK_F18 0x81 F18 key +// VK_F19 0x82 F19 key +// VK_F20 0x83 F20 key +// VK_F21 0x84 F21 key +// VK_F22 0x85 F22 key +// VK_F23 0x86 F23 key +// VK_F24 0x87 F24 key +// - 0x88 - 8F Unassigned +// VK_NUMLOCK 0x90 NUM LOCK key +// VK_SCROLL 0x91 SCROLL LOCK key +// - 0x92 - 96 OEM specific +// - 0x97 - 9F Unassigned +// VK_LSHIFT 0xA0 Left SHIFT key +// VK_RSHIFT 0xA1 Right SHIFT key +// VK_LCONTROL 0xA2 Left CONTROL key +// VK_RCONTROL 0xA3 Right CONTROL key +// VK_LMENU 0xA4 Left MENU key +// VK_RMENU 0xA5 Right MENU key +// VK_BROWSER_BACK 0xA6 Browser Back key +// VK_BROWSER_FORWARD 0xA7 Browser Forward key +// VK_BROWSER_REFRESH 0xA8 Browser Refresh key +// VK_BROWSER_STOP 0xA9 Browser Stop key +// VK_BROWSER_SEARCH 0xAA Browser Search key +// VK_BROWSER_FAVORITES 0xAB Browser Favorites key +// VK_BROWSER_HOME 0xAC Browser Start and Home key +// VK_VOLUME_MUTE 0xAD Volume Mute key +// VK_VOLUME_DOWN 0xAE Volume Down key +// VK_VOLUME_UP 0xAF Volume Up key +// VK_MEDIA_NEXT_TRACK 0xB0 Next Track key +// VK_MEDIA_PREV_TRACK 0xB1 Previous Track key +// VK_MEDIA_STOP 0xB2 Stop Media key +// VK_MEDIA_PLAY_PAUSE 0xB3 Play / Pause Media key +// VK_LAUNCH_MAIL 0xB4 Start Mail key +// VK_LAUNCH_MEDIA_SELECT 0xB5 Select Media key +// VK_LAUNCH_APP1 0xB6 Start Application 1 key +// VK_LAUNCH_APP2 0xB7 Start Application 2 key +// - 0xB8 - B9 Reserved +// VK_OEM_1 0xBA Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the ';:' key +// VK_OEM_PLUS 0xBB For any country / region, the '+' key +// VK_OEM_COMMA 0xBC For any country / region, the ',' key +// VK_OEM_MINUS 0xBD For any country / region, the '-' key +// VK_OEM_PERIOD 0xBE For any country / region, the '.' key +// VK_OEM_2 0xBF Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the '/?' key +// VK_OEM_3 0xC0 Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the '`~' key +// - 0xC1 - D7 Reserved +// - 0xD8 - DA Unassigned +// VK_OEM_4 0xDB Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the '[{' key +// VK_OEM_5 0xDC Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the '\|' key +// VK_OEM_6 0xDD Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the ']}' key +// VK_OEM_7 0xDE Used for miscellaneous characters; it can vary by keyboard.For the US standard keyboard, the 'single-quote/double-quote' key +// VK_OEM_8 0xDF Used for miscellaneous characters; it can vary by keyboard. +// - 0xE0 Reserved +// - 0xE1 OEM specific +// VK_OEM_102 0xE2 Either the angle bracket key or the backslash key on the RT 102 - key keyboard +// - 0xE3 - E4 OEM specific +// - 0xE4 OEM specific +// VK_PROCESSKEY 0xE5 IME PROCESS key +// - 0xE6 OEM specific +// VK_PACKET 0xE7 Used to pass Unicode characters as if they were keystrokes.The VK_PACKET key is the low word of a 32 - bit Virtual Key value used for non - keyboard input methods.For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP +// - 0xE8 Unassigned +// - 0xE9 - F5 OEM specific +// VK_ATTN 0xF6 Attn key +// VK_CRSEL 0xF7 CrSel key +// VK_EXSEL 0xF8 ExSel key +// VK_EREOF 0xF9 Erase EOF key +// VK_PLAY 0xFA Play key +// VK_ZOOM 0xFB Zoom key +// VK_NONAME 0xFC Reserved +// VK_PA1 0xFD PA1 key +// VK_OEM_CLEAR 0xFE Clear key +// ============================================================================ + +// Sytem-Wide Accelerators +// --------------------------- +// ALT + ESC Switches to the next application. +// ALT + F4 Closes an application or a window. +// ALT + HYPHEN Opens the Window menu for a document window. +// ALT + PRINT SCREEN Copies an image in the active window onto the clipboard. +// ALT + SPACEBAR Opens the Window menu for the application's main window. +// ALT + TAB Switches to the next application. +// CTRL + ESC Switches to the Start menu. +// CTRL + F4 Closes the active group or document window. +// F1 Starts the application's help file, if one exists. +// PRINT SCREEN Copies an image on the screen onto the clipboard. +// SHIFT + ALT + TAB Switches to the previous application.The user must press and hold down ALT + SHIFT while pressing TAB. + diff --git a/src/AccelKeys.h b/src/AccelKeys.h new file mode 100644 index 000000000..7ad3f8ea0 --- /dev/null +++ b/src/AccelKeys.h @@ -0,0 +1,33 @@ +/****************************************************************************** +* * +* * +* Notepad3 * +* * +* AccelKeys.h * +* Load Accelerator Keys at Runtime * +* * +* (c) Rizonesoft 2008-2018 * +* https://rizonesoft.com * +* * +* * +*******************************************************************************/ + +#pragma once +#ifndef _ACCELKEYS_H_ +#define _ACCELKEYS_H_ + +// ============================================================================ + + + + +// ---------------------------------------------------------------------------- + + + + + + +// ============================================================================ + +#endif //_ACCELKEYS_H_ diff --git a/src/Dialogs.c b/src/Dialogs.c index 3ee32ece5..c49c01bbe 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2464,13 +2464,10 @@ bool RecodeDlg(HWND hwnd,int *pidREncoding) // // SelectDefLineEndingDlgProc() // -// Controls: 100 Combo -// IDC_CONSISTENTEOLS -// IDC_AUTOSTRIPBLANKS // INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) { - static int *piOption; + static int* piOption; switch(umsg) { @@ -2486,12 +2483,13 @@ INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LP // Load options for (i = 0; i < 3; i++) { GetLngString(IDS_EOL_WIN+i,wch,COUNTOF(wch)); - SendDlgItemMessage(hwnd,100,CB_ADDSTRING,0,(LPARAM)wch); + SendDlgItemMessage(hwnd, IDC_EOLMODELIST,CB_ADDSTRING,0,(LPARAM)wch); } - SendDlgItemMessage(hwnd,100,CB_SETCURSEL,(WPARAM)*piOption,0); - SendDlgItemMessage(hwnd,100,CB_SETEXTENDEDUI,true,0); + SendDlgItemMessage(hwnd, IDC_EOLMODELIST,CB_SETCURSEL,(WPARAM)*piOption,0); + SendDlgItemMessage(hwnd, IDC_EOLMODELIST,CB_SETEXTENDEDUI,true,0); + CheckDlgButton(hwnd,IDC_WARNINCONSISTENTEOLS, DlgBtnChk(Settings.WarnInconsistEOLs)); CheckDlgButton(hwnd,IDC_CONSISTENTEOLS, DlgBtnChk(Settings.FixLineEndings)); CheckDlgButton(hwnd,IDC_AUTOSTRIPBLANKS, DlgBtnChk(Settings.FixTrailingBlanks)); @@ -2504,7 +2502,8 @@ INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LP switch(LOWORD(wParam)) { case IDOK: { - *piOption = (int)SendDlgItemMessage(hwnd,100,CB_GETCURSEL,0,0); + *piOption = (int)SendDlgItemMessage(hwnd,IDC_EOLMODELIST,CB_GETCURSEL,0,0); + Settings.WarnInconsistEOLs = (IsDlgButtonChecked(hwnd,IDC_WARNINCONSISTENTEOLS) == BST_CHECKED); Settings.FixLineEndings = (IsDlgButtonChecked(hwnd,IDC_CONSISTENTEOLS) == BST_CHECKED); Settings.FixTrailingBlanks = (IsDlgButtonChecked(hwnd,IDC_AUTOSTRIPBLANKS) == BST_CHECKED); EndDialog(hwnd,IDOK); @@ -2525,20 +2524,15 @@ INT_PTR CALLBACK SelectDefLineEndingDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LP // // SelectDefLineEndingDlg() // -bool SelectDefLineEndingDlg(HWND hwnd,int *iOption) +bool SelectDefLineEndingDlg(HWND hwnd, LPARAM piOption) { + INT_PTR const iResult = ThemedDialogBoxParam(Globals.hLngResContainer, + MAKEINTRESOURCE(IDD_MUI_DEFEOLMODE), + hwnd, + SelectDefLineEndingDlgProc, + piOption); - INT_PTR iResult; - - iResult = ThemedDialogBoxParam( - Globals.hLngResContainer, - MAKEINTRESOURCE(IDD_MUI_DEFEOLMODE), - hwnd, - SelectDefLineEndingDlgProc, - (LPARAM)iOption); - - return (iResult == IDOK) ? true : false; - + return (iResult == IDOK); } @@ -3532,9 +3526,10 @@ DLGTEMPLATE* LoadThemedDialogTemplate(LPCTSTR lpDialogTemplateID, HINSTANCE hIns INT_PTR ThemedDialogBoxParam(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { + INT_PTR ret = IDABORT; DLGTEMPLATE* pDlgTemplate = LoadThemedDialogTemplate(lpTemplate, hInstance); - INT_PTR ret = DialogBoxIndirectParam(hInstance, pDlgTemplate, hWndParent, lpDialogFunc, dwInitParam); if (pDlgTemplate) { + ret = DialogBoxIndirectParam(hInstance, pDlgTemplate, hWndParent, lpDialogFunc, dwInitParam); FreeMem(pDlgTemplate); } return ret; @@ -3543,9 +3538,10 @@ INT_PTR ThemedDialogBoxParam(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndP HWND CreateThemedDialogParam(HINSTANCE hInstance, LPCTSTR lpTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam) { + HWND hwnd = INVALID_HANDLE_VALUE; DLGTEMPLATE* pDlgTemplate = LoadThemedDialogTemplate(lpTemplate, hInstance); - HWND hwnd = CreateDialogIndirectParam(hInstance, pDlgTemplate, hWndParent, lpDialogFunc, dwInitParam); if (pDlgTemplate) { + hwnd = CreateDialogIndirectParam(hInstance, pDlgTemplate, hWndParent, lpDialogFunc, dwInitParam); FreeMem(pDlgTemplate); } return(hwnd); diff --git a/src/Dialogs.h b/src/Dialogs.h index 89b02775a..b552e3ee0 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -35,7 +35,7 @@ bool TabSettingsDlg(HWND,UINT,int *); bool SelectDefEncodingDlg(HWND,int *); bool SelectEncodingDlg(HWND,int *); bool RecodeDlg(HWND,int *); -bool SelectDefLineEndingDlg(HWND,int *); +bool SelectDefLineEndingDlg(HWND,LPARAM); bool GetMonitorInfoFromRect(const RECT* rc, MONITORINFO* hMonitorInfo); void WinInfoToScreen(WININFO*); diff --git a/src/Edit.c b/src/Edit.c index 790006f1c..6ae8c51c3 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -856,36 +856,64 @@ bool EditCopyAppend(HWND hwnd, bool bAppend) //============================================================================= // -// EditDetectEOLMode() - moved here to handle Unicode files correctly +// EditDetectEOLMode() - moved here to handle Unicode files correctly +// by zufuliu (https://github.com/zufuliu/notepad2) // -int EditDetectEOLMode(HWND hwnd, char* lpData) +void EditDetectEOLMode(LPCSTR lpData, DWORD cbData, EditFileIOStatus* status) { - UNUSED(hwnd); int iEOLMode = Settings.DefaultEOLMode; - LPCSTR cp = lpData ? StrPBrkA(lpData, "\r\n") : NULL; - - if (!cp) { - return iEOLMode; + if (cbData == 0) { + status->iEOLMode = iEOLMode; + return; } - if (*cp == '\r') { - if (*(cp + 1) == '\n') { - iEOLMode = SC_EOL_CRLF; - } - else { - iEOLMode = SC_EOL_CR; + DocLn linesCount[3] = { 0, 0, 0 }; + + LPCSTR cp = lpData; + LPCSTR const end = cp + cbData; + while (cp < end) { + switch (*cp) { + case '\n': + ++cp; + ++linesCount[SC_EOL_LF]; + break; + case '\r': + ++cp; + if (*cp == '\n') { + ++cp; + ++linesCount[SC_EOL_CRLF]; + } + else { + ++linesCount[SC_EOL_CR]; + } + break; + default: + ++cp; + break; } } + + DocLn const linesMax = max_ln(max_ln(linesCount[0], linesCount[1]), linesCount[2]); + + if (linesMax == linesCount[SC_EOL_CRLF]) { + iEOLMode = SC_EOL_CRLF; + } + else if (linesMax == linesCount[SC_EOL_CR]) { + iEOLMode = SC_EOL_CR; + } else { iEOLMode = SC_EOL_LF; } - return iEOLMode; + status->iEOLMode = iEOLMode; + status->bInconsistent = ((!!linesCount[0]) + (!!linesCount[1]) + (!!linesCount[2])) > 1; + status->linesCount[SC_EOL_CRLF] = linesCount[SC_EOL_CRLF]; + status->linesCount[SC_EOL_CR] = linesCount[SC_EOL_CR]; + status->linesCount[SC_EOL_LF] = linesCount[SC_EOL_LF]; } - //============================================================================= // // EditLoadFile() @@ -895,18 +923,11 @@ bool EditLoadFile( LPWSTR pszFile, bool bSkipUTFDetection, bool bSkipANSICPDetection, - int* iEncoding, - int* iEOLMode, - bool *pbUnicodeErr, - bool *pbFileTooBig, - bool *pbUnkownExt) + EditFileIOStatus* status) { - if (pbUnicodeErr) - *pbUnicodeErr = false; - if (pbFileTooBig) - *pbFileTooBig = false; - if (pbUnkownExt) - *pbUnkownExt = false; + status->bUnicodeErr = false; + status->bFileTooBig = false; + status->bUnknownExt = false; HANDLE hFile = CreateFile(pszFile, GENERIC_READ, @@ -932,8 +953,7 @@ bool EditLoadFile( if (!Style_HasLexerForExt(lpszExt)) { if (InfoBoxLng(MBYESNO,L"MsgFileUnknownExt",IDS_MUI_WARN_UNKNOWN_EXT,lpszExt) != IDYES) { CloseHandle(hFile); - if (pbUnkownExt) - *pbUnkownExt = true; + status->bUnknownExt = true; Encoding_SrcCmdLn(CPI_NONE); Encoding_SrcWeak(CPI_NONE); return false; @@ -945,8 +965,7 @@ bool EditLoadFile( if ((dwFileSizeLimit != 0) && ((dwFileSizeLimit * 1024 * 1024) < dwFileSize)) { if (InfoBoxLng(MBYESNO,L"MsgFileSizeWarning",IDS_MUI_WARN_LOAD_BIG_FILE) != IDYES) { CloseHandle(hFile); - if (pbFileTooBig) - *pbFileTooBig = true; + status->bFileTooBig = true; Encoding_SrcCmdLn(CPI_NONE); Encoding_SrcWeak(CPI_NONE); return false; @@ -972,8 +991,7 @@ bool EditLoadFile( if (!lpData) { CloseHandle(hFile); - if (pbFileTooBig) - *pbFileTooBig = false; + status->bFileTooBig = true; Encoding_SrcCmdLn(CPI_NONE); Encoding_SrcWeak(CPI_NONE); return false; @@ -986,7 +1004,6 @@ bool EditLoadFile( bool bReadSuccess = ((readFlag & DECRYPT_FATAL_ERROR) || (readFlag & DECRYPT_FREAD_FAILED)) ? false : true; // ((readFlag == DECRYPT_SUCCESS) || (readFlag & DECRYPT_NO_ENCRYPTION)) => true; - if ((readFlag & DECRYPT_CANCELED_NO_PASS) || (readFlag & DECRYPT_WRONG_PASS)) { bReadSuccess = (InfoBoxLng(MBOKCANCEL, L"MsgNoOrWrongPassphrase", IDS_MUI_NOPASS) == IDOK); @@ -1068,8 +1085,9 @@ bool EditLoadFile( if (cbData == 0) { FileVars_Init(NULL,0,&g_fvCurFile); - *iEOLMode = Settings.DefaultEOLMode; - *iEncoding = !Encoding_IsNONE(iForcedEncoding) ? iForcedEncoding : (Settings.LoadASCIIasUTF8 ? CPI_UTF8 : iPreferedEncoding); + status->iEOLMode = Settings.DefaultEOLMode; + status->iEncoding = !Encoding_IsNONE(iForcedEncoding) ? iForcedEncoding : + (Settings.LoadASCIIasUTF8 ? CPI_UTF8 : iPreferedEncoding); EditSetNewText(hwnd,"",0); SciCall_SetEOLMode(Settings.DefaultEOLMode); FreeMem(lpData); @@ -1094,10 +1112,10 @@ bool EditLoadFile( if (bReverse) { _swab(lpData,lpData,cbData); - *iEncoding = (bBOM ? CPI_UNICODEBEBOM : CPI_UNICODEBE); + status->iEncoding = (bBOM ? CPI_UNICODEBEBOM : CPI_UNICODEBE); } else { - *iEncoding = (bBOM ? CPI_UNICODEBOM : CPI_UNICODE); + status->iEncoding = (bBOM ? CPI_UNICODEBOM : CPI_UNICODE); } char* lpDataUTF8 = AllocMem((cbData * 3) + 2, HEAP_ZERO_MEMORY); @@ -1106,8 +1124,7 @@ bool EditLoadFile( (bBOM) ? (cbData)/sizeof(WCHAR) : cbData/sizeof(WCHAR) + 1,lpDataUTF8,(MBWC_DocPos_Cast)SizeOfMem(lpDataUTF8),NULL,NULL); if (convCnt == 0) { - if (pbUnicodeErr) - *pbUnicodeErr = true; + status->bUnicodeErr = true; convCnt = (DWORD)WideCharToMultiByte(CP_ACP,0,(bBOM) ? (LPWSTR)lpData + 1 : (LPWSTR)lpData, (-1),lpDataUTF8,(MBWC_DocPos_Cast)SizeOfMem(lpDataUTF8),NULL,NULL); } @@ -1117,7 +1134,7 @@ bool EditLoadFile( EditSetNewText(hwnd,"",0); FileVars_Init(lpDataUTF8,convCnt - 1,&g_fvCurFile); EditSetNewText(hwnd,lpDataUTF8,convCnt - 1); - *iEOLMode = EditDetectEOLMode(hwnd,lpDataUTF8); + EditDetectEOLMode(lpDataUTF8, convCnt - 1, status); FreeMem(lpDataUTF8); } else { @@ -1149,13 +1166,13 @@ bool EditLoadFile( EditSetNewText(hwnd,"",0); if (bIsUTF8Sig) { EditSetNewText(hwnd,UTF8StringStart(lpData),cbData-3); - *iEncoding = CPI_UTF8SIGN; - *iEOLMode = EditDetectEOLMode(hwnd,UTF8StringStart(lpData)); + status->iEncoding = CPI_UTF8SIGN; + EditDetectEOLMode(UTF8StringStart(lpData), cbData - 3, status); } else { EditSetNewText(hwnd,lpData,cbData); - *iEncoding = CPI_UTF8; - *iEOLMode = EditDetectEOLMode(hwnd,lpData); + status->iEncoding = CPI_UTF8; + EditDetectEOLMode(lpData, cbData, status); } FreeMem(lpData); } @@ -1163,19 +1180,19 @@ bool EditLoadFile( else { // === ALL OTHER === if (!Encoding_IsNONE(iForcedEncoding)) - *iEncoding = iForcedEncoding; + status->iEncoding = iForcedEncoding; else { - *iEncoding = FileVars_GetEncoding(&g_fvCurFile); - if (Encoding_IsNONE(*iEncoding)) + status->iEncoding = FileVars_GetEncoding(&g_fvCurFile); + if (Encoding_IsNONE(status->iEncoding)) { - *iEncoding = ((g_fvCurFile.mask & FV_ENCODING) ? CPI_ANSI_DEFAULT : iPreferedEncoding); + status->iEncoding = ((g_fvCurFile.mask & FV_ENCODING) ? CPI_ANSI_DEFAULT : iPreferedEncoding); } } - if (((Encoding_GetCodePage(*iEncoding) != CP_UTF7) && Encoding_IsEXTERNAL_8BIT(*iEncoding)) || - ((Encoding_GetCodePage(*iEncoding) == CP_UTF7) && IsValidUTF7(lpData,cbData))) { + if (((Encoding_GetCodePage(status->iEncoding) != CP_UTF7) && Encoding_IsEXTERNAL_8BIT(status->iEncoding)) || + ((Encoding_GetCodePage(status->iEncoding) == CP_UTF7) && IsValidUTF7(lpData,cbData))) { - UINT uCodePage = Encoding_GetCodePage(*iEncoding); + UINT uCodePage = Encoding_GetCodePage(status->iEncoding); LPWSTR lpDataWide = AllocMem(cbData * 2 + 16, HEAP_ZERO_MEMORY); int const cbDataWide = MultiByteToWideChar(uCodePage,0,lpData,cbData,lpDataWide,(MBWC_DocPos_Cast)(SizeOfMem(lpDataWide)/sizeof(WCHAR))); @@ -1189,7 +1206,7 @@ bool EditLoadFile( FreeMem(lpDataWide); EditSetNewText(hwnd,"",0); EditSetNewText(hwnd,lpData,cbData); - *iEOLMode = EditDetectEOLMode(hwnd,lpData); + EditDetectEOLMode(lpData, cbData, status); FreeMem(lpData); } else { @@ -1209,10 +1226,10 @@ bool EditLoadFile( } } else { - *iEncoding = Encoding_IsValid(iForcedEncoding) ? iForcedEncoding : iPreferedEncoding; + status->iEncoding = Encoding_IsValid(iForcedEncoding) ? iForcedEncoding : iPreferedEncoding; EditSetNewText(hwnd,"",0); EditSetNewText(hwnd,lpData,cbData); - *iEOLMode = EditDetectEOLMode(hwnd,lpData); + EditDetectEOLMode(lpData, cbData, status); FreeMem(lpData); } } @@ -1232,8 +1249,7 @@ bool EditLoadFile( bool EditSaveFile( HWND hwnd, LPCWSTR pszFile, - int iEncoding, - bool *pbCancelDataLoss, + EditFileIOStatus* status, bool bSaveCopy) { @@ -1244,7 +1260,7 @@ bool EditSaveFile( DWORD cbData; DWORD dwBytesWritten; - *pbCancelDataLoss = false; + status->bCancelDataLoss = false; hFile = CreateFile(pszFile, GENERIC_WRITE, @@ -1321,13 +1337,13 @@ bool EditSaveFile( } }*/ - if (Encoding_IsUNICODE(iEncoding)) + if (Encoding_IsUNICODE(status->iEncoding)) { SetEndOfFile(hFile); LPWSTR lpDataWide = AllocMem(cbData * 2 + 16, HEAP_ZERO_MEMORY); int bomoffset = 0; - if (Encoding_IsUNICODE_BOM(iEncoding)) { + if (Encoding_IsUNICODE_BOM(status->iEncoding)) { const char* bom = "\xFF\xFE"; CopyMemory((char*)lpDataWide, bom, 2); bomoffset = 1; @@ -1335,7 +1351,7 @@ bool EditSaveFile( int const cbDataWide = bomoffset + MultiByteToWideChar(Encoding_SciCP, 0, lpData, cbData, &lpDataWide[bomoffset], (MBWC_DocPos_Cast)((SizeOfMem(lpDataWide) / sizeof(WCHAR)) - bomoffset)); - if (Encoding_IsUNICODE_REVERSE(iEncoding)) { + if (Encoding_IsUNICODE_REVERSE(status->iEncoding)) { _swab((char*)lpDataWide, (char*)lpDataWide, cbDataWide * sizeof(WCHAR)); } bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpDataWide, cbDataWide * sizeof(WCHAR), &dwBytesWritten); @@ -1345,11 +1361,11 @@ bool EditSaveFile( FreeMem(lpData); } - else if (Encoding_IsUTF8(iEncoding)) + else if (Encoding_IsUTF8(status->iEncoding)) { SetEndOfFile(hFile); - if (Encoding_IsUTF8_SIGN(iEncoding)) { + if (Encoding_IsUTF8_SIGN(status->iEncoding)) { const char* bom = "\xEF\xBB\xBF"; DWORD bomoffset = 3; MoveMemory(&lpData[bomoffset], lpData, cbData); @@ -1363,16 +1379,16 @@ bool EditSaveFile( FreeMem(lpData); } - else if (Encoding_IsEXTERNAL_8BIT(iEncoding)) { + else if (Encoding_IsEXTERNAL_8BIT(status->iEncoding)) { BOOL bCancelDataLoss = FALSE; - UINT uCodePage = Encoding_GetCodePage(iEncoding); + UINT uCodePage = Encoding_GetCodePage(status->iEncoding); LPWSTR lpDataWide = AllocMem(cbData * 2 + 16, HEAP_ZERO_MEMORY); int cbDataWide = MultiByteToWideChar(Encoding_SciCP,0,lpData,cbData, lpDataWide,(MBWC_DocPos_Cast)(SizeOfMem(lpDataWide)/sizeof(WCHAR))); - if (Encoding_IsMBCS(iEncoding)) { + if (Encoding_IsMBCS(status->iEncoding)) { FreeMem(lpData); lpData = AllocMem(SizeOfMem(lpDataWide) * 2, HEAP_ZERO_MEMORY); // need more space cbData = WideCharToMultiByte(uCodePage, 0, lpDataWide, cbDataWide, @@ -1397,9 +1413,8 @@ bool EditSaveFile( } else { bWriteSuccess = false; - *pbCancelDataLoss = true; + status->bCancelDataLoss = true; } - FreeMem(lpData); } @@ -5806,8 +5821,9 @@ HWND EditFindReplaceDlg(HWND hwnd,LPCEDITFINDREPLACE lpefr,bool bReplace) EditFindReplaceDlgProcW, (LPARAM) lpefr); - ShowWindow(hDlg,SW_SHOW); - + if (hDlg != INVALID_HANDLE_VALUE) { + ShowWindow(hDlg, SW_SHOW); + } CoUninitialize(); return hDlg; } diff --git a/src/Edit.h b/src/Edit.h index 6b961749c..64160b381 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -31,9 +31,9 @@ bool EditSetClipboardText(HWND hwnd, const char* pszText, size_t cchText); bool EditClearClipboard(HWND hwnd); bool EditSwapClipboard(HWND hwnd,bool); bool EditCopyAppend(HWND hwnd,bool); -int EditDetectEOLMode(HWND hwnd,char* lpData); -bool EditLoadFile(HWND hwnd,LPWSTR pszFile,bool,bool,int* iEncoding,int* iEOLMode,bool*,bool*,bool*); -bool EditSaveFile(HWND hwnd,LPCWSTR pszFile,int iEncoding,bool*,bool); +void EditDetectEOLMode(LPCSTR lpData, DWORD cbData, EditFileIOStatus* status); +bool EditLoadFile(HWND hwnd, LPWSTR pszFile, bool, bool, EditFileIOStatus* status); +bool EditSaveFile(HWND hwnd,LPCWSTR pszFile, EditFileIOStatus* status, bool bSaveCopy); void EditInvertCase(HWND hwnd); void EditTitleCase(HWND hwnd); diff --git a/src/Encoding.c b/src/Encoding.c index 748a213eb..c7ea3f371 100644 --- a/src/Encoding.c +++ b/src/Encoding.c @@ -109,7 +109,8 @@ int Encoding_SrcWeak(int iSrcWeakEnc) // ============================================================================ -bool Encoding_HasChanged(int iOriginalEncoding) { +bool Encoding_HasChanged(int iOriginalEncoding) +{ static int OriginalEncoding = CPI_NONE; if (iOriginalEncoding >= CPI_NONE) { diff --git a/src/Helpers.c b/src/Helpers.c index 0905af6e8..0fa82b072 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1928,7 +1928,6 @@ void TransformBackslashes(char* pszInput, bool bRegEx, UINT cpEdit, int* iReplac } - void TransformMetaChars(char* pszInput, bool bRegEx, int iEOLMode) { if (!bRegEx) return; diff --git a/src/Notepad3.c b/src/Notepad3.c index 7671f26b1..f705f39ef 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1164,7 +1164,7 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow) SendMessage( Globals.hwndMain, WM_COMMAND, - MAKELONG(IDM_LINEENDINGS_CRLF + s_flagSetEOLMode - 1, 1), + MAKELONG(IDM_LINEENDINGS_CRLF + s_flagSetEOLMode -1,1), 0); s_flagSetEOLMode = 0; } @@ -3327,7 +3327,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_LINEENDINGS_SETDEFAULT: - SelectDefLineEndingDlg(hwnd, &Settings.DefaultEOLMode); + SelectDefLineEndingDlg(hwnd, (LPARAM)&Settings.DefaultEOLMode); break; @@ -6847,6 +6847,7 @@ void LoadSettings() GET_BOOL_VALUE_FROM_INISECTION(LoadNFOasOEM, true); GET_BOOL_VALUE_FROM_INISECTION(NoEncodingTags, false); GET_INT_VALUE_FROM_INISECTION(DefaultEOLMode, SC_EOL_CRLF, SC_EOL_CRLF, SC_EOL_LF); + GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistEOLs, true); GET_BOOL_VALUE_FROM_INISECTION(FixLineEndings, false); GET_BOOL_VALUE_FROM_INISECTION(FixTrailingBlanks, false); GET_INT_VALUE_FROM_INISECTION(PrintHeader, 1, 0, 3); @@ -7205,6 +7206,7 @@ void SaveSettings(bool bSaveSettingsNow) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, LoadNFOasOEM); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, NoEncodingTags); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, DefaultEOLMode); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistEOLs); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixLineEndings); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, FixTrailingBlanks); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, PrintHeader); @@ -9142,9 +9144,7 @@ static int _UndoRedoActionMap(int token, UndoRedoSelection_t* selection) // // bool FileIO(bool fLoad,LPWSTR pszFileName,bool bSkipUnicodeDetect,bool bSkipANSICPDetection, - int *ienc,int *ieol, - bool *pbUnicodeErr,bool *pbFileTooBig, bool* pbUnknownExt, - bool *pbCancelDataLoss,bool bSaveCopy) + EditFileIOStatus* status, bool bSaveCopy) { WCHAR tch[MAX_PATH+40]; bool fSuccess; @@ -9155,12 +9155,12 @@ bool FileIO(bool fLoad,LPWSTR pszFileName,bool bSkipUnicodeDetect,bool bSkipANSI BeginWaitCursor(tch); if (fLoad) { - fSuccess = EditLoadFile(Globals.hwndEdit,pszFileName,bSkipUnicodeDetect,bSkipANSICPDetection,ienc,ieol,pbUnicodeErr,pbFileTooBig,pbUnknownExt); + fSuccess = EditLoadFile(Globals.hwndEdit,pszFileName,bSkipUnicodeDetect,bSkipANSICPDetection,status); } else { int idx; if (MRU_FindFile(Globals.pFileMRU,pszFileName,&idx)) { - Globals.pFileMRU->iEncoding[idx] = *ienc; + Globals.pFileMRU->iEncoding[idx] = status->iEncoding; Globals.pFileMRU->iCaretPos[idx] = (Settings.PreserveCaretPos ? SciCall_GetCurrentPos() : 0); WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' }; EditGetBookmarkList(Globals.hwndEdit, wchBookMarks, COUNTOF(wchBookMarks)); @@ -9168,7 +9168,7 @@ bool FileIO(bool fLoad,LPWSTR pszFileName,bool bSkipUnicodeDetect,bool bSkipANSI LocalFree(Globals.pFileMRU->pszBookMarks[idx]); // StrDup() Globals.pFileMRU->pszBookMarks[idx] = StrDup(wchBookMarks); } - fSuccess = EditSaveFile(Globals.hwndEdit,pszFileName,*ienc,pbCancelDataLoss,bSaveCopy); + fSuccess = EditSaveFile(Globals.hwndEdit,pszFileName, status, bSaveCopy); } dwFileAttributes = GetFileAttributes(pszFileName); @@ -9189,11 +9189,11 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, { WCHAR tch[MAX_PATH] = { L'\0' }; WCHAR szFileName[MAX_PATH] = { L'\0' }; - bool bUnicodeErr = false; - bool bFileTooBig = false; - bool bUnknownExt = false; - bool fSuccess; - int fileEncoding = CPI_ANSI_DEFAULT; + bool fSuccess = false; + + EditFileIOStatus fioStatus = INIT_FILEIO_STATUS; + fioStatus.iEOLMode = Settings.DefaultEOLMode; + fioStatus.iEncoding = CPI_ANSI_DEFAULT; if (bNew || bReload) { if (EditToggleView(Globals.hwndEdit, false)) { @@ -9280,8 +9280,6 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, } // Ask to create a new file... - int _eol_mode = Settings.DefaultEOLMode; - if (!bReload && !PathFileExists(szFileName)) { if (s_flagQuietCreate || MsgBoxLng(MBYESNO,IDS_MUI_ASK_CREATE,szFileName) == IDYES) { @@ -9296,9 +9294,9 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, Style_SetDefaultLexer(Globals.hwndEdit); SciCall_SetEOLMode(Settings.DefaultEOLMode); if (Encoding_SrcCmdLn(CPI_GET) != CPI_NONE) { - fileEncoding = Encoding_SrcCmdLn(CPI_GET); - Encoding_Current(fileEncoding); - Encoding_HasChanged(fileEncoding); + fioStatus.iEncoding = Encoding_SrcCmdLn(CPI_GET); + Encoding_Current(fioStatus.iEncoding); + Encoding_HasChanged(fioStatus.iEncoding); } else { Encoding_Current(Settings.DefaultEncoding); @@ -9317,14 +9315,14 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, else { int idx; if (!bReload && MRU_FindFile(Globals.pFileMRU,szFileName,&idx)) { - fileEncoding = Globals.pFileMRU->iEncoding[idx]; - if (fileEncoding > 0) - Encoding_SrcCmdLn(Encoding_MapUnicode(fileEncoding)); + fioStatus.iEncoding = Globals.pFileMRU->iEncoding[idx]; + if (fioStatus.iEncoding > 0) + Encoding_SrcCmdLn(Encoding_MapUnicode(fioStatus.iEncoding)); } else - fileEncoding = Encoding_Current(CPI_GET); + fioStatus.iEncoding = Encoding_Current(CPI_GET); - fSuccess = FileIO(true,szFileName,bSkipUnicodeDetect,bSkipANSICPDetection,&fileEncoding,&_eol_mode,&bUnicodeErr,&bFileTooBig,&bUnknownExt,NULL,false); + fSuccess = FileIO(true,szFileName,bSkipUnicodeDetect,bSkipANSICPDetection,&fioStatus,false); } if (fSuccess) { StringCchCopy(Globals.CurrentFile,COUNTOF(Globals.CurrentFile),szFileName); @@ -9337,9 +9335,10 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, if (!s_flagLexerSpecified) // flag will be cleared Style_SetLexerFromFile(Globals.hwndEdit,Globals.CurrentFile); - SciCall_SetEOLMode(_eol_mode); - Encoding_Current(fileEncoding); // load may change encoding - Encoding_HasChanged(fileEncoding); + SciCall_SetEOLMode(fioStatus.iEOLMode); + Encoding_Current(fioStatus.iEncoding); // load may change encoding + Encoding_HasChanged(fioStatus.iEncoding); + int idx = 0; DocPos iCaretPos = 0; LPCWSTR pszBookMarks = L""; @@ -9347,7 +9346,7 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, iCaretPos = Globals.pFileMRU->iCaretPos[idx]; pszBookMarks = Globals.pFileMRU->pszBookMarks[idx]; } - MRU_AddFile(Globals.pFileMRU,szFileName,Flags.RelativeFileMRU,Flags.PortableMyDocs,fileEncoding,iCaretPos,pszBookMarks); + MRU_AddFile(Globals.pFileMRU,szFileName,Flags.RelativeFileMRU,Flags.PortableMyDocs,fioStatus.iEncoding,iCaretPos,pszBookMarks); EditSetBookmarkList(Globals.hwndEdit, pszBookMarks); SetFindPattern((Globals.pMRUfind ? Globals.pMRUfind->pszItems[0] : L"")); @@ -9401,13 +9400,28 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, UpdateSettingsCmds(); // Show warning: Unicode file loaded as ANSI - if (bUnicodeErr) - MsgBoxLng(MBWARN,IDS_MUI_ERR_UNICODE); + if (fioStatus.bUnicodeErr) { + MsgBoxLng(MBWARN, IDS_MUI_ERR_UNICODE); + } + // Show inconsistent line endings warning + if (fioStatus.bInconsistent && Settings.WarnInconsistEOLs) + { + WCHAR szDefault[32]; + WCHAR szStatistic[80]; + int const eolm = SciCall_GetEOLMode(); //Settings.DefaultEOLMode; + StringCchPrintf(szDefault, COUNTOF(szDefault), L"%s", + ((eolm == SC_EOL_CRLF) ? L"CRLF (\\r\\n)" : ((eolm == SC_EOL_CR) ? L"CR (\\r)" : L"LF (\\n)"))); + StringCchPrintf(szStatistic, COUNTOF(szStatistic), L">>> #CRLF = %i, #CR = %i, #LF = %i <<<", + fioStatus.linesCount[SC_EOL_CRLF], fioStatus.linesCount[SC_EOL_CR], fioStatus.linesCount[SC_EOL_LF]); + int const res = MsgBoxLng(MBYESNOWARN, IDS_MUI_WARN_INCONSIST_EOLS, szStatistic, szDefault); + if (res == IDYES) { + SciCall_ConvertEOLs(eolm); + } + } + } + else if (!(fioStatus.bFileTooBig || fioStatus.bUnknownExt)) { + MsgBoxLng(MBWARN, IDS_MUI_ERR_LOADFILE, szFileName); } - - else if (!(bFileTooBig || bUnknownExt)) - MsgBoxLng(MBWARN,IDS_MUI_ERR_LOADFILE,szFileName); - return(fSuccess); } @@ -9479,7 +9493,10 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) WCHAR tchFile[MAX_PATH] = { L'\0' }; WCHAR tchBase[MAX_PATH] = { L'\0' }; bool fSuccess = false; - bool bCancelDataLoss = false; + + EditFileIOStatus fioStatus = INIT_FILEIO_STATUS; + fioStatus.iEncoding = Encoding_Current(CPI_GET); + fioStatus.iEOLMode = SciCall_GetEOLMode(); bool bIsEmptyNewFile = false; if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile)) == 0) { @@ -9556,10 +9573,8 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) if (SaveFileDlg(Globals.hwndMain,tchFile,COUNTOF(tchFile),tchInitialDir)) { - int fileEncoding = Encoding_Current(CPI_GET); - int _eol_mode = Settings.DefaultEOLMode; - fSuccess = FileIO(false, tchFile, false, true, &fileEncoding, &_eol_mode, NULL, NULL, NULL, &bCancelDataLoss, bSaveCopy); - //~if (fSuccess) Encoding_Current(fileEncoding); // save should not change encoding + fSuccess = FileIO(false, tchFile, false, true, &fioStatus, bSaveCopy); + //~if (fSuccess) Encoding_Current(fioStatus.iEncoding); // save should not change encoding if (fSuccess) { if (!bSaveCopy) @@ -9581,10 +9596,8 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) return false; } else { - int fileEncoding = Encoding_Current(CPI_GET); - int _eol_mode = Settings.DefaultEOLMode; - fSuccess = FileIO(false, Globals.CurrentFile, false, true, &fileEncoding, &_eol_mode, NULL, NULL, NULL, &bCancelDataLoss, false); - //~if (fSuccess) Encoding_Current(fileEncoding); // save should not change encoding + fSuccess = FileIO(false, Globals.CurrentFile, false, true, &fioStatus, false); + //~if (fSuccess) Encoding_Current(fioStatus.iEncoding); // save should not change encoding } if (fSuccess) @@ -9612,7 +9625,7 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) InstallFileWatching(Globals.CurrentFile); } } - else if (!bCancelDataLoss) + else if (!fioStatus.bCancelDataLoss) { if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile)) > 0) { StringCchCopy(tchFile,COUNTOF(tchFile),Globals.CurrentFile); @@ -9626,10 +9639,8 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) if (GetTempPath(MAX_PATH,lpTempPathBuffer) && GetTempFileName(lpTempPathBuffer,TEXT("NP3"),0,szTempFileName)) { - int _eol_mode = Settings.DefaultEOLMode; - int fileEncoding = Encoding_Current(CPI_GET); - if (FileIO(false,szTempFileName,false,true,&fileEncoding,&_eol_mode,NULL,NULL,NULL,&bCancelDataLoss,true)) { - //~Encoding_Current(fileEncoding); // save should not change encoding + if (FileIO(false,szTempFileName,false,true,&fioStatus,true)) { + //~Encoding_Current(fioStatus.iEncoding); // save should not change encoding WCHAR szArguments[2048] = { L'\0' }; LPWSTR lpCmdLine = GetCommandLine(); size_t const wlen = StringCchLenW(lpCmdLine,0) + 2; diff --git a/src/Notepad3.h b/src/Notepad3.h index eec325e21..a8ca25712 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -160,7 +160,7 @@ void SetFindPatternMB(LPCSTR chFindPattern); void GetFindPattern(LPWSTR wchFindPattern, size_t bufferSize); void GetFindPatternMB(LPSTR chFindPattern, size_t bufferSize); -bool FileIO(bool,LPWSTR pszFileName,bool,bool,int* ienc,int* ieol,bool*,bool*,bool*,bool*,bool); +bool FileIO(bool, LPWSTR pszFileName, bool, bool, EditFileIOStatus* status, bool); bool FileLoad(bool,bool,bool,bool,bool,LPCWSTR lpszFile); bool FileRevert(LPCWSTR szFileName,bool); bool FileSave(bool,bool,bool,bool); diff --git a/src/Notepad3.vcxproj b/src/Notepad3.vcxproj index fb6ed9da1..016c2aff3 100644 --- a/src/Notepad3.vcxproj +++ b/src/Notepad3.vcxproj @@ -367,6 +367,7 @@ + @@ -453,6 +454,7 @@ + diff --git a/src/Notepad3.vcxproj.filters b/src/Notepad3.vcxproj.filters index e5fefc1ef..9e3dd949b 100644 --- a/src/Notepad3.vcxproj.filters +++ b/src/Notepad3.vcxproj.filters @@ -249,6 +249,9 @@ Source Files\StyleLexers + + Source Files + @@ -380,6 +383,9 @@ Source Files\uthash + + Header Files + diff --git a/src/Styles.c b/src/Styles.c index 98ea87a61..bc4a77ab5 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3743,7 +3743,9 @@ HWND Style_CustomizeSchemesDlg(HWND hwnd) GetParent(hwnd), Style_CustomizeSchemesDlgProc, (LPARAM)NULL); - ShowWindow(hDlg, SW_SHOW); + if (hDlg != INVALID_HANDLE_VALUE) { + ShowWindow(hDlg, SW_SHOW); + } return hDlg; } diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 0deb5a25d..1e4c91d13 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -303,6 +303,7 @@ typedef struct _settings_t bool LoadNFOasOEM; bool NoEncodingTags; int DefaultEOLMode; + bool WarnInconsistEOLs; bool FixLineEndings; bool FixTrailingBlanks; int PrintHeader; @@ -408,7 +409,26 @@ typedef struct _flags_t extern FLAGS_T Flags; +//============================================================================= +typedef struct _editfileiostatus +{ + int iEncoding; + int iEOLMode; + + bool bFileTooBig; + bool bUnicodeErr; + + // inconsistent line endings + bool bInconsistent; + DocLn linesCount[3]; + + bool bCancelDataLoss; + bool bUnknownExt; + +} EditFileIOStatus; + +#define INIT_FILEIO_STATUS { CPI_ANSI_DEFAULT, SC_EOL_CRLF, false, false, false, {0,0,0}, false, false } //=============================================================================