IDE: implemented creating designer for hidden component

git-svn-id: trunk@10045 -
This commit is contained in:
mattias 2006-10-06 17:28:20 +00:00
parent d7d43ee618
commit b6f164d0aa
4 changed files with 61 additions and 25 deletions

View File

@ -485,6 +485,8 @@ begin
GlobalDesignHook.PersistentDeleting(FLookupRoot);
end;
// delete
if Form<>nil then
Form.Designer:=nil;
TheFormEditor.DeleteComponent(FLookupRoot,FreeComponent);
end;
Free;

View File

@ -39,7 +39,7 @@ uses
MemCheck,
{$ENDIF}
// LCL+FCL
Classes, SysUtils, TypInfo, Math,
Classes, SysUtils, TypInfo, Math, LCLIntf, LCLType,
AVL_Tree,
LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
// components
@ -832,12 +832,13 @@ var
CompIntf : TComponentInterface;
i: integer;
AForm: TCustomForm;
AWinControl: TWinControl;
Begin
CompIntf := TComponentInterface(FindComponent(AComponent));
if CompIntf <> nil then
FComponentInterfaces.Remove(CompIntf);
DebugLn(['TCustomFormEditor.DeleteControl ',DbgSName(AComponent),' IsJITComponent=',IsJITComponent(AComponent)]);
DebugLn(['TCustomFormEditor.DeleteComponent ',DbgSName(AComponent),' IsJITComponent=',IsJITComponent(AComponent),' FreeComponent=',FreeComponent]);
if IsJITComponent(AComponent) then begin
// value is a top level component
i:=AComponent.ComponentCount-1;
@ -857,7 +858,7 @@ Begin
// free/unbind a non form component and its designer form
AForm:=GetDesignerForm(AComponent);
if (AForm<>nil) and (not (AForm is TNonControlDesignerForm)) then
RaiseException('TCustomFormEditor.DeleteControl Where is the TNonControlDesignerForm? '+AComponent.ClassName);
RaiseException('TCustomFormEditor.DeleteComponent Where is the TNonControlDesignerForm? '+AComponent.ClassName);
if AForm<>nil then begin
FNonControlForms.Remove(AForm);
TNonControlDesignerForm(AForm).LookupRoot:=nil;
@ -866,7 +867,7 @@ Begin
if FreeComponent then
JITNonFormList.DestroyJITComponent(AComponent);
end else
RaiseException('TCustomFormEditor.DeleteControl '+AComponent.ClassName);
RaiseException('TCustomFormEditor.DeleteComponent '+AComponent.ClassName);
CompIntf.Free;
end
else if CompIntf<>nil then begin
@ -876,9 +877,19 @@ Begin
else
CompIntf.Free;
end else if FreeComponent then begin
DebugLn(['WARNING: TCustomFormEditor.DeleteComponent freeing orphaned component ',DbgSName(AComponent)]);
if (AComponent.Owner=nil) then
DebugLn(['WARNING: TCustomFormEditor.DeleteComponent freeing orphaned component ',DbgSName(AComponent)]);
TryFreeComponent(AComponent);
end;
// if not free, then free the handle to hide it
if (not FreeComponent) and (AComponent is TWinControl) then begin
AWinControl:=TWinControl(AComponent);
if AWinControl.HandleAllocated and (AWinControl.Parent=nil) then begin
AWinControl.ControlStyle:=AWinControl.ControlStyle+[csNoDesignVisible];
LCLIntf.ShowWindow(AWinControl.Handle,SW_HIDE);
DebugLn(['TCustomFormEditor.DeleteComponent Hiding: ',dbgsName(AWinControl)]);
end;
end;
end;
Function TCustomFormEditor.FindComponentByName(
@ -1074,6 +1085,7 @@ var
OwnerComponent: TComponent;
begin
Result:=nil;
if AComponent=nil then exit;
OwnerComponent:=AComponent;
while OwnerComponent.Owner<>nil do
OwnerComponent:=OwnerComponent.Owner;

View File

@ -729,8 +729,8 @@ type
var ActiveSourceEditor: TSourceEditor; var ActiveUnitInfo: TUnitInfo); override;
function GetDesignerWithProjectFile(AFile: TLazProjectFile;
LoadForm: boolean): TIDesigner; override;
function GetFormOfSource(AnUnitInfo: TUnitInfo;
LoadForm: boolean): TCustomForm;
function GetDesignerFormOfSource(AnUnitInfo: TUnitInfo;
LoadForm: boolean): TCustomForm;
function GetProjectFileWithRootComponent(AComponent: TComponent): TLazProjectFile; override;
function GetProjectFileWithDesigner(ADesigner: TIDesigner): TLazProjectFile; override;
procedure GetObjectInspectorUnit(
@ -4805,8 +4805,9 @@ begin
if Result<>mrOk then exit;
// check installed packages
if (AnUnitInfo.Component=nil) and AnUnitInfo.IsPartOfProject then begin
// opening a single form of the project -> check installed packages
if (AnUnitInfo.Component=nil) and AnUnitInfo.IsPartOfProject
and (not (ofProjectLoading in OpenFlags)) then begin
// opening a form of the project -> check installed packages
Result:=PkgBoss.CheckProjectHasInstalledPackages(Project1);
if not (Result in [mrOk,mrIgnore]) then exit;
end;
@ -4863,11 +4864,12 @@ begin
// try loading the ancestor first (unit, lfm and component instance)
if (AncestorType=nil) then begin
Result:=DoLoadComponentDependencyHidden(AnUnitInfo,AncestorClassName,OpenFlags,
AncestorType,AncestorUnitInfo);
Result:=DoLoadComponentDependencyHidden(AnUnitInfo,AncestorClassName,
OpenFlags,AncestorType,AncestorUnitInfo);
if Result=mrAbort then exit;
if Result=mrOk then begin
Result:=DoSaveFileResourceToBinStream(AncestorUnitInfo,AncestorBinStream);
Result:=DoSaveFileResourceToBinStream(AncestorUnitInfo,
AncestorBinStream);
if Result<>mrOk then exit;
AncestorBinStream.Position:=0;
end else begin
@ -4938,9 +4940,10 @@ begin
end;
end else begin
// keep old instance, just add a designer
NewComponent:=AnUnitInfo.Component;
DebugLn(['TMainIDE.DoLoadLFM Creating designer for hidden component of ',AnUnitInfo.Filename]);
end;
NewComponent:=AnUnitInfo.Component;
// create the designer
if ([ofProjectLoading,ofLoadHiddenResource]*OpenFlags=[]) then
FormEditor1.ClearSelection;
@ -4951,7 +4954,7 @@ begin
DesignerForm:=nil;
if not (ofLoadHiddenResource in OpenFlags) then begin
CreateDesignerForComponent(NewComponent);
DesignerForm:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
DesignerForm:=FormEditor1.GetDesignerForm(NewComponent);
end;
// select the new form (object inspector, formeditor, control selection)
@ -4963,6 +4966,10 @@ begin
// show new form
if DesignerForm<>nil then begin
DesignerForm.ControlStyle:=DesignerForm.ControlStyle-[csNoDesignVisible];
if NewComponent is TControl then
TControl(NewComponent).ControlStyle:=
TControl(NewComponent).ControlStyle-[csNoDesignVisible];
LCLIntf.ShowWindow(DesignerForm.Handle,SW_SHOWNORMAL);
FLastFormActivated:=DesignerForm;
end;
@ -5147,6 +5154,7 @@ function TMainIDE.CloseUnitComponent(AnUnitInfo: TUnitInfo; Flags: TCloseFlags
begin
CompUnitInfo:=Project1.FirstUnitWithComponent;
while CompUnitInfo<>nil do begin
DebugLn(['FreeUnusedComponents ',CompUnitInfo.Filename,' ',dbgsName(CompUnitInfo.Component),' UnitComponentIsUsed=',UnitComponentIsUsed(CompUnitInfo,true)]);
if not UnitComponentIsUsed(CompUnitInfo,true) then begin
CloseUnitComponent(CompUnitInfo,Flags);
exit;
@ -5162,6 +5170,7 @@ var
begin
LookupRoot:=AnUnitInfo.Component;
if LookupRoot=nil then exit(mrOk);
DebugLn(['TMainIDE.CloseUnitComponent ',AnUnitInfo.Filename,' ',dbgsName(LookupRoot)]);
// save
if (cfSaveFirst in Flags) and (AnUnitInfo.EditorIndex>=0) then begin
@ -5197,7 +5206,6 @@ begin
if UnitComponentIsUsed(AnUnitInfo,false) then begin
// free designer, keep component hidden
DebugLn(['TMainIDE.CloseUnitComponent hiding component and freeing designer: ',AnUnitInfo.Filename,' ',DbgSName(AnUnitInfo.Component)]);
LCLIntf.ShowWindow(AForm.Handle,SW_HIDE);
OldDesigner.FreeDesigner(false);
end else begin
// free designer and design form
@ -5251,7 +5259,7 @@ begin
// check if a designer is open
if CheckHasDesigner then begin
AForm:=FormEditor1.GetDesignerForm(LookupRoot);
if AForm<>nil then exit(true);
if (AForm<>nil) and (AForm.Designer<>nil) then exit(true);
end;
// check if another component uses this component
if Project1.UnitUsingComponentUnit(AnUnitInfo)<>nil then
@ -6473,7 +6481,7 @@ Begin
if Result=mrAbort then exit;
end;
if OnlyForms and (AnUnitInfo.ComponentName<>'') then begin
AForm:=GetFormOfSource(AnUnitInfo,true);
AForm:=GetDesignerFormOfSource(AnUnitInfo,true);
if AForm<>nil then
ShowDesignerForm(AForm);
end;
@ -8754,7 +8762,7 @@ var
AForm: TCustomForm;
begin
AnUnitInfo:=AFile as TUnitInfo;
AForm:=GetFormOfSource(AnUnitInfo,LoadForm);
AForm:=GetDesignerFormOfSource(AnUnitInfo,LoadForm);
if AForm<>nil then
Result:=AForm.Designer;
end;
@ -9189,7 +9197,7 @@ begin
GetCurrentUnit(ActiveSourceEditor,ActiveUnitInfo);
if (ActiveUnitInfo = nil) then exit;
// load the form, if not already done
AForm:=GetFormOfSource(ActiveUnitInfo,true);
AForm:=GetDesignerFormOfSource(ActiveUnitInfo,true);
if AForm=nil then exit;
FDisplayState:= dsForm;
FLastFormActivated:=AForm;
@ -11943,16 +11951,21 @@ begin
end;
end;
function TMainIDE.GetFormOfSource(AnUnitInfo: TUnitInfo; LoadForm: boolean
function TMainIDE.GetDesignerFormOfSource(AnUnitInfo: TUnitInfo; LoadForm: boolean
): TCustomForm;
begin
Result:=nil;
if (AnUnitInfo.Component=nil) and LoadForm
and FilenameIsPascalSource(AnUnitInfo.Filename) then begin
DoLoadLFM(AnUnitInfo,[],[]);
end;
if AnUnitInfo.Component<>nil then
Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if ((Result=nil) or (Result.Designer=nil)) and LoadForm
and FilenameIsPascalSource(AnUnitInfo.Filename) then begin
DebugLn(['TMainIDE.GetFormOfSource ',AnUnitInfo.Filename,' ',dbgsName(AnUnitInfo.Component)]);
DoLoadLFM(AnUnitInfo,[],[]);
end;
if (Result=nil) and (AnUnitInfo.Component<>nil) then
Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if (Result<>nil) and (Result.Designer=nil) then
Result:=nil;
end;
function TMainIDE.GetProjectFileWithRootComponent(AComponent: TComponent

View File

@ -9346,6 +9346,8 @@ begin
GtkWindow:=PGtkWindow(hWnd);
if GtkWindow=nil then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is nil');
if not GtkWidgetIsA(PGtkWidget(GtkWindow),GTK_TYPE_WINDOW) then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is not a gtkwindow');
{$IFDEF Gtk2}
//debugln('TGtkWidgetSet.ShowWindow A ',GetWidgetDebugReport(PGtkWidget(GtkWindow)),' nCmdShow=',dbgs(nCmdShow),' SW_MINIMIZE=',dbgs(SW_MINIMIZE=nCmdShow));
@ -9358,6 +9360,9 @@ begin
gtk_window_unmaximize(GtkWindow);
end;
SW_HIDE:
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
SW_MINIMIZE:
gtk_window_iconify(GtkWindow);
@ -9377,6 +9382,11 @@ begin
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end;
SW_HIDE:
begin
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
end;
SW_MINIMIZE:
begin
GDK_WINDOW_MINIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
@ -9386,7 +9396,6 @@ begin
GDK_WINDOW_MAXIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
end;
end;
Result:=true;