projectgroups: options frame, option to open last group on IDE start

git-svn-id: trunk@61503 -
This commit is contained in:
mattias 2019-06-30 20:44:12 +00:00
parent c212dea70f
commit 982d6c749b
8 changed files with 236 additions and 7 deletions

2
.gitattributes vendored
View File

@ -4215,6 +4215,8 @@ components/projectgroups/languages/projectgroupstrconst.uk.po svneol=native#text
components/projectgroups/languages/projectgroupstrconst.zh_CN.po svneol=native#text/plain
components/projectgroups/lazprojectgroups.lpk svneol=native#text/plain
components/projectgroups/lazprojectgroups.pas svneol=native#text/plain
components/projectgroups/prjgrpoptionsfrm.lfm svneol=native#text/plain
components/projectgroups/prjgrpoptionsfrm.pas svneol=native#text/plain
components/projectgroups/projectgroup.pp svneol=native#text/plain
components/projectgroups/projectgroupeditor.lfm svneol=native#text/plain
components/projectgroups/projectgroupeditor.pas svneol=native#text/plain

View File

@ -17,7 +17,7 @@
<License Value="Same as IDEIntf.
GPL-2."/>
<Version Minor="7"/>
<Files Count="6">
<Files Count="7">
<Item1>
<Filename Value="projectgroupintf.pp"/>
<UnitName Value="ProjectGroupIntf"/>
@ -43,6 +43,10 @@ GPL-2."/>
<Filename Value="projectgroupstrconst.pas"/>
<UnitName Value="ProjectGroupStrConst"/>
</Item6>
<Item7>
<Filename Value="prjgrpoptionsfrm.pas"/>
<UnitName Value="prjgrpoptionsfrm"/>
</Item7>
</Files>
<i18n>
<EnableI18N Value="True"/>

View File

@ -9,7 +9,7 @@ interface
uses
ProjectGroupIntf, ProjectGroup, ProjectGroupEditor, RegProjectGroup,
ProjectGroupStrConst, LazarusPackageIntf;
ProjectGroupStrConst, PrjGrpOptionsFrm, LazarusPackageIntf;
implementation

View File

@ -0,0 +1,31 @@
object ProjGrpOptionsFrame: TProjGrpOptionsFrame
Left = 0
Height = 317
Top = 0
Width = 443
ClientHeight = 317
ClientWidth = 443
TabOrder = 0
DesignLeft = 230
DesignTop = 263
object OpenLastGroupOnStartCheckBox: TCheckBox
Left = 8
Height = 24
Top = 10
Width = 160
Caption = 'Open last group on start'
ParentShowHint = False
ShowHint = True
TabOrder = 0
end
object ShowTargetPathsCheckBox: TCheckBox
Left = 8
Height = 24
Top = 40
Width = 126
Caption = 'Show target paths'
ParentShowHint = False
ShowHint = True
TabOrder = 1
end
end

View File

@ -0,0 +1,95 @@
{ IDE options frame for project groups options
Author: Mattias Gaertner
}
unit PrjGrpOptionsFrm;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
Forms, StdCtrls, Dialogs,
// LazUtils
LazFileCache, LazFileUtils,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, ProjectGroup;
type
{ TProjGrpOptionsFrame }
TProjGrpOptionsFrame = class(TAbstractIDEOptionsEditor)
OpenLastGroupOnStartCheckBox: TCheckBox;
ShowTargetPathsCheckBox: TCheckBox;
private
FLastOpenLastGroupOnStart, FLastShowTargetPaths: Boolean;
public
function GetTitle: String; override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure RestoreSettings({%H-}AOptions: TAbstractIDEOptions); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
end;
implementation
{$R *.lfm}
{ TProjGrpOptionsFrame }
function TProjGrpOptionsFrame.GetTitle: String;
begin
Result:='Project Groups';
end;
procedure TProjGrpOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
OpenLastGroupOnStartCheckBox.Caption:='Open last group on start';
OpenLastGroupOnStartCheckBox.Hint:='On IDE start reopen last open group.';
ShowTargetPathsCheckBox.Caption:='Show target paths';
ShowTargetPathsCheckBox.Hint:='Enable to show target filenames with paths.';
end;
procedure TProjGrpOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
var
Opts: TIDEProjectGroupOptions;
begin
Opts:=IDEProjectGroupManager.Options;
OpenLastGroupOnStartCheckBox.Checked:=Opts.OpenLastGroupOnStart;
FLastOpenLastGroupOnStart:=Opts.OpenLastGroupOnStart;
ShowTargetPathsCheckBox.Checked:=Opts.ShowTargetPaths;
FLastShowTargetPaths:=Opts.ShowTargetPaths;
end;
procedure TProjGrpOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
Opts: TIDEProjectGroupOptions;
begin
Opts:=IDEProjectGroupManager.Options;
Opts.OpenLastGroupOnStart:=OpenLastGroupOnStartCheckBox.Checked;
Opts.ShowTargetPaths:=ShowTargetPathsCheckBox.Checked;
if Opts.Modified then
Opts.SaveSafe;
end;
procedure TProjGrpOptionsFrame.RestoreSettings(AOptions: TAbstractIDEOptions);
begin
OpenLastGroupOnStartCheckBox.Checked:=FLastOpenLastGroupOnStart;
ShowTargetPathsCheckBox.Checked:=FLastShowTargetPaths;
end;
class function TProjGrpOptionsFrame.
SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result:=IDEEditorGroups.GetByIndex(GroupEnvironment)^.GroupClass;
end;
end.

