diff options
Diffstat (limited to 'commands.cpp')
-rw-r--r-- | commands.cpp | 128 |
1 files changed, 119 insertions, 9 deletions
diff --git a/commands.cpp b/commands.cpp index 029978c..e9a9d91 100644 --- a/commands.cpp +++ b/commands.cpp @@ -17,7 +17,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * $Id: commands.cpp 140 2008-06-30 22:10:38Z tom $ + * $Id: commands.cpp 142 2008-07-06 15:50:02Z tom $ */ #include "commands.h" @@ -28,9 +28,125 @@ #include <vdr/osd.h> #include <assert.h> + +namespace SudokuPlugin +{ + /** Command ids */ + enum + { + Cmd_LowerEdge = 100, + CmdGenerate, + CmdReset, + CmdExit, + CmdMark, + CmdNextCell, + CmdNextNumber, + CmdLoad, + CmdSave, + CmdSetup, + CmdUndo, + CmdRedo, + // Add new command ids only here, don't remove commands. + Cmd_UpperEdge, + Cmd_Count = Cmd_UpperEdge-Cmd_LowerEdge-1, + // Default commands + Cmd_KeyRedDefault = CmdMark, + Cmd_KeyGreenDefault = CmdUndo, + Cmd_KeyYellowDefault = CmdRedo + }; +} // namespace SudokuPlugin + + using namespace SudokuPlugin; +//--- class SudokuPlugin::CommandList ------------------------------------------ + +/** List of commands - sorted for the commands menu */ +const struct CommandList::List CommandList::list[] = +{ + { CmdGenerate, trNOOP("Generate a new puzzle"), &Menu::generate }, + { CmdLoad, trNOOP("Load a puzzle"), &Menu::load }, + { CmdSave, trNOOP("Save the puzzle"), &Menu::save }, + { CmdUndo, trNOOP("Undo last action"), &Menu::undo }, + { CmdRedo, trNOOP("Redo last action"), &Menu::redo }, + { CmdMark, trNOOP("Mark/unmark"), &Menu::toggle_mark }, + { CmdNextCell, trNOOP("Next cell"), &Menu::next_cell }, + { CmdNextNumber, trNOOP("Next number"), &Menu::next_number }, + { CmdReset, trNOOP("Reset the puzzle"), &Menu::reset }, + { CmdSetup, trNOOP("Open setup menu"), &Menu::open_setup }, + { CmdExit, trNOOP("Exit"), &Menu::exit } +}; + +/** Command id of a command */ +int CommandList::id(int index) +{ + assert(index >= 0 && index < count()); + return list[index].id; +} + +/** Translated text of a command */ +const char* CommandList::text(int index) +{ + assert(index >= 0 && index < count()); + return tr(list[index].text); +} + +/** Command type of a command */ +CommandType CommandList::command(int index) +{ + assert(index >= 0 && index < count()); + return list[index].cmd; +} + +/** Count of commands */ +int CommandList::count() +{ + assert(Cmd_Count == sizeof(list)/sizeof(*list)); + return Cmd_Count; +} + +/** List with translated texts of all commands */ +const char* const* CommandList::texts() +{ + static const char* text_list[Cmd_Count]; + for (int idx = 0; idx < count(); ++idx) + text_list[idx] = tr(list[idx].text); + return text_list; +} + +/** Search a command id. Return default index if not found. */ +int CommandList::id_to_index(int id, int default_index) +{ + int idx = 0; + for (; idx < count(); ++idx) + if (list[idx].id == id) + break; + if (idx >= count()) + idx = default_index; + assert(idx >= 0 && idx < count()); + return idx; +} + +/** Default index for the red key */ +int CommandList::key_red_default_index() +{ + return id_to_index(Cmd_KeyRedDefault); +} + +/** Default index for the green key */ +int CommandList::key_green_default_index() +{ + return id_to_index(Cmd_KeyGreenDefault); +} + +/** Default index for the yellow key */ +int CommandList::key_yellow_default_index() +{ + return id_to_index(Cmd_KeyYellowDefault); +} + + //--- class SudokuPlugin::CommandMenu ------------------------------------------ /** Constructor */ @@ -38,14 +154,8 @@ CommandMenu::CommandMenu() : cOsdMenu(trVDR("Commands")) { SetHasHotkeys(); - Add(new Command(hk(tr("Generate a new puzzle")), &Menu::generate)); - Add(new Command(hk(tr("Load a puzzle")), &Menu::load)); - Add(new Command(hk(tr("Save the puzzle")), &Menu::save)); - Add(new Command(hk(tr("Undo last action")), &Menu::undo)); - Add(new Command(hk(tr("Redo last action")), &Menu::redo)); - Add(new Command(hk(tr("Reset the puzzle")), &Menu::reset)); - Add(new Command(hk(tr("Open setup menu")), &Menu::open_setup)); - Add(new Command(hk(tr("Exit")), &Menu::exit)); + for (int idx = 0; idx < CommandList::count(); ++idx) + Add(new Command(hk(CommandList::text(idx)), CommandList::command(idx))); command = NULL; } |