GUI: Fix some GUI hacks, add some comments, etc.

* Rename LauncherDialog::selectGame() to selectTarget()
* Get rid of the 'temp_selection' ConfMan entry hack
* Add some Doxygen comments
* Turn a printf(...) into a debug(1,...)
* Don't scroll around if 'Mass Add' is cancelled

svn-id: r46380
This commit is contained in:
Max Horn 2009-12-15 08:19:34 +00:00
parent f692015301
commit 605037342b
4 changed files with 52 additions and 18 deletions

View file

@ -538,7 +538,7 @@ LauncherDialog::LauncherDialog()
// Restore last selection
String last(ConfMan.get("lastselectedgame", ConfigManager::kApplicationDomain));
selectGame(last);
selectTarget(last);
// En-/disable the buttons depending on the list selection
updateButtons();
@ -550,12 +550,12 @@ LauncherDialog::LauncherDialog()
_loadDialog = new SaveLoadChooser("Load game:", "Load");
}
void LauncherDialog::selectGame(const String &name) {
if (!name.empty()) {
void LauncherDialog::selectTarget(const String &target) {
if (!target.empty()) {
int itemToSelect = 0;
StringList::const_iterator iter;
for (iter = _domains.begin(); iter != _domains.end(); ++iter, ++itemToSelect) {
if (name == *iter) {
if (target == *iter) {
_list->setSelected(itemToSelect);
break;
}
@ -657,19 +657,17 @@ void LauncherDialog::addGame() {
if (alert.runModal() == GUI::kMessageOK && _browser->runModal() > 0) {
MassAddDialog massAddDlg(_browser->getResult());
if (_list->getSelected() != -1) {
// Save current game position, so on cancel cursor will move back
ConfMan.set("temp_selection", _domains[_list->getSelected()], ConfigManager::kApplicationDomain);
}
massAddDlg.runModal();
// Update the ListWidget and force a redraw
updateListing();
// Set cursor to first detected game
selectGame(ConfMan.get("temp_selection", ConfigManager::kApplicationDomain));
ConfMan.removeKey("temp_selection", ConfigManager::kApplicationDomain);
// If new target(s) were added, update the ListWidget and move
// the selection to to first newly detected game.
Common::String newTarget = massAddDlg.getFirtAddedTarget();
if (!newTarget.empty()) {
updateListing();
selectTarget(newTarget);
}
draw();
}
@ -750,7 +748,7 @@ void LauncherDialog::addGame() {
// Update the ListWidget, select the new item, and force a redraw
updateListing();
selectGame(editDialog.getDomain());
selectTarget(editDialog.getDomain());
draw();
} else {
// User aborted, remove the the new domain again
@ -840,7 +838,7 @@ void LauncherDialog::editGame(int item) {
// Update the ListWidget, reselect the edited game and force a redraw
updateListing();
selectGame(editDialog.getDomain());
selectTarget(editDialog.getDomain());
draw();
}
}
@ -923,7 +921,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kStartCmd:
case kListItemActivatedCmd:
case kListItemDoubleClickedCmd:
// Print out what was selected
// Start the selected game.
assert(item >= 0);
ConfMan.setActiveDomain(_domains[item]);
close();
@ -940,9 +938,11 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
close();
break;
case kSearchCmd:
// Update the active search filter.
_list->setFilter(_searchWidget->getEditString());
break;
case kSearchClearCmd:
// Reset the active search filter, thus showing all games again
_searchWidget->setEditString("");
_list->setFilter("");
break;

View file

@ -72,17 +72,44 @@ protected:
virtual void reflowLayout();
/**
* Fill the list widget with all currently configured targets, and trigger
* a redraw.
*/
void updateListing();
void updateButtons();
void open();
void close();
/**
* Handle "Add game..." button.
*/
virtual void addGame();
/**
* Handle "Remove game..." button.
*/
void removeGame(int item);
/**
* Handle "Edit game..." button.
*/
void editGame(int item);
/**
* Handle "Load..." button.
*/
void loadGame(int item);
void selectGame(const String &name);
/**
* Select the target with the given name in the launcher game list.
* Also scrolls the list so that the newly selected item is visible.
*
* @target name of target to select
*/
void selectTarget(const String &target);
};
} // End of namespace GUI

View file

@ -139,7 +139,7 @@ void MassAddDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
sort(_games.begin(), _games.end(), GameTargetLess());
// Add all the detected games to the config
for (GameList::iterator iter = _games.begin(); iter != _games.end(); ++iter) {
printf(" Added gameid '%s', desc '%s'\n",
debug(1, " Added gameid '%s', desc '%s'\n",
(*iter)["gameid"].c_str(),
(*iter)["description"].c_str());
(*iter)["gameid"] = addGameToConf(*iter);
@ -157,6 +157,7 @@ void MassAddDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
close();
} else if (cmd == kCancelCmd) {
// User cancelled, so we don't do anything and just leave.
_games.clear();
close();
} else {
Dialog::handleCommand(sender, cmd, data);

View file

@ -44,6 +44,12 @@ public:
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
void handleTickle();
Common::String getFirtAddedTarget() const {
if (!_games.empty())
return _games.front().gameid();
return Common::String();
}
private:
Common::Stack<Common::FSNode> _scanStack;
GameList _games;