Skip to content

Commit

Permalink
Merge pull request #490 from RaiKoHoff/Bugfixes_Release_III
Browse files Browse the repository at this point in the history
Bugfixes for Release Ed. III
  • Loading branch information
rizonesoft authored May 11, 2018
2 parents 07d1a2f + 29b1b20 commit 6b5b9c9
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 75 deletions.
Binary file added Build/Notepad3_redirector.ini
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion scintilla/lexers/LexBatch.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ static inline bool AtEOL(Accessor &styler, Sci_PositionU i) {
// Tests for BATCH Operators
static bool IsBOperator(char ch) {
return (ch == '=') || (ch == '+') || (ch == '>') || (ch == '<') ||
(ch == '|') || (ch == '?') || (ch == '*');
(ch == '|') || (ch == '?') || (ch == '*') ||
(ch == '(') || (ch == ')') || (ch == '[') || (ch == ']');
}

// Tests for BATCH Separators
Expand Down
10 changes: 4 additions & 6 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -6559,7 +6559,6 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi

DocPos start = startPos;
DocPos end = endPos;
int const iStyle = Style_GetHotspotStyleID();

do {
DocPos iPos = _FindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, false, FRMOD_IGNORE);
Expand All @@ -6574,7 +6573,7 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi
// mark this match
SciCall_StartStyling(iPos);
if (bActiveHotspot)
SciCall_SetStyling((DocPosCR)mlen, iStyle);
SciCall_SetStyling((DocPosCR)mlen, (char)Style_GetHotspotStyleID());
else
EditFinalizeStyling(hwnd, endPos);

Expand Down Expand Up @@ -6631,8 +6630,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo
SciCall_SetFoldFlags(0);
//SciCall_SetFoldFlags(SC_FOLDFLAG_LEVELNUMBERS | SC_FOLDFLAG_LINESTATE); // Debug

// hide lines without indicator
const int iStyleHideID = Style_GetInvisibleStyleID();
// --- hide lines without indicator ---

const DocLn iStartLine = SciCall_LineFromPosition(iStartPos);
const DocLn iEndLine = SciCall_LineFromPosition(iEndPos);
Expand All @@ -6651,7 +6649,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo
const DocPos begPos = SciCall_PositionFromLine(iStartLine);
const DocPos lnLen = SciCall_LineLength(iStartLine);
SciCall_StartStyling(begPos);
SciCall_SetStyling((DocPosCR)lnLen, iStyleHideID);
SciCall_SetStyling((DocPosCR)lnLen, (char)Style_GetInvisibleStyleID());
}

int level = baseLevel;
Expand All @@ -6667,7 +6665,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo
const DocPos begPos = SciCall_PositionFromLine(iLine);
const DocPos lnLen = SciCall_LineLength(iLine);
SciCall_StartStyling(begPos);
SciCall_SetStyling((DocPosCR)lnLen, iStyleHideID);
SciCall_SetStyling((DocPosCR)lnLen, (char)Style_GetInvisibleStyleID());

if (level == baseLevel) {
SciCall_SetFoldLevel(iLine - 1, SC_FOLDLEVELHEADERFLAG | level++);
Expand Down
115 changes: 67 additions & 48 deletions src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2747,9 +2747,9 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam)
EnableCmd(hmenu,IDM_VIEW_SAVESETTINGSNOW,g_bEnableSaveSettings && i);

bool bIsHLink = false;
if ((bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0))
if ((bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0))
{
bIsHLink = (Style_GetHotspotStyleID() == (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, SciCall_GetCurrentPos(), 0));
bIsHLink = (SciCall_GetStyleAt(SciCall_GetCurrentPos()) == (char)Style_GetHotspotStyleID());
}
EnableCmd(hmenu, CMD_OPEN_HYPERLINK, bIsHLink);

Expand Down Expand Up @@ -5610,28 +5610,25 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
//
void OpenHotSpotURL(DocPos position, bool bForceBrowser)
{
int iStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, position, 0);
char const cStyle = SciCall_GetStyleAt(position);

if (Style_GetHotspotStyleID() != iStyle)
return;

