UI - Keyboard shortcuts / actions for various things

Quit, play/stop, undo/redo
This commit is contained in:
Emmanuel BENOîT 2017-11-24 11:59:15 +01:00
parent bcf8843436
commit d16e583458
2 changed files with 47 additions and 12 deletions

View file

@ -136,23 +136,17 @@ void T_Main::initDemo( )
void T_Main::makeUI( ) void T_Main::makeUI( )
{ {
using namespace ImGui; using namespace ImGui;
auto& undo( Common::Undo( ) ); auto& main{ UI::Main( ) };
bool eSequencer{ sequencer }; bool eSequencer{ sequencer };
if ( BeginMainMenuBar( ) ) { if ( BeginMainMenuBar( ) ) {
if ( BeginMenu( "File" ) ) { if ( BeginMenu( "File" ) ) {
UI::Main( ).actionMenu( "Save curves" ); main.actionMenu( "Save curves" );
UI::Main( ).actionMenu( "Reload curves" ); main.actionMenu( "Reload curves" );
Separator( ); Separator( );
if ( MenuItem( "Undo" , "C-z" , false , undo.canUndo( ) ) ) { main.actionMenu( "Undo" );
undo.undo( ); main.actionMenu( "Redo" );
}
if ( MenuItem( "Redo" , "C-Z" , false , undo.canRedo( ) ) ) {
undo.redo( );
}
Separator( ); Separator( );
if ( MenuItem( "Quit" ) ) { main.actionMenu( "Quit" );
done = true;
}
EndMenu( ); EndMenu( );
} }
if ( BeginMenu( "Views" ) ) { if ( BeginMenu( "Views" ) ) {

View file

@ -1,4 +1,9 @@
#include "externals.hh" #include "externals.hh"
#include "common.hh"
#include "c-sync.hh"
#include "c-undo.hh"
#include "ui.hh" #include "ui.hh"
#include "ui-app.hh" #include "ui-app.hh"
#include "ui-imgui-sdl.hh" #include "ui-imgui-sdl.hh"
@ -75,6 +80,42 @@ T_UIApp::T_UIApp( )
FontAwesome__compressed_data_base85 , 9.f , FontAwesome__compressed_data_base85 , 9.f ,
&icons , IconsRanges_ ); &icons , IconsRanges_ );
} }
//----------------------------------------------------------------------
// Keyboard shortcuts for undo/redo/quit/etc.
addAction( T_UIAction{ "Undo" , []() {
Common::Undo( ).undo( );
} }.setEnabledCheck( []() {
return Common::Undo( ).canUndo( );
} ).setIcon( ICON_FA_UNDO )
.setShortcut( T_KeyboardShortcut{ 'z' , E_KbdMod::CTRL } ) );
addAction( T_UIAction{ "Redo" , []() {
Common::Undo( ).redo( );
} }.setEnabledCheck( []() {
return Common::Undo( ).canRedo( );
} ).setShortcut( T_KeyboardShortcut{ 'z' , { E_KbdMod::CTRL , E_KbdMod::SHIFT } } ) );
addAction( T_UIAction{ "Play" , []() {
Common::Sync( ).playing( ) = true;
} }.setEnabledCheck( []() {
auto const& s{ Common::Sync( ) };
return !s.playing( ) && !s.finished( );
} ).setIcon( ICON_FA_PLAY )
.setShortcut( T_KeyboardShortcut{ ' ' } ) );
addAction( T_UIAction{ "Stop" , []() {
Common::Sync( ).playing( ) = false;
} }.setEnabledCheck( []() {
auto const& s{ Common::Sync( ) };
return s.playing( );
} ).setIcon( ICON_FA_STOP )
.setShortcut( T_KeyboardShortcut{ ' ' } ) );
addAction( T_UIAction{ "Quit" , [this]() {
exiting_ = true;
} }.setShortcut( T_KeyboardShortcut{ 'q' , E_KbdMod::CTRL } ) );
} }
T_UIApp::~T_UIApp( ) T_UIApp::~T_UIApp( )