dev option editor - 3

This commit is contained in:
Basile Burg 2015-02-19 06:08:06 +01:00
parent b562324894
commit 94ec732c39
2 changed files with 87 additions and 30 deletions

View File

@ -21,14 +21,13 @@ type
(** (**
* Container for the editor and highlither options. * Container for the editor and highlither options.
* The base class is also used to backup settings * The base class is also used to backup the settings
* to allow settings to be previewed in live and restored * to allow a live preview and to restore them when not accepted.
* when not accepted.
*) *)
TCEEditorOptionsBase = class(TWritableLfmTextComponent) TCEEditorOptionsBase = class(TWritableLfmTextComponent)
private private
fDHlOptions: TPersistent; fD2Syn: TPersistent;
fTxtHlOptions: TPersistent; fTxtSyn: TPersistent;
fFont: TFont; fFont: TFont;
// //
fTabWidth: Integer; fTabWidth: Integer;
@ -40,6 +39,8 @@ type
fMouseOptions: TSynEditorMouseOptions; fMouseOptions: TSynEditorMouseOptions;
// //
procedure setFont(aFont: TFont); procedure setFont(aFont: TFont);
procedure setD2Syn(aValue: TPersistent);
procedure setTxtSyn(aValue: TPersistent);
published published
property tabulationWidth: Integer read fTabWidth write fTabWidth; property tabulationWidth: Integer read fTabWidth write fTabWidth;
property blockIdentation: Integer read fBlockIdent write fBlockIdent; property blockIdentation: Integer read fBlockIdent write fBlockIdent;
@ -49,11 +50,11 @@ type
property options1: TSynEditorOptions read fOptions1 write fOptions1; property options1: TSynEditorOptions read fOptions1 write fOptions1;
property options2: TSynEditorOptions2 read fOptions2 write fOptions2; property options2: TSynEditorOptions2 read fOptions2 write fOptions2;
property mouseOptions: TSynEditorMouseOptions read fMouseOptions write fMouseOptions; property mouseOptions: TSynEditorMouseOptions read fMouseOptions write fMouseOptions;
property D2Highlighter: TPersistent read fD2Syn write setD2Syn;
property D_colorizer: TPersistent read fDHlOptions; property TxtHighlighter: TPersistent read fTxtSyn write setTxtSyn;
property TXT_colorizer: TPersistent read fTxtHlOptions;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
// //
procedure assign(src: TPersistent); override; procedure assign(src: TPersistent); override;
end; end;
@ -77,22 +78,25 @@ type
// //
procedure applyChangesFromSelf; procedure applyChangesFromSelf;
procedure applyChangeToEditor(anEditor: TCESynMemo); procedure applyChangeToEditor(anEditor: TCESynMemo);
protected
procedure afterLoad; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
end; end;
implementation
const
edoptFname = 'editor.txt';
var var
EditorOptions: TCEEditorOptions; EditorOptions: TCEEditorOptions;
implementation
{$REGION Standard Comp/Obj -----------------------------------------------------} {$REGION Standard Comp/Obj -----------------------------------------------------}
constructor TCEEditorOptionsBase.Create(AOwner: TComponent); constructor TCEEditorOptionsBase.Create(AOwner: TComponent);
begin begin
inherited; inherited;
fDHlOptions := D2Syn;
fTxtHlOptions := TxtSyn;
// //
fFont := TFont.Create; fFont := TFont.Create;
fFont.Size := 10; fFont.Size := 10;
@ -101,6 +105,11 @@ begin
fFont.Pitch := fpFixed; fFont.Pitch := fpFixed;
fFont.Size:= 10; fFont.Size:= 10;
// //
fD2Syn := TSynD2Syn.create(self);
fD2Syn.Assign(D2Syn);
fTxtSyn := TSynTxtSyn.create(self);
fTxtSyn.Assign(TxtSyn);
//
tabulationWidth := 4; tabulationWidth := 4;
blockIdentation := 4; blockIdentation := 4;
// //
@ -114,16 +123,9 @@ begin
[emAltSetsColumnMode, emDragDropEditing, emCtrlWheelZoom, emShowCtrlMouseLinks]; [emAltSetsColumnMode, emDragDropEditing, emCtrlWheelZoom, emShowCtrlMouseLinks];
end; end;
constructor TCEEditorOptions.Create(AOwner: TComponent); destructor TCEEditorOptionsBase.Destroy;
begin begin
inherited; fFont.Free;
fBackup := TCEEditorOptionsBase.Create(self);
EntitiesConnector.addObserver(self);
end;
destructor TCEEditorOptions.Destroy;
begin
EntitiesConnector.removeObserver(self);
inherited; inherited;
end; end;
@ -136,6 +138,8 @@ begin
srcopt := TCEEditorOptionsBase(src); srcopt := TCEEditorOptionsBase(src);
// //
font.Assign(srcopt.font); font.Assign(srcopt.font);
fD2Syn.Assign(srcopt.fD2Syn);
fTxtSyn.Assign(srcopt.fTxtSyn);
tabulationWidth := srcopt.tabulationWidth; tabulationWidth := srcopt.tabulationWidth;
blockIdentation := srcopt.blockIdentation; blockIdentation := srcopt.blockIdentation;
lineSpacing := srcopt.lineSpacing; lineSpacing := srcopt.lineSpacing;
@ -151,6 +155,43 @@ procedure TCEEditorOptionsBase.setFont(aFont: TFont);
begin begin
fFont.Assign(aFont); fFont.Assign(aFont);
end; end;
procedure TCEEditorOptionsBase.setD2Syn(aValue: TPersistent);
begin
D2Syn.Assign(aValue);
end;
procedure TCEEditorOptionsBase.setTxtSyn(aValue: TPersistent);
begin
TxtSyn.Assign(aValue);
end;
constructor TCEEditorOptions.Create(AOwner: TComponent);
var
fname: string;
begin
inherited;
fBackup := TCEEditorOptionsBase.Create(self);
EntitiesConnector.addObserver(self);
//
fname := getCoeditDocPath + edoptFname;
if fileExists(fname) then loadFromFile(fname);
end;
destructor TCEEditorOptions.Destroy;
begin
saveToFile(getCoeditDocPath + edoptFname);
//
EntitiesConnector.removeObserver(self);
inherited;
end;
procedure TCEEditorOptions.afterLoad;
begin
inherited;
D2Syn.Assign(fD2Syn);
TxtSyn.Assign(fTxtSyn);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEMultiDocObserver ----------------------------------------------------} {$REGION ICEMultiDocObserver ----------------------------------------------------}
@ -185,7 +226,11 @@ end;
function TCEEditorOptions.optionedWantContainer: TPersistent; function TCEEditorOptions.optionedWantContainer: TPersistent;
begin begin
fD2Syn := D2Syn;
fTxtSyn := TxtSyn;
fBackup.Assign(self); fBackup.Assign(self);
fBackup.fD2Syn.Assign(D2Syn);
fBackup.fTxtSyn.Assign(TxtSyn);
exit(self); exit(self);
end; end;
@ -193,12 +238,21 @@ procedure TCEEditorOptions.optionedEvent(anEvent: TOptionEditorEvent);
begin begin
// restores // restores
if anEvent = oeeCancel then if anEvent = oeeCancel then
begin
self.assign(fBackup); self.assign(fBackup);
// apply D2Syn.Assign(fBackup.fD2Syn);
TxtSyn.Assign(fBackup.fTxtSyn);
end;
// apply, if change/accept event
// to get a live preview
applyChangesFromSelf; applyChangesFromSelf;
// new backup values based on accepted values. // new backup values based on accepted values.
if anEvent = oeeAccept then if anEvent = oeeAccept then
begin
fBackup.assign(self); fBackup.assign(self);
fBackup.fD2Syn.Assign(D2Syn);
fBackup.fTxtSyn.Assign(TxtSyn);
end;
end; end;
{$ENDREGION} {$ENDREGION}
@ -208,16 +262,16 @@ var
multied: ICEMultiDocHandler; multied: ICEMultiDocHandler;
i: Integer; i: Integer;
begin begin
// editors
multied := getMultiDocHandler; multied := getMultiDocHandler;
for i := 0 to multied.documentCount-1 do for i := 0 to multied.documentCount-1 do
applyChangeToEditor(multied.document[i]); applyChangeToEditor(multied.document[i]);
// highlighter(s)
// ...
end; end;
procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo); procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo);
begin begin
anEditor.defaultFontSize := font.Size;
// current editor zoom cant be mainainted.
anEditor.Font.Assign(font); anEditor.Font.Assign(font);
anEditor.TabWidth := tabulationWidth; anEditor.TabWidth := tabulationWidth;
anEditor.BlockIndent := blockIdentation; anEditor.BlockIndent := blockIdentation;

