Added Exit command to the menu.

This commit is contained in:
Aloshi 2012-11-14 09:07:09 -06:00
parent 38bbbb3fb7
commit 4bbec51a6f
3 changed files with 22 additions and 4 deletions

View file

@ -1,3 +1,6 @@
November 14
-Added Exit command to the menu.
October 31 October 31
-Added custom font support. Check out THEMES.md. -Added custom font support. Check out THEMES.md.
-Happy halloween! -Happy halloween!

View file

@ -1,5 +1,6 @@
#include "GuiMenu.h" #include "GuiMenu.h"
#include <iostream> #include <iostream>
#include <SDL/SDL.h>
GuiMenu::GuiMenu(GuiComponent* parent) GuiMenu::GuiMenu(GuiComponent* parent)
{ {
@ -41,10 +42,21 @@ void GuiMenu::onInput(InputManager::InputButton button, bool keyDown)
if(button == InputManager::BUTTON1 && keyDown) if(button == InputManager::BUTTON1 && keyDown)
{ {
if(system(mList->getSelectedObject().c_str()) != 0) executeCommand(mList->getSelectedObject());
{ }
std::cout << "(menu command terminated with a nonzero errorcode)\n"; }
}
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) //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 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 //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("Restart", "sudo shutdown -r now", 0x0000FFFF);
mList->addObject("Shutdown", "sudo shutdown -h 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() void GuiMenu::onRender()

View file

@ -19,6 +19,7 @@ private:
GuiList<std::string>* mList; GuiList<std::string>* mList;
void populateList(); void populateList();
void executeCommand(std::string command);
bool mSkippedMenuClose; bool mSkippedMenuClose;
}; };