mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 11:36:02 +02:00
IDE: Improve adding a command and separator in Toolbar Config dialog. Issue #31890.
git-svn-id: trunk@55078 -
This commit is contained in:
parent
6e70be5335
commit
1e3c5c2752
@ -24,13 +24,15 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
// LCL and LazControls
|
// LCL
|
||||||
LCLProc, Forms, Graphics, ExtCtrls, Buttons, StdCtrls,
|
LCLProc, LclIntf, Controls, Forms, Graphics, ExtCtrls, Buttons, StdCtrls,
|
||||||
Controls, ComCtrls, Menus, ButtonPanel, TreeFilterEdit, LclIntf,
|
ComCtrls, Menus, ButtonPanel,
|
||||||
|
// LazControls
|
||||||
|
TreeFilterEdit,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
Laz2_XMLCfg,
|
Laz2_XMLCfg,
|
||||||
// IdeIntf
|
// IdeIntf
|
||||||
IDECommands, ToolBarIntf, IDEImagesIntf,
|
ToolBarIntf, IDEImagesIntf,
|
||||||
// IDE
|
// IDE
|
||||||
LazarusIDEStrConsts;
|
LazarusIDEStrConsts;
|
||||||
|
|
||||||
@ -95,10 +97,10 @@ type
|
|||||||
procedure AddCommand;
|
procedure AddCommand;
|
||||||
procedure AddTailItem;
|
procedure AddTailItem;
|
||||||
function GetMainListIndex(Item: TListItem): Integer;
|
function GetMainListIndex(Item: TListItem): Integer;
|
||||||
procedure InsertMainListItem (Item,NextItem: TListItem);
|
procedure InsertMainListItem(Item, NextItem: TListItem);
|
||||||
procedure RemoveCommand;
|
procedure RemoveCommand;
|
||||||
procedure RemoveMainListItem (Item:TListItem);
|
procedure RemoveMainListItem(Item: TListItem);
|
||||||
procedure ExchangeMainListItem (Item1,Item2: TListItem);
|
procedure ExchangeMainListItem(Item1, Item2: TListItem);
|
||||||
procedure SetupCaptions;
|
procedure SetupCaptions;
|
||||||
procedure LoadCategories;
|
procedure LoadCategories;
|
||||||
procedure AddMenuItem(ParentNode: TTreeNode; Item: TIDEButtonCommand);
|
procedure AddMenuItem(ParentNode: TTreeNode; Item: TIDEButtonCommand);
|
||||||
@ -194,7 +196,7 @@ begin
|
|||||||
TIDEImages.AssignImage(btnMoveDown.Glyph, 'arrow_down');
|
TIDEImages.AssignImage(btnMoveDown.Glyph, 'arrow_down');
|
||||||
TIDEImages.AssignImage(btnAddDivider.Glyph, 'menu_divider16');
|
TIDEImages.AssignImage(btnAddDivider.Glyph, 'menu_divider16');
|
||||||
|
|
||||||
btnAddDivider.Caption:='---';
|
btnAddDivider.Caption := '---';
|
||||||
|
|
||||||
btnAdd.Hint := lisCoolBarAddSelected;
|
btnAdd.Hint := lisCoolBarAddSelected;
|
||||||
btnRemove.Hint := lisCoolBarRemoveSelected;
|
btnRemove.Hint := lisCoolBarRemoveSelected;
|
||||||
@ -247,12 +249,11 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
i:=lvToolbar.ItemIndex;
|
i:=lvToolbar.ItemIndex;
|
||||||
|
btnAdd.Enabled:=(Assigned(TV.Selected) and Assigned((TV.Selected).Data));
|
||||||
btnAdd.Enabled:={(ActiveControl=TV) and} (Assigned(TV.Selected) and Assigned((TV.Selected).Data));
|
|
||||||
btnRemove.Enabled:=(ActiveControl=lvToolbar) and (i>-1) and (i<lvToolbar.Items.Count-1);
|
btnRemove.Enabled:=(ActiveControl=lvToolbar) and (i>-1) and (i<lvToolbar.Items.Count-1);
|
||||||
btnMoveUp.Enabled:=(ActiveControl=lvToolbar) and (i>0) and (i<lvToolbar.Items.Count-1);
|
btnMoveUp.Enabled:=(ActiveControl=lvToolbar) and (i>0) and (i<lvToolbar.Items.Count-1);
|
||||||
btnMoveDown.Enabled:=(ActiveControl=lvToolbar) and (i>-1) and (i<lvToolbar.Items.Count-2);
|
btnMoveDown.Enabled:=(ActiveControl=lvToolbar) and (i>-1) and (i<lvToolbar.Items.Count-2);
|
||||||
btnAddDivider.Enabled:=(ActiveControl=lvToolbar);
|
btnAddDivider.Enabled:=(lvToolbar.Selected = nil) or (lvToolbar.Selected.Caption <> cIDEToolbarDivider);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TToolBarConfig.TVSelectionChanged(Sender: TObject);
|
procedure TToolBarConfig.TVSelectionChanged(Sender: TObject);
|
||||||
@ -270,23 +271,21 @@ begin
|
|||||||
Result := -1;
|
Result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TToolBarConfig.InsertMainListItem(Item,NextItem: TListItem);
|
procedure TToolBarConfig.InsertMainListItem(Item, NextItem: TListItem);
|
||||||
var
|
var
|
||||||
I,J: Integer;
|
NextInd, I: Integer;
|
||||||
aMainListItem: TLvItem;
|
aMainListItem: TLvItem;
|
||||||
begin
|
begin
|
||||||
aMainListItem := TLvItem.Create;
|
aMainListItem := TLvItem.Create;
|
||||||
aMainListItem.Item := TIDEButtonCommand(Item.Data);
|
aMainListItem.Item := TIDEButtonCommand(Item.Data);
|
||||||
aMainListItem.LvIndex := Item.Index;
|
aMainListItem.LvIndex := Item.Index;
|
||||||
if NextItem = Nil then
|
Assert(Assigned(NextItem), 'TToolBarConfig.InsertMainListItem: NextItem = Nil.');
|
||||||
MainList.AddObject(Item.Caption,aMainListItem)
|
NextInd := GetMainListIndex(NextItem);
|
||||||
else begin
|
MainList.InsertObject(NextInd, Item.Caption, aMainListItem);
|
||||||
I := GetMainListIndex(NextItem);
|
for I := NextInd+1 to MainList.Count -1 do
|
||||||
MainList.InsertObject(I,Item.Caption,aMainListItem);
|
begin
|
||||||
for J := I+1 to MainList.Count -1 do begin
|
aMainListItem := TLvItem(MainList.Objects[I]);
|
||||||
aMainListItem := TLvItem(MainList.Objects[J]);
|
aMainListItem.LvIndex := aMainListItem.LvIndex +1;
|
||||||
aMainListItem.LvIndex:= aMainListItem.LvIndex +1;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -300,7 +299,7 @@ begin
|
|||||||
MainList.Delete(I);
|
MainList.Delete(I);
|
||||||
for J := I to MainList.Count -1 do begin
|
for J := I to MainList.Count -1 do begin
|
||||||
aMainListItem := TLvItem(MainList.Objects[J]);
|
aMainListItem := TLvItem(MainList.Objects[J]);
|
||||||
aMainListItem.LvIndex:= aMainListItem.LvIndex -1;
|
aMainListItem.LvIndex := aMainListItem.LvIndex -1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -324,7 +323,6 @@ begin
|
|||||||
AddCommand;
|
AddCommand;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TToolBarConfig.AddCommand;
|
procedure TToolBarConfig.AddCommand;
|
||||||
var
|
var
|
||||||
n, nNext: TTreeNode;
|
n, nNext: TTreeNode;
|
||||||
@ -333,41 +331,59 @@ var
|
|||||||
anIndex: Integer;
|
anIndex: Integer;
|
||||||
begin
|
begin
|
||||||
n := TV.Selected;
|
n := TV.Selected;
|
||||||
if (Assigned(n) and Assigned(n.Data)) then
|
if (n = Nil) or (n.Data = Nil) then
|
||||||
|
Exit;
|
||||||
|
ACaption := TIDEButtonCommand(n.Data).Caption;
|
||||||
|
DeleteAmpersands(ACaption);
|
||||||
|
anIndex := lvToolbar.ItemIndex;
|
||||||
|
if anIndex = -1 then
|
||||||
begin
|
begin
|
||||||
anIndex:= lvToolbar.ItemIndex;
|
anIndex := lvToolbar.Items.Count-1; // Add before the last empty item.
|
||||||
ACaption:= TIDEButtonCommand(n.Data).Caption;
|
Assert(anIndex >= 0, 'TToolBarConfig.AddCommand: Index < 0.');
|
||||||
DeleteAmpersands(ACaption);
|
|
||||||
if anIndex > -1 then
|
|
||||||
lvItem := lvToolbar.Items.Insert(lvToolbar.ItemIndex)
|
|
||||||
else
|
|
||||||
lvItem := lvToolbar.Items.Add;
|
|
||||||
lvItem.Caption := ACaption;
|
|
||||||
lvItem.Data := n.Data;
|
|
||||||
{$IF not DEFINED(LCLQt) and not DEFINED(LCLQt5)}
|
|
||||||
if n.ImageIndex > -1 then
|
|
||||||
lvItem.ImageIndex := n.ImageIndex
|
|
||||||
else
|
|
||||||
lvItem.ImageIndex := defImageIndex;
|
|
||||||
{$ENDIF}
|
|
||||||
//lvItem.SubItems.Add(IntToStr(CurrProfile));
|
|
||||||
if anIndex > -1 then begin
|
|
||||||
// clear previous selection to avoid double sel in Qt
|
|
||||||
lvToolbar.Selected := nil;
|
|
||||||
lvToolbar.ItemIndex := lvItem.Index;
|
|
||||||
InsertMainListItem(lvItem,lvToolbar.Items[anIndex]);
|
|
||||||
end
|
|
||||||
else begin
|
|
||||||
// lvToolbar.ItemIndex := lvToolbar.Items.Count-1;
|
|
||||||
InsertMainListItem(lvItem,Nil);
|
|
||||||
end;
|
|
||||||
lvToolbar.ItemIndex := lvToolbar.ItemIndex+1;
|
|
||||||
nNext := TV.Selected.GetNext;
|
|
||||||
TV.Selected.Visible:= False;
|
|
||||||
if nNext <> nil then
|
|
||||||
TV.Selected := nNext;
|
|
||||||
UpdateButtonsState;
|
|
||||||
end;
|
end;
|
||||||
|
lvItem := lvToolbar.Items.Insert(anIndex);
|
||||||
|
lvItem.Caption := ACaption;
|
||||||
|
lvItem.Data := n.Data;
|
||||||
|
{$IF not DEFINED(LCLQt) and not DEFINED(LCLQt5)}
|
||||||
|
if n.ImageIndex > -1 then
|
||||||
|
lvItem.ImageIndex := n.ImageIndex
|
||||||
|
else
|
||||||
|
lvItem.ImageIndex := defImageIndex;
|
||||||
|
{$ENDIF}
|
||||||
|
//lvItem.SubItems.Add(IntToStr(CurrProfile));
|
||||||
|
// clear previous selection to avoid double sel in Qt
|
||||||
|
lvToolbar.Selected := nil;
|
||||||
|
lvToolbar.ItemIndex := lvItem.Index;
|
||||||
|
InsertMainListItem(lvItem, lvToolbar.Items[anIndex]);
|
||||||
|
// Update selection in TreeView.
|
||||||
|
nNext := TV.Selected.GetNext;
|
||||||
|
TV.Selected.Visible:= False;
|
||||||
|
if nNext <> nil then
|
||||||
|
TV.Selected := nNext;
|
||||||
|
UpdateButtonsState;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TToolBarConfig.btnAddDividerClick(Sender: TObject);
|
||||||
|
var
|
||||||
|
lvItem: TListItem;
|
||||||
|
anIndex: Integer;
|
||||||
|
begin
|
||||||
|
anIndex := lvToolbar.ItemIndex;
|
||||||
|
if anIndex = -1 then
|
||||||
|
begin
|
||||||
|
anIndex := lvToolbar.Items.Count-1; // Add before the last empty item.
|
||||||
|
Assert(anIndex >= 0, 'TToolBarConfig.btnAddDividerClick: Index < 0.');
|
||||||
|
end;
|
||||||
|
lvItem := lvToolbar.Items.Insert(anIndex);
|
||||||
|
//lvItem.Selected := False;
|
||||||
|
lvItem.Caption:= cIDEToolbarDivider;
|
||||||
|
{$IF not DEFINED(LCLQt) and not DEFINED(LCLQt5)}
|
||||||
|
lvItem.ImageIndex := divImageIndex;
|
||||||
|
{$ENDIF}
|
||||||
|
lvToolbar.Selected := nil;
|
||||||
|
lvToolbar.ItemIndex := lvItem.Index;
|
||||||
|
InsertMainListItem(lvItem, lvToolbar.Items[anIndex]);
|
||||||
|
UpdateButtonsState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TToolBarConfig.btnRemoveClick(Sender: TObject);
|
procedure TToolBarConfig.btnRemoveClick(Sender: TObject);
|
||||||
@ -446,30 +462,6 @@ begin
|
|||||||
lblSelect.Caption:=Format('%d+ / %d', [lvToolbar.ItemIndex, lvToolbar.Items.Count-1])
|
lblSelect.Caption:=Format('%d+ / %d', [lvToolbar.ItemIndex, lvToolbar.Items.Count-1])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TToolBarConfig.btnAddDividerClick(Sender: TObject);
|
|
||||||
var
|
|
||||||
lvItem: TListItem;
|
|
||||||
anIndex: Integer;
|
|
||||||
begin
|
|
||||||
if not (ActiveControl=lvToolbar) then Exit;
|
|
||||||
anIndex := lvToolbar.ItemIndex;
|
|
||||||
if anIndex > -1 then
|
|
||||||
lvItem := lvToolbar.Items.Insert(anIndex)
|
|
||||||
else
|
|
||||||
lvItem := lvToolbar.Items.Add;
|
|
||||||
lvItem.Selected := False;
|
|
||||||
lvItem.Caption:= cIDEToolbarDivider;
|
|
||||||
{$IF not DEFINED(LCLQt) and not DEFINED(LCLQt5)}
|
|
||||||
lvItem.ImageIndex:= divImageIndex;
|
|
||||||
{$ENDIF}
|
|
||||||
//lvItem.SubItems.Add(IntToStr(CurrProfile));
|
|
||||||
if lvToolbar.ItemIndex > -1 then
|
|
||||||
InsertMainListItem(lvItem,lvToolbar.Items[anIndex])
|
|
||||||
else
|
|
||||||
InsertMainListItem(lvItem,Nil);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TToolBarConfig.btnMoveDownClick(Sender: TObject);
|
procedure TToolBarConfig.btnMoveDownClick(Sender: TObject);
|
||||||
var
|
var
|
||||||
Index1,Index2: Integer;
|
Index1,Index2: Integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user