View File

@ -153,11 +153,15 @@ type
TIDEProjectGroupOptions = class
private
FChangeStamp: integer;
FLastGroupFile: string;
FLastSavedChangeStamp: integer;
FOpenLastGroupOnStart: Boolean;
FRecentProjectGroups: TStringList;
FShowTargetPaths: boolean;
function GetModified: boolean;
procedure SetLastGroupFile(const AValue: string);
procedure SetModified(AValue: boolean);
procedure SetOpenLastGroupOnStart(const AValue: Boolean);
procedure SetShowTargetPaths(AValue: boolean);
public
constructor Create;
@ -174,6 +178,8 @@ type
property RecentProjectGroups: TStringList read FRecentProjectGroups;
procedure AddToRecentProjectGroups(aFilename: string);
// misc
property LastGroupFile: string read FLastGroupFile write SetLastGroupFile;
property OpenLastGroupOnStart: Boolean read FOpenLastGroupOnStart write SetOpenLastGroupOnStart;
property ShowTargetPaths: boolean read FShowTargetPaths write SetShowTargetPaths;
end;
@ -196,12 +202,16 @@ type
TIDEProjectGroupManager = Class(TProjectGroupManager)
private
FIdleConnected: boolean;
FUndoList: TObjectList; // list of TPGUndoItem
FRedoList: TObjectList; // list of TPGUndoItem
FOptions: TIDEProjectGroupOptions;
procedure AddToRecentGroups(aFilename: string);
function GetNewFileName: Boolean;
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
procedure SetIdleConnected(const AValue: boolean);
protected
FIDEStarted: boolean;
FProjectGroup: TIDEProjectGroup;
protected
function GetCurrentProjectGroup: TProjectGroup; override;
@ -228,6 +238,7 @@ type
procedure SaveProjectGroup; override;
public
property Options: TIDEProjectGroupOptions read FOptions;
property IdleConnected: boolean read FIdleConnected write SetIdleConnected;
end;
TEditProjectGroupHandler = procedure(Sender: TObject; AProjectGroup: TProjectGroup);
@ -365,6 +376,13 @@ begin
Result:=FLastSavedChangeStamp<>FChangeStamp
end;
procedure TIDEProjectGroupOptions.SetLastGroupFile(const AValue: string);
begin
if FLastGroupFile=AValue then Exit;
FLastGroupFile:=AValue;
IncreaseChangeStamp;
end;
procedure TIDEProjectGroupOptions.SetModified(AValue: boolean);
begin
if AValue then
@ -373,6 +391,14 @@ begin
FLastSavedChangeStamp:=FChangeStamp;
end;
procedure TIDEProjectGroupOptions.SetOpenLastGroupOnStart(const AValue: Boolean
);
begin
if FOpenLastGroupOnStart=AValue then Exit;
FOpenLastGroupOnStart:=AValue;
IncreaseChangeStamp;
end;
procedure TIDEProjectGroupOptions.SetShowTargetPaths(AValue: boolean);
begin
if FShowTargetPaths=AValue then Exit;
@ -383,6 +409,7 @@ end;
constructor TIDEProjectGroupOptions.Create;
begin
FRecentProjectGroups:=TStringList.Create;
FOpenLastGroupOnStart:=true;
end;
destructor TIDEProjectGroupOptions.Destroy;
@ -420,7 +447,9 @@ begin
Cfg:=GetIDEConfigStorage(aFilename,false);
try
Cfg.SetValue('RecentProjectGroups/',FRecentProjectGroups);
Cfg.SetDeleteValue('ShowTargetPaths/',ShowTargetPaths,false);
Cfg.SetDeleteValue('OpenLastGroupOnStart/Value',OpenLastGroupOnStart,true);
Cfg.SetDeleteValue('LastGroupFile/Value',LastGroupFile,'');
Cfg.SetDeleteValue('ShowTargetPaths/Value',ShowTargetPaths,false);
finally
Cfg.Free;
end;
@ -433,7 +462,9 @@ begin
Cfg:=GetIDEConfigStorage(aFilename,true);
try
Cfg.GetValue('RecentProjectGroups/',FRecentProjectGroups);
ShowTargetPaths:=Cfg.GetValue('ShowTargetPaths/',false);
OpenLastGroupOnStart:=Cfg.GetValue('OpenLastGroupOnStart/Value',true);
LastGroupFile:=Cfg.GetValue('LastGroupFile/Value','');
ShowTargetPaths:=Cfg.GetValue('ShowTargetPaths/Value',false);
finally
Cfg.Free;
end;
@ -544,6 +575,7 @@ begin
FOptions:=TIDEProjectGroupOptions.Create;
FUndoList:=TObjectList.Create(true);
FRedoList:=TObjectList.Create(true);
IdleConnected:=true;
end;
destructor TIDEProjectGroupManager.Destroy;
@ -658,6 +690,37 @@ begin
end;
end;
procedure TIDEProjectGroupManager.OnIdle(Sender: TObject; var Done: Boolean);
begin
if FIDEStarted then
begin
IdleConnected:=false;
exit;
end;
if Screen.GetCurrentModalForm<>nil then
exit;
FIDEStarted:=true;
if (CurrentProjectGroup=nil)
and Options.OpenLastGroupOnStart
and (Options.LastGroupFile<>'')
and FileExistsCached(Options.LastGroupFile) then
begin
LoadProjectGroup(Options.LastGroupFile,[pgloLoadRecursively,pgloSkipInvalid]);
end;
IdleConnected:=false;
end;
procedure TIDEProjectGroupManager.SetIdleConnected(const AValue: boolean);
begin
if FIdleConnected=AValue then Exit;
FIdleConnected:=AValue;
if IdleConnected then
Application.AddOnIdleHandler(@OnIdle)
else
Application.RemoveOnIdleHandler(@OnIdle);
end;
procedure TIDEProjectGroupManager.AddToRecentGroups(aFilename: string);
begin
Options.AddToRecentProjectGroups(AFileName);