if (!(bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0))
return;
if (cStyle != (char)Style_GetHotspotStyleID()) { return; }
if (!(bool)SendMessage(g_hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) { return; }

// get left most position of style
DocPos pos = position;
int iNewStyle = iStyle;
while ((iNewStyle == iStyle) && (--pos > 0)) {
iNewStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, pos, 0);
char cNewStyle = cStyle;
while ((cNewStyle == cStyle) && (--pos > 0)) {
cNewStyle = SciCall_GetStyleAt(pos);
}
DocPos firstPos = (pos != 0) ? (pos + 1) : 0;

// get right most position of style
pos = position;
iNewStyle = iStyle;
cNewStyle = cStyle;
DocPos posTextLength = SciCall_GetTextLength();
while ((iNewStyle == iStyle) && (++pos < posTextLength)) {
iNewStyle = (int)SendMessage(g_hwndEdit, SCI_GETSTYLEAT, pos, 0);
while ((cNewStyle == cStyle) && (++pos < posTextLength)) {
cNewStyle = SciCall_GetStyleAt(pos);
}
DocPos lastPos = pos;
DocPos length = (lastPos - firstPos);
Expand Down Expand Up @@ -6126,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:
Expand Down Expand Up @@ -7269,7 +7268,7 @@ void LoadFlags()
// FindIniFile()
//
//
bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule)
static bool __fastcall _CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule)
{
WCHAR tchFileExpanded[MAX_PATH] = { L'\0' };
WCHAR tchBuild[MAX_PATH] = { L'\0' };
Expand All @@ -7279,12 +7278,20 @@ bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule)
// program directory
StringCchCopy(tchBuild,COUNTOF(tchBuild),lpszModule);
StringCchCopy(PathFindFileName(tchBuild),COUNTOF(tchBuild),tchFileExpanded);

if (PathFileExists(tchBuild)) {
StringCchCopy(lpszFile,MAX_PATH,tchBuild);
return true;
}
// %appdata%
// sub directory (.\np3\)
StringCchCopy(tchBuild, COUNTOF(tchBuild), lpszModule);
PathRemoveFileSpec(tchBuild);
StringCchCat(tchBuild,COUNTOF(tchBuild),L"\\np3\\");
StringCchCat(tchBuild,COUNTOF(tchBuild),tchFileExpanded);
if (PathFileExists(tchBuild)) {
StringCchCopy(lpszFile, MAX_PATH, tchBuild);
return true;
}
// %APPDATA%
//if (S_OK == SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tchBuild)) {
if (GetKnownFolderPath(&FOLDERID_RoamingAppData, tchBuild, COUNTOF(tchBuild))) {
PathCchAppend(tchBuild,COUNTOF(tchBuild),tchFileExpanded);
Expand All @@ -7299,20 +7306,19 @@ bool CheckIniFile(LPWSTR lpszFile,LPCWSTR lpszModule)
return true;
}
}

else if (PathFileExists(tchFileExpanded)) {
StringCchCopy(lpszFile,MAX_PATH,tchFileExpanded);
return true;
}

return false;
}

bool CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule)

