IDE: Refactor. Use one const for all ToolBar dividers. Reorder code.

git-svn-id: trunk@49738 -
This commit is contained in:
juha 2015-09-02 10:10:42 +00:00
parent d784776662
commit c910ea98c3
3 changed files with 87 additions and 93 deletions

View File

@ -28,10 +28,6 @@ uses
MenuIntf, IDEImagesIntf, SrcEditorIntf, BaseIDEIntf, LazIDEIntf,
LazarusIDEStrConsts, LazConfigStorage, Laz2_XMLCfg, LCLProc, ToolbarConfig;
const
cSettingsFile = 'editortoolbar.xml';
cDivider = '---------------';
type
{ TEditorToolBarOptions }
@ -106,6 +102,8 @@ uses EnvironmentOpts;
const
BasePath = 'EditorToolBarOptions/';
cSettingsFile = 'editortoolbar.xml';
procedure ToggleToolbar (Sender:TObject);
var
@ -221,73 +219,6 @@ begin
XMLConfig.SetDeleteValue(Path + 'Button' + IntToStr(I+1) + '/Name', ButtonNames[I], '');
end;
{ TAllEditorToolbars }
constructor TAllEditorToolbars.Create;
begin
inherited;
FToolBars := TEditorToolbarList.Create;
if SourceEditorManagerIntf <> nil then
begin
SourceEditorManagerIntf.RegisterChangeEvent(semWindowCreate, @SourceWindowCreated);
SourceEditorManagerIntf.RegisterChangeEvent(semWindowDestroy,@SourceWindowDestroyed);
end;
end;
destructor TAllEditorToolbars.Destroy;
begin
while FToolBars.Count > 0 do
FToolBars[0].Free;
FreeAndNil(FToolBars);
inherited Destroy;
end;
procedure TAllEditorToolbars.SourceWindowCreated(Sender: TObject);
var
ETB: TEditorToolbar;
i: Integer;
begin
ETB := TEditorToolbar.Create(Sender as TSourceEditorWindowInterface, Self);
i := FToolBars.Add(ETB);
FToolBars[i].AddStaticItems;
FToolBars[i].CopyFromOptions(EnvironmentOptions.Desktop.EditorToolBarOptions);
end;
procedure TAllEditorToolbars.SourceWindowDestroyed(Sender: TObject);
var
i: integer;
aBar: TEditorToolbar;
begin
// Let's remove from our list the destroyed window and then destroy the ToolBar
for i:= 0 to FToolBars.Count -1 do begin
aBar := FToolBars[i];
if aBar.OwnerWindow = TSourceEditorWindowInterface(Sender) then
begin
FToolBars.Remove(aBar);
aBar.Free;
exit;
end;
end;
end;
procedure TAllEditorToolbars.DoConfigureEditorToolbar(Sender: TObject);
begin
if Assigned(FConfigEvent) then
FConfigEvent(Sender);
end;
procedure TAllEditorToolbars.ReloadAll;
var
i: Integer;
begin
for i := 0 to FToolBars.Count-1 do
begin
FToolBars[i].ClearToolbar;
FToolBars[i].AddStaticItems;
FToolBars[i].CopyFromOptions(EnvironmentOptions.Desktop.EditorToolBarOptions);
end;
end;
{ TEditorToolbar }
constructor TEditorToolbar.Create(AOwner: TComponent; ACollection: TAllEditorToolbars);
@ -390,7 +321,7 @@ begin
for i := 0 to Options.ButtonNames.Count-1 do
begin
ButtonName := Options.ButtonNames[i];
if ButtonName = cDivider then
if ButtonName = cIDEToolbarDivider then
AddDivider
else
begin
@ -400,11 +331,11 @@ begin
end;
end;
SetTbPos;
EditorMenuCommand.Checked:= Options.Visible;
EditorMenuCommand.Checked := Options.Visible;
finally
FToolBar.EndUpdate;
end;
FToolBar.Visible:= Options.Visible;
FToolBar.Visible := Options.Visible;
end;
procedure CreateEditorToolBar(aConfigEvent: TNotifyEvent);
@ -422,6 +353,73 @@ begin
EditorMenuCommand.ImageIndex := IDEImages.LoadImage(16, MenuIcon);
end;
{ TAllEditorToolbars }
constructor TAllEditorToolbars.Create;
begin
inherited;
FToolBars := TEditorToolbarList.Create;
if SourceEditorManagerIntf <> nil then
begin
SourceEditorManagerIntf.RegisterChangeEvent(semWindowCreate, @SourceWindowCreated);
SourceEditorManagerIntf.RegisterChangeEvent(semWindowDestroy,@SourceWindowDestroyed);
end;
end;
destructor TAllEditorToolbars.Destroy;
begin
while FToolBars.Count > 0 do
FToolBars[0].Free;
FreeAndNil(FToolBars);
inherited Destroy;
end;
procedure TAllEditorToolbars.SourceWindowCreated(Sender: TObject);
var
ETB: TEditorToolbar;
i: Integer;
begin
ETB := TEditorToolbar.Create(Sender as TSourceEditorWindowInterface, Self);
i := FToolBars.Add(ETB);
FToolBars[i].AddStaticItems;
FToolBars[i].CopyFromOptions(EnvironmentOptions.Desktop.EditorToolBarOptions);
end;
procedure TAllEditorToolbars.SourceWindowDestroyed(Sender: TObject);
var
i: integer;
aBar: TEditorToolbar;
begin
// Let's remove from our list the destroyed window and then destroy the ToolBar
for i:= 0 to FToolBars.Count -1 do begin
aBar := FToolBars[i];
if aBar.OwnerWindow = TSourceEditorWindowInterface(Sender) then
begin
FToolBars.Remove(aBar);
aBar.Free;
exit;
end;
end;
end;
procedure TAllEditorToolbars.DoConfigureEditorToolbar(Sender: TObject);
begin
if Assigned(FConfigEvent) then
FConfigEvent(Sender);
end;
procedure TAllEditorToolbars.ReloadAll;
var
i: Integer;
begin
for i := 0 to FToolBars.Count-1 do
begin
FToolBars[i].ClearToolbar;
FToolBars[i].AddStaticItems;
FToolBars[i].CopyFromOptions(EnvironmentOptions.Desktop.EditorToolBarOptions);
end;
end;
initialization
//CreateEditorToolBar;