View File

@ -152,6 +152,7 @@ type
// Project group callbacks
procedure InitTVNode(Node: TTreeNode; Const ACaption: String;
ANodeData: TNodeData);
procedure OnIDEClose(Sender: TObject);
procedure OnProjectGroupDestroy(Sender: TObject);
procedure OnProjectGroupFileNameChanged(Sender: TObject);
procedure OnTargetInserted(Sender: TObject; Target: TPGCompileTarget);
@ -525,6 +526,8 @@ begin
SetItem(MnuCmdTargetCopyFilename,@ATargetCopyFilenameExecute);
SetItem(MnuCmdProjGrpUndo,@AProjectGroupUndoExecute);
SetItem(MnuCmdProjGrpRedo,@AProjectGroupRedoExecute);
LazarusIDE.AddHandlerOnIDEClose(@OnIDEClose);
end;
procedure TProjectGroupEditorForm.FormDestroy(Sender: TObject);
@ -911,7 +914,7 @@ end;
procedure TProjectGroupEditorForm.AProjectGroupRedoExecute(Sender: TObject);
begin
// ToDo
writeln('TProjectGroupEditorForm.AProjectGroupRedoExecute Todo');
debugln(['TProjectGroupEditorForm.AProjectGroupRedoExecute Todo']);
end;
procedure TProjectGroupEditorForm.AProjectGroupRedoUpdate(Sender: TObject);
@ -1136,6 +1139,25 @@ begin
Node.StateIndex:=-1;
end;
procedure TProjectGroupEditorForm.OnIDEClose(Sender: TObject);
var
Opts: TIDEProjectGroupOptions;
begin
if IsVisible then
begin
Opts:=IDEProjectGroupManager.Options;
if Opts.OpenLastGroupOnStart then
begin
if (ProjectGroup<>nil) and FilenameIsAbsolute(ProjectGroup.FileName) then
Opts.LastGroupFile:=ProjectGroup.FileName
else
Opts.LastGroupFile:='';
if Opts.Modified then
Opts.SaveSafe;
end;
end;
end;
procedure TProjectGroupEditorForm.OnProjectGroupDestroy(Sender: TObject);
begin
if Sender=FProjectGroup then begin

View File

@ -7,8 +7,14 @@ unit RegProjectGroup;
interface
uses
Classes, SysUtils, ProjectGroupIntf, MenuIntf, IDECommands, ToolBarIntf,
ProjectGroupStrConst, ProjectGroup, ProjectGroupEditor, LCLType;
Classes, SysUtils, LCLType,
MenuIntf, IDECommands, ToolBarIntf, IDEOptEditorIntf, IDEOptionsIntf,
LazIDEIntf, ProjectGroupIntf,
// project groups
ProjectGroupStrConst, ProjectGroup, ProjectGroupEditor, PrjGrpOptionsFrm;
var
PGOptionsFrameID: integer = 1000;
procedure RegisterProjectGroupEditorMenuItems;
procedure Register;
@ -131,6 +137,12 @@ begin
if ViewProjectGroupsButtonCommand=nil then ;
end;
end;
// add IDE options frame
PGOptionsFrameID:=RegisterIDEOptionsEditor(GroupEnvironment,
TProjGrpOptionsFrame,PGOptionsFrameID)^.Index;
end;
finalization