IDEIntf: rewrote TIDEMenuSection to handle changes in hidden sections, tests: added menuintf tests, IDE: clean up

git-svn-id: trunk@52918 -
This commit is contained in:
mattias 2016-09-05 15:18:02 +00:00
parent 8d39f093f0
commit 444a926616
10 changed files with 894 additions and 548 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2753,7 +2753,7 @@ var
VisibleCnt: Integer;
begin
MessagesMenuRoot.MenuItem:=MsgCtrlPopupMenu.Items;
MessagesMenuRoot.BeginUpdate;
//MessagesMenuRoot.BeginUpdate;
try
HasText:=false;
HasFilename:=false;
@ -2891,7 +2891,7 @@ begin
UpdateQuickFixes(Line);
finally
MessagesMenuRoot.EndUpdate;
//MessagesMenuRoot.EndUpdate;
end;
end;

View File

@ -7876,7 +7876,7 @@ var
begin
ToolCount:=ExternalUserTools.Count;
Section:=itmCustomTools;
Section.BeginUpdate;
//Section.BeginUpdate;
try
// add enough menuitems
while Section.Count-1<ToolCount do
@ -7897,7 +7897,7 @@ begin
CurMenuItem.OnClick:=@mnuExternalUserToolClick;
end;
finally
Section.EndUpdate;
//Section.EndUpdate;
end;
end;

View File

@ -1748,7 +1748,7 @@ procedure TMainIDEBase.UpdateWindowMenu;
Result := ASection.Items[Index]
else
begin
Result := RegisterIDEMenuCommand(ASection.GetPath,'Window'+IntToStr(Index)+ASection.Name,'');
Result := RegisterIDEMenuCommand(ASection,'Window'+IntToStr(Index)+ASection.Name,'');
Result.CreateMenuItem;
end;
end;
@ -1768,7 +1768,7 @@ var
EdList: TStringList;
EditorCur: TSourceEditor;
P: TIDEPackage;
M: TIDEMenuSection;
aSection: TIDEMenuSection;
s: String;
begin
//DebugLn('TMainIDEBase.UpdateWindowMenu: enter');
@ -1810,7 +1810,7 @@ begin
CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Name
else
CurMenuItem.Caption:=TCustomForm(WindowsList[i]).Caption;
CurMenuItem.MenuItem.Checked := WindowMenuActiveForm = TCustomForm(WindowsList[i]);
CurMenuItem.Checked := WindowMenuActiveForm = TCustomForm(WindowsList[i]);
CurMenuItem.OnClick:=@mnuWindowItemClick;
// in the 'center' list
CurMenuItem := GetMenuItem(i, itmCenterWindowLists);
@ -1824,8 +1824,8 @@ begin
//create source page menuitems
itmTabListProject.Visible := False;
itmTabListOther.Visible := False;
itmTabListProject.MenuItem.Checked := False;
itmTabListOther.MenuItem.Checked := False;
itmTabListProject.Checked := False;
itmTabListOther.Checked := False;
itmTabListPackage.Clear;
if SourceEditorManager.SourceEditorCount > 0 then begin
@ -1847,25 +1847,25 @@ begin
j := PtrUInt(EdList.Objects[i]);
EditorCur := SourceEditorManager.SourceEditors[j];
if (EditorCur.GetProjectFile <> nil) and (EditorCur.GetProjectFile.IsPartOfProject) then begin
M := itmTabListProject;
CurMenuItem := GetMenuItem(ItemCountProject, M);
aSection := itmTabListProject;
CurMenuItem := GetMenuItem(ItemCountProject, aSection);
inc(ItemCountProject);
end else begin
SourceEditorManager.OnPackageForSourceEditor(P, EditorCur);
if P <> nil then begin
s := Format(lisTabsFor, [p.Name]);
if itmTabListPackage.FindByName(S) is TIDEMenuSection then
M := TIDEMenuSection(itmTabListPackage.FindByName(S))
aSection := TIDEMenuSection(itmTabListPackage.FindByName(S))
else
M := RegisterIDESubMenu(itmTabListPackage, S, S);
CurMenuItem := GetMenuItem(M.Count, M);
aSection := RegisterIDESubMenu(itmTabListPackage, S, S);
CurMenuItem := GetMenuItem(aSection.Count, aSection);
end else begin
M := itmTabListOther;
CurMenuItem := GetMenuItem(ItemCountOther, M);
aSection := itmTabListOther;
CurMenuItem := GetMenuItem(ItemCountOther, aSection);
inc(ItemCountOther);
end;
end;
M.Visible := True;
aSection.Visible := True;
if EditorCur.SharedEditorCount > 1 then
CurMenuItem.Caption := EditorCur.PageName + ' ('+TForm(EditorCur.Owner).Caption+')'
//CurMenuItem.Caption := EditorCur.PageName
@ -1873,9 +1873,9 @@ begin
else
CurMenuItem.Caption := EditorCur.PageName;
if CurMenuItem.MenuItem <> nil then
CurMenuItem.MenuItem.Checked := SourceEditorManager.ActiveEditor = EditorCur;
if (SourceEditorManager.ActiveEditor = EditorCur) and (M.MenuItem <> nil) then
M.MenuItem.Checked := true;
CurMenuItem.Checked := SourceEditorManager.ActiveEditor = EditorCur;
if (SourceEditorManager.ActiveEditor = EditorCur) and (aSection.MenuItem <> nil) then
aSection.Checked := true;
CurMenuItem.OnClick := @mnuWindowSourceItemClick;
CurMenuItem.Tag := j;
end;
@ -1884,8 +1884,8 @@ begin
ClearMenuItem(ItemCountOther, itmTabListOther);
for i := 0 to itmTabListPackage.Count - 1 do begin
if itmTabListPackage.Items[i] is TIDEMenuSection then begin
M := itmTabListPackage.Items[i] as TIDEMenuSection;
M.Caption := M.Caption + Format(' (%d)', [M.Count]);
aSection := itmTabListPackage.Items[i] as TIDEMenuSection;
aSection.Caption := aSection.Caption + Format(' (%d)', [aSection.Count]);
end;
end;
itmTabListProject.Caption := dlgEnvProject + Format(' (%d)', [itmTabListProject.Count]);

