IDE: Improve adding a command and separator in Toolbar Config dialog. Issue #31890.

git-svn-id: trunk@55078 -
This commit is contained in:
juha 2017-05-25 11:56:04 +00:00
parent 6e70be5335
commit 1e3c5c2752

View File

@ -24,13 +24,15 @@ interface
uses
Classes, SysUtils,
// LCL and LazControls
LCLProc, Forms, Graphics, ExtCtrls, Buttons, StdCtrls,
Controls, ComCtrls, Menus, ButtonPanel, TreeFilterEdit, LclIntf,
// LCL
LCLProc, LclIntf, Controls, Forms, Graphics, ExtCtrls, Buttons, StdCtrls,
ComCtrls, Menus, ButtonPanel,
// LazControls
TreeFilterEdit,
// LazUtils
Laz2_XMLCfg,
// IdeIntf
IDECommands, ToolBarIntf, IDEImagesIntf,
ToolBarIntf, IDEImagesIntf,
// IDE
LazarusIDEStrConsts;
@ -247,12 +249,11 @@ var
i: Integer;
begin
i:=lvToolbar.ItemIndex;
btnAdd.Enabled:={(ActiveControl=TV) and} (Assigned(TV.Selected) and Assigned((TV.Selected).Data));
btnAdd.Enabled:=(Assigned(TV.Selected) and Assigned((TV.Selected).Data));
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);
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;
procedure TToolBarConfig.TVSelectionChanged(Sender: TObject);
@ -272,23 +273,21 @@ end;
procedure TToolBarConfig.InsertMainListItem(Item, NextItem: TListItem);
var
I,J: Integer;
NextInd, I: Integer;
aMainListItem: TLvItem;
begin
aMainListItem := TLvItem.Create;
aMainListItem.Item := TIDEButtonCommand(Item.Data);
aMainListItem.LvIndex := Item.Index;
if NextItem = Nil then
MainList.AddObject(Item.Caption,aMainListItem)
else begin
I := GetMainListIndex(NextItem);
MainList.InsertObject(I,Item.Caption,aMainListItem);
for J := I+1 to MainList.Count -1 do begin
aMainListItem := TLvItem(MainList.Objects[J]);
Assert(Assigned(NextItem), 'TToolBarConfig.InsertMainListItem: NextItem = Nil.');
NextInd := GetMainListIndex(NextItem);
MainList.InsertObject(NextInd, Item.Caption, aMainListItem);
for I := NextInd+1 to MainList.Count -1 do
begin
aMainListItem := TLvItem(MainList.Objects[I]);
aMainListItem.LvIndex := aMainListItem.LvIndex +1;
end;
end;
end;
procedure TToolBarConfig.RemoveMainListItem(Item: TListItem);
var
@ -324,7 +323,6 @@ begin
AddCommand;
end;
procedure TToolBarConfig.AddCommand;
var
n, nNext: TTreeNode;
@ -333,15 +331,17 @@ var
anIndex: Integer;
begin
n := TV.Selected;
if (Assigned(n) and Assigned(n.Data)) then
begin
anIndex:= lvToolbar.ItemIndex;
if (n = Nil) or (n.Data = Nil) then
Exit;
ACaption := TIDEButtonCommand(n.Data).Caption;
DeleteAmpersands(ACaption);
if anIndex > -1 then
lvItem := lvToolbar.Items.Insert(lvToolbar.ItemIndex)
else
lvItem := lvToolbar.Items.Add;
anIndex := lvToolbar.ItemIndex;
if anIndex = -1 then
begin
anIndex := lvToolbar.Items.Count-1; // Add before the last empty item.
Assert(anIndex >= 0, 'TToolBarConfig.AddCommand: Index < 0.');
end;
lvItem := lvToolbar.Items.Insert(anIndex);
lvItem.Caption := ACaption;
lvItem.Data := n.Data;
{$IF not DEFINED(LCLQt) and not DEFINED(LCLQt5)}
@ -351,23 +351,39 @@ begin
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;
// 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;
procedure TToolBarConfig.btnRemoveClick(Sender: TObject);
@ -446,30 +462,6 @@ begin
lblSelect.Caption:=Format('%d+ / %d', [lvToolbar.ItemIndex, lvToolbar.Items.Count-1])
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);
var
Index1,Index2: Integer;