Merge pull request #2876 from RaiKoHoff/Dev_NewFeatures

Customize Schemes title assembling
This commit is contained in:
Rainer Kottenhoff 2020-09-23 01:02:11 +02:00 committed by GitHub
commit 91a5bc75be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 138 additions and 93 deletions

View File

@ -287,7 +287,7 @@ END
IDD_MUI_STYLESELECT DIALOGEX 0, 0, 200, 194
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Syntax Schema"
CAPTION "Syntax Schema auswählen"
FONT 9, "Segoe UI", 400, 0, 0x1
BEGIN
CONTROL "",IDC_STYLELIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,7,7,184,130
@ -301,7 +301,7 @@ END
IDD_MUI_STYLECONFIG DIALOGEX 0, 0, 467, 254
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Syntax Schema"
CAPTION "Schema"
FONT 9, "Segoe UI", 400, 0, 0x1
BEGIN
CONTROL "",IDC_STYLELIST,"SysTreeView32",TVS_SHOWSELALWAYS | TVS_SINGLEEXPAND | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,164,240
@ -309,10 +309,10 @@ BEGIN
EDITTEXT IDC_STYLEEDIT_ROOT,181,152,279,12,ES_AUTOHSCROLL
LTEXT "",IDC_STYLELABEL,181,171,279,8
EDITTEXT IDC_STYLEEDIT,181,183,279,12,ES_AUTOHSCROLL
PUSHBUTTON "&Farbe...",IDC_STYLEFORE,181,201,46,14
PUSHBUTTON "&Grund...",IDC_STYLEBACK,232,201,46,14
PUSHBUTTON "&Schriftart...",IDC_STYLEFONT,283,201,52,14
PUSHBUTTON "&Vorschau",IDC_PREVIEW,330,201,42,14
PUSHBUTTON "&Farbe...",IDC_STYLEFORE,180,201,46,14
PUSHBUTTON "&Grund...",IDC_STYLEBACK,230,201,46,14
PUSHBUTTON "&Schriftart...",IDC_STYLEFONT,280,201,50,14
PUSHBUTTON "&Vorschau",IDC_PREVIEW,334,201,40,14
PUSHBUTTON "&Standard",IDC_STYLEDEFAULT,377,201,42,14
PUSHBUTTON "",IDC_PREVSTYLE,426,201,15,14,BS_BITMAP
PUSHBUTTON "",IDC_NEXTSTYLE,445,201,15,14,BS_BITMAP
@ -321,7 +321,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,355,232,50,14
PUSHBUTTON "Abbrechen",IDCANCEL,410,232,50,14
GROUPBOX "Information",IDC_INFO_GROUPBOX,181,7,280,127
CTEXT "Syntax Schema",IDC_TITLE,240,20,180,24,SS_CENTERIMAGE
CTEXT "-",IDC_TITLE,240,20,180,24,SS_CENTERIMAGE
EDITTEXT IDC_STYLEEDIT_HELP,197,54,252,74,ES_MULTILINE | ES_READONLY | NOT WS_BORDER
END

View File

@ -287,7 +287,7 @@ END
IDD_MUI_STYLESELECT DIALOGEX 0, 0, 165, 194
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Select Scheme"
CAPTION "Select Syntax Scheme"
FONT 9, "Segoe UI", 400, 0, 0x1
BEGIN
CONTROL "",IDC_STYLELIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,7,7,151,130
@ -301,7 +301,7 @@ END
IDD_MUI_STYLECONFIG DIALOGEX 0, 0, 467, 254
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Customize Schemes"
CAPTION "Scheme"
FONT 9, "Segoe UI", 400, 0, 0x1
BEGIN
CONTROL "",IDC_STYLELIST,"SysTreeView32",TVS_SHOWSELALWAYS | TVS_SINGLEEXPAND | WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,164,239
@ -321,7 +321,7 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,355,232,50,14
PUSHBUTTON "Cancel",IDCANCEL,410,232,50,14
GROUPBOX "Info",IDC_INFO_GROUPBOX,181,7,280,127
CTEXT "Customize Schemes",IDC_TITLE,240,20,180,24,SS_CENTERIMAGE
CTEXT "-",IDC_TITLE,240,20,180,24,SS_CENTERIMAGE
EDITTEXT IDC_STYLEEDIT_HELP,197,54,252,74,ES_MULTILINE | ES_READONLY | NOT WS_BORDER
END

