Skip to content
Closed
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
22 changes: 19 additions & 3 deletions StandaloneExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ static void Close ()
MessageBox.ErrorQuery (50, 5, "Error", "There is nothing to close", "Ok");
}

static void Help() {
MessageBox.Query(50, 7, "Help", "This is a small help\nBe kind.", "Ok");
}

static void ExitProgram() {
if (Quit ()) Application.Top.Running = false;
}

public static Label ml;
static void Main ()
{
Expand All @@ -185,7 +193,7 @@ static void Main ()
new MenuItem ("_New", "Creates new file", NewFile),
new MenuItem ("_Open", "", null),
new MenuItem ("_Close", "", () => Close ()),
new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
new MenuItem ("_Quit", "^X", () => ExitProgram())
}),
new MenuBarItem ("_Edit", new MenuItem [] {
new MenuItem ("_Copy", "", null),
Expand All @@ -194,6 +202,14 @@ static void Main ()
})
});

var statusBar = new StatusBar(new StatusItem[] {
new StatusItem(Key.F1, "~F1~ Help", () => Help()),
new StatusItem(Key.F2, "~F2~ Load", null),
new StatusItem(Key.F3, "~F3~ Save", null),
new StatusItem(Key.ControlX, "~^X~ Quit", () => ExitProgram()),
});


ShowEntries (win);
int count = 0;
ml = new Label (new Rect (3, 17, 47, 1), "Mouse: ");
Expand All @@ -203,8 +219,8 @@ static void Main ()

win.Add (ml);

top.Add (win, menu);
top.Add (menu);
top.Add (win, menu, statusBar);

Application.Run ();
}
}
3 changes: 2 additions & 1 deletion StandaloneExample/StandaloneExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Terminal.Gui" Version="0.17.0" />
<ProjectReference Include="..\Terminal.Gui\Terminal.Gui.csproj" />
<!-- PackageReference Include="Terminal.Gui" Version="0.17.0" / -->
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions Terminal.Gui/Views/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ static Rect MakeFrame (int x, int y, MenuItem [] items)
maxW = Math.Max (l, maxW);
}

current = -1;
/* current = -1;
for (int i = 0; i < items.Length; i++) {
if (items [i] != null) {
current = i;
break;
}
}
} */
return new Rect (x, y, maxW + 2, items.Length + 2);
}

Expand Down Expand Up @@ -205,15 +205,15 @@ public override bool ProcessKey (KeyEvent kb)
current--;
if (current < 0)
current = barItems.Children.Length - 1;
} while (barItems.Children [current] == null)
} while (barItems.Children [current] == null);
SetNeedsDisplay ();
break;
case Key.CursorDown:
do {
current++;
if (current == barItems.Children.Length)
current = 0;
} while (barItems.Children [current] == null)
} while (barItems.Children [current] == null);
SetNeedsDisplay ();
break;
case Key.CursorLeft:
Expand Down Expand Up @@ -424,22 +424,22 @@ internal void NextMenu ()
internal bool FindAndOpenMenuByHotkey(KeyEvent kb)
{
int pos = 0;
var c = ((uint)kb.Key & (uint)Key.CharMask);
var c = ((uint)kb.Key & (uint)Key.CharMask);
for (int i = 0; i < Menus.Length; i++)
{
// TODO: this code is duplicated, hotkey should be part of the MenuBarItem
var mi = Menus[i];
int p = mi.Title.IndexOf('_');
if (p != -1 && p + 1 < mi.Title.Length) {
if (mi.Title[p + 1] == c) {
OpenMenu(i);
if (mi.Title[p + 1] == c) {
OpenMenu(i);
return true;
}
}
}
}
return false;
}
}

public override bool ProcessHotKey (KeyEvent kb)
{
if (kb.Key == Key.F9) {
Expand Down
88 changes: 88 additions & 0 deletions Terminal.Gui/Views/StatusBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using NStack;

namespace Terminal.Gui
{
public class StatusItem
{
public StatusItem(Key shortCut, ustring title, Action action)
{
Title = title ?? "";
ShortCut = shortCut;
Action = action;

}

/// <summary>
/// This is the global setting that can be used as a global shortcut to invoke the action on the menu.
/// </summary>
public Key ShortCut;

/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>The title.</value>
public ustring Title { get; set; }

/// <summary>
/// Gets or sets the action to be invoked when the menu is triggered
/// </summary>
/// <value>Method to invoke.</value>
public Action Action { get; set; }
};

public class StatusBar : View
{
public StatusItem [] Items { get; set; }

public StatusBar(StatusItem [] items) : base()
{
X = 0;
Y = Application.Driver.Rows-1; // TODO: using internals of Application
Width = Dim.Fill ();
Height = 1;
Items = items;
CanFocus = false;
ColorScheme = Colors.Menu;
}

Attribute ToggleScheme(Attribute scheme) {
var result = scheme==ColorScheme.Normal ? ColorScheme.HotNormal : ColorScheme.Normal;
Driver.SetAttribute(result);
return result;
}

public override void Redraw(Rect region) {
Move (0, 0);
Driver.SetAttribute (ColorScheme.Normal);
for (int i = 0; i < Frame.Width; i++)
Driver.AddRune (' ');

Move (1, 0);
var scheme = ColorScheme.Normal;
Driver.SetAttribute(scheme);
for(int i=0; i<Items.Length; i++) {
var title = Items[i].Title;
for(int n=0; n<title.Length; n++) {
if(title[n]=='~') {
scheme = ToggleScheme(scheme);
continue;
}
Driver.AddRune(title[n]);
}
Driver.AddRune (' ');
}
}

public override bool ProcessHotKey (KeyEvent kb)
{
foreach(var item in Items) {
if(kb.Key==item.ShortCut) {
if( item.Action!=null ) item.Action();
return true;
}
}
return false;
}
}
}