View File

@ -62,7 +62,8 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget
Indent = 16 Indent = 16
NameFont.Color = clWindowText NameFont.Color = clWindowText
OnModified = inspectorModified OnModified = inspectorModified
SplitterX = 200 PreferredSplitterX = 170
SplitterX = 170
ValueFont.Color = clMaroon ValueFont.Color = clMaroon
end end
end end
@ -85,20 +86,22 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget
ClientWidth = 540 ClientWidth = 540
TabOrder = 1 TabOrder = 1
object btnCancel: TSpeedButton object btnCancel: TSpeedButton
Left = 333 Left = 473
Height = 24 Height = 24
Hint = 'cancel and revert modifications'
Top = 3 Top = 3
Width = 100 Width = 30
Align = alRight Align = alRight
BorderSpacing.Left = 2 BorderSpacing.Left = 2
BorderSpacing.Around = 2 BorderSpacing.Around = 2
OnClick = btnCancelClick OnClick = btnCancelClick
end end
object btnAccept: TSpeedButton object btnAccept: TSpeedButton
Left = 437 Left = 507
Height = 24 Height = 24
Hint = 'accept modifications'
Top = 3 Top = 3
Width = 100 Width = 30
Align = alRight Align = alRight
BorderSpacing.Left = 2 BorderSpacing.Left = 2
BorderSpacing.Around = 2 BorderSpacing.Around = 2