From 185e09cde87f994c35bed10cca5763138eb2ed7f Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 10 May 2018 14:02:57 +0200 Subject: [PATCH] + enh: handling of default/standard lexer styles --- src/Notepad3.c | 34 +++++++++++++++++++++------------- src/Styles.c | 19 +++++++++++++++++-- src/Styles.h | 1 + 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 3910cf790..12697474c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -6123,7 +6123,9 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) return true; case STATUS_2ND_DEF: - PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + if (!Style_IsCurLexerStandard()) { + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + } return true; case STATUS_LEXER: @@ -7946,17 +7948,25 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - static bool s_bUse2ndDefault = -1; - bool bUse2ndDefault = Style_GetUse2ndDefault(); - if (s_bUse2ndDefault != bUse2ndDefault) { - if (bUse2ndDefault) - { - StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s2ND", g_mxStatusBarPrefix[STATUS_2ND_DEF]); - } - else { + static int s_iUse2ndDefault = -1; + int iUse2ndDefault = Style_IsCurLexerStandard() ? 0 : (Style_GetUse2ndDefault() ? 2 : 1); + + if (s_iUse2ndDefault != iUse2ndDefault) { + switch (iUse2ndDefault) { + case 0: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + case 1: StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%sSTD", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + case 2: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%s2ND", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; + default: + StringCchPrintf(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"%sXXX", g_mxStatusBarPrefix[STATUS_2ND_DEF]); + break; } - s_bUse2ndDefault = bUse2ndDefault; + s_iUse2ndDefault = iUse2ndDefault; bIsUpdateNeeded = true; } // ------------------------------------------------------ @@ -7964,13 +7974,11 @@ static void __fastcall _UpdateStatusbarDelayed(bool bForceRedraw) static WCHAR tchLexerName[MINI_BUFFER]; static int s_iCurLexer = -1; - static bool s_bIs2ndDefault = -1; int const iCurLexer = Style_GetCurrentLexerRID(); - if ((s_iCurLexer != iCurLexer) || (s_bIs2ndDefault != bUse2ndDefault)) { + if (s_iCurLexer != iCurLexer) { Style_GetCurrentLexerName(tchLexerName, MINI_BUFFER); StringCchPrintf(tchStatusBar[STATUS_LEXER], txtWidth, L"%s%s", g_mxStatusBarPrefix[STATUS_LEXER], tchLexerName); s_iCurLexer = iCurLexer; - s_bIs2ndDefault = bUse2ndDefault; bIsUpdateNeeded = true; } // ------------------------------------------------------ diff --git a/src/Styles.c b/src/Styles.c index 407fa2910..4839b45da 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3043,6 +3043,17 @@ PEDITLEXER __fastcall GetDefaultLexer() } + +//============================================================================= +// +// IsLexerStandard() +// +bool Style_IsCurLexerStandard() +{ + return IsLexerStandard(g_pLexCurrent); +} + + //============================================================================= // // _SetBaseFontSize(), _GetBaseFontSize() @@ -3358,10 +3369,14 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) const WCHAR* const wchNewLexerStyleStrg = pLexNew->Styles[STY_DEFAULT].szValue; // first set standard lexer's default values - if (IsLexerStandard(pLexNew)) + if (IsLexerStandard(pLexNew)) { g_pLexCurrent = pLexNew; - else + EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_USE2NDDEFAULT, false); + } + else { g_pLexCurrent = GetCurrentStdLexer(); + EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_USE2NDDEFAULT, true); + } const WCHAR* const wchStandardStyleStrg = g_pLexCurrent->Styles[STY_DEFAULT].szValue; diff --git a/src/Styles.h b/src/Styles.h index b0f576683..92b220e8f 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -105,6 +105,7 @@ void Style_CopyStyles_IfNotDefined(LPWSTR,LPWSTR,int,bool,bool); bool Style_SelectFont(HWND,LPWSTR,int,LPCWSTR,LPCWSTR,bool,bool,bool,bool); bool Style_SelectColor(HWND,bool,LPWSTR,int,bool); void Style_SetStyles(HWND,int,LPCWSTR,bool); +bool Style_IsCurLexerStandard(); int Style_GetCurrentLexerRID(); void Style_GetCurrentLexerName(LPWSTR,int); int Style_GetLexerIconId(PEDITLEXER);