tpl to be treated as diff tpl, inheriting the default tpl

This commit is contained in:
Massimo Melina 2020-05-24 17:03:31 +02:00
parent 0884a2434a
commit 8f1965f863
2 changed files with 22 additions and 19 deletions

View File

@ -909,18 +909,22 @@ end;
function Ttpl.getSection(section:string; inherit:boolean=TRUE):PtplSection; function Ttpl.getSection(section:string; inherit:boolean=TRUE):PtplSection;
begin begin
try result:=sections[section] if sections.containsKey(section) then
except result:=NIL result:=sections[section]
end; else
result:=NIL;
if inherit and assigned(over) and ((result = NIL) or (trim(result.txt) = '')) then if inherit and assigned(over) and ((result = NIL) or (trim(result.txt) = '')) then
result:=over.getSection(section); result:=over.getSection(section);
end; // getSection end; // getSection
function Ttpl.getTxt(section:string):string; function Ttpl.getTxt(section:string):string;
var p: PtplSection;
begin begin
try result:=getSection(section).txt p:=getSection(section);
except result:='' if p = NIL then
end; result:=''
else
result:=p.txt
end; // getTxt end; // getTxt
function Ttpl.getTxtByExt(fileExt:string):string; function Ttpl.getTxtByExt(fileExt:string):string;

View File

@ -1131,9 +1131,8 @@ var
addingItemsCounter: integer = -1; // -1 is disabled addingItemsCounter: integer = -1; // -1 is disabled
stopAddingItems, queryingClose: boolean; stopAddingItems, queryingClose: boolean;
port: string; port: string;
defaultTpl: string;
lastWindowRect: Trect; lastWindowRect: Trect;
dmBrowserTpl, filelistTpl: Ttpl; defaultTpl, dmBrowserTpl, filelistTpl: Ttpl;
tplEditor: string; tplEditor: string;
tplLast: Tdatetime; tplLast: Tdatetime;
tplImport: boolean; tplImport: boolean;
@ -4496,7 +4495,7 @@ finally
end; // runTplImport end; // runTplImport
// returns true if template was patched // returns true if template was patched
function setTplText(text:string):boolean; function setTplText(text:string=''):boolean;
(* postponed to next release (* postponed to next release
procedure patch290(); procedure patch290();
{$J+} {$J+}
@ -4528,8 +4527,10 @@ function setTplText(text:string):boolean;
begin begin
result:=FALSE; // mod by mars result:=FALSE; // mod by mars
//patch290(); //patch290();
if trim(text) = trim(defaultTpl.fullText) then
text:='';
tpl.fullText:=text; tpl.fullText:=text;
tplIsCustomized:= text <> defaultTpl; tplIsCustomized:= text > '';
if boolOnce(tplImport) then if boolOnce(tplImport) then
runTplImport(); runTplImport();
end; // setTplText end; // setTplText
@ -4545,7 +4546,7 @@ if fileExists(tplFilename) then
else if tplLast <> 0 then else if tplLast <> 0 then
begin begin
tplLast:=0; // we have no modified-time in this case, but this will stop the refresh tplLast:=0; // we have no modified-time in this case, but this will stop the refresh
setTplText(defaultTpl); setTplText();
end; end;
end; // keepTplUpdated end; // keepTplUpdated
@ -7161,7 +7162,7 @@ if lastGoodLogWidth > 0 then
if lastGoodConnHeight > 0 then if lastGoodConnHeight > 0 then
connPnl.Height:=lastGoodConnHeight; connPnl.Height:=lastGoodConnHeight;
if not fileExists(tplFilename) then if not fileExists(tplFilename) then
setTplText(defaultTpl); setTplText();
srv.persistentConnections:=persistentconnectionsChk.Checked; srv.persistentConnections:=persistentconnectionsChk.Checked;
applyFilesBoxRatio(); applyFilesBoxRatio();
updateRecentFilesMenu(); updateRecentFilesMenu();
@ -11575,7 +11576,7 @@ begin
if not fileExists(tplFilename) then if not fileExists(tplFilename) then
begin begin
tplFilename:=TPL_FILE; tplFilename:=TPL_FILE;
saveTextFile(tplFilename, defaultTpl); saveTextFile(tplFilename, defaultTpl.fullText);
end; end;
exec(getTplEditor(), '"'+tplFilename+'"'); exec(getTplEditor(), '"'+tplFilename+'"');
end; end;
@ -11931,7 +11932,7 @@ and only1instanceChk.checked and not mono.master then
end; end;
if not cfgLoaded then if not cfgLoaded then
setTplText(defaultTpl); setTplText();
processParams_before(params); processParams_before(params);
@ -12526,11 +12527,8 @@ else
tmpPath:=getTempDir(); tmpPath:=getTempDir();
lastUpdateCheckFN:=tmpPath+'HFS last update check.tmp'; lastUpdateCheckFN:=tmpPath+'HFS last update check.tmp';
setCurrentDir(exePath); // sometimes people mess with the working directory, so we force it to the exe path setCurrentDir(exePath); // sometimes people mess with the working directory, so we force it to the exe path
if fileExists('default.tpl') then defaultTpl:=Ttpl.create(getRes('defaultTpl'));
defaultTpl:=loadTextfile('default.tpl') tpl:=Ttpl.create('', defaultTpl);
else
defaultTpl:=getRes('defaultTpl');
tpl:=Ttpl.create();
defSorting:='name'; defSorting:='name';
dmBrowserTpl:=Ttpl.create(getRes('dmBrowserTpl')); dmBrowserTpl:=Ttpl.create(getRes('dmBrowserTpl'));
filelistTpl:=Ttpl.create(getRes('filelistTpl')); filelistTpl:=Ttpl.create(getRes('filelistTpl'));
@ -12590,6 +12588,7 @@ FINALIZATION
progFrm.free; progFrm.free;
toDelete.free; toDelete.free;
tpl.free; tpl.free;
defaultTpl.Free;
filelistTpl.free; filelistTpl.free;
autoupdatedFiles.free; autoupdatedFiles.free;
iconsCache.free; iconsCache.free;