View File

@ -426,8 +426,6 @@ begin
end;
procedure TIDEToolBar.AddCustomItems(Index: Integer);
const
cDivider = '---------------';
var
mi: TIDEMenuItem;
AName: string;
@ -437,7 +435,7 @@ begin
AName := FButtonNames[Index];
if AName <> '' then
begin
if AName = cDivider then
if AName = cIDEToolbarDivider then
AddDivider
else
begin

View File

@ -114,13 +114,15 @@ type
FToolBar: TToolBar;
procedure AddButton(ACommand: TIDEMenuCommand);
procedure AddDivider;
procedure PositionAtEnd(AToolbar: TToolbar; AButton: TToolButton);
procedure PositionAtEnd(AToolBar: TToolBar; AButton: TToolButton);
public
//constructor Create(AOwner: TComponent); override;
//destructor Destroy; override;
property ToolBar: TToolBar read FToolBar;
end;
const
cIDEToolbarDivider = '---------------';
function ShowToolBarConfig(aNames: TStringList): TModalResult;
function GetShortcut(AMenuItem: TIDEMenuItem): string;
@ -130,9 +132,6 @@ implementation
{$R *.lfm}
const
cDivider = '---------------';
function ShowToolBarConfig(aNames: TStringList): TModalResult;
var
Conf: TToolBarConfig;
@ -398,7 +397,7 @@ begin
end;
FillRect(ARect);
if AItem.Caption = cDivider then
if AItem.Caption = cIDEToolbarDivider then
ImageIndex := divImageIndex
else if Assigned(AItem.Data) and (TIDEMenuItem(AItem.Data).ImageIndex > -1) then
ImageIndex := TIDEMenuItem(AItem.Data).ImageIndex
@ -433,7 +432,7 @@ begin
else
lvItem := lvToolbar.Items.Add;
lvItem.Selected := False;
lvItem.Caption:= cDivider;
lvItem.Caption:= cIDEToolbarDivider;
{$IF not DEFINED(LCLQt)}
lvItem.ImageIndex:= divImageIndex;
{$ENDIF}
@ -574,7 +573,7 @@ begin
end
else begin
aListItem.Item := nil;
MainList.AddObject(cDivider,aListItem);
MainList.AddObject(cIDEToolbarDivider,aListItem);
end;
end;
@ -608,7 +607,7 @@ var
lvItem: TListItem;
begin
lvItem := lvToolbar.Items.Add;
lvItem.Caption:= cDivider;
lvItem.Caption:= cIDEToolbarDivider;
{$IF not DEFINED(LCLQt)}
lvItem.ImageIndex:= divImageIndex;
{$ENDIF}
@ -627,7 +626,7 @@ begin
aListItem := TLvItem(MainList.Objects[I]);
mi := aListItem.Item;
aCaption := MainList.Strings[I];
if aCaption = cDivider then
if aCaption = cIDEToolbarDivider then
AddDivider
else
AddToolBarItem(mi);
@ -645,7 +644,7 @@ begin
begin
Value := SL.Strings[I];
if Value = '' then Continue;
if Value = cDivider then
if Value = cIDEToolbarDivider then
MI := nil
else
MI := IDEMenuRoots.FindByPath(Value, false);
@ -663,8 +662,8 @@ begin
for i := 0 to MainList.Count - 1 do
begin
lvItem := TLvItem(MainList.Objects[I]);
if MainList[I] = cDivider then
SL.Add(cDivider)
if MainList[I] = cIDEToolbarDivider then
SL.Add(cIDEToolbarDivider)
else
SL.Add(lvItem.Item.GetPath);
end;
@ -691,10 +690,10 @@ begin
ACaption := ACommand.Caption;
DeleteAmpersands(ACaption);
B.Caption := ACaption;
// Get Shortcut, if any, and append to Hint
// Get Shortcut if any, and append to Hint.
ACaption := ACaption + GetShortcut(ACommand);
B.Hint := ACaption;
// If we have a image, us it. Otherwise supply a default.
// If we have a image, use it. Otherwise supply a default.
if ACommand.ImageIndex <> -1 then
B.ImageIndex := ACommand.ImageIndex
else
@ -714,8 +713,7 @@ begin
PositionAtEnd(FToolBar, B);
end;
procedure TIDEToolbarBase.PositionAtEnd(AToolbar: TToolbar; AButton: TToolButton
);
procedure TIDEToolbarBase.PositionAtEnd(AToolBar: TToolBar; AButton: TToolButton);
// position the button next to the last button
var
SiblingButton: TToolButton;