View File

@ -6523,7 +6523,7 @@ var
begin
PopM:=TPopupMenu(Sender);
SourceTabMenuRoot.MenuItem:=PopM.Items;
SourceTabMenuRoot.BeginUpdate;
//SourceTabMenuRoot.BeginUpdate;
try
// Get the tab that was clicked
if PopM.PopupComponent is TPageControl then begin
@ -6625,7 +6625,7 @@ begin
end;
finally
SourceTabMenuRoot.EndUpdate;
//SourceTabMenuRoot.EndUpdate;
end;
end;
@ -6661,7 +6661,7 @@ begin
IDECommandList.ExecuteUpdateEvents;
SourceEditorMenuRoot.MenuItem:=SrcPopupMenu.Items;
SourceEditorMenuRoot.BeginUpdate;
//SourceEditorMenuRoot.BeginUpdate;
try
RemoveUserDefinedMenuItems;
RemoveContextMenuItems;
@ -6746,7 +6746,7 @@ begin
Manager.OnPopupMenu(@AddContextPopupMenuItem);
SourceEditorMenuRoot.NotifySubSectionOnShow(Self);
finally
SourceEditorMenuRoot.EndUpdate;
//SourceEditorMenuRoot.EndUpdate;
end;
end;

View File

@ -250,7 +250,7 @@ type
procedure DisableI18NForLFMCheckBoxChange(Sender: TObject);
procedure EditVirtualUnitMenuItemClick(Sender: TObject);
procedure ExpandDirectoryMenuItemClick(Sender: TObject);
procedure FilterEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FilterEditKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure FindInFilesMenuItemClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
@ -798,7 +798,7 @@ begin
//debugln(['TPackageEditorForm.FilesPopupMenuPopup START ',ItemsPopupMenu.Items.Count]);
PackageEditorMenuFilesRoot.MenuItem:=ItemsPopupMenu.Items;
//debugln(['TPackageEditorForm.FilesPopupMenuPopup START after connect ',ItemsPopupMenu.Items.Count]);
PackageEditorMenuRoot.BeginUpdate;
//PackageEditorMenuRoot.BeginUpdate;
try
CollectSelected;
Writable := not LazPackage.ReadOnly;
@ -862,7 +862,7 @@ begin
end;
finally
PackageEditorMenuRoot.EndUpdate;
//PackageEditorMenuRoot.EndUpdate;
end;
FSingleSelectedFile := Nil;
FSingleSelectedDep := Nil;
@ -936,7 +936,7 @@ var
begin
PackageEditorMenuRoot.MenuItem:=MorePopupMenu.Items;
PackageEditorMenuRoot.BeginUpdate;
//PackageEditorMenuRoot.BeginUpdate;
try
Writable:=(not LazPackage.ReadOnly);
@ -964,7 +964,7 @@ begin
// under section PkgEditMenuSectionMisc
SetItem(PkgEditMenuViewPackageSource,@ViewPkgSourceClick);
finally
PackageEditorMenuRoot.EndUpdate;
//PackageEditorMenuRoot.EndUpdate;
end;
end;

