Skip to content

Menu v2 #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 105 additions & 105 deletions Showcase/Menu.Designer.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Showcase/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal class Program
{
private static Type[] views = new[]
{
typeof(NumericUpDown)

typeof(NumericUpDown) ,
typeof(Menu)
};
static void Main(string[] args)
{
Expand Down
2 changes: 1 addition & 1 deletion Showcase/Showcase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4400" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4405" />
</ItemGroup>

</Project>
19 changes: 0 additions & 19 deletions src/ContextMenuExtensions.cs

This file was deleted.

6 changes: 4 additions & 2 deletions src/TerminalGuiDesigner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageOutputPath>./nupkg</PackageOutputPath>
<ImplicitUsings>enable</ImplicitUsings>
<PackageId>TerminalGuiDesigner</PackageId>
<Version>2.0.0-develop.4400</Version>
<Version>2.0.0-develop.4424</Version>
<Authors>Thomas Nind</Authors>
<Nullable>enable</Nullable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -33,6 +33,8 @@
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
2.0.0-alpha.4401
* Add keybinding screen and save in app data
2.0.0-alpha.4400
* V2 driver support
2.0.0-alpha.2203
Expand Down Expand Up @@ -153,7 +155,7 @@
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4400" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4424" />
<PackageReference Include="nlog" Version="5.3.3" />
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.7.7" />
<PackageReference Include="System.CodeDom" Version="8.0.0" />
Expand Down
26 changes: 14 additions & 12 deletions src/UI/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,20 +939,22 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
var setPropsItems = setProps.Select(ToMenuItem).ToArray();
bool hasPropsItems = setPropsItems.Any();

var all = new List<MenuItem>();
var all = new List<MenuItemv2>();

// only add the set properties category if there are some
if (hasPropsItems)
{
all.Add(new MenuBarItem(name, setPropsItems)
all.Add(new MenuItemv2()
{
Title = name,
Action = () =>
{
if (selected.Length == 1 || rightClicked != null)
{
this.ShowEditProperties(rightClicked ?? selected[0]);
}
},
SubMenu = new Menuv2(setPropsItems)
});
}

Expand All @@ -970,7 +972,7 @@ private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked)
// Add categories first
all.Insert(
hasPropsItems ? 1 : 0,
new MenuBarItem(g.Key, g.ToArray()));
new MenuBarItemv2(g.Key, g.ToArray()));
}
}

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

var menu = new ContextMenu();
menu.SetMenuItems(new MenuBarItem(all.ToArray()));

var menu = new PopoverMenu(all.ToArray());
Point position;
if (m != null)
{
menu.Position = m.Position;
position = m.Position;
}
else
{
var d = SelectionManager.Instance.Selected.FirstOrDefault() ?? this.viewBeingEdited;
var pt = d.View.ContentToScreen(new Point(0, 0));
menu.Position = new Point(pt.X, pt.Y);
position = new Point(pt.X, pt.Y);
}

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


// TODO: rly? you have to pass it its own menu items!?
menu.Show(menu.MenuItems);
menu.MenuBar.MenuAllClosed += (_, _) =>
menu.MakeVisible(position);
menu.Accepted += (_, _) =>
{
this.menuOpen = false;
SelectionManager.Instance.LockSelection = false;
};
}

private static MenuItem ToMenuItem(IOperation operation)
private static MenuItemv2 ToMenuItem(IOperation operation)
{
return new MenuItem(operation.ToString(), string.Empty, () => Try(() => OperationManager.Instance.Do(operation)));
return new MenuItemv2(operation.ToString(), string.Empty, () => Try(() => OperationManager.Instance.Do(operation)));

static void Try(Action action)
{
Expand Down
12 changes: 6 additions & 6 deletions src/UI/Windows/ArrayEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void BtnMoveUp_Clicked(object sender, CommandEventArgs e)
lvElements.SetNeedsDraw();
}

e.Cancel = true;
e.Handled = true;
}

private void BtnMoveDown_Clicked(object sender, CommandEventArgs e)
Expand All @@ -109,7 +109,7 @@ private void BtnMoveDown_Clicked(object sender, CommandEventArgs e)
lvElements.SetNeedsDraw();
}

e.Cancel = true;
e.Handled = true;
}

private void LvElements_KeyDown(object sender, Key e)
Expand Down Expand Up @@ -145,7 +145,7 @@ private void BtnAddElement_Clicked(object sender, CommandEventArgs e)
lvElements.Source = ResultAsList.ToListDataSource();
lvElements.SelectedItem = ResultAsList.Count - 1;
lvElements.SetNeedsDraw();
e.Cancel = true;
e.Handled = true;
}
private void BtnEdit_Clicked(object sender, CommandEventArgs e)
{
Expand All @@ -167,19 +167,19 @@ private void BtnEdit_Clicked(object sender, CommandEventArgs e)
lvElements.SetNeedsDraw();
}

