jvcllaz: More improvements in JvOutlookBar component editor.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6358 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-04-26 12:18:09 +00:00
parent fe7d894bc7
commit a20e7f7f74
2 changed files with 88 additions and 107 deletions

View File

@ -73,8 +73,6 @@ type
procedure BuildTreeData; procedure BuildTreeData;
procedure DeleteItem(Item: TPersistent); procedure DeleteItem(Item: TPersistent);
procedure ExchangeItems(Node1, Node2: TTreeNode); procedure ExchangeItems(Node1, Node2: TTreeNode);
// class function GetButtonName(OLBar: TJvCustomOutlookBar): string;
// class function GetPageName(OLBar: TJvCustomOutlookBar): string;
// procedure OnComponentRenamed(AComponent: TComponent); // procedure OnComponentRenamed(AComponent: TComponent);
procedure OnGetSelection(const ASelection: TPersistentSelectionList); procedure OnGetSelection(const ASelection: TPersistentSelectionList);
procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean); procedure OnPersistentAdded(APersistent: TPersistent; Select: boolean);
@ -90,6 +88,7 @@ type
function CheckValidButtonNode(Node: TTreeNode): boolean; function CheckValidButtonNode(Node: TTreeNode): boolean;
function CheckValidPageNode(Node: TTreeNode): boolean; function CheckValidPageNode(Node: TTreeNode): boolean;
function FindNode(ACandidate: TPersistent; out ANode: TTreeNode): Boolean; function FindNode(ACandidate: TPersistent; out ANode: TTreeNode): Boolean;
procedure Modified;
procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SelectionChanged(AOrderChanged: Boolean = false); procedure SelectionChanged(AOrderChanged: Boolean = false);
@ -109,7 +108,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
PropEditUtils, IDEWindowIntf, IDEImagesIntf, PropEditUtils, IDEWindowIntf, IDEImagesIntf, ObjInspStrConsts,
JvConsts; JvConsts;
type type
@ -140,7 +139,7 @@ begin
popNew.Images := AlActions.Images; popNew.Images := AlActions.Images;
popForm.Images := AlActions.Images; popForm.Images := AlActions.Images;
popToolbar.Images := AlActions.Images; popToolbar.Images := AlActions.Images;
(*
if Assigned(GlobalDesignHook) then if Assigned(GlobalDesignHook) then
begin begin
// GlobalDesignHook.AddHandlerComponentRenamed(@OnComponentRenamed); // GlobalDesignHook.AddHandlerComponentRenamed(@OnComponentRenamed);
@ -149,42 +148,27 @@ begin
GlobalDesignHook.AddHandlerSetSelection(@OnSetSelection); GlobalDesignHook.AddHandlerSetSelection(@OnSetSelection);
GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded); GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded);
end; end;
*)
end; end;
procedure TFrmOLBEditor.AcDeleteExecute(Sender: TObject); procedure TFrmOLBEditor.AcDeleteExecute(Sender: TObject);
var var
P: TPersistent; s: String;
page: TJvOutlookBarPage;
node: TTreeNode;
begin begin
if (FOutlookBar = nil) or (FDesigner = nil) or (TvItems.Selected = nil) then if (FOutlookBar = nil) or (FDesigner = nil) or (TvItems.Selected = nil) then
exit; exit;
BeginUpdateSelection; s := TCollectionItem(TvItems.Selected.Data).DisplayName;
FDesigner.DeleteSelection; if MessageDlg(oisConfirmDelete, Format(oisDeleteItem, [s]),
EndUpdateSelection; mtConfirmation, [mbYes, mbNo], 0) <> mrYes
then
exit; exit;
BeginUpdateSelection;
TvItems.Items.BeginUpdate;
try try
node := TvItems.Selected; FDesigner.DeleteSelection;
P := TPersistent(node.Data);
if P is TJvOutlookBarPage then
THackOutlookBar(FOutlookBar).Pages.Delete(TJvOutlookBarPage(P).Index)
else
if P is TJvOutlookBarButton then
begin
page := TJvOutlookBarPage(node.Parent.Data);
page.Buttons.Delete(TJvOutlookBarButton(P).Index);
end;
DeleteItem(node);
finally finally
TvItems.Items.EndUpdate; EndUpdateSelection;
end; end;
end; end;
@ -232,7 +216,7 @@ begin
page := TJvOutlookBarPage(N.Data); page := TJvOutlookBarPage(N.Data);
btn := page.Buttons.Add; btn := page.Buttons.Add;
FDesigner.PropertyEditorHook.PersistentAdded(btn, True); FDesigner.PropertyEditorHook.PersistentAdded(btn, True);
FDesigner.Modified; Modified;
if FindNode(btn, N) then TvItems.Selected := N; if FindNode(btn, N) then TvItems.Selected := N;
//TvItems.Selected := TvItems.Items.AddChildObject(N, btn.Caption, btn); //TvItems.Selected := TvItems.Items.AddChildObject(N, btn.Caption, btn);
@ -251,10 +235,8 @@ begin
page := THackOutlookBar(FOutlookBar).Pages.Add; page := THackOutlookBar(FOutlookBar).Pages.Add;
FDesigner.PropertyEditorHook.PersistentAdded(page,True); FDesigner.PropertyEditorHook.PersistentAdded(page,True);
FDesigner.Modified; Modified;
if FindNode(page, node) then TvItems.Selected := node; if FindNode(page, node) then TvItems.Selected := node;
//TvItems.Selected := TvItems.Items.AddObject(nil, page.Caption, page);
//SelectionChanged;
end; end;
procedure TFrmOLBEditor.AcShowToolbarCaptionsExecute(Sender: TObject); procedure TFrmOLBEditor.AcShowToolbarCaptionsExecute(Sender: TObject);
@ -306,6 +288,7 @@ var
pageNode: TTreeNode; pageNode: TTreeNode;
button: TJvOutlookBarButton; button: TJvOutlookBarButton;
olb: THackOutlookBar; olb: THackOutlookBar;
s: String;
begin begin
TvItems.OnDeletion := nil; TvItems.OnDeletion := nil;
TvItems.Items.Clear; TvItems.Items.Clear;
@ -321,10 +304,14 @@ begin
olb := THackOutlookbar(FOutlookbar); olb := THackOutlookbar(FOutlookbar);
for i := 0 to olb.Pages.Count-1 do begin for i := 0 to olb.Pages.Count-1 do begin
page := olb.Pages[i]; page := olb.Pages[i];
pageNode := TvItems.Items.AddObject(nil, page.Caption, page); s := page.Caption;
if s = '' then s := page.DisplayName;
pageNode := TvItems.Items.AddObject(nil, s, page);
for j := 0 to page.Buttons.Count-1 do begin for j := 0 to page.Buttons.Count-1 do begin
button := page.Buttons[j]; button := page.Buttons[j];
TvItems.Items.AddChildObject(pageNode, button.Caption, button); s := button.Caption;
if s = '' then s := button.DisplayName;
TvItems.Items.AddChildObject(pageNode, s, button);
end; end;
pageNode.Expand(false); pageNode.Expand(false);
end; end;
@ -408,13 +395,31 @@ end;
procedure TFrmOLBEditor.ExchangeItems(Node1, Node2: TTreeNode); procedure TFrmOLBEditor.ExchangeItems(Node1, Node2: TTreeNode);
var var
I: Integer; I: Integer;
page1, page2: TJvOutlookBarPage;
btn1, btn2: TJvOutlookBarButton;
begin begin
(*
if TObject(Node1.Data) is TJvOutlookBarButton then
begin
btn1 := TJvOutlookBarButton(Node1.Data);
btn2 := TJvOutlookBarButton(Node2.Data);
btn1.Collection.Exchange(btn1.Index, btn2.Index);
end else
if TObject(Node1.Data) is TJvOutlookBarPage then
begin
page1 := TJvOutlookBarPage(Node1.Data);
page2 := TJvOutlookBarPage(Node2.Data);
page1.Collection.Exchange(page1.Index, page2.Index);
end;
// FDesigner.Modified;
FDesigner.PropertyEditorHook.RefreshPropertyValues;
*)
if TObject(Node1.Data) is TJvOutlookBarButton then if TObject(Node1.Data) is TJvOutlookBarButton then
begin begin
I := TJvOutlookBarButton(Node1.Data).Index; I := TJvOutlookBarButton(Node1.Data).Index;
TJvOutlookBarButton(Node1.Data).Index := TJvOutlookBarButton(Node2.Data).Index; TJvOutlookBarButton(Node1.Data).Index := TJvOutlookBarButton(Node2.Data).Index;
TJvOutlookBarButton(Node2.Data).Index := I; TJvOutlookBarButton(Node2.Data).Index := I;
FDesigner.PropertyEditorHook.PersistentAdded(TJvOutlookBarButton(Node1.Data), True);
end end
else else
if TObject(Node1.Data) is TJvOutlookBarPage then if TObject(Node1.Data) is TJvOutlookBarPage then
@ -422,9 +427,8 @@ begin
I := TJvOutlookBarPage(Node1.Data).Index; I := TJvOutlookBarPage(Node1.Data).Index;
TJvOutlookBarPage(Node1.Data).Index := TJvOutlookBarPage(Node2.Data).Index; TJvOutlookBarPage(Node1.Data).Index := TJvOutlookBarPage(Node2.Data).Index;
TJvOutlookBarPage(Node2.Data).Index := I; TJvOutlookBarPage(Node2.Data).Index := I;
FDesigner.PropertyEditorHook.PersistentAdded(TJvOutlookBarPage(Node1.Data), True);
end; end;
FDesigner.Modified; Modified;
end; end;
function TFrmOLBEditor.FindNode(ACandidate: TPersistent; function TFrmOLBEditor.FindNode(ACandidate: TPersistent;
@ -498,74 +502,15 @@ begin
exit; exit;
BuildTreeData; BuildTreeData;
end; end;
(*
class function TFrmOLBEditor.GetButtonName(OLBar: TJvCustomOutlookBar): string;
const
cPrefix = 'JvOutlookBarButton';
cTemplate = cPrefix + '%d';
var
K: Integer;
Tmp: string;
function IsUnique(const S: string): Boolean; procedure TFrmOLBEditor.Modified;
var
I, J: Integer;
begin begin
Result := False; FDesigner.PropertyEditorHook.RefreshPropertyValues;
for I := 0 to THackOutlookBar(OLBar).Pages.Count - 1 do FDesigner.Modified;
for J := 0 to THackOutlookBar(OLBar).Pages[I].Buttons.Count - 1 do if GlobalDesignHook <> nil then
if AnsiSameText(THackOutlookBar(OLBar).Pages[I].Buttons[J].Caption, S) then GlobalDesignHook.Modified(self);
Exit;
Result := True;
end; end;
begin
Result := cPrefix;
if OLBar <> nil then
for K := 1 to MaxInt - 1 do
begin
Tmp := Format(cTemplate, [K]);
if IsUnique(Tmp) then
begin
Result := Tmp;
Exit;
end;
end;
end;
class function TFrmOLBEditor.GetPageName(OLBar: TJvCustomOutlookBar): string;
const
cPrefix = 'JvOutlookBarPage';
cTemplate = cPrefix + '%d';
var
K: Integer;
Tmp: string;
function IsUnique(const S: string): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to THackOutlookBar(OLBar).Pages.Count - 1 do
if AnsiSameText(THackOutlookBar(OLBar).Pages[I].Caption, S) then
Exit;
Result := True;
end;
begin
Result := cPrefix;
if OLBar <> nil then
for K := 1 to MaxInt - 1 do
begin
Tmp := Format(cTemplate, [K]);
if IsUnique(Tmp) then
begin
Result := Tmp;
Exit;
end;
end;
end;
*)
procedure TFrmOLBEditor.Notification(AComponent: TComponent; procedure TFrmOLBEditor.Notification(AComponent: TComponent;
Operation: TOperation); Operation: TOperation);
begin begin
@ -628,7 +573,29 @@ var
button: TJvOutlookBarButton; button: TJvOutlookBarButton;
node: TTreeNode; node: TTreeNode;
begin begin
if not Assigned(APersistent) then exit; if not Assigned(APersistent) then
exit;
if (APersistent is TJvOutlookBarPage) then begin
page := TJvOutlookBarPage(APersistent);
olb := page.GetOutlookBar;
if olb = FOutlookBar then begin
BuildTreeData;
if FindNode(page, node) then
TvItems.Selected := node;
end;
end else
if (APersistent is TJvOutlookBarButton) then begin
button := TJvOutlookBarButton(APersistent);
olb := button.GetOutlookBar;
if olb = FOutlookBar then begin
BuildTreeData;
if FindNode(button, node) then
TvItems.Selected := node;
end;
end;
{
if (APersistent is TJvOutlookBarPage) then begin if (APersistent is TJvOutlookBarPage) then begin
page := TJvOutlookBarPage(APersistent); page := TJvOutlookBarPage(APersistent);
olb := THackOutlookbar((page.Collection).Owner); olb := THackOutlookbar((page.Collection).Owner);
@ -648,6 +615,7 @@ begin
TvItems.Selected := node; TvItems.Selected := node;
end; end;
end; end;
}
end; end;
procedure TFrmOLBEditor.OnPersistentDeleting(APersistent: TPersistent); procedure TFrmOLBEditor.OnPersistentDeleting(APersistent: TPersistent);
@ -779,6 +747,18 @@ begin
if FOutlookBar <> nil then if FOutlookBar <> nil then
FOutlookBar.FreeNotification(self); FOutlookBar.FreeNotification(self);
if GlobalDesignHook <> nil then
begin
GlobalDesignHook.RemoveAllHandlersForObject(Self);
if FOutlookbar <> nil then
begin
GlobalDesignHook.AddHandlerPersistentAdded(@OnPersistentAdded);
GlobalDesignHook.AddHandlerPersistentDeleting(@OnPersistentDeleting);
GlobalDesignHook.AddHandlerGetSelection(@OnGetSelection);
GlobalDesignHook.AddHandlerSetSelection(@OnSetSelection);
end;
end;
BuildTreeData; BuildTreeData;
end; end;
@ -825,8 +805,7 @@ begin
end else end else
FDesigner.SelectOnlyThisComponent(FOutlookBar); FDesigner.SelectOnlyThisComponent(FOutlookBar);
FDesigner.Modified; Modified;
// CheckActionsAvailability;
end; end;
procedure TFrmOLBEditor.TvItemsCollapsing(Sender: TObject; Node: TTreeNode; procedure TFrmOLBEditor.TvItemsCollapsing(Sender: TObject; Node: TTreeNode;
@ -850,13 +829,13 @@ begin
begin begin
page := TJvOutlookBarPage(Node.Data); page := TJvOutlookBarPage(Node.Data);
page.Caption := S; page.Caption := S;
FDesigner.Modified; Modified;
end else end else
if TObject(Node.Data) is TJvOutlookBarButton then if TObject(Node.Data) is TJvOutlookBarButton then
begin begin
btn := TJvOutlookBarButton(Node.Data); btn := TJvOutlookBarButton(Node.Data);
btn.Caption := S; btn.Caption := S;
FDesigner.Modified; Modified;
end else end else
raise Exception.Create('TFrmOLBEditor.TvItemsEdited: ' + SDamagedTreeStructure); raise Exception.Create('TFrmOLBEditor.TvItemsEdited: ' + SDamagedTreeStructure);
end; end;

View File

@ -1101,6 +1101,7 @@ function TJvOutlookBarButtons.Add: TJvOutlookBarButton;
begin begin
Result := TJvOutlookBarButton(inherited Add); Result := TJvOutlookBarButton(inherited Add);
Result.Caption := GetUniqueButtonName(Result.GetOutlookBar); Result.Caption := GetUniqueButtonName(Result.GetOutlookBar);
Result.DisplayName := Result.Caption;
end; end;
procedure TJvOutlookBarButtons.Assign(Source: TPersistent); procedure TJvOutlookBarButtons.Assign(Source: TPersistent);
@ -1419,6 +1420,7 @@ function TJvOutlookBarPages.Add: TJvOutlookBarPage;
begin begin
Result := TJvOutlookBarPage(inherited Add); Result := TJvOutlookBarPage(inherited Add);
Result.Caption := GetUniquePageName(Result.GetOutlookBar); Result.Caption := GetUniquePageName(Result.GetOutlookBar);
Result.DisplayName := Result.Caption;
end; end;
procedure TJvOutlookBarPages.Assign(Source: TPersistent); procedure TJvOutlookBarPages.Assign(Source: TPersistent);