View File

@ -1,9 +1,9 @@
object TestMenuIntfForm: TTestMenuIntfForm
object TestMenuIntfDlg: TTestMenuIntfDlg
Left = 287
Height = 237
Top = 215
Width = 541
Caption = 'TestMenuIntfForm'
Caption = 'TestMenuIntfDlg'
Menu = TestMainMenuIntf1
LCLVersion = '1.7'
object TestMainMenuIntf1: TMainMenu

View File

@ -1,4 +1,4 @@
unit testmenuintf;
unit TestMenuIntf;
{$mode objfpc}{$H+}
@ -10,9 +10,9 @@ uses
type
{ TTestMenuIntfForm }
{ TTestMenuIntfDlg }
TTestMenuIntfForm = class(TForm)
TTestMenuIntfDlg = class(TForm)
TestMainMenuIntf1: TMainMenu;
TestPopupMenuIntf1: TPopupMenu;
private
@ -22,13 +22,31 @@ type
{ TMenuIntfTest }
TTestMenuIntf = class(TTestCase)
private
FDialog: TTestMenuIntfDlg;
FMainMenuRoot: TIDEMenuSection;
FPopupMenuRoot: TIDEMenuSection;
protected
procedure SetUp; override;
procedure TearDown; override;
public
function CreateCommand(aParent: TIDEMenuSection; aName: string): TIDEMenuCommand;
function CreateSection(aParent: TIDEMenuSection; aName: string): TIDEMenuSection;
property Dialog: TTestMenuIntfDlg read FDialog;
property MainMenuRoot: TIDEMenuSection read FMainMenuRoot;
property PopupMenuRoot: TIDEMenuSection read FPopupMenuRoot;
published
procedure TestMainMenu;
procedure TestEmptyMainMenu;
procedure TestSinglePopupMenu;
procedure TestPopupMenuList;
procedure TestPopupMenuLogicalSection;
procedure TestPopupMenuSubMenu;
procedure TestPopupMenuVisible;
procedure TestPopupMenuClearHiddenSection;
end;
var
TestMenuIntfForm: TTestMenuIntfForm;
TestMenuIntfDlg: TTestMenuIntfDlg;
implementation
@ -37,9 +55,220 @@ implementation
{ TMenuIntfTest }
procedure TTestMenuIntf.TestMainMenu;
procedure TTestMenuIntf.SetUp;
begin
inherited SetUp;
IDEMenuRoots:=TIDEMenuRoots.Create;
FMainMenuRoot:=RegisterIDEMenuRoot('MainMenuRoot');
FPopupMenuRoot:=RegisterIDEMenuRoot('PopupMenuRoot');
FDialog:=TTestMenuIntfDlg.Create(nil);
end;
procedure TTestMenuIntf.TearDown;
begin
FreeAndNil(FDialog);
FMainMenuRoot:=nil;
FPopupMenuRoot:=nil;
FreeAndNil(IDEMenuRoots);
inherited TearDown;
end;
function TTestMenuIntf.CreateCommand(aParent: TIDEMenuSection; aName: string): TIDEMenuCommand;
begin
Result:=RegisterIDEMenuCommand(aParent,aName,aName);
end;
function TTestMenuIntf.CreateSection(aParent: TIDEMenuSection; aName: string
): TIDEMenuSection;
begin
Result:=RegisterIDEMenuSection(aParent,aName);
end;
procedure TTestMenuIntf.TestEmptyMainMenu;
begin
FMainMenuRoot.MenuItem:=Dialog.TestMainMenuIntf1.Items;
MainMenuRoot.ConsistencyCheck;
end;
procedure TTestMenuIntf.TestSinglePopupMenu;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
RegisterIDEMenuCommand(PopupMenuRoot,'Help','Help');
PopupMenuRoot.ConsistencyCheck;
end;
procedure TTestMenuIntf.TestPopupMenuList;
var
i: Integer;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
for i:=1 to 3 do begin
RegisterIDEMenuCommand(PopupMenuRoot,'Item'+IntToStr(i),'Item'+IntToStr(i));
PopupMenuRoot.ConsistencyCheck;
end;
end;
procedure TTestMenuIntf.TestPopupMenuLogicalSection;
var
Section1: TIDEMenuSection;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
Section1:=RegisterIDEMenuSection(PopupMenuRoot,'Section1');
PopupMenuRoot.ConsistencyCheck;
Section1.ChildrenAsSubMenu:=false;
PopupMenuRoot.ConsistencyCheck;
RegisterIDEMenuCommand(Section1,'Item1','Item1');
PopupMenuRoot.ConsistencyCheck;
end;
procedure TTestMenuIntf.TestPopupMenuSubMenu;
var
Section1: TIDEMenuSection;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
Section1:=RegisterIDEMenuSection(PopupMenuRoot,'Section1');
PopupMenuRoot.ConsistencyCheck;
RegisterIDEMenuCommand(Section1,'Item1','Item1');
PopupMenuRoot.ConsistencyCheck;
end;
procedure TTestMenuIntf.TestPopupMenuVisible;
var
LogSection1, SubMenu2, LogSection2: TIDEMenuSection;
Item1, Item2, Item3, Item4: TIDEMenuCommand;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
LogSection1:=RegisterIDEMenuSection(PopupMenuRoot,'LogSection1');
PopupMenuRoot.ConsistencyCheck;
Item1:=RegisterIDEMenuCommand(LogSection1,'Item1','Item1');
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
SubMenu2:=RegisterIDEMenuSection(PopupMenuRoot,'SubMenu2');
PopupMenuRoot.ConsistencyCheck;
Item2:=RegisterIDEMenuCommand(SubMenu2,'Item2','Item2');
PopupMenuRoot.ConsistencyCheck;
AssertEquals('SubMenu2.VisibleActive',true,SubMenu2.VisibleActive);
AssertEquals('SubMenu2.VisibleCommandCount',1,SubMenu2.VisibleCommandCount);
LogSection2:=RegisterIDEMenuSection(PopupMenuRoot,'LogSection2');
PopupMenuRoot.ConsistencyCheck;
Item3:=RegisterIDEMenuCommand(LogSection2,'Item3','Item3');
Item4:=RegisterIDEMenuCommand(LogSection2,'Item4','Item4');
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection2.VisibleActive',true,LogSection2.VisibleActive);
AssertEquals('LogSection2.VisibleCommandCount',2,LogSection2.VisibleCommandCount);
// hide Item1 -> auto hides LogSection1
Item1.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',false,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',0,LogSection1.VisibleCommandCount);
// show Item1 -> auto shows LogSection1
Item1.Visible:=true;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
// hide Item2 -> auto hides SubMenu2
Item2.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('SubMenu2.VisibleActive',false,SubMenu2.VisibleActive);
AssertEquals('SubMenu2.VisibleCommandCount',0,SubMenu2.VisibleCommandCount);
// show Item2 -> auto shows SubMenu2
Item2.Visible:=true;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('SubMenu2.VisibleActive',true,SubMenu2.VisibleActive);
AssertEquals('SubMenu2.VisibleCommandCount',1,SubMenu2.VisibleCommandCount);
// hide Item3, Item4 still visible
Item3.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection2.VisibleActive',true,LogSection2.VisibleActive);
AssertEquals('LogSection2.VisibleCommandCount',1,LogSection2.VisibleCommandCount);
// hide Item4 -> auto hide LogSection2
Item4.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection2.VisibleActive',false,LogSection2.VisibleActive);
AssertEquals('LogSection2.VisibleCommandCount',0,LogSection2.VisibleCommandCount);
// show Item3 -> auto shows LogSection2
Item3.Visible:=true;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection2.VisibleActive',true,LogSection2.VisibleActive);
AssertEquals('LogSection2.VisibleCommandCount',1,LogSection2.VisibleCommandCount);
end;
procedure TTestMenuIntf.TestPopupMenuClearHiddenSection;
var
LogSection1, SubSection2: TIDEMenuSection;
Item2: TIDEMenuCommand;
begin
FPopupMenuRoot.MenuItem:=Dialog.TestPopupMenuIntf1.Items;
PopupMenuRoot.ConsistencyCheck;
LogSection1:=RegisterIDEMenuSection(PopupMenuRoot,'LogSection1');
PopupMenuRoot.ConsistencyCheck;
RegisterIDEMenuCommand(LogSection1,'Item1','Item1');
PopupMenuRoot.ConsistencyCheck;
SubSection2:=RegisterIDEMenuSection(LogSection1,'SubSection2');
PopupMenuRoot.ConsistencyCheck;
Item2:=RegisterIDEMenuCommand(SubSection2,'Item2','Item2');
PopupMenuRoot.ConsistencyCheck;
writeln('TTestMenuIntf.TestPopupMenuClearHiddenSection START');
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',2,LogSection1.VisibleCommandCount);
AssertEquals('SubSection2.VisibleActive',true,SubSection2.VisibleActive);
AssertEquals('SubSection2.VisibleCommandCount',1,SubSection2.VisibleCommandCount);
// hide SubSection2 -> LogSection1 looses one command
writeln('TTestMenuIntf.TestPopupMenuClearHiddenSection hide SubSection2 -> LogSection1 looses one command');
SubSection2.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
AssertEquals('SubSection2.VisibleActive',false,SubSection2.VisibleActive);
AssertEquals('SubSection2.VisibleCommandCount',1,SubSection2.VisibleCommandCount);
// hide Item2 -> no effect on LogSection1
writeln('TTestMenuIntf.TestPopupMenuClearHiddenSection hide Item2 -> no effect on LogSection1');
Item2.Visible:=false;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
AssertEquals('SubSection2.VisibleActive',false,SubSection2.VisibleActive);
AssertEquals('SubSection2.VisibleCommandCount',0,SubSection2.VisibleCommandCount);
// show Item2 -> no effect on LogSection1
writeln('TTestMenuIntf.TestPopupMenuClearHiddenSection show Item2 -> no effect on LogSection1');
Item2.Visible:=true;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
AssertEquals('SubSection2.VisibleActive',false,SubSection2.VisibleActive);
AssertEquals('SubSection2.VisibleCommandCount',1,SubSection2.VisibleCommandCount);
// clear SubSection2 -> no effect on LogSection1
writeln('TTestMenuIntf.TestPopupMenuClearHiddenSection clear SubSection2 -> no effect on LogSection1');
SubSection2.Clear;
Item2:=nil;
PopupMenuRoot.ConsistencyCheck;
AssertEquals('LogSection1.VisibleActive',true,LogSection1.VisibleActive);
AssertEquals('LogSection1.VisibleCommandCount',1,LogSection1.VisibleCommandCount);
AssertEquals('SubSection2.VisibleActive',false,SubSection2.VisibleActive);
AssertEquals('SubSection2.VisibleCommandCount',0,SubSection2.VisibleCommandCount);
end;
initialization

View File

@ -107,8 +107,10 @@
<Unit14>
<Filename Value="ideintf\testmenuintf.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="TestMenuIntfForm"/>
<ComponentName Value="TestMenuIntfDlg"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="TestMenuIntf"/>
</Unit14>
</Units>
</ProjectOptions>

View File

@ -29,7 +29,7 @@ begin
Application.Title:='Run Lazarus tests';
Application.Initialize;
Application.CreateForm(TGuiTestRunner, TestRunner);
Application.CreateForm(TTestMenuIntfForm, TestMenuIntfForm);
Application.CreateForm(TTestMenuIntfDlg, TestMenuIntfDlg);
Application.Run;
end.