Skip to content

Commit

Permalink
Use just one global shortcut and place the rest in a popup menu
Browse files Browse the repository at this point in the history
  • Loading branch information
magiblot committed Oct 24, 2024
1 parent fdb9ac1 commit f1ff82c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 36 deletions.
101 changes: 66 additions & 35 deletions source/tvterm/app.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
Expand All @@ -22,7 +23,6 @@
#include <stdlib.h>
#include <signal.h>

TVTermApp* TVTermApp::app;
TCommandSet TVTermApp::tileCmds = []()
{
TCommandSet ts;
Expand All @@ -36,9 +36,7 @@ TCommandSet TVTermApp::tileCmds = []()
int main(int, char**)
{
TVTermApp app;
TVTermApp::app = &app;
app.run();
TVTermApp::app = nullptr;
app.shutDown();
}

Expand All @@ -56,46 +54,45 @@ TVTermApp::TVTermApp() :

TMenuBar *TVTermApp::initMenuBar(TRect r)
{
r.b.y = r.a.y+1;
return new TMenuBar( r,
*new TSubMenu( "~F~ile", kbAltF, hcNoContext ) +
*new TMenuItem( "~N~ew", cmNewTerm, kbCtrlN, hcNoContext, "Ctrl-N" ) +
r.b.y = r.a.y + 1;
return new TMenuBar(r,
*new TSubMenu("File", kbNoKey) +
*new TMenuItem("~N~ew Term", cmNewTerm, kbNoKey) +
newLine() +
*new TMenuItem( "~C~hange dir...", cmChangeDir, kbNoKey ) +
*new TMenuItem( "S~u~spend", cmDosShell, kbNoKey, hcNoContext ) +
*new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X" ) +
*new TSubMenu( "~W~indows", kbAltW ) +
*new TMenuItem( "~S~ize/move",cmResize, kbCtrlF5, hcNoContext, "Ctrl-F5" ) +
*new TMenuItem( "~Z~oom", cmZoom, kbF5, hcNoContext, "F5" ) +
*new TMenuItem( "~T~ile (Columns First)", cmTileCols, kbNoKey ) +
*new TMenuItem( "Tile (~R~ows First)", cmTileRows, kbNoKey ) +
*new TMenuItem( "C~a~scade", cmCascade, kbNoKey ) +
*new TMenuItem( "~N~ext", cmNext, kbF6, hcNoContext, "F6" ) +
*new TMenuItem( "~P~revious", cmPrev, kbShiftF6, hcNoContext, "Shift-F6" ) +
*new TMenuItem( "~C~lose", cmClose, kbAltF3, hcNoContext, "Alt+F3" )
*new TMenuItem("~C~hange dir...", cmChangeDir, kbNoKey) +
*new TMenuItem("S~u~spend", cmDosShell, kbNoKey) +
*new TMenuItem("E~x~it", cmQuit, kbNoKey) +
*new TSubMenu("Windows", kbNoKey) +
*new TMenuItem("Re~s~ize/Move", cmResize, kbNoKey) +
*new TMenuItem("Maximi~z~e/Restore", cmZoom, kbNoKey) +
*new TMenuItem("~T~ile (Columns First)", cmTileCols, kbNoKey) +
*new TMenuItem("Tile (~R~ows First)", cmTileRows, kbNoKey) +
*new TMenuItem("C~a~scade", cmCascade, kbNoKey) +
*new TMenuItem("~N~ext", cmNext, kbNoKey) +
*new TMenuItem("~P~revious", cmPrev, kbNoKey) +
*new TMenuItem("~C~lose", cmClose, kbNoKey)
);
}

TStatusLine *TVTermApp::initStatusLine( TRect r )
TStatusLine *TVTermApp::initStatusLine(TRect r)
{
r.a.y = r.b.y-1;
return new TStatusLine( r,
*new TStatusDef( hcDragging, hcDragging ) +
*new TStatusItem( "~Arrow~ Move", kbNoKey, cmValid ) +
*new TStatusItem( "~Shift-Arrow~ Resize", kbNoKey, cmValid ) +
*new TStatusItem( "~Enter~ Done", kbNoKey, cmValid ) +
*new TStatusItem( "~Esc~ Abort", kbNoKey, cmValid ) +
*new TStatusDef( hcInputGrabbed, hcInputGrabbed ) +
*new TStatusItem( "~Alt-PgDn~ Release Input", kbAltPgDn, cmReleaseInput ) +
*new TStatusDef( 0, 0xFFFF ) +
*new TStatusItem( "~Ctrl-N~ New", kbNoKey, cmNewTerm ) +
*new TStatusItem( "~F6~ Next", kbNoKey, cmNext ) +
*new TStatusItem( "~Alt-PgUp~ Grab Input", kbAltPgUp, cmGrabInput ) +
*new TStatusItem( "~F12~ Menu" , kbF12, cmMenu )
r.a.y = r.b.y - 1;
return new TStatusLine(r,
*new TStatusDef(hcDragging, hcDragging) +
*new TStatusItem("~Arrow~ Move", kbNoKey, 0) +
*new TStatusItem("~Shift-Arrow~ Resize", kbNoKey, 0) +
*new TStatusItem("~Enter~ Done", kbNoKey, 0) +
*new TStatusItem("~Esc~ Cancel", kbNoKey, 0) +
*new TStatusDef(hcInputGrabbed, hcInputGrabbed) +
*new TStatusItem("~Alt-PgDn~ Release Input", kbAltPgDn, cmReleaseInput) +
*new TStatusDef(hcQuickMenu, hcQuickMenu) +
*new TStatusItem("~Esc~ Hide Menu", kbEsc, 0) +
*new TStatusDef(0, 0xFFFF) +
*new TStatusItem("~Ctrl-B~ Quick Menu" , kbCtrlB, cmQuickMenu)
);
}

TDeskTop *TVTermApp::initDeskTop( TRect r )
TDeskTop *TVTermApp::initDeskTop(TRect r)
{
r.grow(0, -1);
return new TVTermDesk(r);
Expand All @@ -110,6 +107,7 @@ void TVTermApp::handleEvent(TEvent &event)
case evCommand:
switch (event.message.command)
{
case cmQuickMenu: showQuickMenu(); break;
case cmNewTerm: newTerm(); break;
case cmChangeDir: changeDir(); break;
case cmTileCols: getDeskTop()->tileVertical(getTileRect()); break;
Expand Down Expand Up @@ -172,6 +170,39 @@ void TVTermApp::idle()
message(this, evBroadcast, cmCheckTerminalUpdates, nullptr);
}

void TVTermApp::showQuickMenu()
{
TMenuItem &menuItems =
*new TMenuItem("New Term", cmNewTerm, 'N', hcNoContext, "~N~") +
*new TMenuItem("Close Term", cmClose, 'W', hcNoContext, "~W~") +
newLine() +
*new TMenuItem("Next Term", cmNext, kbTab, hcNoContext, "~Tab~") +
*new TMenuItem("Previous Term", cmPrev, kbShiftTab, hcNoContext, "~Shift-Tab~") +
*new TMenuItem("Tile (Columns First)", cmTileCols, 'V', hcNoContext, "~V~") +
*new TMenuItem("Tile (Rows First)", cmTileRows, 'H', hcNoContext, "~H~") +
*new TMenuItem("Resize", cmResize, 'R', hcNoContext, "~R~") +
*new TMenuItem("Grab Input", cmGrabInput, 'I', hcNoContext, "~I~") +
newLine() +
*new TMenuItem("Top Menu", cmMenu, 'M', hcNoContext, "~M~") +
*new TMenuItem("Suspend", cmDosShell, 'U', hcNoContext, "~U~") +
*new TMenuItem("Exit", cmQuit, 'Q', hcNoContext, "~Q~");

TMenu *menu = new TMenu(menuItems);
TMenuPopup *menuPopup = new CenteredMenuPopup(menu);
menuPopup->helpCtx = hcQuickMenu;

if (ushort cmd = execView(menuPopup))
{
TEvent event = {};
event.what = evCommand;
event.message.command = cmd;
putEvent(event);
}

TObject::destroy(menuPopup);
delete menu;
}

static void onTermError(const char *reason)
{
messageBox(mfError | mfOKButton, "Cannot create terminal: %s.", reason);
Expand Down
2 changes: 1 addition & 1 deletion source/tvterm/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class TVTermDesk;

struct TVTermApp : public TApplication
{
static TVTermApp *app;
static TCommandSet tileCmds;

TVTermApp();
Expand All @@ -27,6 +26,7 @@ struct TVTermApp : public TApplication

// Command handlers

void showQuickMenu();
void newTerm();
void changeDir();

Expand Down
20 changes: 20 additions & 0 deletions source/tvterm/apputil.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#define Uses_TProgram
#define Uses_TDeskTop
#define Uses_TMenuPopup
#include <tvision/tv.h>

inline ushort execDialog(TDialog *d)
Expand All @@ -17,4 +18,23 @@ inline ushort execDialog(TDialog *d)
return cmCancel;
}

class CenteredMenuPopup : public TMenuPopup
{
public:

CenteredMenuPopup(TMenu *aMenu) noexcept :
TMenuPopup(TRect(0, 0, 0, 0), aMenu)
{
options |= ofCentered;
}

void calcBounds(TRect &bounds, TPoint delta) override
{
bounds.a.x = (owner->size.x - size.x)/2;
bounds.a.y = (owner->size.y - size.y)/2;
bounds.b.x = bounds.a.x + size.x;
bounds.b.y = bounds.a.y + size.y;
}
};

#endif // TVTERM_APPUTIL_H
2 changes: 2 additions & 0 deletions source/tvterm/cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ enum : ushort
cmCheckTerminalUpdates,
cmTerminalUpdated,
cmGetOpenTerms,
cmQuickMenu,
};

enum : ushort
{
hcInputGrabbed = 1000,
hcQuickMenu,
};

#endif // TVTERM_CMDS_H

0 comments on commit f1ff82c

Please sign in to comment.