Merge pull request #4788 from RaiKoHoff/Dev_Master

Option: do not save blank new files
This commit is contained in:
Pairi Daiza 2023-05-04 19:52:51 +02:00 committed by GitHub
commit 3dca6473ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -31,6 +31,7 @@ SettingsVersion=5
;FindReplaceOpacityLevel=50
;RelativeFileMRU=1
;ReuseWindow=0
;SaveBlankNewFile=true
;SciFontQuality=3
;SimpleIndentGuides=0
;SingleFileInstance=1

View File

@ -89,6 +89,7 @@ static void ColouriseInnoDoc(Sci_PositionU startPos, Sci_Position length, int, W
// using the hand-written state machine shown below
styler.StartAt(startPos);
styler.StartSegment(startPos);
for (Sci_Position i = startPos; i < lengthDoc; i++) {
chPrev = ch;
ch = chNext;

View File

@ -1216,6 +1216,8 @@ void LoadSettings()
Flags.NoHTMLGuess = IniSectionGetBool(IniSecSettings2, L"NoHTMLGuess", DefaultFlags.NoHTMLGuess);
Flags.NoCGIGuess = IniSectionGetBool(IniSecSettings2, L"NoCGIGuess", DefaultFlags.NoCGIGuess);
Flags.NoFileVariables = IniSectionGetBool(IniSecSettings2, L"NoFileVariables", DefaultFlags.NoFileVariables);
Flags.SaveBlankNewFile = IniSectionGetBool(IniSecSettings2, L"SaveBlankNewFile", DefaultFlags.SaveBlankNewFile);
Flags.PrintFileAndLeave = Globals.CmdLnFlag_PrintFileAndLeave;

View File

@ -779,6 +779,7 @@ static void _InitGlobals()
Flags.NoHTMLGuess =DefaultFlags.NoHTMLGuess = false;
Flags.NoCGIGuess = DefaultFlags.NoCGIGuess = false;
Flags.NoFileVariables = DefaultFlags.NoFileVariables = false;
Flags.SaveBlankNewFile = DefaultFlags.SaveBlankNewFile = true;
Flags.ShellUseSystemMRU = DefaultFlags.ShellUseSystemMRU = true;
Flags.PrintFileAndLeave = DefaultFlags.PrintFileAndLeave = 0;
Flags.bPreserveFileModTime = DefaultFlags.bPreserveFileModTime = false;
@ -11787,24 +11788,24 @@ bool FileSave(FileSaveFlags fSaveFlags)
fioStatus.iEncoding = Encoding_GetCurrent();
fioStatus.iEOLMode = SciCall_GetEOLMode();
#if 0
bool bIsEmptyNewFile = false;
if (Path_IsEmpty(Paths.CurrentFile)) {
DocPos const cchText = SciCall_GetTextLength();
if (cchText <= 0) {
bIsEmptyNewFile = true;
} else if (cchText < 2048) {
char chTextBuf[2048] = { '\0' };
SciCall_GetText(COUNTOF(chTextBuf) - 1, chTextBuf);
StrTrimA(chTextBuf, " \t\n\r");
if (StrIsEmptyA(chTextBuf)) {
if (Flags.SaveBlankNewFile) {
bIsEmptyNewFile = (Path_IsEmpty(Paths.CurrentFile) && (SciCall_GetTextLength() <= 0LL));
}
else {
if (Path_IsEmpty(Paths.CurrentFile)) {
DocPos const cchText = SciCall_GetTextLength();
if (cchText <= 0) {
bIsEmptyNewFile = true;
}
else {
struct Sci_TextToFindFull ft = { { 0, 0 }, "\\S+", { 0, 0 } };
ft.chrg.cpMax = Sci_GetDocEndPosition();
DocPos const iPos = SciCall_FindTextFull(SCFIND_REGEXP, &ft);
bIsEmptyNewFile = ((iPos < 0) || (iPos >= ft.chrg.cpMax));
}
}
}
#else
bool const bIsEmptyNewFile = (Path_IsEmpty(Paths.CurrentFile) && (SciCall_GetTextLength() <= 0LL));
#endif
bool const bSaveNeeded = (IsSaveNeeded() || IsFileChangedFlagSet()) && !bIsEmptyNewFile;

View File

@ -722,6 +722,7 @@ typedef struct FLAGS_T {
bool RelativeFileMRU;
bool PortableMyDocs;
bool NoFadeHidden;
bool SaveBlankNewFile;
bool SimpleIndentGuides;
bool NoHTMLGuess;
bool NoCGIGuess;