tvplanit: Fix IDE crashing at end if VpNavBar component editor is still open after editing a property in object inspector.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6381 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
4a68ab4027
commit
c599028a0c
@ -116,12 +116,14 @@ type
|
|||||||
FDesigner: TComponentEditorDesigner;
|
FDesigner: TComponentEditorDesigner;
|
||||||
procedure AddDesignHookHandlers;
|
procedure AddDesignHookHandlers;
|
||||||
procedure OnGetSelection(const ASelection: TPersistentSelectionList);
|
procedure OnGetSelection(const ASelection: TPersistentSelectionList);
|
||||||
procedure OnObjectPropertyChanged(Sender: TObject; ANewObject: TPersistent);
|
|
||||||
procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean);
|
procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean);
|
||||||
procedure OnPersistentDeleting(APersistent: TPersistent);
|
procedure OnPersistentDeleting(APersistent: TPersistent);
|
||||||
procedure OnRefreshPropertyValues;
|
procedure OnRefreshPropertyValues;
|
||||||
procedure OnSetSelection(const ASelection: TPersistentSelectionList);
|
procedure OnSetSelection(const ASelection: TPersistentSelectionList);
|
||||||
|
|
||||||
|
protected
|
||||||
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
|
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(AOwner: TComponent; ABar: TVpNavBar;
|
constructor Create(AOwner: TComponent; ABar: TVpNavBar;
|
||||||
@ -218,7 +220,6 @@ begin
|
|||||||
if FBar <> nil then
|
if FBar <> nil then
|
||||||
begin
|
begin
|
||||||
GlobalDesignHook.AddHandlerGetSelection(OnGetSelection);
|
GlobalDesignHook.AddHandlerGetSelection(OnGetSelection);
|
||||||
GlobalDesignHook.AddHandlerObjectPropertyChanged(OnObjectPropertyChanged);
|
|
||||||
GlobalDesignHook.AddHandlerPersistentAdded(OnPersistentAdded);
|
GlobalDesignHook.AddHandlerPersistentAdded(OnPersistentAdded);
|
||||||
GlobalDesignHook.AddHandlerPersistentDeleting(OnPersistentDeleting);
|
GlobalDesignHook.AddHandlerPersistentDeleting(OnPersistentDeleting);
|
||||||
GlobalDesignHook.AddHandlerRefreshPropertyValues(OnRefreshPropertyValues);
|
GlobalDesignHook.AddHandlerRefreshPropertyValues(OnRefreshPropertyValues);
|
||||||
@ -285,8 +286,6 @@ procedure TfrmNavBarEd.OnGetSelection(const ASelection: TPersistentSelectionList
|
|||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
DebugLn('OnGetSelection: ENTERING...');
|
|
||||||
|
|
||||||
if not Assigned(ASelection) then
|
if not Assigned(ASelection) then
|
||||||
exit;
|
exit;
|
||||||
if ASelection.Count > 0 then
|
if ASelection.Count > 0 then
|
||||||
@ -302,37 +301,6 @@ begin
|
|||||||
if lbItems.Selected[i] then
|
if lbItems.Selected[i] then
|
||||||
ASelection.Add(TPersistent(lbItems.Items.Objects[i]));
|
ASelection.Add(TPersistent(lbItems.Items.Objects[i]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ASelection.Count > 0 then
|
|
||||||
DebugLn('OnGetSelection EXITING: ASelection[0] = ' + ASelection[0].ClassName + ', ASelection.Count = ' + IntToStr(ASelection.Count));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TfrmNavBarEd.OnObjectPropertyChanged(Sender: TObject; ANewObject: TPersistent);
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
item: TVpNavBtnItem;
|
|
||||||
folder: TVpNavFolder;
|
|
||||||
begin
|
|
||||||
DebugLn('OnObjectPropertyChanged: Sender = ' + Sender.ClassName + ', NewObject = ' + ANewObject.ClassName);
|
|
||||||
|
|
||||||
if ANewObject is TVpNavBtnItem then begin
|
|
||||||
item := TVpNavBtnItem(ANewObject);
|
|
||||||
i := FindBtnIndex(item);
|
|
||||||
if i > -1 then
|
|
||||||
with lbItems.Items do begin
|
|
||||||
Strings[i] := GetItemDisplayName(item);
|
|
||||||
Objects[i] := item;
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
if ANewObject is TVpNavFolder then begin
|
|
||||||
folder := TVpNavFolder(ANewObject);
|
|
||||||
i := FindFolderIndex(folder);
|
|
||||||
if i > -1 then
|
|
||||||
with lbFolders.Items do begin
|
|
||||||
Strings[i] := GetFolderDisplayName(folder);
|
|
||||||
Objects[i] := folder;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfrmNavBarEd.OnPersistentAdded(APersistent: TPersistent; Select: boolean);
|
procedure TfrmNavBarEd.OnPersistentAdded(APersistent: TPersistent; Select: boolean);
|
||||||
@ -388,6 +356,9 @@ var
|
|||||||
selections: TPersistentSelectionList;
|
selections: TPersistentSelectionList;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
if FBar = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
selections := TPersistentSelectionList.Create;
|
selections := TPersistentSelectionList.Create;
|
||||||
try
|
try
|
||||||
Assert(Assigned(GlobalDesignHook));
|
Assert(Assigned(GlobalDesignHook));
|
||||||
@ -409,28 +380,21 @@ procedure TfrmNavBarEd.OnSetSelection(const ASelection: TPersistentSelectionList
|
|||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
begin
|
begin
|
||||||
if ASelection = nil then
|
|
||||||
DebugLn('OnSetSelection: ASelection = nil')
|
|
||||||
else
|
|
||||||
DebugLn('OnSetSelection: ASelection[0] = ' + ASelection[0].ClassName + ', ASelection.Count = ' + IntToStr(ASelection.Count));
|
|
||||||
|
|
||||||
if Assigned(ASelection) and (ASelection.Count > 0) then
|
if Assigned(ASelection) and (ASelection.Count > 0) then
|
||||||
begin
|
begin
|
||||||
if TPersistent(ASelection[0]) is TVpNavFolder then begin
|
if ASelection[0] is TVpNavFolder then begin
|
||||||
//Unselect all
|
//Unselect all
|
||||||
for i := 0 to lbFolders.Items.Count-1 do
|
lbFolders.ClearSelection;
|
||||||
lbFolders.Selected[i] := false;
|
|
||||||
//select from list
|
//select from list
|
||||||
for i := 0 to ASelection.Count - 1 do begin
|
for i := 0 to ASelection.Count - 1 do begin
|
||||||
j := FindFolderIndex(ASelection[i]);
|
j := FindFolderIndex(ASelection[i]);
|
||||||
if j <> -1 then lbFolders.Selected[j] := true;
|
if j <> -1 then lbFolders.Selected[j] := true;
|
||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
if TPersistent(ASelection[0]) is TVpNavBtnItem then
|
if ASelection[0] is TVpNavBtnItem then
|
||||||
begin
|
begin
|
||||||
// Unselect all
|
// Unselect all
|
||||||
for i := 0 to lbItems.Items.Count - 1 do
|
lbItems.ClearSelection;
|
||||||
lbItems.Selected[i] := false;
|
|
||||||
// Select from list
|
// Select from list
|
||||||
for i := 0 to ASelection.Count - 1 do begin
|
for i := 0 to ASelection.Count - 1 do begin
|
||||||
j := FindBtnIndex(ASelection[i]);
|
j := FindBtnIndex(ASelection[i]);
|
||||||
@ -446,9 +410,12 @@ var
|
|||||||
S : string;
|
S : string;
|
||||||
begin
|
begin
|
||||||
lbFolders.Clear;
|
lbFolders.Clear;
|
||||||
for I := 0 to Pred(Bar.FolderCount) do begin
|
if FBar = nil then
|
||||||
S := GetFolderDisplayName(Bar.Folders[I]);
|
exit;
|
||||||
lbFolders.Items.AddObject(S, Bar.Folders[I]);
|
|
||||||
|
for I := 0 to FBar.FolderCount-1 do begin
|
||||||
|
S := GetFolderDisplayName(FBar.Folders[I]);
|
||||||
|
lbFolders.Items.AddObject(S, FBar.Folders[I]);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -460,7 +427,7 @@ begin
|
|||||||
if (FBar = nil) or (FBar.Images = nil) then
|
if (FBar = nil) or (FBar.Images = nil) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
for i:=0 to Bar.Images.Count-1 do
|
for i:=0 to FBar.Images.Count-1 do
|
||||||
lbImages.Items.Add('');
|
lbImages.Items.Add('');
|
||||||
|
|
||||||
lbImages.ItemHeight := FBar.Images.Width + 2*IMG_MARGIN_HOR;
|
lbImages.ItemHeight := FBar.Images.Width + 2*IMG_MARGIN_HOR;
|
||||||
@ -473,9 +440,11 @@ var
|
|||||||
S : string;
|
S : string;
|
||||||
begin
|
begin
|
||||||
lbItems.Clear;
|
lbItems.Clear;
|
||||||
if lbFolders.ItemIndex = -1 then exit;
|
if (lbFolders.ItemIndex = -1) or (FBar = nil) then
|
||||||
with Bar.Folders[lbFolders.ItemIndex] do
|
exit;
|
||||||
for I := 0 to pred(ItemCount) do begin
|
|
||||||
|
with FBar.Folders[lbFolders.ItemIndex] do
|
||||||
|
for I := 0 to ItemCount-1 do begin
|
||||||
S := GetItemDisplayName(Items[I]);
|
S := GetItemDisplayName(Items[I]);
|
||||||
lbItems.Items.AddObject(S, Items[i]);
|
lbItems.Items.AddObject(S, Items[i]);
|
||||||
end;
|
end;
|
||||||
@ -506,8 +475,11 @@ var
|
|||||||
SelList: TPersistentSelectionList;
|
SelList: TPersistentSelectionList;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
if FBar = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
PopulateItemList;
|
PopulateItemList;
|
||||||
Bar.ActiveFolder := lbFolders.ItemIndex;
|
FBar.ActiveFolder := lbFolders.ItemIndex;
|
||||||
lbImages.ItemIndex := -1;
|
lbImages.ItemIndex := -1;
|
||||||
|
|
||||||
SelList := TPersistentSelectionList.Create;
|
SelList := TPersistentSelectionList.Create;
|
||||||
@ -516,7 +488,7 @@ begin
|
|||||||
for i := 0 to pred(lbFolders.Items.Count) do
|
for i := 0 to pred(lbFolders.Items.Count) do
|
||||||
if lbFolders.Selected[i] then begin
|
if lbFolders.Selected[i] then begin
|
||||||
SelList.Add(TPersistent(lbFolders.Items.Objects[i]));
|
SelList.Add(TPersistent(lbFolders.Items.Objects[i]));
|
||||||
Bar.FolderCollection.DoOnItemSelected(i);
|
FBar.FolderCollection.DoOnItemSelected(i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if SelList.Count > 0 then
|
if SelList.Count > 0 then
|
||||||
@ -555,8 +527,12 @@ begin
|
|||||||
else
|
else
|
||||||
lbImages.Canvas.Brush.Color := clWindow;
|
lbImages.Canvas.Brush.Color := clWindow;
|
||||||
lbImages.Canvas.FillRect(ARect);
|
lbImages.Canvas.FillRect(ARect);
|
||||||
x := (ARect.Left + ARect.Right - Bar.Images.Width) div 2;
|
|
||||||
y := (ARect.Top + ARect.Bottom - Bar.Images.Height) div 2;
|
if (FBar = nil) or (FBar.Images = nil) then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
x := (ARect.Left + ARect.Right - FBar.Images.Width) div 2;
|
||||||
|
y := (ARect.Top + ARect.Bottom - FBar.Images.Height) div 2;
|
||||||
FBar.Images.Draw(lbImages.Canvas, x, y, Index);
|
FBar.Images.Draw(lbImages.Canvas, x, y, Index);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -564,7 +540,7 @@ procedure TfrmNavBarEd.lbItemsMeasureItem(Control: TWinControl;
|
|||||||
Index: Integer; var Height: Integer);
|
Index: Integer; var Height: Integer);
|
||||||
begin
|
begin
|
||||||
Unused(Control, Index);
|
Unused(Control, Index);
|
||||||
if (Bar.Images <> nil) then
|
if (FBar <> nil) and (Bar.Images <> nil) then
|
||||||
Height := Bar.Images.Height + 2 * ITEMS_MARGIN;
|
Height := Bar.Images.Height + 2 * ITEMS_MARGIN;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -581,16 +557,16 @@ begin
|
|||||||
lb := TListBox(Control);
|
lb := TListBox(Control);
|
||||||
lb.Canvas.FillRect(Rect);
|
lb.Canvas.FillRect(Rect);
|
||||||
|
|
||||||
if Index = -1 then
|
if (FBar = nil) or (Index = -1) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
// Draw button image
|
// Draw button image
|
||||||
delta := ITEMS_MARGIN;
|
delta := ITEMS_MARGIN;
|
||||||
btn := TVpNavBtnItem(lbItems.Items.Objects[Index]);
|
btn := TVpNavBtnItem(lbItems.Items.Objects[Index]);
|
||||||
if (Bar.Images <> nil) and (btn <> nil) and
|
if (FBar.Images <> nil) and (btn <> nil) and
|
||||||
(btn.IconIndex > -1) and (btn.IconIndex < Bar.Images.Count) then
|
(btn.IconIndex > -1) and (btn.IconIndex < Bar.Images.Count) then
|
||||||
begin
|
begin
|
||||||
Bar.Images.Draw(
|
FBar.Images.Draw(
|
||||||
lb.Canvas,
|
lb.Canvas,
|
||||||
Rect.Right - Bar.Images.Width - delta,
|
Rect.Right - Bar.Images.Width - delta,
|
||||||
(Rect.Top + Rect.Bottom - Bar.Images.Height) div 2,
|
(Rect.Top + Rect.Bottom - Bar.Images.Height) div 2,
|
||||||
@ -627,7 +603,7 @@ begin
|
|||||||
if lbItems.Selected[i] then
|
if lbItems.Selected[i] then
|
||||||
begin
|
begin
|
||||||
SelList.Add(TPersistent(lbItems.Items.Objects[i]));
|
SelList.Add(TPersistent(lbItems.Items.Objects[i]));
|
||||||
Bar.Folders[Bar.ActiveFolder].ItemCollection.DoOnItemSelected(I);
|
FBar.Folders[FBar.ActiveFolder].ItemCollection.DoOnItemSelected(I);
|
||||||
end;
|
end;
|
||||||
if SelList.Count > 0 then
|
if SelList.Count > 0 then
|
||||||
SelectList(SelList);
|
SelectList(SelList);
|
||||||
@ -740,7 +716,7 @@ end;
|
|||||||
|
|
||||||
procedure TfrmNavBarEd.btnFolderDeleteClick(Sender: TObject);
|
procedure TfrmNavBarEd.btnFolderDeleteClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if (lbFolders.ItemIndex <> -1) then begin
|
if (lbFolders.ItemIndex <> -1) and (FBar <> nil) then begin
|
||||||
TVpNavFolder(lbFolders.Items.Objects[lbFolders.ItemIndex]).Free;
|
TVpNavFolder(lbFolders.Items.Objects[lbFolders.ItemIndex]).Free;
|
||||||
lbFolders.ItemIndex := -1;
|
lbFolders.ItemIndex := -1;
|
||||||
FBar.Activefolder := -1;
|
FBar.Activefolder := -1;
|
||||||
@ -757,19 +733,11 @@ procedure TfrmNavBarEd.btnFolderAddClick(Sender: TObject);
|
|||||||
var
|
var
|
||||||
folder: TVpNavFolder;
|
folder: TVpNavFolder;
|
||||||
begin
|
begin
|
||||||
|
if FBar = nil then
|
||||||
|
exit;
|
||||||
folder := TVpNavFolder(FBar.FolderCollection.Add);
|
folder := TVpNavFolder(FBar.FolderCollection.Add);
|
||||||
// folder.Name := Designer.CreateUniqueComponentName('TVpNavFolder');
|
|
||||||
GlobalDesignHook.PersistentAdded(folder, true);
|
GlobalDesignHook.PersistentAdded(folder, true);
|
||||||
(*
|
|
||||||
PopulateFolderList;
|
|
||||||
lbFolders.ItemIndex := lbFolders.Items.Count - 1;
|
|
||||||
SelectionChanged(true);
|
|
||||||
if Assigned(Designer) then
|
|
||||||
Designer.Modified;
|
|
||||||
lbFoldersClick(Self);
|
|
||||||
*)
|
|
||||||
lbFoldersClick(self);
|
lbFoldersClick(self);
|
||||||
// UpdateBtnStates;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfrmNavBarEd.btnItemAddClick(Sender: TObject);
|
procedure TfrmNavBarEd.btnItemAddClick(Sender: TObject);
|
||||||
@ -810,10 +778,10 @@ end;
|
|||||||
|
|
||||||
procedure TfrmNavBarEd.Selectlist(SelList: TPersistentSelectionList);
|
procedure TfrmNavBarEd.Selectlist(SelList: TPersistentSelectionList);
|
||||||
begin
|
begin
|
||||||
if GlobalDesignHook <> nil then
|
if (GlobalDesignHook <> nil) and (FBar <> nil) then
|
||||||
begin
|
begin
|
||||||
GlobalDesignHook.SetSelection(SelList);
|
GlobalDesignHook.SetSelection(SelList);
|
||||||
GlobalDesignHook.LookupRoot := GetLookupRootForComponent(Bar);
|
GlobalDesignHook.LookupRoot := GetLookupRootForComponent(FBar);
|
||||||
end;
|
end;
|
||||||
SelList.Free;
|
SelList.Free;
|
||||||
end;
|
end;
|
||||||
@ -838,6 +806,13 @@ begin
|
|||||||
btnItemDown.Enabled := canChangeItems and (lbItems.ItemIndex < lbItems.Items.Count-1);
|
btnItemDown.Enabled := canChangeItems and (lbItems.ItemIndex < lbItems.Items.Count-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TfrmNavBarEd.Notification(AComponent: TComponent; Operation: TOperation);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if Operation = opRemove then begin
|
||||||
|
if AComponent = FBar then FBar := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user