mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 02:18:03 +02:00
IDEIntf: added handlers for opened and close project
git-svn-id: trunk@14451 -
This commit is contained in:
parent
b895d72611
commit
bd4b61b421
@ -25,10 +25,10 @@
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
<PackageName Value="LazOpenGLContext"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LazOpenGLContext"/>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
|
70
ide/main.pp
70
ide/main.pp
@ -7561,8 +7561,10 @@ begin
|
||||
end;
|
||||
|
||||
function TMainIDE.DoNewProject(ProjectDesc: TProjectDescriptor):TModalResult;
|
||||
var i:integer;
|
||||
Begin
|
||||
var
|
||||
i:integer;
|
||||
HandlerResult: TModalResult;
|
||||
begin
|
||||
DebugLn('TMainIDE.DoNewProject A');
|
||||
|
||||
// init the descriptor (it can now ask the user for options)
|
||||
@ -7597,36 +7599,45 @@ Begin
|
||||
// create new project (TProject will automatically create the mainunit)
|
||||
|
||||
Project1:=CreateProjectObject(ProjectDesc,ProjectDescriptorProgram);
|
||||
Project1.BeginUpdate(true);
|
||||
try
|
||||
Project1.CompilerOptions.CompilerPath:='$(CompPath)';
|
||||
UpdateCaption;
|
||||
if ProjInspector<>nil then ProjInspector.LazProject:=Project1;
|
||||
Project1.BeginUpdate(true);
|
||||
try
|
||||
Project1.CompilerOptions.CompilerPath:='$(CompPath)';
|
||||
UpdateCaption;
|
||||
if ProjInspector<>nil then ProjInspector.LazProject:=Project1;
|
||||
|
||||
// add and load default required packages
|
||||
PkgBoss.AddDefaultDependencies(Project1);
|
||||
// add and load default required packages
|
||||
PkgBoss.AddDefaultDependencies(Project1);
|
||||
|
||||
if ProjectDesc.CreateStartFiles(Project1)<>mrOk then begin
|
||||
debugln('TMainIDE.DoNewProject ProjectDesc.CreateStartFiles failed');
|
||||
if ProjectDesc.CreateStartFiles(Project1)<>mrOk then begin
|
||||
debugln('TMainIDE.DoNewProject ProjectDesc.CreateStartFiles failed');
|
||||
end;
|
||||
|
||||
// rebuild codetools defines
|
||||
MainBuildBoss.RescanCompilerDefines(true,true);
|
||||
// (i.e. remove old project specific things and create new)
|
||||
IncreaseCompilerParseStamp;
|
||||
Project1.DefineTemplates.AllChanged;
|
||||
Project1.DefineTemplates.Active:=true;
|
||||
finally
|
||||
Project1.EndUpdate;
|
||||
end;
|
||||
|
||||
// rebuild codetools defines
|
||||
MainBuildBoss.RescanCompilerDefines(true,true);
|
||||
// (i.e. remove old project specific things and create new)
|
||||
IncreaseCompilerParseStamp;
|
||||
Project1.DefineTemplates.AllChanged;
|
||||
Project1.DefineTemplates.Active:=true;
|
||||
// set all modified to false
|
||||
for i:=0 to Project1.UnitCount-1 do
|
||||
Project1.Units[i].ClearModifieds;
|
||||
Project1.Modified:=false;
|
||||
Result:=mrOk;
|
||||
finally
|
||||
Project1.EndUpdate;
|
||||
// call handlers
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtOnProjectOpened,Project1);
|
||||
if not (HandlerResult in [mrOk,mrCancel,mrAbort]) then
|
||||
HandlerResult:=mrCancel;
|
||||
if (Result=mrOk) then
|
||||
Result:=HandlerResult;
|
||||
end;
|
||||
|
||||
// set all modified to false
|
||||
for i:=0 to Project1.UnitCount-1 do
|
||||
Project1.Units[i].ClearModifieds;
|
||||
Project1.Modified:=false;
|
||||
|
||||
//DebugLn('TMainIDE.DoNewProject end ');
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
function TMainIDE.DoSaveProject(Flags: TSaveFlags):TModalResult;
|
||||
@ -7788,6 +7799,11 @@ begin
|
||||
debugln('TMainIDE.DoCloseProject DebugBoss.DoStopProject failed');
|
||||
exit;
|
||||
end;
|
||||
|
||||
// call handlers
|
||||
Result:=DoCallProjectChangedHandler(lihtOnProjectClose,Project1);
|
||||
if Result=mrAbort then exit;
|
||||
|
||||
// close all loaded files
|
||||
while SourceNotebook.Notebook<>nil do begin
|
||||
Result:=DoCloseEditorFile(SourceNotebook.Notebook.PageCount-1,
|
||||
@ -7817,6 +7833,7 @@ var
|
||||
LastDesigner: TDesigner;
|
||||
AnUnitInfo: TUnitInfo;
|
||||
FileReadable: Boolean;
|
||||
HandlerResult: TModalResult;
|
||||
begin
|
||||
// close the old project
|
||||
if SomethingOfProjectIsModified then begin
|
||||
@ -8007,7 +8024,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// call handlers
|
||||
HandlerResult:=DoCallProjectChangedHandler(lihtOnProjectOpened,Project1);
|
||||
if not (HandlerResult in [mrOk,mrCancel,mrAbort]) then
|
||||
HandlerResult:=mrCancel;
|
||||
if (Result=mrOk) then
|
||||
Result:=HandlerResult;
|
||||
end;
|
||||
if Result=mrAbort then exit;
|
||||
{$IFDEF IDE_VERBOSE}
|
||||
debugln('TMainIDE.DoOpenProjectFile end CodeToolBoss.ConsistencyCheck=',IntToStr(CodeToolBoss.ConsistencyCheck));
|
||||
{$ENDIF}
|
||||
|
@ -115,10 +115,14 @@ type
|
||||
TFindSourceFlags = set of TFindSourceFlag;
|
||||
|
||||
TModalResultFunction = function(Sender: TObject): TModalResult of object;
|
||||
TLazProjectChangedFunction = function(Sender: TObject;
|
||||
AProject: TLazProject): TModalResult of object;
|
||||
|
||||
TLazarusIDEHandlerType = (
|
||||
lihtOnSavingAll, // called before IDE saves everything
|
||||
lihtOnSavedAll // called after IDE saved everything
|
||||
lihtOnSavedAll, // called after IDE saved everything
|
||||
lihtOnProjectOpened,// called after IDE opened a project
|
||||
lihtOnProjectClose // called before IDE closes a project
|
||||
);
|
||||
|
||||
{ TLazIDEInterface }
|
||||
@ -140,6 +144,8 @@ type
|
||||
procedure DoCallNotifyHandler(HandlerType: TLazarusIDEHandlerType);
|
||||
function DoCallModalFunctionHandler(HandlerType: TLazarusIDEHandlerType
|
||||
): TModalResult;
|
||||
function DoCallProjectChangedHandler(HandlerType: TLazarusIDEHandlerType;
|
||||
AProject: TLazProject): TModalResult;
|
||||
procedure SetMainBarSubTitle(const AValue: string); virtual;
|
||||
public
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
@ -230,6 +236,16 @@ type
|
||||
procedure AddHandlerOnSavedAll(const OnSaveAllEvent: TModalResultFunction;
|
||||
AsLast: boolean = false);
|
||||
procedure RemoveHandlerOnSavedAll(const OnSaveAllEvent: TModalResultFunction);
|
||||
procedure AddHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction;
|
||||
AsLast: boolean = false);
|
||||
procedure RemoveHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction);
|
||||
procedure AddHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction;
|
||||
AsLast: boolean = false);
|
||||
procedure RemoveHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction);
|
||||
end;
|
||||
|
||||
var
|
||||
@ -280,6 +296,21 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TLazIDEInterface.DoCallProjectChangedHandler(
|
||||
HandlerType: TLazarusIDEHandlerType; AProject: TLazProject): TModalResult;
|
||||
var
|
||||
i: Integer;
|
||||
CurResult: TModalResult;
|
||||
begin
|
||||
Result:=mrOk;
|
||||
i:=FLazarusIDEHandlers[HandlerType].Count;
|
||||
while FLazarusIDEHandlers[HandlerType].NextDownIndex(i) do begin
|
||||
CurResult:=TLazProjectChangedFunction(FLazarusIDEHandlers[HandlerType][i])(Self,AProject);
|
||||
if CurResult=mrAbort then exit(mrAbort);
|
||||
if CurResult<>mrOk then Result:=mrCancel;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TLazIDEInterface.Create(TheOwner: TComponent);
|
||||
begin
|
||||
LazarusIDE:=Self;
|
||||
@ -335,6 +366,30 @@ begin
|
||||
RemoveHandler(lihtOnSavedAll,TMethod(OnSaveAllEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectOpened,TMethod(OnProjectOpenedEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectOpened(
|
||||
const OnProjectOpenedEvent: TLazProjectChangedFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectOpened,TMethod(OnProjectOpenedEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.AddHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction; AsLast: boolean);
|
||||
begin
|
||||
AddHandler(lihtOnProjectClose,TMethod(OnProjectCloseEvent));
|
||||
end;
|
||||
|
||||
procedure TLazIDEInterface.RemoveHandlerOnProjectClose(
|
||||
const OnProjectCloseEvent: TLazProjectChangedFunction);
|
||||
begin
|
||||
RemoveHandler(lihtOnProjectClose,TMethod(OnProjectCloseEvent));
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterPropertyEditor(TypeInfo(AnsiString),
|
||||
THTMLBrowserHelpViewer,'BrowserPath',TFileNamePropertyEditor);
|
||||
|
Loading…
Reference in New Issue
Block a user