e.Cancel = true;
e.Handled = true;
}

private void BtnCancel_Clicked(object sender, CommandEventArgs e)
{
e.Cancel = true;
e.Handled = true;
Cancelled = true;
Application.RequestStop();
}

private void BtnOk_Clicked(object sender, CommandEventArgs e)
{
e.Cancel = true;
e.Handled = true;
Cancelled = false;
Application.RequestStop();
}
Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/BigListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public BigListBox(string prompt,
};
btnOk.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
this.Accept();
};

Expand All @@ -117,7 +117,7 @@ public BigListBox(string prompt,
};
btnCancel.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
Application.RequestStop();
};

Expand Down
2 changes: 1 addition & 1 deletion src/UI/Windows/ChoicesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ChoicesDialog(string title, string message, params string[] options) {

buttons[i].Accepting += (s,e) => {
Result = i2;
e.Cancel = true;
e.Handled = true;
Application.RequestStop();

};
Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public ColorPicker(Attribute? currentValue)

btnOk.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
Ok();
};
btnCancel.Accepting += (s, e) => { e.Cancel = true; Cancel(); };
btnCancel.Accepting += (s, e) => { e.Handled = true; Cancel(); };
}

private void Ok()
Expand Down
14 changes: 7 additions & 7 deletions src/UI/Windows/ColorSchemeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,51 @@ public ColorSchemeEditor(ColorScheme scheme) {

btnEditNormal.Accepting += (s, e)=>
{
e.Cancel = true;
e.Handled = true;
_result.Normal = PickNewColorsFor(Result.Normal);
SetColorPatches();
};


btnEditHotNormal.Accepting += (s, e)=>
{
e.Cancel = true;
e.Handled = true;
_result.HotNormal = PickNewColorsFor(Result.HotNormal);
SetColorPatches();
};


btnEditFocus.Accepting += (s, e)=>{
e.Cancel = true;
e.Handled = true;
_result.Focus = PickNewColorsFor(Result.Focus);
SetColorPatches();
};


btnEditHotFocus.Accepting += (s, e)=>
{
e.Cancel = true;
e.Handled = true;
_result.HotFocus = PickNewColorsFor(Result.HotFocus);
SetColorPatches();
};


btnEditDisabled.Accepting += (s, e)=>{
e.Cancel = true;
e.Handled = true;
_result.Disabled = PickNewColorsFor(Result.Disabled);
SetColorPatches();
};

btnCancel.Accepting += (s, e)=>
{
e.Cancel = true;
e.Handled = true;
Cancelled = true;
Application.RequestStop();
};

btnOk.Accepting += (s, e)=>
{
e.Cancel = true;
e.Handled = true;
Cancelled = false;
Application.RequestStop();
};
Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/DimEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ private void SetupForCurrentDimType()

private void BtnCancel_Clicked(object sender, CommandEventArgs e)
{
e.Cancel = true;
e.Handled = true;
Cancelled = true;
Application.RequestStop();
}

private void BtnOk_Clicked(object sender, CommandEventArgs e)
{
e.Cancel = true;
e.Handled = true;
Cancelled = false;
Result = BuildResult();
Application.RequestStop();
Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/EditDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public EditDialog(Design design)

btnSet.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
this.SetProperty(false);
};

Expand All @@ -70,7 +70,7 @@ public EditDialog(Design design)
};
btnClose.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
Application.RequestStop();
};

Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/ExceptionViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void ShowException(string errorText, Exception exception)

btnOk.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
Application.RequestStop();
};
var btnStack = new Button()
Expand All @@ -49,7 +49,7 @@ public static void ShowException(string errorText, Exception exception)
};
btnStack.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
// flip between stack / no stack
textView.Text = GetExceptionText(errorText, exception, toggleStack);
textView.SetNeedsDraw();
Expand Down
6 changes: 3 additions & 3 deletions src/UI/Windows/GetTextDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public GetTextDialog(DialogArgs args, string? initialValue)
};
btnOk.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
this.Accept();
};

Expand All @@ -96,7 +96,7 @@ public GetTextDialog(DialogArgs args, string? initialValue)
};
btnCancel.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
this.okClicked = false;
Application.RequestStop();
};
Expand All @@ -109,7 +109,7 @@ public GetTextDialog(DialogArgs args, string? initialValue)
};
btnClear.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
this.textView.Text = string.Empty;
};

Expand Down
4 changes: 2 additions & 2 deletions src/UI/Windows/KeyBindingsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public KeyBindingsUI(KeyMap keyMap) {
btnSave.Accepting += (s, e) =>
{
Save = true;
e.Cancel = true;
e.Handled = true;
Application.RequestStop();
};
btnCancel.Accepting += (s, e) =>
{
e.Cancel = true;
e.Handled = true;
Application.RequestStop();
};
}
Expand Down
Loading
Loading