From 9cbd03c301cd22b3a96edbf85f3b2f90c2168a2c Mon Sep 17 00:00:00 2001 From: LEONARDO SILVA Date: Wed, 23 Feb 2022 13:51:58 -0300 Subject: [PATCH] Add more API for custom auto-indentation and current macro status 4 new API are added: - NPPM_GETEXTERNALLEXERAUTOINDENTMODE - NPPM_SETEXTERNALLEXERAUTOINDENTMODE - NPPM_ISAUTOINDENTON - NPPM_GETCURRENTMACROSTATUS * Added support for custom auto-indentation for external lexer. * Also added messages to fetch current Macro status (Idle, Recording, Stopped, Running) -> for this also affects auto-indentation behavior. * Also added capability to query for the current User Settings of "Use Auto Indentation". Fix #11253, close #11278 --- PowerEditor/src/MISC/Common/Common.h | 4 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 30 ++++++++++++++++- PowerEditor/src/Notepad_plus.cpp | 13 +++++++- PowerEditor/src/NppBigSwitch.cpp | 33 +++++++++++++++++-- PowerEditor/src/Parameters.h | 1 + .../src/ScintillaComponent/FindReplaceDlg.cpp | 4 +-- .../src/WinControls/shortcut/RunMacroDlg.cpp | 4 +-- PowerEditor/src/resource.h | 2 +- 8 files changed, 77 insertions(+), 14 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 7137236df..bc5e05d89 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -159,10 +159,6 @@ protected: }; - -#define MACRO_RECORDING_IN_PROGRESS 1 -#define MACRO_RECORDING_HAS_STOPPED 2 - #define REBARBAND_SIZE sizeof(REBARBANDINFO) generic_string PathRemoveFileSpec(generic_string & path); diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 0ea9756fc..d2688ec32 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -36,8 +36,10 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\ // Don't use L_JS, use L_JAVASCRIPT instead // The end of enumated language type, so it should be always at the end L_EXTERNAL}; +enum class ExternalLexerAutoIndentMode { Standard, C_Like, Custom }; +enum class MacroStatus { Idle, RecordInProgress, RecordingStopped, PlayingBack }; -enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10 }; +enum winVer { WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10 }; enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; @@ -454,6 +456,32 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; HICON hToolbarIconDarkMode; }; + #define NPPM_GETEXTERNALLEXERAUTOINDENTMODE (NPPMSG + 103) + // BOOL NPPM_GETEXTERNALLEXERAUTOINDENTMODE(const TCHAR *languageName, ExternalLexerAutoIndentMode &autoIndentMode) + // Get ExternalLexerAutoIndentMode for an installed external programming language. + // - Standard means Notepad++ will keep the same TAB indentation between lines; + // - C_Like means Notepad++ will perform a C-Language style indentation for the selected external language; + // - Custom means a Plugin will be controlling auto-indentation for the current language. + // returned values: TRUE for successful searches, otherwise FALSE. + + #define NPPM_SETEXTERNALLEXERAUTOINDENTMODE (NPPMSG + 104) + // BOOL NPPM_SETEXTERNALLEXERAUTOINDENTMODE(const TCHAR *languageName, ExternalLexerAutoIndentMode autoIndentMode) + // Set ExternalLexerAutoIndentMode for an installed external programming language. + // - Standard means Notepad++ will keep the same TAB indentation between lines; + // - C_Like means Notepad++ will perform a C-Language style indentation for the selected external language; + // - Custom means a Plugin will be controlling auto-indentation for the current language. + // returned value: TRUE if function call was successful, otherwise FALSE. + + #define NPPM_ISAUTOINDENTON (NPPMSG + 105) + // BOOL NPPM_ISAUTOINDENTON(0, 0) + // Returns the current Use Auto-Indentation setting in Notepad++ Preferences. + + #define NPPM_GETCURRENTMACROSTATUS (NPPMSG + 106) + // MacroStatus NPPM_GETCURRENTMACROSTATUS(0, 0) + // Gets current enum class MacroStatus { Idle - means macro is not in use and it's empty, RecordInProgress, RecordingStopped, PlayingBack } + + + #define VAR_NOT_RECOGNIZED 0 #define FULL_CURRENT_PATH 1 #define CURRENT_DIRECTORY 2 diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 2838154a3..6a1c752a2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3103,6 +3103,16 @@ void Notepad_plus::maintainIndentation(TCHAR ch) intptr_t tabWidth = _pEditView->execute(SCI_GETTABWIDTH); LangType type = _pEditView->getCurrentBuffer()->getLangType(); + ExternalLexerAutoIndentMode autoIndentMode = ExternalLexerAutoIndentMode::Standard; + + // For external languages, query for custom auto-indentation funcionality + if (type >= L_EXTERNAL) + { + NppParameters& nppParam = NppParameters::getInstance(); + autoIndentMode = nppParam.getELCFromIndex(type - L_EXTERNAL)._autoIndentMode; + if (autoIndentMode == ExternalLexerAutoIndentMode::Custom) + return; + } // Do not alter indentation if we were at the beginning of the line and we pressed Enter if ((((eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) && ch == '\n') || @@ -3110,7 +3120,8 @@ void Notepad_plus::maintainIndentation(TCHAR ch) return; if (type == L_C || type == L_CPP || type == L_JAVA || type == L_CS || type == L_OBJC || - type == L_PHP || type == L_JS || type == L_JAVASCRIPT || type == L_JSP || type == L_CSS || type == L_PERL || type == L_RUST || type == L_POWERSHELL || type == L_JSON) + type == L_PHP || type == L_JS || type == L_JAVASCRIPT || type == L_JSP || type == L_CSS || type == L_PERL || + type == L_RUST || type == L_POWERSHELL || type == L_JSON || autoIndentMode == ExternalLexerAutoIndentMode::C_Like) { if (((eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) && ch == '\n') || (eolMode == SC_EOL_CR && ch == '\r')) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index f2d145718..2cdcfb2ef 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1295,11 +1295,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return MAKELONG(auxVer, mainVer); } - case WM_GETCURRENTMACROSTATUS: + case NPPM_GETCURRENTMACROSTATUS: { if (_recordingMacro) - return MACRO_RECORDING_IN_PROGRESS; - return (_macro.empty())?0:MACRO_RECORDING_HAS_STOPPED; + return static_cast(MacroStatus::RecordInProgress); + if (_playingBackMacro) + return static_cast(MacroStatus::PlayingBack); + return (_macro.empty()) ? static_cast(MacroStatus::Idle) : static_cast(MacroStatus::RecordingStopped); } case WM_FRSAVE_INT: @@ -2553,6 +2555,31 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return langDesc.length(); } + case NPPM_GETEXTERNALLEXERAUTOINDENTMODE: + { + int index = nppParam.getExternalLangIndexFromName(reinterpret_cast(wParam)); + if (index < 0) + return FALSE; + + *(reinterpret_cast(lParam)) = nppParam.getELCFromIndex(index)._autoIndentMode; + return TRUE; + } + + case NPPM_SETEXTERNALLEXERAUTOINDENTMODE: + { + int index = nppParam.getExternalLangIndexFromName(reinterpret_cast(wParam)); + if (index < 0) + return FALSE; + + nppParam.getELCFromIndex(index)._autoIndentMode = static_cast(lParam); + return TRUE; + } + + case NPPM_ISAUTOINDENTON: + { + return nppParam.getNppGUI()._maitainIndent; + } + case NPPM_DOCLISTDISABLEPATHCOLUMN: case NPPM_DOCLISTDISABLEEXTCOLUMN: { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 3f5b876e8..a33b4a510 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1082,6 +1082,7 @@ class ExternalLangContainer final public: TCHAR _name[MAX_EXTERNAL_LEXER_NAME_LEN]; TCHAR _desc[MAX_EXTERNAL_LEXER_DESC_LEN]; + ExternalLexerAutoIndentMode _autoIndentMode = ExternalLexerAutoIndentMode::Standard; ExternalLangContainer(const TCHAR* name, const TCHAR* desc) { diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index a30cc7108..36a4768b9 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -1182,7 +1182,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA case WM_COMMAND : { - bool isMacroRecording = (::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS,0,0) == MACRO_RECORDING_IN_PROGRESS); + bool isMacroRecording = (static_cast(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS,0,0)) == MacroStatus::RecordInProgress); NppParameters& nppParamInst = NppParameters::getInstance(); FindHistory & findHistory = nppParamInst.getFindHistory(); switch (LOWORD(wParam)) @@ -2066,7 +2066,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op msg = TEXT("^ ") + msg; (*_ppEditView)->showCallTip(start, msg.c_str()); } - if (::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS,0,0) == MACRO_RECORDING_IN_PROGRESS) + if (static_cast(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS,0,0)) == MacroStatus::RecordInProgress) (*_ppEditView)->execute(SCI_STARTRECORD); delete [] pText; diff --git a/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp index 569f5ad04..663ac8d70 100644 --- a/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp +++ b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp @@ -30,7 +30,7 @@ void RunMacroDlg::initMacroList() ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_RESETCONTENT, 0, 0); - if (::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS, 0, 0) == MACRO_RECORDING_HAS_STOPPED) + if (static_cast(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS, 0, 0)) == MacroStatus::RecordingStopped) ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_ADDSTRING, 0, reinterpret_cast(TEXT("Current recorded macro"))); for (size_t i = 0, len = macroList.size(); i < len ; ++i) @@ -174,6 +174,6 @@ void RunMacroDlg::check(int id) int RunMacroDlg::getMacro2Exec() const { - bool isCurMacroPresent = ::SendMessage(_hParent, WM_GETCURRENTMACROSTATUS, 0, 0) == MACRO_RECORDING_HAS_STOPPED; + bool isCurMacroPresent = static_cast(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS, 0, 0)) == MacroStatus::RecordingStopped; return isCurMacroPresent?(_macroIndex - 1):_macroIndex; } diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index 0d3762fa4..b70c7c7c1 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -667,7 +667,7 @@ #define MACRO_USER (WM_USER + 4000) - #define WM_GETCURRENTMACROSTATUS (MACRO_USER + 01) +// #define WM_GETCURRENTMACROSTATUS (MACRO_USER + 01) // Replaced with NPPM_GETCURRENTMACROSTATUS #define WM_MACRODLGRUNMACRO (MACRO_USER + 02)