fix #293 - Changes to hardcoded highlighter presets are not visible until the old setting file is deleted

This commit is contained in:
Basile Burg 2018-04-13 23:47:26 +02:00
parent ddf268e685
commit ab68e7287e
1 changed files with 282 additions and 245 deletions

View File

@ -36,6 +36,7 @@ type
fSelAttribs: TSynSelectedColor;
fd2syn: TPersistent;
fName: string;
fIsHardcoded: boolean;
procedure setBracketMatchColor(value: TSynSelectedColor);
procedure setCurrLineAttribs(value: TSynSelectedColor);
procedure setFoldedColor(value: TSynSelectedColor);
@ -54,6 +55,7 @@ type
property identifierMatch: TSynSelectedColor read fIdentifierMarkup write setIdentifierMarkup stored true;
property mouseLink: TSynSelectedColor read fMouseLinkAttribs write setMouseLinkColor stored true;
property selection: TSynSelectedColor read fSelAttribs write setSelCol stored true;
property isHardCoded: boolean read fIsHardcoded stored false;
public
constructor Create(ACollection: TCollection); override;
destructor destroy; override;
@ -73,6 +75,7 @@ type
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function addPreset: TCED2SynPreset;
function insertPreset(index: integer): TCED2SynPreset;
function count: integer;
property preset[index: integer]: TCED2SynPreset read getPreset ; default;
end;
@ -254,6 +257,11 @@ begin
exit(TCED2SynPreset(fCollection.Add));
end;
function TCED2SynPresets.insertPreset(index: integer): TCED2SynPreset;
begin
exit(TCED2SynPreset(fCollection.Insert(index)));
end;
function TCED2SynPresets.count: integer;
begin
exit(fCollection.Count);
@ -323,17 +331,28 @@ constructor TCED2SynPresetsLoaderForm.Create(AOwner: TComponent);
var
fname: string;
pnl: TPanel;
i: integer;
const
h: array[0..5] of string = ('bright', 'dark', 'Mustard', 'Mars bright',
'Mars dark', 'Soft dust');
begin
inherited;
fBackup:= TCED2SynPreset.Create(nil);
fPresets:= TCED2SynPresets.Create(self);
fname := getCoeditDocPath + optfname;
if fname.fileExists then
fPresets.loadFromFile(fname)
else
fPresets.loadFromFile(fname);
//TODO-cmaintenance: remove this the second version following 3.6.7
for i:= 5 downto 0 do
begin
with fPresets.addPreset do
if (i < fPresets.count) and (fPresets[i].name = h[i]) then
fPresets.fCollection.Delete(i);
end;
with fPresets.insertPreset(0) do
begin
fIsHardcoded := true;
fName :='bright';
fBackground := clWhite;
getHl.whites.define(clNone);
@ -377,8 +396,9 @@ begin
getHl.types.Style:=[fsBold];
getHl.phobosStyleType := True;
end;
with fPresets.addPreset do
with fPresets.insertPreset(1) do
begin
fIsHardcoded := true;
fName :='dark';
getHl.whites.FrameEdges := sfeNone;
getHl.numbers.Foreground := 16761218;
@ -421,8 +441,9 @@ begin
selection.BackPriority:= 2;
getHl.phobosStyleType := True;
end;
with fPresets.addPreset do
with fPresets.insertPreset(2) do
begin
fIsHardcoded := true;
fName :='Mustard';
getHl.whites.FrameEdges := sfeNone;
getHl.numbers.FrameEdges := sfeNone;
@ -462,8 +483,9 @@ begin
selection.BackPriority := 1;
getHl.phobosStyleType := True;
end;
with fPresets.addPreset do
with fPresets.insertPreset(3) do
begin
fIsHardcoded := true;
name := 'Mars bright';
getHl.identifiers.Foreground := clBlack;
getHl.identifiers.FrameEdges := sfeNone;
@ -498,8 +520,9 @@ begin
selection.BackPriority := 10;
getHl.phobosStyleType := True;
end;
with fPresets.addPreset do
with fPresets.insertPreset(4) do
begin
fIsHardcoded := true;
name := 'Mars dark';
getHl.numbers.Foreground := 7763655;
getHl.symbols.Foreground := 5460961;
@ -534,8 +557,9 @@ begin
selection.Foreground := clNone;
getHl.phobosStyleType := True;
end;
with fPresets.addPreset do
with fPresets.insertPreset(5) do
begin
fIsHardcoded := true;
name := 'Soft dust';
getHl.phobosStyleType := True;
getHl.foldKinds := [fkBrackets, fkRegion];
@ -575,7 +599,6 @@ begin
selection.Background := $9DAABC;
selection.Foreground := clNone;
end;
end;
fEditor := TSynEdit.Create(self);
fEditor.Parent:= self;
@ -657,7 +680,12 @@ begin
end;
destructor TCED2SynPresetsLoaderForm.Destroy;
var
i: integer;
begin
for i:= fPresets.count-1 downto 0 do
if fPresets.preset[i].isHardCoded then
fPresets.fCollection.Delete(i);
fPresets.saveToFile(getCoeditDocPath + optfname);
fBackup.Free;
EntitiesConnector.removeObserver(self);
@ -722,8 +750,17 @@ begin
end;
procedure TCED2SynPresetsLoaderForm.btnDelClick(sender: TObject);
var
o: integer;
begin
if (fPresets.preset[fList.ItemIndex].isHardCoded) then
exit;
o := fList.ItemIndex;
fPropEd.TIObject := nil;
fPresets.fCollection.Delete(fList.ItemIndex);
if o >= fPresets.count then
o -= 1 ;
fList.ItemIndex:=o;
updateList;
lstBoxSelChange(nil);
end;