Skip to content

Commit 6060923

Browse files
author
tznind
committed
Update ContextMenu to instead use PopoverMenu
1 parent 132b02e commit 6060923

4 files changed

Lines changed: 17 additions & 34 deletions

File tree

Showcase/Showcase.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4401" />
12+
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4405" />
1313
</ItemGroup>
1414

1515
</Project>

src/ContextMenuExtensions.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/TerminalGuiDesigner.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageOutputPath>./nupkg</PackageOutputPath>
2121
<ImplicitUsings>enable</ImplicitUsings>
2222
<PackageId>TerminalGuiDesigner</PackageId>
23-
<Version>2.0.0-develop.4401</Version>
23+
<Version>2.0.0-develop.4405</Version>
2424
<Authors>Thomas Nind</Authors>
2525
<Nullable>enable</Nullable>
2626
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -155,7 +155,7 @@
155155
<PackageReference Include="Serilog" Version="4.2.0" />
156156
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
157157
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
158-
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4401" />
158+
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4405" />
159159
<PackageReference Include="nlog" Version="5.3.3" />
160160
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.7.7" />
161161
<PackageReference Include="System.CodeDom" Version="8.0.0" />

src/UI/Editor.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -939,20 +939,22 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
939939
var setPropsItems = setProps.Select(ToMenuItem).ToArray();
940940
bool hasPropsItems = setPropsItems.Any();
941941

942-
var all = new List<MenuItem>();
942+
var all = new List<MenuItemv2>();
943943

944944
// only add the set properties category if there are some
945945
if (hasPropsItems)
946946
{
947-
all.Add(new MenuBarItem(name, setPropsItems)
947+
all.Add(new MenuItemv2()
948948
{
949+
Title = name,
949950
Action = () =>
950951
{
951952
if (selected.Length == 1 || rightClicked != null)
952953
{
953954
this.ShowEditProperties(rightClicked ?? selected[0]);
954955
}
955956
},
957+
SubMenu = new Menuv2(setPropsItems)
956958
});
957959
}
958960

@@ -970,7 +972,7 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
970972
// Add categories first
971973
all.Insert(
972974
hasPropsItems ? 1 : 0,
973-
new MenuBarItem(g.Key, g.ToArray()));
975+
new MenuBarItemv2(g.Key, g.ToArray()));
974976
}
975977
}
976978

@@ -980,18 +982,17 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
980982
return;
981983
}
982984

983-
var menu = new ContextMenu();
984-
menu.SetMenuItems(new MenuBarItem(all.ToArray()));
985-
985+
var menu = new PopoverMenu(all.ToArray());
986+
Point position;
986987
if (m != null)
987988
{
988-
menu.Position = m.Position;
989+
position = m.Position;
989990
}
990991
else
991992
{
992993
var d = SelectionManager.Instance.Selected.FirstOrDefault() ?? this.viewBeingEdited;
993994
var pt = d.View.ContentToScreen(new Point(0, 0));
994-
menu.Position = new Point(pt.X, pt.Y);
995+
position = new Point(pt.X, pt.Y);
995996
}
996997

997998
this.menuOpen = true;
@@ -1002,18 +1003,19 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
10021003
m.Handled = true;
10031004
}
10041005

1006+
10051007
// TODO: rly? you have to pass it its own menu items!?
1006-
menu.Show(menu.MenuItems);
1007-
menu.MenuBar.MenuAllClosed += (_, _) =>
1008+
menu.MakeVisible(position);
1009+
menu.Accepted += (_, _) =>
10081010
{
10091011
this.menuOpen = false;
10101012
SelectionManager.Instance.LockSelection = false;
10111013
};
10121014
}
10131015

1014-
private static MenuItem ToMenuItem(IOperation operation)
1016+
private static MenuItemv2 ToMenuItem(IOperation operation)
10151017
{
1016-
return new MenuItem(operation.ToString(), string.Empty, () => Try(() => OperationManager.Instance.Do(operation)));
1018+
return new MenuItemv2(operation.ToString(), string.Empty, () => Try(() => OperationManager.Instance.Do(operation)));
10171019

10181020
static void Try(Action action)
10191021
{

0 commit comments

Comments
 (0)