cody: moved options to codyopts

git-svn-id: trunk@34197 -
This commit is contained in:
mattias 2011-12-15 05:21:53 +00:00
parent 1f7b476a9c
commit cdcfe47a33
7 changed files with 234 additions and 182 deletions

1
.gitattributes vendored
View File

@ -581,6 +581,7 @@ components/codetools/ide/codymiscoptsframe.lfm svneol=native#text/plain
components/codetools/ide/codymiscoptsframe.pas svneol=native#text/plain
components/codetools/ide/codynodeinfodlg.lfm svneol=native#text/plain
components/codetools/ide/codynodeinfodlg.pas svneol=native#text/plain
components/codetools/ide/codyopts.pas svneol=native#text/plain
components/codetools/ide/codyregistration.pas svneol=native#text/plain
components/codetools/ide/codystrconsts.pas svneol=native#text/pascal
components/codetools/ide/codyutils.pas svneol=native#text/pascal

View File

@ -19,7 +19,7 @@
<Description Value="IDE extensions using Codetools."/>
<License Value="GPL2"/>
<Version Major="1" Minor="1"/>
<Files Count="13">
<Files Count="14">
<Item1>
<Filename Value="ppulistdlg.pas"/>
<UnitName Value="PPUListDlg"/>
@ -73,6 +73,10 @@
<Filename Value="codymiscoptsframe.pas"/>
<UnitName Value="CodyMiscOptsFrame"/>
</Item13>
<Item14>
<Filename Value="codyopts.pas"/>
<UnitName Value="codyopts"/>
</Item14>
</Files>
<LazDoc Paths="doc"/>
<i18n>

View File

@ -10,14 +10,14 @@ uses
PPUListDlg, CodyStrConsts, AddAssignMethodDlg, CodyCtrls, CodyFrm,
CodyRegistration, DeclareVarDlg, CodyUtils, CodyNodeInfoDlg,
CodyCopyDeclaration, AddWithBlockDlg, CodyIdentifiersDlg, CodyMiscOptsFrame,
LazarusPackageIntf;
CodyOpts, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('CodyRegistration', @CodyRegistration.Register);
end;
end;
initialization
RegisterPackage('Cody', @Register);

View File

