mirror of https://gitlab.com/basile.b/dexed.git
refactored some classes with the new TWritableComponent class
This commit is contained in:
parent
0eac0fffb6
commit
9e202f7c52
|
@ -135,7 +135,7 @@
|
|||
<PackageName Value="LCL"/>
|
||||
</Item6>
|
||||
</RequiredPackages>
|
||||
<Units Count="24">
|
||||
<Units Count="25">
|
||||
<Unit0>
|
||||
<Filename Value="coedit.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
|
@ -286,6 +286,11 @@
|
|||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="ce_observer"/>
|
||||
</Unit23>
|
||||
<Unit24>
|
||||
<Filename Value="..\src\ce_writablecomponent.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="ce_writableComponent"/>
|
||||
</Unit24>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
|
|
@ -7,7 +7,7 @@ uses
|
|||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, Forms, lazcontrols, runtimetypeinfocontrols,
|
||||
ce_dcd, ce_observer, ce_main;
|
||||
ce_dcd, ce_observer, ce_main, ce_writableComponent;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ unit ce_customtools;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, process, ce_common;
|
||||
Classes, SysUtils, process, ce_common, ce_writableComponent;
|
||||
|
||||
type
|
||||
|
||||
|
@ -33,22 +33,16 @@ type
|
|||
procedure execute;
|
||||
end;
|
||||
|
||||
TCETools = class(TComponent)
|
||||
TCETools = class(TWritableComponent)
|
||||
private
|
||||
fTools: TCollection;
|
||||
function getTool(index: Integer): TCEToolItem;
|
||||
procedure setTools(const aValue: TCollection);
|
||||
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
procedure readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
published
|
||||
property tools: TCollection read fTools write setTools;
|
||||
public
|
||||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
procedure saveToFile(const aFilename: string);
|
||||
procedure loadFromFile(const aFilename: string);
|
||||
//
|
||||
function addTool: TCEToolItem;
|
||||
property tool[index: integer]: TCEToolItem read getTool;
|
||||
|
@ -125,29 +119,6 @@ begin
|
|||
result := TCEToolItem(fTools.Add);
|
||||
end;
|
||||
|
||||
procedure TCETools.readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
begin
|
||||
Skip := true;
|
||||
Handled := false;
|
||||
end;
|
||||
|
||||
procedure TCETools.readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
end;
|
||||
|
||||
procedure TCETools.loadFromFile(const aFilename: string);
|
||||
begin
|
||||
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
|
||||
end;
|
||||
|
||||
procedure TCETools.saveToFile(const aFilename: string);
|
||||
begin
|
||||
saveCompToTxtFile(self, aFilename);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterClasses([TCEToolItem, TCETools]);
|
||||
end.
|
||||
|
|
|
@ -6,7 +6,7 @@ unit ce_libman;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ce_common, ce_dcd;
|
||||
Classes, SysUtils, ce_common, ce_writableComponent, ce_dcd;
|
||||
|
||||
type
|
||||
|
||||
|
@ -28,14 +28,12 @@ type
|
|||
(**
|
||||
* Represents all the D libraries present on this system.
|
||||
*)
|
||||
TLibraryManager = class(TComponent)
|
||||
TLibraryManager = class(TWritableComponent)
|
||||
private
|
||||
fCol: TCollection;
|
||||
procedure setCol(const aValue: TCollection);
|
||||
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
procedure readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
protected
|
||||
procedure afterLoad; override;
|
||||
published
|
||||
property libraries: TCollection read fCol write setCol;
|
||||
public
|
||||
|
@ -45,9 +43,6 @@ type
|
|||
procedure getLibFiles(const someAliases, aList: TStrings);
|
||||
procedure getLibSources(const someAliases, aList: TStrings);
|
||||
//
|
||||
procedure loadFromFile(const aFilename: string);
|
||||
procedure saveToFile(const aFilename: string);
|
||||
//
|
||||
procedure updateDCD;
|
||||
end;
|
||||
|
||||
|
@ -143,30 +138,11 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TLibraryManager.readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
procedure TLibraryManager.afterLoad;
|
||||
begin
|
||||
Skip := true;
|
||||
Handled := false;
|
||||
end;
|
||||
|
||||
procedure TLibraryManager.readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
end;
|
||||
|
||||
procedure TLibraryManager.loadFromFile(const aFilename: string);
|
||||
begin
|
||||
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
|
||||
updateDCD;
|
||||
end;
|
||||
|
||||
procedure TLibraryManager.saveToFile(const aFilename: string);
|
||||
begin
|
||||
saveCompToTxtFile(self, aFilename);
|
||||
end;
|
||||
|
||||
initialization
|
||||
registerClasses([TLibraryManager, TLibraryItem]);
|
||||
end.
|
||||
|
|
|
@ -12,7 +12,7 @@ uses
|
|||
ce_common, ce_dmdwrap, ce_project, ce_dcd, ce_plugin, ce_synmemo, ce_widget,
|
||||
ce_messages, ce_interfaces, ce_editor, ce_projinspect, ce_projconf, ce_search,
|
||||
ce_staticexplorer, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_customtools,
|
||||
ce_observer;
|
||||
ce_observer, ce_writableComponent;
|
||||
|
||||
type
|
||||
|
||||
|
@ -26,20 +26,12 @@ type
|
|||
(**
|
||||
* Encapsulates the options in a writable component.
|
||||
*)
|
||||
TCEOptions = class(TComponent)
|
||||
TCEOptions = class(TWritableComponent)
|
||||
private
|
||||
fFileMru, fProjMru: TMruFileList;
|
||||
fLeft, FTop, fWidth, fHeight: Integer;
|
||||
fErrorFlg: boolean;
|
||||
procedure setFileMru(aValue: TMruFileList);
|
||||
procedure setProjMru(aValue: TMruFileList);
|
||||
procedure saveLayout(str: TStream);
|
||||
procedure loadLayout(str: TStream);
|
||||
//
|
||||
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
procedure readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
published
|
||||
property APP_Left: Integer read fLeft write fLeft;
|
||||
property APP_Top: Integer read fTop write fTop;
|
||||
|
@ -52,12 +44,8 @@ type
|
|||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
procedure defineProperties(Filer: TFiler); override;
|
||||
procedure saveToFile(const aFilename: string);
|
||||
procedure loadFromFile(const aFilename: string);
|
||||
procedure beforeSave;
|
||||
procedure afterLoad;
|
||||
//
|
||||
property hasLoaded: boolean read fErrorFlg;
|
||||
procedure beforeSave; override;
|
||||
procedure afterLoad; override;
|
||||
end;
|
||||
|
||||
{ TCEMainForm }
|
||||
|
@ -1707,20 +1695,6 @@ begin
|
|||
inherited;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
begin
|
||||
Skip := true;
|
||||
Handled := true;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
fErrorFlg := false;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.setFileMru(aValue: TMruFileList);
|
||||
begin
|
||||
fFileMru.Assign(aValue);
|
||||
|
@ -1731,39 +1705,6 @@ begin
|
|||
fProjMru.Assign(aValue);
|
||||
end;
|
||||
|
||||
procedure TCEOptions.saveLayout(str: TStream);
|
||||
var
|
||||
st: TXMLConfigStorage;
|
||||
cf: TPropStorageXMLConfig;
|
||||
begin
|
||||
cf := TPropStorageXMLConfig.Create(nil);
|
||||
st := TXMLConfigStorage.Create(cf);
|
||||
try
|
||||
DockMaster.SaveLayoutToConfig(st);
|
||||
cf.SaveToStream(str);
|
||||
str.Position := 0;
|
||||
finally
|
||||
st.Free;
|
||||
cf.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.loadLayout(str: TStream);
|
||||
var
|
||||
st: TXMLConfigStorage;
|
||||
cf: TPropStorageXMLConfig;
|
||||
begin
|
||||
cf := TPropStorageXMLConfig.Create(nil);
|
||||
st := TXMLConfigStorage.Create(cf);
|
||||
try
|
||||
cf.LoadFromStream(str);
|
||||
DockMaster.LoadLayoutFromConfig(st,true);
|
||||
finally
|
||||
st.Free;
|
||||
cf.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.defineProperties(Filer: TFiler);
|
||||
var
|
||||
i: NativeInt;
|
||||
|
@ -1790,20 +1731,6 @@ begin
|
|||
CEMainForm.WidgetList.widget[i].beforeSave(nil);
|
||||
end;
|
||||
|
||||
procedure TCEOptions.saveToFile(const aFilename: string);
|
||||
begin
|
||||
fErrorFlg := true;
|
||||
beforeSave;
|
||||
ce_common.saveCompToTxtFile(self, aFilename);
|
||||
end;
|
||||
|
||||
procedure TCEOptions.loadFromFile(const aFilename: string);
|
||||
begin
|
||||
fErrorFlg := true;
|
||||
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
|
||||
afterLoad;
|
||||
end;
|
||||
|
||||
procedure TCEOptions.afterLoad;
|
||||
var
|
||||
i: NativeInt;
|
||||
|
|
|
@ -6,7 +6,8 @@ unit ce_project;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ce_common, ce_dmdwrap, ce_libman, ce_observer;
|
||||
Classes, SysUtils, ce_common, ce_writableComponent ,ce_dmdwrap, ce_libman,
|
||||
ce_observer;
|
||||
|
||||
type
|
||||
|
||||
|
@ -18,12 +19,11 @@ type
|
|||
*
|
||||
* Basically it' s designed to provide the options for the dmd process.
|
||||
*)
|
||||
TCEProject = class(TComponent)
|
||||
TCEProject = class(TWritableComponent)
|
||||
private
|
||||
fOnChange: TNotifyEvent;
|
||||
fModified: boolean;
|
||||
fRootFolder: string;
|
||||
fFilename: string;
|
||||
fBasePath: string;
|
||||
fLibAliases: TStringList;
|
||||
fOptsColl: TCollection;
|
||||
|
@ -36,16 +36,17 @@ type
|
|||
procedure setLibAliases(const aValue: TStringList);
|
||||
procedure subMemberChanged(sender : TObject);
|
||||
procedure setOptsColl(const aValue: TCollection);
|
||||
procedure setFname(const aValue: string);
|
||||
procedure setRoot(const aValue: string);
|
||||
procedure setSrcs(const aValue: TStringList);
|
||||
procedure setConfIx(aValue: Integer);
|
||||
function getConfig(const ix: integer): TCompilerConfiguration;
|
||||
function getCurrConf: TCompilerConfiguration;
|
||||
protected
|
||||
procedure afterSave; override;
|
||||
procedure afterLoad; override;
|
||||
procedure setFilename(const aValue: string); override;
|
||||
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
procedure readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean); override;
|
||||
published
|
||||
property RootFolder: string read fRootFolder write setRoot;
|
||||
property OptionsCollection: TCollection read fOptsColl write setOptsColl;
|
||||
|
@ -64,14 +65,11 @@ type
|
|||
procedure addSource(const aFilename: string);
|
||||
function addConfiguration: TCompilerConfiguration;
|
||||
procedure getOpts(const aList: TStrings);
|
||||
procedure saveToFile(const aFilename: string);
|
||||
procedure loadFromFile(const aFilename: string);
|
||||
function outputFilename: string;
|
||||
//
|
||||
property libraryManager: TLibraryManager read fLibMan write fLibMan;
|
||||
property configuration[ix: integer]: TCompilerConfiguration read getConfig;
|
||||
property currentConfiguration: TCompilerConfiguration read getCurrConf;
|
||||
property fileName: string read fFilename write setFname;
|
||||
property onChange: TNotifyEvent read fOnChange write fOnChange;
|
||||
property modified: boolean read fModified;
|
||||
end;
|
||||
|
@ -147,7 +145,7 @@ begin
|
|||
afterChanged;
|
||||
end;
|
||||
|
||||
procedure TCEProject.setFname(const aValue: string);
|
||||
procedure TCEProject.setFilename(const aValue: string);
|
||||
var
|
||||
oldAbs, newRel, oldBase: string;
|
||||
i: NativeInt;
|
||||
|
@ -341,16 +339,13 @@ begin
|
|||
result := expandFileNameEx(fBasePath, aFilename);
|
||||
end;
|
||||
|
||||
procedure TCEProject.saveToFile(const aFilename: string);
|
||||
procedure TCEProject.afterSave;
|
||||
begin
|
||||
saveCompToTxtFile(self, aFilename);
|
||||
fModified := false;
|
||||
end;
|
||||
|
||||
procedure TCEProject.loadFromFile(const aFilename: string);
|
||||
procedure TCEProject.afterLoad;
|
||||
begin
|
||||
Filename := aFilename;
|
||||
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
|
||||
patchPlateformPaths(fSrcs);
|
||||
doChanged;
|
||||
fModified := false;
|
||||
|
@ -389,12 +384,6 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TCEProject.readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterClasses([TCEProject]);
|
||||
end.
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
unit ce_writableComponent;
|
||||
|
||||
{$MODE OBJFPC}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ce_common;
|
||||
|
||||
type
|
||||
|
||||
(**
|
||||
* The ancestor of classes which can be saved or reloaded to/from
|
||||
* a text file. It's used each time some options or data have to
|
||||
* persist from a cession to another.
|
||||
*)
|
||||
TWritableComponent = class(TComponent)
|
||||
protected
|
||||
fFilename: string;
|
||||
fHasLoaded: boolean;
|
||||
fHasSaved: boolean;
|
||||
procedure setFilename(const aValue: string); virtual;
|
||||
procedure beforeLoad; virtual;
|
||||
procedure beforeSave; virtual;
|
||||
procedure afterLoad; virtual;
|
||||
procedure afterSave; virtual;
|
||||
procedure readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean); virtual;
|
||||
procedure readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean); virtual;
|
||||
public
|
||||
procedure saveToFile(const aFilename: string); virtual;
|
||||
procedure loadFromFile(const aFilename: string); virtual;
|
||||
//
|
||||
property Filename: string read fFilename write setFilename;
|
||||
property hasLoaded: boolean read fHasLoaded;
|
||||
property hasSaved: boolean read fHasSaved;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
procedure TWritableComponent.beforeSave;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.beforeLoad;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.afterLoad;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.afterSave;
|
||||
begin
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.setFilename(const aValue: string);
|
||||
begin
|
||||
fFilename := aValue;
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.readerPropNoFound(Reader: TReader; Instance: TPersistent;
|
||||
var PropName: string; IsPath: boolean; var Handled, Skip: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
Skip := true;
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.readerError(Reader: TReader; const Message: string;
|
||||
var Handled: Boolean);
|
||||
begin
|
||||
Handled := true;
|
||||
fHasLoaded := false;
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.saveToFile(const aFilename: string);
|
||||
begin
|
||||
fHasSaved := true;
|
||||
beforeSave;
|
||||
try
|
||||
saveCompToTxtFile(self, aFilename);
|
||||
except
|
||||
fHasSaved := false;
|
||||
end;
|
||||
setFilename(aFilename);
|
||||
afterSave;
|
||||
end;
|
||||
|
||||
procedure TWritableComponent.loadFromFile(const aFilename: string);
|
||||
begin
|
||||
fHasLoaded := true;
|
||||
beforeLoad;
|
||||
setFilename(aFilename);
|
||||
loadCompFromTxtFile(self, aFilename, @readerPropNoFound, @readerError);
|
||||
afterLoad;
|
||||
end;
|
||||
|
||||
initialization
|
||||
registerClasses([TWritableComponent]);
|
||||
end.
|
Loading…
Reference in New Issue