mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 01:59:34 +02:00
IDEIntf: added handler IDEClose
git-svn-id: trunk@25944 -
This commit is contained in:
parent
02573ad6a6
commit
0e14f732e0
@ -35,37 +35,57 @@ unit RegisterEasyDockMgr;
|
||||
interface
|
||||
|
||||
uses
|
||||
Math, Classes, SysUtils, LCLProc, Forms, Controls, IDEWindowIntf,
|
||||
Math, Classes, SysUtils, LCLProc, Forms, Controls, FileUtil,
|
||||
LazIDEIntf, IDEWindowIntf,
|
||||
uMakeSite;
|
||||
|
||||
const
|
||||
DefaultConfigFileName = 'easydocklayout.lyt';
|
||||
type
|
||||
|
||||
{ TIDEEasyDockMaster }
|
||||
|
||||
TIDEEasyDockMaster = class(TIDEDockMaster)
|
||||
function DockMasterRestore(const CtrlName: string; ASite: TWinControl
|
||||
): TControl;
|
||||
private
|
||||
procedure GetDefaultBounds(AForm: TCustomForm; out Creator: TIDEWindowCreator;
|
||||
out NewBounds: TRect; out DockSiblingName: string; out DockAlign: TAlign);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure MakeIDEWindowDockSite(AForm: TCustomForm); override;
|
||||
procedure MakeIDEWindowDockable(AControl: TWinControl); override;
|
||||
function IsDockSite(AForm: TCustomForm): boolean;
|
||||
function IsDockable(AForm: TCustomForm): boolean;
|
||||
function GetDefaultLayoutFilename: string;
|
||||
procedure LoadDefaultLayout; override;
|
||||
procedure SaveDefaultLayout;
|
||||
procedure ShowForm(AForm: TCustomForm; BringToFront: boolean); override;
|
||||
procedure CloseAll; override;
|
||||
procedure OnIDEClose(Sender: TObject);
|
||||
end;
|
||||
|
||||
var
|
||||
IDEEasyDockMaster: TIDEEasyDockMaster = nil;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
// ToDo: register menu items, events and options
|
||||
LazarusIDE.AddHandlerOnIDEClose(@IDEEasyDockMaster.OnIDEClose);
|
||||
end;
|
||||
|
||||
{ TIDEEasyDockMaster }
|
||||
|
||||
function TIDEEasyDockMaster.DockMasterRestore(const CtrlName: string;
|
||||
ASite: TWinControl): TControl;
|
||||
begin
|
||||
Result:=IDEWindowCreators.GetForm(CtrlName,true);
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.GetDefaultBounds(AForm: TCustomForm; out
|
||||
Creator: TIDEWindowCreator; out NewBounds: TRect; out DockSiblingName: string;
|
||||
out DockAlign: TAlign);
|
||||
@ -88,6 +108,18 @@ begin
|
||||
NewBounds.Bottom:=Max(NewBounds.Top+100,NewBounds.Bottom);
|
||||
end;
|
||||
|
||||
constructor TIDEEasyDockMaster.Create;
|
||||
begin
|
||||
IDEEasyDockMaster:=Self;
|
||||
DockMaster.OnRestore:=@DockMasterRestore;
|
||||
end;
|
||||
|
||||
destructor TIDEEasyDockMaster.Destroy;
|
||||
begin
|
||||
IDEEasyDockMaster:=nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.MakeIDEWindowDockSite(AForm: TCustomForm);
|
||||
var
|
||||
Creator: TIDEWindowCreator;
|
||||
@ -131,9 +163,25 @@ begin
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.LoadDefaultLayout;
|
||||
function TIDEEasyDockMaster.GetDefaultLayoutFilename: string;
|
||||
begin
|
||||
// ToDo: load the users default layout
|
||||
Result:=AppendPathDelim(LazarusIDE.GetPrimaryConfigPath)+DefaultConfigFileName;
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.LoadDefaultLayout;
|
||||
var
|
||||
Filename: String;
|
||||
begin
|
||||
// load the users default layout
|
||||
Filename:=GetDefaultLayoutFilename;
|
||||
if FileExistsUTF8(Filename) then
|
||||
DockMaster.LoadFromFile(Filename);
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.SaveDefaultLayout;
|
||||
begin
|
||||
// load the users default layout
|
||||
DockMaster.SaveToFile(GetDefaultLayoutFilename);
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.ShowForm(AForm: TCustomForm; BringToFront: boolean
|
||||
@ -146,12 +194,16 @@ var
|
||||
DockAlign: TAlign;
|
||||
DockSibling: TCustomForm;
|
||||
NewDockSite: TWinControl;
|
||||
AControl: TControl;
|
||||
begin
|
||||
debugln(['TIDEEasyDockMaster.ShowForm ',DbgSName(AForm),' BringToFront=',BringToFront,' IsDockSite=',IsDockSite(AForm),' IsDockable=',IsDockable(AForm)]);
|
||||
try
|
||||
if not (IsDockSite(AForm) or IsDockable(AForm)) then
|
||||
AForm.DisableAlign;
|
||||
if AForm.HostDockSite<>nil then
|
||||
begin
|
||||
// already docked
|
||||
end else if not (IsDockSite(AForm) or IsDockable(AForm)) then
|
||||
begin
|
||||
AForm.DisableAlign;
|
||||
// this form was not yet docked
|
||||
// place it at a default position and make it dockable
|
||||
GetDefaultBounds(AForm,Creator,NewBounds,DockSiblingName,DockAlign);
|
||||
@ -186,21 +238,39 @@ begin
|
||||
MakeIDEWindowDockable(AForm);
|
||||
end;
|
||||
end;
|
||||
AForm.EnableAlign;
|
||||
end;
|
||||
|
||||
finally
|
||||
Parent:=GetParentForm(AForm);
|
||||
// ToDo switch pageindex of all parent note books
|
||||
if Parent<>nil then
|
||||
if BringToFront then
|
||||
Parent.ShowOnTop
|
||||
AControl:=AForm;
|
||||
while AControl<>nil do begin
|
||||
// ToDo: if this is a page switch pageindex of parent
|
||||
if AControl is TCustomForm then
|
||||
TCustomForm(AControl).Show
|
||||
else
|
||||
Parent.Show;
|
||||
AControl.Visible:=true;
|
||||
AControl:=AControl.Parent;
|
||||
end;
|
||||
AForm.EnableAlign;
|
||||
|
||||
if BringToFront then begin
|
||||
Parent:=GetParentForm(AForm);
|
||||
if Parent<>nil then
|
||||
Parent.ShowOnTop;
|
||||
end;
|
||||
end;
|
||||
debugln(['TIDEEasyDockMaster.ShowForm END ',DbgSName(AForm),' ',dbgs(AForm.BoundsRect)]);
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.CloseAll;
|
||||
begin
|
||||
inherited CloseAll;
|
||||
end;
|
||||
|
||||
procedure TIDEEasyDockMaster.OnIDEClose(Sender: TObject);
|
||||
begin
|
||||
SaveDefaultLayout;
|
||||
end;
|
||||
|
||||
initialization
|
||||
// create the dockmaster in the initialization section, so that is ready
|
||||
// when the Register procedures of the packages are called.
|
||||
|
17
ide/main.pp
17
ide/main.pp
@ -1700,6 +1700,7 @@ end;
|
||||
procedure TMainIDE.MainIDEFormClose(Sender: TObject;
|
||||
var CloseAction: TCloseAction);
|
||||
begin
|
||||
DoCallNotifyHandler(lihtIDEClose);
|
||||
SaveEnvironment;
|
||||
CloseIDEWindows;
|
||||
SaveIncludeLinks;
|
||||
@ -9656,7 +9657,7 @@ begin
|
||||
Result:=mrOk;
|
||||
finally
|
||||
// call handlers
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtOnProjectOpened,Project1);
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtProjectOpened,Project1);
|
||||
if not (HandlerResult in [mrOk,mrCancel,mrAbort]) then
|
||||
HandlerResult:=mrCancel;
|
||||
if (Result=mrOk) then
|
||||
@ -9777,7 +9778,7 @@ begin
|
||||
end;
|
||||
|
||||
// call handlers
|
||||
Result:=DoCallProjectChangedHandler(lihtOnProjectClose,Project1);
|
||||
Result:=DoCallProjectChangedHandler(lihtProjectClose,Project1);
|
||||
if Result=mrAbort then exit;
|
||||
|
||||
// close all loaded files
|
||||
@ -10022,7 +10023,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
// call handlers
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtOnProjectOpened,Project1);
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtProjectOpened,Project1);
|
||||
if not (HandlerResult in [mrOk,mrCancel,mrAbort]) then
|
||||
HandlerResult:=mrCancel;
|
||||
if (Result=mrOk) then
|
||||
@ -10684,7 +10685,7 @@ begin
|
||||
DoArrangeSourceEditorAndMessageView(false);
|
||||
|
||||
// now building can start: call handler
|
||||
Result:=DoCallModalFunctionHandler(lihtOnProjectBuilding);
|
||||
Result:=DoCallModalFunctionHandler(lihtProjectBuilding);
|
||||
if Result<>mrOk then exit;
|
||||
|
||||
// get main source filename
|
||||
@ -10698,7 +10699,7 @@ begin
|
||||
|
||||
// compile required packages
|
||||
if not (pbfDoNotCompileDependencies in Flags) then begin
|
||||
Result:=DoCallModalFunctionHandler(lihtOnProjectDependenciesCompiling);
|
||||
Result:=DoCallModalFunctionHandler(lihtProjectDependenciesCompiling);
|
||||
if Result<>mrOk then exit;
|
||||
PkgFlags:=[pcfDoNotSaveEditorFiles];
|
||||
if pbfCompileDependenciesClean in Flags then
|
||||
@ -10709,7 +10710,7 @@ begin
|
||||
CompileProgress.Ready(lisInfoBuildError);
|
||||
exit;
|
||||
end;
|
||||
Result:=DoCallModalFunctionHandler(lihtOnProjectDependenciesCompiled);
|
||||
Result:=DoCallModalFunctionHandler(lihtProjectDependenciesCompiled);
|
||||
if Result<>mrOk then exit;
|
||||
end;
|
||||
|
||||
@ -10976,7 +10977,7 @@ var
|
||||
CurResult: TModalResult;
|
||||
begin
|
||||
Result:=mrOk;
|
||||
CurResult:=DoCallModalFunctionHandler(lihtOnSavingAll);
|
||||
CurResult:=DoCallModalFunctionHandler(lihtSavingAll);
|
||||
if CurResult=mrAbort then exit(mrAbort);
|
||||
if CurResult<>mrOk then Result:=mrCancel;
|
||||
CurResult:=DoSaveProject(Flags);
|
||||
@ -10986,7 +10987,7 @@ begin
|
||||
InputHistories.Save;
|
||||
if CurResult=mrAbort then exit(mrAbort);
|
||||
if CurResult<>mrOk then Result:=mrCancel;
|
||||
CurResult:=DoCallModalFunctionHandler(lihtOnSavedAll);
|
||||
CurResult:=DoCallModalFunctionHandler(lihtSavedAll);
|
||||
if CurResult=mrAbort then exit(mrAbort);
|
||||
if CurResult<>mrOk then Result:=mrCancel;
|
||||
UpdateSaveMenuItemsAndButtons(true);
|
||||
|
@ -204,11 +204,11 @@ type
|
||||
|
||||
TIDEDockMaster = class
|
||||
public
|
||||
// ToDo: save/restore layout
|
||||
procedure MakeIDEWindowDockable(AControl: TWinControl); virtual; abstract;
|
||||
procedure MakeIDEWindowDockSite(AForm: TCustomForm); virtual; abstract;
|
||||
procedure LoadDefaultLayout; virtual; abstract; // called before opening the first project
|
||||
procedure ShowForm(AForm: TCustomForm; BringToFront: boolean); virtual; abstract;
|
||||
procedure CloseAll; virtual;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -719,6 +719,23 @@ begin
|
||||
AForm.Show;
|
||||
end;
|
||||
|
||||
{ TIDEDockMaster }
|
||||
|
||||
procedure TIDEDockMaster.CloseAll;
|
||||
var
|
||||
i: Integer;
|
||||
AForm: TCustomForm;
|
||||
begin
|
||||
i:=Screen.CustomFormCount-1;
|
||||
while i>=0 do begin
|
||||
AForm:=Screen.CustomForms[i];
|
||||
if AForm<>Application.MainForm then
|
||||
AForm.Close;
|
||||
dec(i);
|
||||
if i>=Screen.CustomFormCount then i:=Screen.CustomFormCount-1;
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
IDEWindowCreators:=TIDEWindowCreatorList.Create;
|
||||
finalization
|
||||
|
@ -127,13 +127,14 @@ type
|
||||
AProject: TLazProject): TModalResult of object;
|
||||
|
||||
TLazarusIDEHandlerType = (
|
||||
lihtOnSavingAll, // called before IDE saves everything
|
||||
lihtOnSavedAll, // called after IDE saved everything
|
||||
lihtOnProjectOpened,// called after IDE opened a project
|
||||
lihtOnProjectClose, // called before IDE closes a project
|
||||
lihtOnProjectBuilding, // called before IDE builds the project
|
||||
lihtOnProjectDependenciesCompiling, // called before IDE compiles dependencies of project
|
||||
lihtOnProjectDependenciesCompiled // called after IDE compiled dependencies of project
|
||||
lihtSavingAll, // called before IDE saves everything
|
||||
lihtSavedAll, // called after IDE saved everything
|
||||
lihtIDEClose, // called when IDE is shutting down (after closequery, so no more interactivity)
|
||||
lihtProjectOpened,// called after IDE opened a project
|
||||
lihtProjectClose, // called before IDE closes a project
|
||||
lihtProjectBuilding, // called before IDE builds the project
|
||||
lihtProjectDependenciesCompiling, // called before IDE compiles dependencies of project
|
||||
lihtProjectDependenciesCompiled // called after IDE compiled dependencies of project
|
||||
);
|
||||
|
||||
{ TLazIDEInterface }
|
||||
@ -284,6 +285,9 @@ type
|
||||
procedure AddHandlerOnSavedAll(const OnSaveAllEvent: TModalResultFunction;
|
||||
AsLast: boolean = false);
|
||||
procedure RemoveHandlerOnSavedAll(const OnSaveAllEvent: TModalResultFunction);
|
||||
procedure AddHandlerOnIDEClose(const OnIDECloseEvent: TNotifyEvent;
|
||||
AsLast: boolean = false);
|
||||
procedure RemoveHandlerOnIDEClose(const OnIDECloseEvent: TNotifyEvent);
|
||||
procedure AddHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction;
|
||||
AsLast: boolean = false);
|
||||
@ -408,74 +412,86 @@ end;
|
||||
procedure TLazIDEInterface.AddHandlerOnSavingAll(
|
||||
const OnSaveAllEvent: TModalResultFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnSavingAll,TMethod(OnSaveAllEvent));
|
||||
AddHandler(lihtSavingAll,TMethod(OnSaveAllEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnSavingAll(
|
||||
const OnSaveAllEvent: TModalResultFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnSavingAll,TMethod(OnSaveAllEvent));
|
||||
RemoveHandler(lihtSavingAll,TMethod(OnSaveAllEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnSavedAll(
|
||||
const OnSaveAllEvent: TModalResultFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnSavedAll,TMethod(OnSaveAllEvent));
|
||||
AddHandler(lihtSavedAll,TMethod(OnSaveAllEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnSavedAll(
|
||||
const OnSaveAllEvent: TModalResultFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnSavedAll,TMethod(OnSaveAllEvent));
|
||||
RemoveHandler(lihtSavedAll,TMethod(OnSaveAllEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnIDEClose(
|
||||
const OnIDECloseEvent: TNotifyEvent; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtIDEClose,TMethod(OnIDECloseEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnIDEClose(
|
||||
const OnIDECloseEvent: TNotifyEvent);
|
||||
begin
|
||||
RemoveHandler(lihtIDEClose,TMethod(OnIDECloseEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectOpened,TMethod(OnProjectOpenedEvent));
|
||||
AddHandler(lihtProjectOpened,TMethod(OnProjectOpenedEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectOpened,TMethod(OnProjectOpenedEvent));
|
||||
RemoveHandler(lihtProjectOpened,TMethod(OnProjectOpenedEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectClose,TMethod(OnProjectCloseEvent));
|
||||
AddHandler(lihtProjectClose,TMethod(OnProjectCloseEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectClose,TMethod(OnProjectCloseEvent));
|
||||
RemoveHandler(lihtProjectClose,TMethod(OnProjectCloseEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectBuilding(
|
||||
const OnProjBuildingEvent: TModalResultFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectBuilding,TMethod(OnProjBuildingEvent));
|
||||
AddHandler(lihtProjectBuilding,TMethod(OnProjBuildingEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectBuilding(
|
||||
const OnProjBuildingEvent: TModalResultFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectBuilding,TMethod(OnProjBuildingEvent));
|
||||
RemoveHandler(lihtProjectBuilding,TMethod(OnProjBuildingEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectDependenciesCompiling(
|
||||
const OnProjDependenciesCompilingEvent: TModalResultFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectDependenciesCompiling,
|
||||
TMethod(OnProjDependenciesCompilingEvent));
|
||||
AddHandler(lihtProjectDependenciesCompiling,
|
||||
TMethod(OnProjDependenciesCompilingEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectDependenciesCompiling(
|
||||
const OnProjDependenciesCompilingEvent: TModalResultFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectDependenciesCompiling,
|
||||
RemoveHandler(lihtProjectDependenciesCompiling,
|
||||
TMethod(OnProjDependenciesCompilingEvent));
|
||||
end;
|
||||
|
||||
@ -483,14 +499,14 @@ procedure TLazIDEInterface.AddHandlerOnProjectDependenciesCompiled(
|
||||
const OnProjDependenciesCompiledEvent: TModalResultFunction; AsLast: boolean
|
||||
);
|
||||
begin
|
||||
AddHandler(lihtOnProjectDependenciesCompiled,
|
||||
TMethod(OnProjDependenciesCompiledEvent));
|
||||
AddHandler(lihtProjectDependenciesCompiled,
|
||||
TMethod(OnProjDependenciesCompiledEvent),AsLast);
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectDependenciesCompiled(
|
||||
const OnProjDependenciesCompiledEvent: TModalResultFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectDependenciesCompiled,
|
||||
RemoveHandler(lihtProjectDependenciesCompiled,
|
||||
TMethod(OnProjDependenciesCompiledEvent));
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user