From 4bbec51a6f478ce5fd8d18af0c9cb26e803eb705 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 14 Nov 2012 09:07:09 -0600 Subject: [PATCH] Added Exit command to the menu. --- changelog.txt | 3 +++ src/components/GuiMenu.cpp | 22 ++++++++++++++++++---- src/components/GuiMenu.h | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index fe9ce7ce1..405627c5d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +November 14 +-Added Exit command to the menu. + October 31 -Added custom font support. Check out THEMES.md. -Happy halloween! diff --git a/src/components/GuiMenu.cpp b/src/components/GuiMenu.cpp index c3ccee996..e99d30baf 100644 --- a/src/components/GuiMenu.cpp +++ b/src/components/GuiMenu.cpp @@ -1,5 +1,6 @@ #include "GuiMenu.h" #include +#include GuiMenu::GuiMenu(GuiComponent* parent) { @@ -41,10 +42,21 @@ void GuiMenu::onInput(InputManager::InputButton button, bool keyDown) if(button == InputManager::BUTTON1 && keyDown) { - if(system(mList->getSelectedObject().c_str()) != 0) - { - std::cout << "(menu command terminated with a nonzero errorcode)\n"; - } + executeCommand(mList->getSelectedObject()); + } +} + +void GuiMenu::executeCommand(std::string command) +{ + if(command == "exit") + { + //push SDL quit event + SDL_Event* event = new SDL_Event(); + event->type = SDL_QUIT; + SDL_PushEvent(event); + }else{ + if(system(command.c_str()) != 0) + std::cout << "(warning: command terminated with nonzero result!)\n"; } } @@ -56,8 +68,10 @@ void GuiMenu::populateList() //commands added here are called with system() when selected (so are executed as shell commands) //the method is GuiList::addObject(std::string displayString, std::string commandString, unsigned int displayHexColor); //the list will automatically adjust as items are added to it, this should be the only area you need to change + //if you want to do something special within ES, override your command in the executeComand() method mList->addObject("Restart", "sudo shutdown -r now", 0x0000FFFF); mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FFFF); + mList->addObject("Exit", "exit", 0xFF0000FF); //a special case; pushes an SDL quit event to the event stack instead of being called by system() } void GuiMenu::onRender() diff --git a/src/components/GuiMenu.h b/src/components/GuiMenu.h index ac7223c82..981383ebc 100644 --- a/src/components/GuiMenu.h +++ b/src/components/GuiMenu.h @@ -19,6 +19,7 @@ private: GuiList* mList; void populateList(); + void executeCommand(std::string command); bool mSkippedMenuClose; };