Skip to content

Commit 3cfbe96

Browse files
author
tznind
committed
Workaround for root menu event and fixes for Enum and string property modals
1 parent 9584c16 commit 3cfbe96

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/UI/Editor.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,25 +954,42 @@ private void CreateAndShowContextMenu(Mouse? m, Design? rightClicked)
954954
.Except(setProps)
955955
.GroupBy(k => k.Category, p=>ToMenuItem(app,p));
956956

957-
var setPropsItems = setProps.Select(p=>ToMenuItem(app,p)).ToArray();
957+
var setPropsItems = setProps.Select(p=>ToMenuItem(app,p)).ToList();
958958
bool hasPropsItems = setPropsItems.Any();
959959

960960
var all = new List<MenuItem>();
961961

962962
// only add the set properties category if there are some
963963
if (hasPropsItems)
964964
{
965+
// Also add to the submenu an 'All' version
966+
// Workaround for https://github.com/gui-cs/Terminal.Gui/issues/4876
967+
// Previously user could do it by selecting the root 'Properties' expandable
968+
// menu
969+
setPropsItems.Insert(0, new MenuItem() {
970+
Title="(All)",
971+
Action = () =>
972+
{
973+
if (selected.Length == 1 || rightClicked != null)
974+
{
975+
this.ShowEditProperties(rightClicked ?? selected[0]);
976+
}
977+
},
978+
});
979+
965980
all.Add(new MenuItem()
966981
{
967982
Title = name,
968-
Action = () =>
983+
SubMenu = new Menu(setPropsItems)
984+
/*
985+
* No longer supported, see https://github.com/gui-cs/Terminal.Gui/issues/4876
986+
* ,Action = () =>
969987
{
970988
if (selected.Length == 1 || rightClicked != null)
971989
{
972990
this.ShowEditProperties(rightClicked ?? selected[0]);
973991
}
974-
},
975-
SubMenu = new Menu(setPropsItems)
992+
},*/
976993
});
977994
}
978995

src/UI/ValueFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ internal static bool GetNewValue(IApplication app, string propertyName, Design d
9191
}
9292

9393
if (
94-
type.IsGenericType(typeof(IEnumerable<>)) ||
95-
type.IsAssignableTo(typeof(IList))
94+
type != typeof(string) &&
95+
(type.IsGenericType(typeof(IEnumerable<>)) ||
96+
type.IsAssignableTo(typeof(IList)))
9697
)
9798
{
9899
var elementType = type.GetElementTypeEx()
@@ -227,6 +228,7 @@ private static bool IsEnumOrNullableEnum(Type type, object? oldValue, out Enum?
227228
if(type.IsEnum)
228229
{
229230
enumValue = (Enum?)oldValue;
231+
return true;
230232
}
231233

232234
if(Nullable.GetUnderlyingType(type) is Type underlying && underlying.IsEnum)

0 commit comments

Comments
 (0)