static bool __fastcall _CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule)
{
WCHAR tch[MAX_PATH] = { L'\0' };
if (GetPrivateProfileString(L"Notepad3",L"Notepad3.ini",L"",tch,COUNTOF(tch),lpszFile)) {
if (CheckIniFile(tch,lpszModule)) {
if (_CheckIniFile(tch,lpszModule)) {
StringCchCopy(lpszFile,MAX_PATH,tch);
return true;
}
Expand All @@ -7333,44 +7339,51 @@ bool CheckIniFileRedirect(LPWSTR lpszFile,LPCWSTR lpszModule)
return false;
}


int FindIniFile() {

WCHAR tchTest[MAX_PATH] = { L'\0' };
WCHAR tchPath[MAX_PATH] = { L'\0' };
WCHAR tchModule[MAX_PATH] = { L'\0' };

GetModuleFileName(NULL,tchModule,COUNTOF(tchModule));

// set env path to module dir
StringCchCopy(tchPath, COUNTOF(tchPath), tchModule);
PathRemoveFileSpec(tchPath);
SetEnvironmentVariable(L"NOTEPAD3MODULEDIR", tchPath);

if (StringCchLenW(g_wchIniFile,COUNTOF(g_wchIniFile))) {
if (StringCchCompareIX(g_wchIniFile,L"*?") == 0)
return(0);
else {
if (!CheckIniFile(g_wchIniFile,tchModule)) {
if (!_CheckIniFile(g_wchIniFile,tchModule)) {
ExpandEnvironmentStringsEx(g_wchIniFile,COUNTOF(g_wchIniFile));
if (PathIsRelative(g_wchIniFile)) {
StringCchCopy(tchTest,COUNTOF(tchTest),tchModule);
PathRemoveFileSpec(tchTest);
PathCchAppend(tchTest,COUNTOF(tchTest),g_wchIniFile);
StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchTest);
StringCchCopy(tchPath,COUNTOF(tchPath),tchModule);
PathRemoveFileSpec(tchPath);
PathCchAppend(tchPath,COUNTOF(tchPath),g_wchIniFile);
StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchPath);
}
}
}
}
else {
StringCchCopy(tchTest,COUNTOF(tchTest),PathFindFileName(tchModule));
PathCchRenameExtension(tchTest,COUNTOF(tchTest),L".ini");
bool bFound = CheckIniFile(tchTest,tchModule);
StringCchCopy(tchPath,COUNTOF(tchPath),PathFindFileName(tchModule));
PathCchRenameExtension(tchPath,COUNTOF(tchPath),L".ini");
bool bFound = _CheckIniFile(tchPath,tchModule);

if (!bFound) {
StringCchCopy(tchTest,COUNTOF(tchTest),L"Notepad3.ini");
bFound = CheckIniFile(tchTest,tchModule);
StringCchCopy(tchPath,COUNTOF(tchPath),L"Notepad3.ini");
bFound = _CheckIniFile(tchPath,tchModule);
}

if (bFound) {

// allow two redirections: administrator -> user -> custom
if (CheckIniFileRedirect(tchTest,tchModule))
CheckIniFileRedirect(tchTest,tchModule);
if (_CheckIniFileRedirect(tchPath,tchModule))
_CheckIniFileRedirect(tchPath,tchModule);

StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchTest);
StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchPath);
}
else {
StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),tchModule);
Expand Down Expand Up @@ -7949,31 +7962,37 @@ 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;
}
// ------------------------------------------------------

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;
}
// ------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions src/Notepad3.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ void LoadSettings();
void SaveSettings(bool);
void ParseCommandLine();
void LoadFlags();
bool CheckIniFile(LPWSTR,LPCWSTR);
bool CheckIniFileRedirect(LPWSTR,LPCWSTR);
int FindIniFile();
int TestIniFile();
int CreateIniFile();
Expand Down
7 changes: 4 additions & 3 deletions src/SciCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ DeclareSciCallR1(DocLineFromVisible, DOCLINEFROMVISIBLE, DocLn, DocLn, line)
//
// Style definition
//
DeclareSciCallR1(StyleGetFore, STYLEGETFORE, COLORREF, int, styleNumber)
DeclareSciCallR1(StyleGetBack, STYLEGETBACK, COLORREF, int, styleNumber)
DeclareSciCallV2(SetStyling, SETSTYLING, DocPosCR, length, int, style)
DeclareSciCallR1(StyleGetFore, STYLEGETFORE, COLORREF, char, style)
DeclareSciCallR1(StyleGetBack, STYLEGETBACK, COLORREF, char, style)
DeclareSciCallR1(GetStyleAt, GETSTYLEAT, char, DocPos, position)
DeclareSciCallV2(SetStyling, SETSTYLING, DocPosCR, length, char, style)
DeclareSciCallV1(StartStyling, STARTSTYLING, DocPos, position)
DeclareSciCallR0(GetEndStyled, GETENDSTYLED, DocPos)

Expand Down
Loading

0 comments on commit 6b5b9c9

Please sign in to comment.