mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-27 04:29:14 +02:00
New files for integrated EditorToolbar.
git-svn-id: trunk@49380 -
This commit is contained in:
parent
744810b288
commit
22d69cef54
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -5635,6 +5635,7 @@ ide/editormacrolistviewer.pas svneol=native#text/pascal
|
||||
ide/editoroptions.pp svneol=native#text/pascal
|
||||
ide/editoroptions.rc svneol=native#text/plain
|
||||
ide/editoroptions.res -text
|
||||
ide/editortoolbarstatic.pas svneol=native#text/pascal
|
||||
ide/emptymethodsdlg.lfm svneol=native#text/plain
|
||||
ide/emptymethodsdlg.pas svneol=native#text/plain
|
||||
ide/encloseifdef.lfm svneol=native#text/plain
|
||||
@ -5757,6 +5758,8 @@ ide/frames/editor_mouseaction_options_advanced.lfm svneol=native#text/plain
|
||||
ide/frames/editor_mouseaction_options_advanced.pas svneol=native#text/pascal
|
||||
ide/frames/editor_multiwindow_options.lfm svneol=native#text/plain
|
||||
ide/frames/editor_multiwindow_options.pas svneol=native#text/pascal
|
||||
ide/frames/editortoolbar_options.lfm svneol=native#text/plain
|
||||
ide/frames/editortoolbar_options.pas svneol=native#text/pascal
|
||||
ide/frames/env_file_filters.lfm svneol=native#text/plain
|
||||
ide/frames/env_file_filters.pas svneol=native#text/plain
|
||||
ide/frames/files_options.lfm svneol=native#text/plain
|
||||
|
559
ide/editortoolbarstatic.pas
Normal file
559
ide/editortoolbarstatic.pas
Normal file
@ -0,0 +1,559 @@
|
||||
{
|
||||
Copyright (C) 2007 Graeme Geldenhuys (graemeg@gmail.com)
|
||||
Modified by Giuliano Colla and Juha Manninen
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Library General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
}
|
||||
|
||||
unit EditorToolbarStatic;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes, Forms, ComCtrls, Controls, ExtCtrls, fgl,
|
||||
MenuIntf, IDEImagesIntf, SrcEditorIntf, BaseIDEIntf,
|
||||
IDECommands, LazarusIDEStrConsts, LazConfigStorage, Laz2_XMLCfg, LCLProc;
|
||||
|
||||
const
|
||||
cSettingsFile = 'editortoolbar.xml';
|
||||
cDivider = '---------------';
|
||||
|
||||
type
|
||||
|
||||
{ TEditorToolBarOptions }
|
||||
|
||||
TEditorToolBarOptions = class
|
||||
private
|
||||
FVisible: Boolean;
|
||||
FPosition: string;
|
||||
FButtonNames: TStringList;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
function Equals(Opts: TEditorToolBarOptions): boolean; overload;
|
||||
procedure Assign(Source: TEditorToolBarOptions);
|
||||
procedure CreateDefaults;
|
||||
function Load(XMLConfig: TXMLConfig): Boolean;
|
||||
function Save(XMLConfig: TXMLConfig): Boolean;
|
||||
published
|
||||
property Visible: Boolean read FVisible write FVisible;
|
||||
property Position: string read FPosition write FPosition;
|
||||
property ButtonNames: TStringList read FButtonNames write FButtonNames;
|
||||
end;
|
||||
|
||||
TIDEMenuItemList = specialize TFPGList<TIDEMenuItem>;
|
||||
TAllEditorToolbars = class;
|
||||
|
||||
{ TEditorToolbar }
|
||||
|
||||
TEditorToolbar = class(TComponent)
|
||||
private
|
||||
FCollection: TAllEditorToolbars;
|
||||
FWindow: TSourceEditorWindowInterface;
|
||||
TB: TToolbar;
|
||||
CfgButton: TToolButton;
|
||||
FButtonList: TIDEMenuItemList;
|
||||
UpdateTimer: TTimer;
|
||||
procedure CreateToolbar(AW: TForm; var ATB: TToolbar);
|
||||
procedure SetTbPos;
|
||||
procedure UpdateBar(Sender: TObject);
|
||||
protected
|
||||
procedure AddButton(AMenuItem: TIDEMenuItem);
|
||||
procedure PositionAtEnd(AToolbar: TToolbar; AButton: TToolButton);
|
||||
public
|
||||
constructor Create(AOwner: TComponent; ACollection: TAllEditorToolbars); overload;
|
||||
destructor Destroy; override;
|
||||
procedure InitEditorToolBar;
|
||||
procedure AddDivider;
|
||||
procedure AddStaticItems;
|
||||
procedure ClearToolbar;
|
||||
procedure CopyFromOptions(Options: TEditorToolBarOptions);
|
||||
property OwnerWindow: TSourceEditorWindowInterface read FWindow;
|
||||
end;
|
||||
|
||||
|
||||
TEditorToolbarList = specialize TFPGList<TEditorToolbar>;
|
||||
|
||||
{ TAllEditorToolbars }
|
||||
|
||||
TAllEditorToolbars = class
|
||||
private
|
||||
FToolBars: TEditorToolbarList;
|
||||
FConfigEvent: TNotifyEvent;
|
||||
procedure SourceWindowCreated(Sender: TObject);
|
||||
procedure SourceWindowDestroyed(Sender: TObject);
|
||||
procedure DoConfigureEditorToolbar(Sender: TObject);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure ReloadAll;
|
||||
end;
|
||||
|
||||
function GetShortcut(AMenuItem: TIDEMenuItem): string;
|
||||
procedure CreateEditorToolBar(aConfigEvent: TNotifyEvent);
|
||||
|
||||
var
|
||||
uAllEditorToolbars: TAllEditorToolbars;
|
||||
EditorMenuCommand: TIDEMenuCommand;
|
||||
|
||||
implementation
|
||||
|
||||
uses EnvironmentOpts;
|
||||
|
||||
const
|
||||
BasePath = 'EditorToolBarOptions/';
|
||||
|
||||
type
|
||||
|
||||
{ TEditToolBarToolButton }
|
||||
|
||||
TEditToolBarToolButton = class(TToolButton)
|
||||
private
|
||||
FMenuItem: TIDEMenuItem;
|
||||
public
|
||||
procedure Click; override;
|
||||
property IdeMenuItem: TIDEMenuItem read FMenuItem write FMenuItem;
|
||||
end;
|
||||
|
||||
procedure ToggleToolbar (Sender:TObject);
|
||||
var
|
||||
ToolBarVisible: Boolean;
|
||||
begin
|
||||
ToolBarVisible := not EnvironmentOptions.EditorToolBarOptions.Visible;
|
||||
EditorMenuCommand.Checked := ToolBarVisible;
|
||||
EnvironmentOptions.EditorToolBarOptions.Visible := ToolBarVisible;
|
||||
uAllEditorToolbars.ReloadAll;
|
||||
end;
|
||||
|
||||
{ TEditToolBarToolButton }
|
||||
|
||||
procedure TEditToolBarToolButton.Click;
|
||||
begin
|
||||
inherited Click;
|
||||
if assigned(FMenuItem) then
|
||||
FMenuItem.TriggerClick;
|
||||
end;
|
||||
|
||||
{ TEditorToolBarOptions }
|
||||
|
||||
constructor TEditorToolBarOptions.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
ButtonNames := TStringList.Create;
|
||||
FVisible := True;
|
||||
end;
|
||||
|
||||
destructor TEditorToolBarOptions.Destroy;
|
||||
begin
|
||||
ButtonNames.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TEditorToolBarOptions.Clear;
|
||||
begin
|
||||
ButtonNames.Clear;
|
||||
FVisible := True;
|
||||
end;
|
||||
|
||||
function TEditorToolBarOptions.Equals(Opts: TEditorToolBarOptions): boolean;
|
||||
begin
|
||||
Result := (FVisible = Opts.FVisible) and (FPosition = Opts.FPosition)
|
||||
and FButtonNames.Equals(Opts.FButtonNames);
|
||||
end;
|
||||
|
||||
procedure TEditorToolBarOptions.Assign(Source: TEditorToolBarOptions);
|
||||
begin
|
||||
FVisible := Source.FVisible;
|
||||
FPosition := Source.FPosition;
|
||||
FButtonNames.Assign(Source.FButtonNames);
|
||||
end;
|
||||
|
||||
procedure TEditorToolBarOptions.CreateDefaults;
|
||||
begin
|
||||
FButtonNames.Clear;
|
||||
FButtonNames.Add('IDEMainMenu/Search/itmJumpings/itmJumpBack');
|
||||
FButtonNames.Add('IDEMainMenu/Search/itmJumpings/itmJumpForward');
|
||||
FButtonNames.Add('---------------');
|
||||
end;
|
||||
|
||||
function TEditorToolBarOptions.Load(XMLConfig: TXMLConfig): Boolean;
|
||||
var
|
||||
ButtonCount: Integer;
|
||||
s: string;
|
||||
I: Integer;
|
||||
cfg: TConfigStorage;
|
||||
begin
|
||||
Result := True;
|
||||
if XMLConfig.HasPath(BasePath + 'Count', True) then
|
||||
begin
|
||||
FVisible := XMLConfig.GetValue(BasePath + 'Visible', True);
|
||||
FPosition := XMLConfig.GetValue(BasePath + 'Position', 'Top');
|
||||
ButtonCount := XMLConfig.GetValue(BasePath + 'Count', 0);
|
||||
for I := 1 to ButtonCount do
|
||||
begin
|
||||
s := Trim(XMLConfig.GetValue(BasePath + 'Buttons/Name' + IntToStr(I) + '/Value', ''));
|
||||
if s <> '' then
|
||||
FButtonNames.Add(s);
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
// Plan B: Load the old configuration. User settings are not lost.
|
||||
DebugLn('TEditorToolBarOptions.Load: Using old configuration in editortoolbar.xml.');
|
||||
cfg := GetIDEConfigStorage(cSettingsFile, True);
|
||||
try
|
||||
FVisible := cfg.GetValue('Visible',True);
|
||||
FPosition := cfg.GetValue('Position','Top');
|
||||
ButtonCount := cfg.GetValue('Count', 0);
|
||||
if ButtonCount > 0 then
|
||||
begin
|
||||
for I := 1 to ButtonCount do
|
||||
begin
|
||||
s := Trim(cfg.GetValue('Button' + Format('%2.2d', [I]) + '/Value', ''));
|
||||
if s <> '' then
|
||||
FButtonNames.Add(s);
|
||||
end;
|
||||
end
|
||||
else
|
||||
CreateDefaults;
|
||||
finally
|
||||
cfg.Free;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEditorToolBarOptions.Save(XMLConfig: TXMLConfig): Boolean;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
Result := True;
|
||||
XMLConfig.SetDeleteValue(BasePath + 'Visible', FVisible, False);
|
||||
XMLConfig.SetDeleteValue(BasePath + 'Position', FPosition, 'Top');
|
||||
XMLConfig.SetDeleteValue(BasePath + 'Count', ButtonNames.Count, 0);
|
||||
for I := 0 to ButtonNames.Count-1 do
|
||||
XMLConfig.SetDeleteValue(BasePath + 'Buttons/Name' + IntToStr(I+1) + '/Value',
|
||||
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.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.EditorToolBarOptions);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TEditorToolbar }
|
||||
|
||||
procedure TEditorToolbar.CreateToolbar(AW: TForm; var ATB: TToolbar);
|
||||
begin
|
||||
// It must be created with Align = alTop, so that the first positioning of buttons is correct.
|
||||
ATB := TToolbar.Create(AW);
|
||||
ATB.Parent := AW;
|
||||
ATB.Height := 26;
|
||||
ATB.Align := alTop;
|
||||
ATB.Flat := True;
|
||||
ATB.Images := IDEImages.Images_16;
|
||||
ATB.ShowHint := True;
|
||||
ATB.Hint := lisEditorToolbarHint;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.UpdateBar(Sender: TObject);
|
||||
var
|
||||
i, j: integer;
|
||||
begin
|
||||
TB.BeginUpdate;
|
||||
try
|
||||
for i := TB.ButtonCount - 1 downto 0 do
|
||||
begin
|
||||
if TB.Buttons[I].tag <> 0 then
|
||||
begin
|
||||
j := TB.Buttons[I].tag-1;
|
||||
if FButtonList[j] <> nil then
|
||||
TB.Buttons[I].Enabled := FButtonList[j].Enabled;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
TB.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
constructor TEditorToolbar.Create(AOwner: TComponent; ACollection: TAllEditorToolbars);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Assert(not Assigned(TB), 'TEditorToolbar.Create: TB is assigned');
|
||||
FCollection := ACollection;
|
||||
FButtonList := TIDEMenuItemList.Create;
|
||||
FWindow := TSourceEditorWindowInterface(AOwner);
|
||||
|
||||
CreateToolbar(FWindow, TB);
|
||||
AddStaticItems;
|
||||
|
||||
UpdateTimer := TTimer.Create(Self);
|
||||
UpdateTimer.Interval := 500;
|
||||
UpdateTimer.OnTimer := @UpdateBar;
|
||||
UpdateTimer.Enabled := True;
|
||||
end;
|
||||
|
||||
destructor TEditorToolbar.Destroy;
|
||||
begin
|
||||
uAllEditorToolbars.FToolBars.Remove(Self);
|
||||
FButtonList.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.InitEditorToolBar;
|
||||
begin
|
||||
TB := nil;
|
||||
CfgButton := nil;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.AddButton(AMenuItem: TIDEMenuItem);
|
||||
var
|
||||
B: TEditToolBarToolButton;
|
||||
ACaption: string;
|
||||
iPos: Integer;
|
||||
begin
|
||||
B := TEditToolBarToolButton.Create(TB);
|
||||
ACaption := AMenuItem.Caption;
|
||||
DeleteAmpersands(ACaption);
|
||||
B.Caption := ACaption;
|
||||
// Get Shortcut, if any, and append to Hint
|
||||
ACaption := ACaption + GetShortcut(AMenuItem);
|
||||
B.Hint := ACaption;
|
||||
// If we have a image, us it. Otherwise supply a default.
|
||||
if AMenuItem.ImageIndex <> -1 then
|
||||
B.ImageIndex := AMenuItem.ImageIndex
|
||||
else
|
||||
B.ImageIndex := IDEImages.LoadImage(16, 'execute');
|
||||
|
||||
B.Style := tbsButton;
|
||||
B.IdeMenuItem := AMenuItem;
|
||||
iPos := FButtonList.Add(AMenuItem);
|
||||
B.Tag:= iPos+1;
|
||||
PositionAtEnd(TB, B);
|
||||
end;
|
||||
|
||||
// position the button next to the last button
|
||||
procedure TEditorToolbar.PositionAtEnd(AToolbar: TToolbar; AButton: TToolButton);
|
||||
var
|
||||
SiblingButton: TToolButton;
|
||||
begin
|
||||
if AToolbar.ButtonCount > 0 then
|
||||
begin
|
||||
SiblingButton := AToolbar.Buttons[AToolbar.ButtonCount-1];
|
||||
AButton.SetBounds(SiblingButton.Left + SiblingButton.Width,
|
||||
SiblingButton.Top, AButton.Width, AButton.Height);
|
||||
end;
|
||||
AButton.Parent := AToolbar;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.SetTbPos;
|
||||
begin
|
||||
case EnvironmentOptions.EditorToolBarOptions.Position of
|
||||
'Top': begin
|
||||
TB.Align:= alTop;
|
||||
TB.Height:= 26;
|
||||
end;
|
||||
'Bottom': begin
|
||||
TB.Align:= alBottom;
|
||||
TB.Height:= 26;
|
||||
end;
|
||||
'Left': begin
|
||||
TB.Align:= alLeft;
|
||||
TB.Width:= 26;
|
||||
end;
|
||||
'Right': begin
|
||||
TB.Align:= alRight;
|
||||
TB.Width:= 26;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.AddDivider;
|
||||
var
|
||||
B: TToolButton;
|
||||
begin
|
||||
B := TToolbutton.Create(TB);
|
||||
B.Style := tbsDivider;
|
||||
PositionAtEnd(TB, B);
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.AddStaticItems;
|
||||
begin
|
||||
TB.BeginUpdate;
|
||||
try
|
||||
// Config Button
|
||||
if CfgButton = nil then
|
||||
CfgButton := TToolbutton.Create(TB);
|
||||
CfgButton.Caption := lisConfigureEditorToolbar;
|
||||
CfgButton.Hint := CfgButton.Caption;
|
||||
CfgButton.ImageIndex := IDEImages.LoadImage(16, 'preferences');
|
||||
CfgButton.Style := tbsButton;
|
||||
CfgButton.OnClick := @FCollection.DoConfigureEditorToolbar;
|
||||
PositionAtEnd(TB, CfgButton);
|
||||
AddDivider;
|
||||
finally
|
||||
TB.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.ClearToolbar;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
TB.BeginUpdate;
|
||||
try
|
||||
FButtonList.Clear;
|
||||
for i := TB.ButtonCount - 1 downto 0 do
|
||||
if TB.Buttons[i] <> CfgButton then
|
||||
TB.Buttons[i].Free
|
||||
else
|
||||
TB.Buttons[i].Parent := nil;
|
||||
finally
|
||||
TB.EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbar.CopyFromOptions(Options: TEditorToolBarOptions);
|
||||
var
|
||||
mi: TIDEMenuItem;
|
||||
ButtonName: string;
|
||||
i: Integer;
|
||||
begin
|
||||
TB.BeginUpdate;
|
||||
try
|
||||
for i := 0 to Options.ButtonNames.Count-1 do
|
||||
begin
|
||||
ButtonName := Options.ButtonNames[i];
|
||||
if ButtonName = cDivider then
|
||||
AddDivider
|
||||
else
|
||||
begin
|
||||
mi := IDEMenuRoots.FindByPath(ButtonName,false);
|
||||
if Assigned(mi) then
|
||||
AddButton(mi);
|
||||
end;
|
||||
end;
|
||||
SetTbPos;
|
||||
EditorMenuCommand.Checked:= Options.Visible;
|
||||
finally
|
||||
TB.EndUpdate;
|
||||
end;
|
||||
TB.Visible:= Options.Visible;
|
||||
end;
|
||||
|
||||
function GetShortcut(AMenuItem: TIDEMenuItem): string;
|
||||
var
|
||||
ACommand: TIDECommand;
|
||||
AShortcut: string;
|
||||
begin
|
||||
Result := '';
|
||||
AShortcut:= '';
|
||||
if AMenuItem is TIDEMenuCommand then
|
||||
begin
|
||||
ACommand := TIDEMenuCommand(AMenuItem).Command;
|
||||
if Assigned(ACommand) then
|
||||
AShortcut:= ShortCutToText(ACommand.AsShortCut);
|
||||
if AShortcut <> '' then
|
||||
Result:= ' (' + AShortcut +')';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure CreateEditorToolBar(aConfigEvent: TNotifyEvent);
|
||||
var
|
||||
MenuIcon: string;
|
||||
begin
|
||||
uAllEditorToolbars := TAllEditorToolbars.Create;
|
||||
uAllEditorToolbars.FConfigEvent := aConfigEvent;
|
||||
EditorMenuCommand := RegisterIDEMenuCommand(itmViewSecondaryWindows,'EditorToolBar',
|
||||
lisEditorToolbar,nil,@ToggleToolbar);
|
||||
EditorMenuCommand.Checked := True;
|
||||
EditorMenuCommand.Enabled := True;
|
||||
MenuIcon:= 'menu_editor_options';
|
||||
//MenuIcon:= 'menu_editor_toolbar'; TODO!
|
||||
EditorMenuCommand.ImageIndex := IDEImages.LoadImage(16, MenuIcon);
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
//CreateEditorToolBar;
|
||||
|
||||
finalization
|
||||
uAllEditorToolbars.Free;
|
||||
|
||||
end.
|
||||
|
132
ide/frames/editortoolbar_options.lfm
Normal file
132
ide/frames/editortoolbar_options.lfm
Normal file
@ -0,0 +1,132 @@
|
||||
object EditorToolbarOptionsFrame: TEditorToolbarOptionsFrame
|
||||
Left = 0
|
||||
Height = 342
|
||||
Top = 0
|
||||
Width = 503
|
||||
ClientHeight = 342
|
||||
ClientWidth = 503
|
||||
TabOrder = 0
|
||||
DesignLeft = 521
|
||||
DesignTop = 251
|
||||
object pnTop: TPanel
|
||||
Left = 0
|
||||
Height = 342
|
||||
Top = 0
|
||||
Width = 503
|
||||
Align = alClient
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 342
|
||||
ClientWidth = 503
|
||||
Constraints.MinWidth = 350
|
||||
TabOrder = 0
|
||||
object dbGeneralSettings: TDividerBevel
|
||||
Left = 0
|
||||
Height = 17
|
||||
Top = 5
|
||||
Width = 503
|
||||
Caption = 'Editor Toolbars Settings'
|
||||
Align = alTop
|
||||
BorderSpacing.Top = 5
|
||||
BorderSpacing.Bottom = 5
|
||||
Font.Style = [fsBold]
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object cbCoolBarVisible: TCheckBox
|
||||
AnchorSideLeft.Control = pnTop
|
||||
AnchorSideTop.Control = dbGeneralSettings
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 22
|
||||
Top = 34
|
||||
Width = 119
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 12
|
||||
Caption = 'Toolbar is visible'
|
||||
OnClick = cbCoolBarVisibleClick
|
||||
TabOrder = 0
|
||||
end
|
||||
object pnTopCenterLabel: TLabel
|
||||
AnchorSideLeft.Control = pnTop
|
||||
AnchorSideLeft.Side = asrCenter
|
||||
AnchorSideTop.Control = pnTop
|
||||
Left = 251
|
||||
Height = 1
|
||||
Top = 0
|
||||
Width = 1
|
||||
ParentColor = False
|
||||
end
|
||||
object bConfig: TBitBtn
|
||||
AnchorSideLeft.Control = cbCoolBarVisible
|
||||
AnchorSideTop.Control = cbCoolBarVisible
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 29
|
||||
Top = 77
|
||||
Width = 69
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Top = 21
|
||||
Caption = 'Configure'
|
||||
OnClick = bConfigClick
|
||||
TabOrder = 1
|
||||
end
|
||||
object bDefaultToolbar: TBitBtn
|
||||
AnchorSideTop.Control = bConfig
|
||||
AnchorSideRight.Control = pnTop
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 435
|
||||
Height = 29
|
||||
Top = 77
|
||||
Width = 56
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Right = 12
|
||||
Caption = 'Default'
|
||||
OnClick = bDefaultToolbarClick
|
||||
TabOrder = 2
|
||||
end
|
||||
object lblpos: TLabel
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = cbPos
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = cbPos
|
||||
Left = 207
|
||||
Height = 17
|
||||
Top = 37
|
||||
Width = 35
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Right = 6
|
||||
Caption = 'lblpos'
|
||||
ParentColor = False
|
||||
end
|
||||
object cbPos: TComboBox
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = cbCoolBarVisible
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 248
|
||||
Height = 23
|
||||
Top = 34
|
||||
Width = 100
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Bottom = 6
|
||||
ItemHeight = 17
|
||||
ItemIndex = 0
|
||||
Items.Strings = (
|
||||
'Top'
|
||||
'Bottom'
|
||||
'Right'
|
||||
'Left'
|
||||
)
|
||||
OnChange = cbPosChange
|
||||
TabOrder = 3
|
||||
Text = 'Top'
|
||||
end
|
||||
end
|
||||
object imButtons: TImageList
|
||||
left = 464
|
||||
end
|
||||
end
|
184
ide/frames/editortoolbar_options.pas
Normal file
184
ide/frames/editortoolbar_options.pas
Normal file
@ -0,0 +1,184 @@
|
||||
{
|
||||
***************************************************************************
|
||||
* *
|
||||
* This source is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This code is distributed in the hope that it will be useful, but *
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* General Public License for more details. *
|
||||
* *
|
||||
* A copy of the GNU General Public License is available on the World *
|
||||
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
|
||||
* obtain it by writing to the Free Software Foundation, *
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
* *
|
||||
***************************************************************************
|
||||
Author: Juha Manninen
|
||||
Abstract:
|
||||
Frame for editortoolbar options.
|
||||
}
|
||||
unit editortoolbar_options;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ExtCtrls, ComCtrls, Buttons, Controls, StdCtrls, DividerBevel,
|
||||
LazarusIDEStrConsts, IDEOptionsIntf, EnvironmentOpts, EditorToolbarStatic, ToolbarConfig, LCLProc;
|
||||
|
||||
type
|
||||
|
||||
{ TEditorToolbarOptionsFrame }
|
||||
|
||||
TEditorToolbarOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||
bConfig: TBitBtn;
|
||||
bDefaultToolbar: TBitBtn;
|
||||
cbCoolBarVisible: TCheckBox;
|
||||
cbPos: TComboBox;
|
||||
imButtons: TImageList;
|
||||
dbGeneralSettings: TDividerBevel;
|
||||
lblpos: TLabel;
|
||||
pnTopCenterLabel: TLabel;
|
||||
pnTop: TPanel;
|
||||
procedure bConfigClick(Sender: TObject);
|
||||
procedure bDefaultToolbarClick(Sender: TObject);
|
||||
procedure cbCoolBarVisibleClick(Sender: TObject);
|
||||
procedure cbPosChange(Sender: TObject);
|
||||
private
|
||||
FLocalOptions: TEditorToolBarOptions;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
function GetTitle: string; override;
|
||||
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
|
||||
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
|
||||
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
|
||||
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
|
||||
end;
|
||||
|
||||
var
|
||||
sPosValues: array[0..3] of string = ('Top','Bottom','Right','Left');
|
||||
sLocalizedPosValues: array[0..3] of string;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
function IndexFromEnglish (AValue: string): Integer;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 0 to 3 do
|
||||
if AValue = sPosValues[i] then
|
||||
exit(i);
|
||||
Result := 0; // default is Top
|
||||
end;
|
||||
|
||||
{ TEditorToolbarOptionsFrame }
|
||||
|
||||
function TEditorToolbarOptionsFrame.GetTitle: string;
|
||||
begin
|
||||
Result := lisEditorToolbar;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
sLocalizedPosValues[0] := lisTop;
|
||||
sLocalizedPosValues[1] := lisBottom;
|
||||
sLocalizedPosValues[2] := lisRight;
|
||||
sLocalizedPosValues[3] := lisLeft;
|
||||
for i := 0 to high(sLocalizedPosValues) do
|
||||
cbPos.Items[i] := sLocalizedPosValues[i]; // localized
|
||||
|
||||
dbGeneralSettings.Caption := 'Editor Toolbars Settings'; // ToDo: Will be removed ...
|
||||
cbCoolBarVisible.Caption := lisEditorToolbarVisible;
|
||||
lblpos.Caption := lisPosition;
|
||||
bDefaultToolbar.Caption := lisCoolbarRestoreDefaults;
|
||||
bConfig.Caption := lisCoolbarConfigure;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
var
|
||||
Opts: TEditorToolBarOptions;
|
||||
begin
|
||||
Opts := (AOptions as TEnvironmentOptions).EditorToolBarOptions;
|
||||
cbCoolBarVisible.Checked := Opts.Visible;
|
||||
cbPos.Caption := Opts.Position;
|
||||
// Disable controls when toolbar is hidden.
|
||||
cbPos.Enabled := Opts.Visible;
|
||||
bConfig.Enabled := Opts.Visible;
|
||||
bDefaultToolbar.Enabled := Opts.Visible;
|
||||
// Copy from environment options to local options.
|
||||
FLocalOptions.Assign(Opts);
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
var
|
||||
Opts: TEditorToolBarOptions;
|
||||
begin
|
||||
Opts := (AOptions as TEnvironmentOptions).EditorToolBarOptions;
|
||||
Opts.Assign(FLocalOptions);
|
||||
uAllEditorToolbars.ReloadAll;
|
||||
end;
|
||||
|
||||
class function TEditorToolbarOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
|
||||
begin
|
||||
Result := TEnvironmentOptions;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.cbCoolBarVisibleClick(Sender: TObject);
|
||||
var
|
||||
chk: Boolean;
|
||||
begin
|
||||
chk := (Sender as TCheckBox).Checked;
|
||||
FLocalOptions.Visible := chk;
|
||||
// Disable controls when toolbar is hidden.
|
||||
cbPos.Enabled := chk;
|
||||
bConfig.Enabled := chk;
|
||||
bDefaultToolbar.Enabled := chk;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.cbPosChange(Sender: TObject);
|
||||
begin
|
||||
DebugLn(['TEditorToolbarOptionsFrame.cbPosChange: cbPos.ItemIndex=', cbPos.ItemIndex]);
|
||||
if cbPos.ItemIndex >= 0 then
|
||||
FLocalOptions.Position := sPosValues[cbPos.ItemIndex];
|
||||
end;
|
||||
|
||||
constructor TEditorToolbarOptionsFrame.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
FLocalOptions := TEditorToolBarOptions.Create;
|
||||
end;
|
||||
|
||||
destructor TEditorToolbarOptionsFrame.Destroy;
|
||||
begin
|
||||
FreeAndNil(FLocalOptions);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.bConfigClick(Sender: TObject);
|
||||
begin
|
||||
if ShowToolBarConfig(FLocalOptions.ButtonNames) = mrOK then
|
||||
; // Do Nothing, changed options were copied.
|
||||
end;
|
||||
|
||||
procedure TEditorToolbarOptionsFrame.bDefaultToolbarClick(Sender: TObject);
|
||||
begin
|
||||
FLocalOptions.CreateDefaults;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
RegisterIDEOptionsEditor(GroupEnvironment, TEditorToolbarOptionsFrame, EnvOptionsEditorToolbar);
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user