View File

@ -338,8 +338,8 @@ static bool _inComment(StyleContext& sc, Sci_Position& pos)
bool isInComment = false;
auto const posCurrent = static_cast<Sci_Position>(sc.currentPos);
Sci_Position p = pos;
while (p >= 0)
Sci_Position p = pos + 1;
while (--p >= 0)
{
Sci_Position const d = p - posCurrent;
int const ch = sc.GetRelative(d);
@ -349,10 +349,9 @@ static bool _inComment(StyleContext& sc, Sci_Position& pos)
}
else if (IsCommentChar(ch)) {
isInComment = true;
pos = p - 1;
pos = p;
break;
}
--p;
}
return isInComment;
}
@ -360,6 +359,7 @@ static bool _inComment(StyleContext& sc, Sci_Position& pos)
constexpr bool _isQuoted(const bool q1, const bool q2) noexcept { return (q1 || q2); }
static int GetSquareBracketLevel(StyleContext& sc, const bool stopAtLnBreak)
{
auto const posCurrent = static_cast<Sci_Position>(sc.currentPos);
@ -368,9 +368,9 @@ static int GetSquareBracketLevel(StyleContext& sc, const bool stopAtLnBreak)
bool inSQStrg = false;
bool inDQStrg = false;
Sci_Position pos = posCurrent - 1;
Sci_Position pos = posCurrent;
while ((pos >= 0) && (iBracketLevel <= 0))
while ((--pos >= 0) && (iBracketLevel <= 0))
{
Sci_Position const diff = pos - posCurrent;
int const ch = sc.GetRelative(diff);
@ -378,43 +378,42 @@ static int GetSquareBracketLevel(StyleContext& sc, const bool stopAtLnBreak)
if (stopAtLnBreak && IsLineBreak(ch)) {
break;
}
int const ch_p = sc.GetRelative(diff - 1);
if (_inComment(sc, pos)) {
continue;
}
if (!_inComment(sc, pos))
int const ch_p = sc.GetRelative(diff - 1);
if (ch_p != '\\') // not ESCaped
{
if (ch_p != '\\') // not ESCaped
if (ch == '"')
{
if (ch == '"')
{
if (inDQStrg) {
inDQStrg = false;
}
else {
inDQStrg = !inSQStrg;
}
if (inDQStrg) {
inDQStrg = false;
}
else if (ch == '\'')
{
if (inSQStrg) {
inSQStrg = false;
}
else {
inSQStrg = !inDQStrg;
}
else {
inDQStrg = !inSQStrg;
}
}
if (!_isQuoted(inDQStrg, inSQStrg)) {
if (ch == ']') {
--iBracketLevel;
else if (ch == '\'')
{
if (inSQStrg) {
inSQStrg = false;
}
else if (ch == '[') {
++iBracketLevel;
else {
inSQStrg = !inDQStrg;
}
}
}
--pos;
if (!_isQuoted(inDQStrg, inSQStrg)) {
if (ch == ']') {
--iBracketLevel;
}
else if (ch == '[') {
++iBracketLevel;
}
}
}
return iBracketLevel;
}
@ -435,7 +434,9 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
bool isSectKeyEnd = false;
bool inMultiLnString = (sc.state == SCE_TOML_STR_BASIC) || (sc.state == SCE_TOML_STR_LITERAL);
bool inMultiLnArrayDef = (GetSquareBracketLevel(sc, false) > 0);
int const iSqrBraLevBeg = GetSquareBracketLevel(sc, false);
int iSqrBraLev = iSqrBraLevBeg;
bool inMultiLnArrayDef = (iSqrBraLev > 0);
bool inHex = false;
bool inBin = false;
@ -452,7 +453,7 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
// reset context infos
if (sc.atLineStart)
{
inMultiLnArrayDef = (GetSquareBracketLevel(sc, false) > 0);
inMultiLnArrayDef = (iSqrBraLev > 0);
inSQuotedKey = inDQuotedKey = false;
isSectKeyBeg = isSectKeyEnd = false;
bPossibleKeyword = true;
@ -481,7 +482,7 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
case SCE_TOML_KEY:
case SCE_TOML_ASSIGNMENT:
SetStateParsingError(sc);
//???SetStateParsingError(sc);
break;
case SCE_TOML_COMMENT:
@ -500,6 +501,20 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
}
}
// square-bracket level
if (sc.ch == '[') {
auto p = static_cast<Sci_Position>(sc.currentPos);
if (!_inComment(sc, p) && !_isQuoted(inSQuotedKey, inDQuotedKey)) {
++iSqrBraLev;
}
}
else if (sc.ch == ']') {
auto p = static_cast<Sci_Position>(sc.currentPos);
if (!_inComment(sc, p) && !_isQuoted(inSQuotedKey, inDQuotedKey)) {
--iSqrBraLev;
}
}
// -------------------------
// current state independent
// -------------------------
@ -544,7 +559,7 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
sc.SetState(SCE_TOML_COMMENT);
}
else if (sc.ch == '[') {
inSectionDef = true;
inSectionDef = !inMultiLnArrayDef;// true;
sc.SetState(SCE_TOML_SECTION);
}
else if (validKey.Contains(sc.ch)) {
@ -596,16 +611,15 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
// Array of Tables - eat
}
else if (sc.ch == ']') {
int const level = GetSquareBracketLevel(sc, true);
if (isSectKeyBeg) {
isSectKeyEnd = true;
}
if (level == 1) {
if (iSqrBraLev <= 0) {
inSectionDef = false;
}
else if (level < 1) {
SetStateParsingError(sc);
}
//~else if (level < 1) {
//~ SetStateParsingError(sc);
//~}
}
else if (IsCommentChar(sc.ch)) {
if (!inSectionDef) {
@ -712,16 +726,15 @@ void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int
bPossibleKeyword = false;
}
if (sc.ch == '[') {
inMultiLnArrayDef = (GetSquareBracketLevel(sc, false) > 0);
inMultiLnArrayDef = (iSqrBraLev > 0);
}
else if (sc.ch == ']') {
int const level = GetSquareBracketLevel(sc, false);
if (level == 1) {
if (iSqrBraLev <= 0) {
inMultiLnArrayDef = false;
}
else if (level <= 0) {
SetStateParsingError(sc);
}
//~else if (iSqrBraLev < 0) {
//~ SetStateParsingError(sc);
//~}
}
else if (sc.ch == '}') {
if (bInInlBracket) {

View File

@ -72,7 +72,7 @@ WCHAR* StrCutIW(WCHAR* s,const WCHAR* pattern)
do {
p = StrStrIW(s,pattern);
if (p) {
WCHAR* q = p + StringCchLen(pattern,0);
WCHAR* q = p + StringCchLenW(pattern,0);
while (*p != L'\0') { *p++ = *q++; }
}
} while (p);
@ -88,8 +88,9 @@ WCHAR* StrCutIW(WCHAR* s,const WCHAR* pattern)
//
bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove)
{
if (!pszSource || !pCharsToRemove)
if (!pszSource || !pCharsToRemove) {
return false;
}
LPSTR pch = pszSource;
while (*pch) {
@ -106,11 +107,34 @@ bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove)
}
//=============================================================================
//
// StrDelChrW()
//
bool StrDelChrW(LPWSTR pszSource, LPCWSTR pCharsToRemove)
{
if (!pszSource || !pCharsToRemove) {
return false;
}
LPWSTR pch = pszSource;
while (*pch) {
LPWSTR prem = pch;
while (StrChrW(pCharsToRemove, *prem)) {
++prem;
}
if (prem > pch) {
MoveMemory(pch, prem, sizeof(WCHAR)*(StringCchLenW(prem,0) + 1));
}
++pch;
}
return true;
}
//=============================================================================
//
// Find next token in string
//
CHAR* StrNextTokA(CHAR* strg, const CHAR* tokens)
{
CHAR* n = NULL;

View File

@ -537,6 +537,13 @@ WCHAR* StrNextTokW(WCHAR* strg, const WCHAR* tokens);
// ----------------------------------------------------------------------------
bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove);
bool StrDelChrW(LPWSTR pszSource, LPCWSTR pCharsToRemove);
#if defined(UNICODE) || defined(_UNICODE)
#define StrDelChr(s,r) StrDelChrW((s),(r))
#else
#define StrDelChr(s,r) StrDelChrA((s),(r))
#endif
//==== StrSafe lstrlen() =======================================================
//inline size_t StringCchLenA(LPCSTR s, size_t n) {

View File

@ -426,8 +426,8 @@ LANGID LoadLanguageResources()
//
void FreeLanguageResources()
{
CloseNonModalDialogs();
if (Globals.hLngResContainer != Globals.hInstance) {
CloseNonModalDialogs();
HINSTANCE const _hLngResContainer = Globals.hLngResContainer;
Globals.hLngResContainer = Globals.hInstance;
MUI_LanguageDLLs[0].bIsActive = true;

View File

@ -5354,8 +5354,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
else {
SetForegroundWindow(Globals.hwndDlgCustomizeSchemes);
}
PostWMCommand(Globals.hwndDlgCustomizeSchemes, IDC_SETCURLEXERTV);
UpdateMarginWidth();
SendWMCommand(Globals.hwndDlgCustomizeSchemes, IDC_SETCURLEXERTV);
UpdateUI();
break;

View File

@ -405,7 +405,6 @@ bool Style_IsCurLexerStandard()
//
// Style_GetBaseFontSize()
//
static float _SetBaseFontSize(float fSize)
{
static float fBaseFontSize = 11.0f;
@ -425,34 +424,17 @@ float Style_GetBaseFontSize()
return _SetBaseFontSize(-1.0);
}
//=============================================================================
//
// Style_RgbAlpha()
//
int Style_RgbAlpha(int rgbFore, int rgbBack, int alpha)
{
alpha = clampi(alpha, SC_ALPHA_TRANSPARENT, SC_ALPHA_OPAQUE);
return (int)RGB(\
(0xFF - alpha) * (int)GetRValue(rgbBack) / 0xFF + alpha * (int)GetRValue(rgbFore) / 0xFF, \
(0xFF - alpha) * (int)GetGValue(rgbBack) / 0xFF + alpha * (int)GetGValue(rgbFore) / 0xFF, \
(0xFF - alpha) * (int)GetBValue(rgbBack) / 0xFF + alpha * (int)GetBValue(rgbFore) / 0xFF);
}
//=============================================================================
//
// _SetCurrentFontSize(), _GetCurrentFontSize()
//
static float _SetCurrentFontSize(float fSize)
{
static float fCurrentFontSize = 10.0f;
static float fCurrentFontSize = 11.0f;
if (signbit(fSize) == 0) {
float const fSizeR10th = Round10th(fSize);
fCurrentFontSize = (0.5f < fSizeR10th) ? fSizeR10th : 0.5f;
fCurrentFontSize = (0.5f < fSizeR10th) ? fSizeR10th : 0.5f;
}
return fCurrentFontSize;
}
@ -463,6 +445,20 @@ float Style_GetCurrentFontSize()
}
//=============================================================================
//
// Style_RgbAlpha()
//
int Style_RgbAlpha(int rgbFore, int rgbBack, int alpha) {
alpha = clampi(alpha, SC_ALPHA_TRANSPARENT, SC_ALPHA_OPAQUE);
return (int)RGB(
(0xFF - alpha) * (int)GetRValue(rgbBack) / 0xFF + alpha * (int)GetRValue(rgbFore) / 0xFF,
(0xFF - alpha) * (int)GetGValue(rgbBack) / 0xFF + alpha * (int)GetGValue(rgbFore) / 0xFF,
(0xFF - alpha) * (int)GetBValue(rgbBack) / 0xFF + alpha * (int)GetBValue(rgbFore) / 0xFF);
}
//=============================================================================
//
// Style_Init()
@ -2366,7 +2362,8 @@ void Style_ToggleUse2ndDefault(HWND hwnd)
if (IsLexerStandard(s_pLexCurrent)) {
s_pLexCurrent = GetCurrentStdLexer(); // sync
}
Style_ResetCurrentLexer(hwnd);
Style_ResetCurrentLexer(Globals.hwndEdit);
UNUSED(hwnd);
}
@ -2393,7 +2390,7 @@ void Style_SetDefaultFont(HWND hwnd, bool bGlobalDefault)
{
// set new styles to current lexer's default text
StringCchCopyW(pLexerDefStyle->szValue, COUNTOF(pLexerDefStyle->szValue), newStyle);
Style_ResetCurrentLexer(hwnd);
Style_ResetCurrentLexer(Globals.hwndEdit);
}
}
@ -4070,17 +4067,20 @@ static bool _ApplyDialogItemText(HWND hwnd,
}
static WCHAR s_OrigTitle[64] = { L'\0' };
static WCHAR s_TitleTxt[128] = { L'\0' };
static void _UpdateTitleText(HWND hwnd)
{
static WCHAR s_OrigTitle[64] = { L'\0' };
if (StrIsEmpty(s_OrigTitle)) {
GetWindowText(hwnd, s_OrigTitle, COUNTOF(s_OrigTitle));
}
unsigned const iTheme = GetModeThemeIndex();
const WCHAR *const strThemeName = (iTheme <= 1) ? L"Standard" : Theme_Files[iTheme].szName;
StringCchPrintf(s_TitleTxt, COUNTOF(s_TitleTxt), L"%s - %s", s_OrigTitle, strThemeName);
unsigned const iTheme = max_u(1, GetModeThemeIndex());
WCHAR scheme[96] = { L'\0' };
StringCchCopy(scheme, COUNTOF(scheme), Theme_Files[iTheme].szName);
StrDelChr(scheme, L"&"); // rm hotkey mark
PWCHAR const e = StrChr(scheme, L' '); if (e) { *e = L'\0'; } // until 1st space
StringCchPrintf(s_TitleTxt, COUNTOF(s_TitleTxt), L"%s - %s", s_OrigTitle, scheme);
SetWindowText(hwnd, s_TitleTxt);
}
@ -4333,7 +4333,7 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
SendMessage(hwndTV, WM_THEMECHANGED, 0, 0);
_UpdateTitleText(hwnd);
SendDlgItemMessageW(hwnd, IDC_TITLE, WM_SETTEXT, 0, (LPARAM)s_TitleTxt); // scheme may have changed
Style_ResetCurrentLexer(hwnd);
Style_ResetCurrentLexer(Globals.hwndEdit);
SendWMCommandEx(hwnd, IDC_STYLEEDIT, EN_CHANGE); // button color inlay
UpdateWindowEx(hwnd);
}
@ -4382,11 +4382,13 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
DeleteObject(hFontTitle);
hFontTitle = NULL;
}
s_TitleTxt[0] = L'\0';
s_OrigTitle[0] = L'\0';
pCurrentLexer = NULL;
pCurrentStyle = NULL;
iCurStyleIdx = -1;
}
return false;
return FALSE;
case WM_SYSCOMMAND:
if (wParam == IDS_MUI_SAVEPOS)
@ -4400,7 +4402,7 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
return TRUE;
}
else
return 0;
return FALSE;
case WM_NOTIFY: