diff options
author | Max Horn | 2004-10-01 21:12:18 +0000 |
---|---|---|
committer | Max Horn | 2004-10-01 21:12:18 +0000 |
commit | ee3158cb8ca8b05d7c1a474f09ade8ac91209fbc (patch) | |
tree | 33a41f126af456cf18e93b338ca3d8be391be89b | |
parent | ca12f3f996bd8775002c58248dc8e2fb133d4caa (diff) | |
download | scummvm-rg350-ee3158cb8ca8b05d7c1a474f09ade8ac91209fbc.tar.gz scummvm-rg350-ee3158cb8ca8b05d7c1a474f09ade8ac91209fbc.tar.bz2 scummvm-rg350-ee3158cb8ca8b05d7c1a474f09ade8ac91209fbc.zip |
Patch #896096 (Restoring last selected game selection) with some personal modifications
svn-id: r15372
-rw-r--r-- | gui/ListWidget.cpp | 24 | ||||
-rw-r--r-- | gui/ListWidget.h | 1 | ||||
-rw-r--r-- | gui/launcher.cpp | 30 | ||||
-rw-r--r-- | gui/launcher.h | 1 |
4 files changed, 51 insertions, 5 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 506785e332..b1efd5a38d 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -53,6 +53,28 @@ ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h) ListWidget::~ListWidget() { } +void ListWidget::setSelected(int item) { + assert(item >= -1 && item < (int)_list.size()); + + if (isEnabled() && _selectedItem != item) { + int oldSelectedItem = _selectedItem; + _selectedItem = item; + + if (_editMode) { + // undo any changes made + _list[oldSelectedItem] = _backupString; + _editMode = false; + drawCaret(true); + } + + sendCommand(kListSelectionChangedCmd, _selectedItem); + + _currentPos = _selectedItem - _entriesPerPage / 2; + scrollToCurrent(); + draw(); + } +} + void ListWidget::setList(const StringList &list) { if (_editMode && _caretVisible) drawCaret(true); @@ -379,6 +401,8 @@ void ListWidget::scrollToCurrent() { if (_currentPos < 0) _currentPos = 0; + else if (_currentPos + _entriesPerPage > (int)_list.size()) + _currentPos = _list.size() - _entriesPerPage; _scrollBar->_currentPos = _currentPos; _scrollBar->recalc(); diff --git a/gui/ListWidget.h b/gui/ListWidget.h index f2e9092660..05543e4e57 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -69,6 +69,7 @@ public: void setList(const StringList& list); const StringList& getList() const { return _list; } int getSelected() const { return _selectedItem; } + void setSelected(int item); const String& getSelectedString() const { return _list[_selectedItem]; } void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; } bool isEditable() const { return _editable; } diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 54fc742268..23764fda90 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -421,9 +421,19 @@ LauncherDialog::LauncherDialog(GameDetector &detector) // Populate the list updateListing(); - // TODO - make a default selection (maybe the game user played last?) - //_list->setSelected(0); - + // Restore last selection + String last = ConfMan.get(String("lastselectedgame"), ConfigManager::kApplicationDomain); + if (!last.isEmpty()) { + int itemToSelect = 0; + StringList::const_iterator iter; + for (iter = _domains.begin(); iter != _domains.end(); ++iter, ++itemToSelect) { + if (last == *iter) { + _list->setSelected(itemToSelect); + break; + } + } + } + // En-/Disable the buttons depending on the list selection updateButtons(); @@ -435,6 +445,18 @@ LauncherDialog::~LauncherDialog() { delete _browser; } +void LauncherDialog::close() { + // Save last selection + const int sel = _list->getSelected(); + if (sel >= 0) + ConfMan.set(String("lastselectedgame"), _domains[sel], ConfigManager::kApplicationDomain); + else + ConfMan.removeKey(String("lastselectedgame"), ConfigManager::kApplicationDomain); + + ConfMan.flushToDisk(); + Dialog::close(); +} + void LauncherDialog::updateListing() { Common::StringList l; @@ -654,9 +676,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat updateButtons(); break; case kQuitCmd: -#ifdef __PALM_OS__ close(); -#endif g_system->quit(); break; default: diff --git a/gui/launcher.h b/gui/launcher.h index 8823048174..a58146c11a 100644 --- a/gui/launcher.h +++ b/gui/launcher.h @@ -52,6 +52,7 @@ protected: void updateListing(); void updateButtons(); + void close(); virtual void addGame(); void removeGame(int item); void editGame(int item); |