@ -42,7 +42,7 @@ uses
PackageIntf, LazIDEIntf, SrcEditorIntf, ProjectIntf, CompOptsIntf, IDEDialogs,
CodeCache, BasicCodeTools, CustomCodeTool, CodeToolManager, UnitDictionary,
CodeTree, LinkScanner, DefineTemplates, CodeToolsStructs,
CodyStrConsts, CodyUtils;
CodyStrConsts, CodyUtils, CodyOpts;
const
PackageNameFPCSrcDir = 'FPCSrcDir';
@ -66,7 +66,6 @@ type
private
FLoadAfterStartInS: integer;
FLoadSaveError: string;
FPreferImplementationUsesSection: boolean;
FSaveIntervalInS: integer;
fTimer: TTimer;
FIdleConnected: boolean;
@ -89,6 +88,7 @@ type
procedure OnTimer(Sender: TObject);
function StartLoadSaveThread: boolean;
procedure OnIDEClose(Sender: TObject);
procedure OnApplyOptions(Sender: TObject);
public
constructor Create;
destructor Destroy; override;
@ -103,8 +103,6 @@ type
procedure EndCritSec;
procedure CheckFileAsync(aFilename: string); // check eventually if file exists and delete unit/group
property LoadSaveError: string read FLoadSaveError write SetLoadSaveError;
property PreferImplementationUsesSection: boolean
read FPreferImplementationUsesSection write FPreferImplementationUsesSection;
end;
TCodyIdentifierDlgAction = (
@ -461,6 +459,12 @@ begin
FreeAndNil(fTimer);
end;
procedure TCodyUnitDictionary.OnApplyOptions(Sender: TObject);
begin
LoadAfterStartInS:=CodyOptions.UDLoadDelayInS;
SaveIntervalInS:=CodyOptions.UDSaveIntervalInS;
end;
procedure TCodyUnitDictionary.SetIdleConnected(AValue: boolean);
begin
if FIdleConnected=AValue then Exit;
@ -537,11 +541,13 @@ begin
fQueuedTools:=TAVLTree.Create;
CodeToolBoss.AddHandlerToolTreeChanging(@ToolTreeChanged);
LazarusIDE.AddHandlerOnIDEClose(@OnIDEClose);
CodyOptions.AddHandlerApply(@OnApplyOptions);
end;
destructor TCodyUnitDictionary.Destroy;
begin
fClosing:=true;
CodyOptions.RemoveHandlerApply(@OnApplyOptions);
FreeAndNil(fCheckFiles);
CodeToolBoss.RemoveHandlerToolTreeChanging(@ToolTreeChanged);
FreeAndNil(fTimer);
@ -637,7 +643,7 @@ end;
procedure TCodyIdentifiersDlg.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
CodyUnitDictionary.PreferImplementationUsesSection:=
CodyOptions.PreferImplementationUsesSection:=
AddToImplementationUsesCheckBox.Checked;
FreeAndNil(FItems);
end;
@ -928,7 +934,7 @@ begin
CurInImplementation:=true;
AddToImplementationUsesCheckBox.Enabled:=CurInImplementation;
AddToImplementationUsesCheckBox.Checked:=
CodyUnitDictionary.PreferImplementationUsesSection;
CodyOptions.PreferImplementationUsesSection;
CurSrcEdit:=SourceEditorManagerIntf.ActiveEditor;
if CurTool<>nil then begin

View File

@ -6,45 +6,11 @@ interface
uses
Classes, SysUtils, FileUtil, DividerBevel, LResources, Forms, Controls,
LazConfigStorage, StdCtrls, ComCtrls, IDEOptionsIntf, LazIDEIntf, BaseIDEIntf,
FileProcs, CodyIdentifiersDlg;
StdCtrls, ComCtrls, FileProcs,
IDEOptionsIntf, LazIDEIntf,
CodyOpts, CodyIdentifiersDlg;
const
CodyConfigVersion = 1;
var
CodyMiscOptionID: integer = 1000;
type
{ TCodyMiscOptions }
TCodyMiscOptions = class(TPersistent)
private
FChangeStep: integer;
FUDLoadDelayInS: integer;
FUDSaveIntervalInS: integer;
fLastSavedChangeStep: integer;
function GetModified: boolean;
procedure SetModified(AValue: boolean);
procedure SetUDLoadDelayInS(AValue: integer);
procedure SetUDSaveIntervalInS(AValue: integer);
public
// unit / identifier dictionary
property UDLoadDelayInS: integer read FUDLoadDelayInS write SetUDLoadDelayInS;
property UDSaveIntervalInS: integer read FUDSaveIntervalInS write SetUDSaveIntervalInS;
procedure Assign(Source: TPersistent); override;
constructor Create;
function Equals(Obj: TObject): boolean; override;
procedure SaveSafe;
procedure LoadSafe;
procedure SaveToFile(Filename: string);
procedure LoadFromFile(Filename: string);
procedure Clear;
procedure Apply;
property ChangeStep: integer read FChangeStep;
procedure IncreaseChangeStep;
property Modified: boolean read GetModified write SetModified;
end;
{ TCodyMiscOptionsFrame }
TCodyMiscOptionsFrame = class(TAbstractIDEOptionsEditor)
@ -79,9 +45,6 @@ type
property OldOptions: TCodyMiscOptions read FOldOptions;
end;
var
CodyOptions: TCodyMiscOptions = nil;
const
UDLoadDelayTrackbarValues: array[0..9] of integer = (
// 0,1,2,3,4, 5, 6, 7, 8, 9
@ -94,135 +57,6 @@ const
implementation
{ TCodyMiscOptions }
procedure TCodyMiscOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStep
else
fLastSavedChangeStep:=FChangeStep;
end;
function TCodyMiscOptions.GetModified: boolean;
begin
Result:=fLastSavedChangeStep<>FChangeStep;
end;
procedure TCodyMiscOptions.SetUDLoadDelayInS(AValue: integer);
begin
if FUDLoadDelayInS=AValue then Exit;
FUDLoadDelayInS:=AValue;
IncreaseChangeStep;
end;
procedure TCodyMiscOptions.SetUDSaveIntervalInS(AValue: integer);
begin
if FUDSaveIntervalInS=AValue then Exit;
FUDSaveIntervalInS:=AValue;
IncreaseChangeStep;
end;
constructor TCodyMiscOptions.Create;
begin
inherited Create;
FChangeStep:=CTInvalidChangeStamp;
end;
procedure TCodyMiscOptions.Assign(Source: TPersistent);
var
aSource: TCodyMiscOptions;
begin
if Source is TCodyMiscOptions then
begin
aSource:=TCodyMiscOptions(Source);
UDSaveIntervalInS:=aSource.UDSaveIntervalInS;
UDLoadDelayInS:=aSource.UDLoadDelayInS;
end else
inherited Assign(Source);
end;
function TCodyMiscOptions.Equals(Obj: TObject): boolean;
var
Src: TCodyMiscOptions;
begin
Result:=false;
if not (Obj is TCodyMiscOptions) then exit;
Src:=TCodyMiscOptions(Obj);
if (UDLoadDelayInS<>Src.UDLoadDelayInS)
or (UDSaveIntervalInS<>Src.UDSaveIntervalInS)
then exit;
Result:=true;
end;
procedure TCodyMiscOptions.SaveSafe;
begin
try
SaveToFile('codyoptions.xml');
except
on E: Exception do
debugln(['TCodyMiscOptions.SaveSafe ',E.Message]);
end;
Modified:=false;
end;
procedure TCodyMiscOptions.LoadSafe;
begin
try
LoadFromFile('codyoptions.xml');
except
on E: Exception do
debugln(['TCodyMiscOptions.LoadSafe ',E.Message]);
end;
Modified:=false;
end;
procedure TCodyMiscOptions.SaveToFile(Filename: string);
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(Filename,false);
try
Cfg.SetDeleteValue('UnitDictionary/LoadDelay',UDLoadDelayInS,10);
Cfg.SetDeleteValue('UnitDictionary/SaveInterval',UDSaveIntervalInS,600);
finally
Cfg.Free;
end;
end;
procedure TCodyMiscOptions.LoadFromFile(Filename: string);
var
Cfg: TConfigStorage;
begin
Clear;
Cfg:=GetIDEConfigStorage(Filename,true);
try
UDLoadDelayInS:=Cfg.GetValue('UnitDictionary/LoadDelay',10);
UDSaveIntervalInS:=Cfg.GetValue('UnitDictionary/SaveInterval',600);
//debugln(['TCodyMiscOptions.LoadFromFile UDSaveIntervalInS=',UDSaveIntervalInS,' LoadDelay=',UDLoadDelayInS]);
finally
Cfg.Free;
end;
end;
procedure TCodyMiscOptions.Clear;
begin
UDLoadDelayInS:=10;
UDSaveIntervalInS:=600;
end;
procedure TCodyMiscOptions.Apply;
begin
CodyUnitDictionary.LoadAfterStartInS:=UDLoadDelayInS;
CodyUnitDictionary.SaveIntervalInS:=UDSaveIntervalInS;
//debugln(['TCodyMiscOptions.Apply Save=',CodyUnitDictionary.SaveIntervalInS,' Load=',CodyUnitDictionary.LoadAfterStartInS]);
end;
procedure TCodyMiscOptions.IncreaseChangeStep;
begin
CTIncreaseChangeStamp(FChangeStep);
end;
{ TCodyMiscOptionsFrame }
procedure TCodyMiscOptionsFrame.UDSaveButtonClick(Sender: TObject);
@ -362,8 +196,5 @@ end;
{$R *.lfm}
finalization
FreeAndNil(CodyOptions);
end.

View File

@ -0,0 +1,210 @@
unit CodyOpts;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileProcs, LazMethodList, LazConfigStorage, BaseIDEIntf;
const
CodyConfigVersion = 1;
var
CodyMiscOptionID: integer = 1000;
type
{ TCodyMiscOptions }
TCodyMiscOptions = class(TPersistent)
private
FChangeStep: integer;
FPreferImplementationUsesSection: boolean;
FUDLoadDelayInS: integer;
FUDSaveIntervalInS: integer;
fLastSavedChangeStep: integer;
fApplyHandlers: TMethodList;
function GetModified: boolean;
procedure SetModified(AValue: boolean);
procedure SetUDLoadDelayInS(AValue: integer);
procedure SetUDSaveIntervalInS(AValue: integer);
public
// unit / identifier dictionary
property UDLoadDelayInS: integer read FUDLoadDelayInS write SetUDLoadDelayInS;
property UDSaveIntervalInS: integer read FUDSaveIntervalInS write SetUDSaveIntervalInS;
property PreferImplementationUsesSection: boolean
read FPreferImplementationUsesSection write FPreferImplementationUsesSection;
procedure Assign(Source: TPersistent); override;
constructor Create;
destructor Destroy; override;
function Equals(Obj: TObject): boolean; override;
procedure SaveSafe;
procedure LoadSafe;
procedure SaveToFile(Filename: string);
procedure LoadFromFile(Filename: string);
procedure Clear;
procedure Apply;
procedure AddHandlerApply(const OnApplyEvent: TNotifyEvent; AsLast: boolean = false);
procedure RemoveHandlerApply(const OnApplyEvent: TNotifyEvent);
property ChangeStep: integer read FChangeStep;
procedure IncreaseChangeStep;
property Modified: boolean read GetModified write SetModified;
end;
var
CodyOptions: TCodyMiscOptions = nil;
implementation
{ TCodyMiscOptions }
procedure TCodyMiscOptions.SetModified(AValue: boolean);
begin
if AValue then
IncreaseChangeStep
else
fLastSavedChangeStep:=FChangeStep;
end;
function TCodyMiscOptions.GetModified: boolean;
begin
Result:=fLastSavedChangeStep<>FChangeStep;
end;
procedure TCodyMiscOptions.SetUDLoadDelayInS(AValue: integer);
begin
if FUDLoadDelayInS=AValue then Exit;
FUDLoadDelayInS:=AValue;
IncreaseChangeStep;
end;
procedure TCodyMiscOptions.SetUDSaveIntervalInS(AValue: integer);
begin
if FUDSaveIntervalInS=AValue then Exit;
FUDSaveIntervalInS:=AValue;
IncreaseChangeStep;
end;
constructor TCodyMiscOptions.Create;
begin
inherited Create;
FChangeStep:=CTInvalidChangeStamp;
fApplyHandlers:=TMethodList.Create;
end;
destructor TCodyMiscOptions.Destroy;
begin
FreeAndNil(fApplyHandlers);
inherited Destroy;
end;
procedure TCodyMiscOptions.Assign(Source: TPersistent);
var
aSource: TCodyMiscOptions;
begin
if Source is TCodyMiscOptions then
begin
aSource:=TCodyMiscOptions(Source);
UDSaveIntervalInS:=aSource.UDSaveIntervalInS;
UDLoadDelayInS:=aSource.UDLoadDelayInS;
end else
inherited Assign(Source);
end;
function TCodyMiscOptions.Equals(Obj: TObject): boolean;
var
Src: TCodyMiscOptions;
begin
Result:=false;
if not (Obj is TCodyMiscOptions) then exit;
Src:=TCodyMiscOptions(Obj);
if (UDLoadDelayInS<>Src.UDLoadDelayInS)
or (UDSaveIntervalInS<>Src.UDSaveIntervalInS)
then exit;
Result:=true;
end;
procedure TCodyMiscOptions.SaveSafe;
begin
try
SaveToFile('codyoptions.xml');
except
on E: Exception do
debugln(['TCodyMiscOptions.SaveSafe ',E.Message]);
end;
Modified:=false;
end;
procedure TCodyMiscOptions.LoadSafe;
begin
try
LoadFromFile('codyoptions.xml');
except
on E: Exception do
debugln(['TCodyMiscOptions.LoadSafe ',E.Message]);
end;
Modified:=false;
end;
procedure TCodyMiscOptions.SaveToFile(Filename: string);
var
Cfg: TConfigStorage;
begin
Cfg:=GetIDEConfigStorage(Filename,false);
try
Cfg.SetDeleteValue('UnitDictionary/LoadDelay',UDLoadDelayInS,10);
Cfg.SetDeleteValue('UnitDictionary/SaveInterval',UDSaveIntervalInS,600);
Cfg.SetDeleteValue('Uses/PreferImplementationSection',PreferImplementationUsesSection,false);
finally
Cfg.Free;
end;
end;
procedure TCodyMiscOptions.LoadFromFile(Filename: string);
var
Cfg: TConfigStorage;
begin
Clear;
Cfg:=GetIDEConfigStorage(Filename,true);
try
UDLoadDelayInS:=Cfg.GetValue('UnitDictionary/LoadDelay',10);
UDSaveIntervalInS:=Cfg.GetValue('UnitDictionary/SaveInterval',600);
PreferImplementationUsesSection:=Cfg.GetValue('Uses/PreferImplementationSection',false);
//debugln(['TCodyMiscOptions.LoadFromFile UDSaveIntervalInS=',UDSaveIntervalInS,' LoadDelay=',UDLoadDelayInS]);
finally
Cfg.Free;
end;
end;
procedure TCodyMiscOptions.Clear;
begin
UDLoadDelayInS:=10;
UDSaveIntervalInS:=600;
end;
procedure TCodyMiscOptions.Apply;
begin
fApplyHandlers.CallNotifyEvents(Self);
end;
procedure TCodyMiscOptions.AddHandlerApply(const OnApplyEvent: TNotifyEvent;
AsLast: boolean);
begin
fApplyHandlers.Add(TMethod(OnApplyEvent),AsLast);
end;
procedure TCodyMiscOptions.RemoveHandlerApply(const OnApplyEvent: TNotifyEvent
);
begin
fApplyHandlers.Remove(TMethod(OnApplyEvent));
end;
procedure TCodyMiscOptions.IncreaseChangeStep;
begin
CTIncreaseChangeStamp(FChangeStep);
end;
finalization
FreeAndNil(CodyOptions);
end.

View File

@ -34,7 +34,7 @@ uses
IDECommands, MenuIntf, IDEWindowIntf, SrcEditorIntf, IDEOptionsIntf,
CodyStrConsts, CodyCtrls, PPUListDlg, AddAssignMethodDlg, AddWithBlockDlg,
CodyUtils, CodyNodeInfoDlg, CodyFrm, DeclareVarDlg, CodyCopyDeclaration,
CodyIdentifiersDlg, CodyMiscOptsFrame;
CodyIdentifiersDlg, CodyMiscOptsFrame, CodyOpts;
procedure Register;