Improvements to laucher dialog

- Made quicksearch turned off in the launcher game list
- Turn ListWidget into CommandSender
- Turn quicksearch off in launcher game list
- Connect laucher list widget with search box so search is initiated by typing

svn-id: r41269
This commit is contained in:
Eugene Sandulenko 2009-06-06 17:54:28 +00:00
parent 5fc047dddf
commit f66da82f03
3 changed files with 42 additions and 28 deletions

View file

@ -33,8 +33,8 @@
namespace GUI { namespace GUI {
ListWidget::ListWidget(GuiObject *boss, const String &name) ListWidget::ListWidget(GuiObject *boss, const String &name, uint32 cmd)
: EditableWidget(boss, name) { : EditableWidget(boss, name), _cmd(cmd) {
_scrollBar = NULL; _scrollBar = NULL;
_textWidth = NULL; _textWidth = NULL;
@ -60,10 +60,12 @@ ListWidget::ListWidget(GuiObject *boss, const String &name)
// FIXME: This flag should come from widget definition // FIXME: This flag should come from widget definition
_editable = true; _editable = true;
_quickSelect = true;
} }
ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h) ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd)
: EditableWidget(boss, x, y, w, h) { : EditableWidget(boss, x, y, w, h), _cmd(cmd) {
_scrollBar = NULL; _scrollBar = NULL;
_textWidth = NULL; _textWidth = NULL;
@ -234,8 +236,6 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
// Quick selection mode: Go to first list item starting with this key // Quick selection mode: Go to first list item starting with this key
// (or a substring accumulated from the last couple key presses). // (or a substring accumulated from the last couple key presses).
// Only works in a useful fashion if the list entries are sorted. // Only works in a useful fashion if the list entries are sorted.
// TODO: Maybe this should be off by default, and instead we add a
// method "enableQuickSelect()" or so ?
uint32 time = getMillis(); uint32 time = getMillis();
if (_quickSelectTime < time) { if (_quickSelectTime < time) {
_quickSelectStr = (char)state.ascii; _quickSelectStr = (char)state.ascii;
@ -244,7 +244,7 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
} }
_quickSelectTime = time + 300; // TODO: Turn this into a proper constant (kQuickSelectDelay ?) _quickSelectTime = time + 300; // TODO: Turn this into a proper constant (kQuickSelectDelay ?)
if (_quickSelect) {
// FIXME: This is bad slow code (it scans the list linearly each time a // FIXME: This is bad slow code (it scans the list linearly each time a
// key is pressed); it could be much faster. Only of importance if we have // key is pressed); it could be much faster. Only of importance if we have
// quite big lists to deal with -- so for now we can live with this lazy // quite big lists to deal with -- so for now we can live with this lazy
@ -264,6 +264,9 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
} }
scrollToCurrent(); scrollToCurrent();
} else {
sendCommand(_cmd, 0);
}
} else if (_editMode) { } else if (_editMode) {
// Class EditableWidget handles all text editing related key presses for us // Class EditableWidget handles all text editing related key presses for us
handled = EditableWidget::handleKeyDown(state); handled = EditableWidget::handleKeyDown(state);

View file

@ -75,10 +75,13 @@ protected:
int _scrollBarWidth; int _scrollBarWidth;
String _filter; String _filter;
bool _quickSelect;
uint32 _cmd;
public: public:
ListWidget(GuiObject *boss, const String &name); ListWidget(GuiObject *boss, const String &name, uint32 cmd = 0);
ListWidget(GuiObject *boss, int x, int y, int w, int h); ListWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd = 0);
virtual ~ListWidget(); virtual ~ListWidget();
virtual Widget *findWidget(int x, int y); virtual Widget *findWidget(int x, int y);
@ -94,6 +97,8 @@ public:
void setEditable(bool editable) { _editable = editable; } void setEditable(bool editable) { _editable = editable; }
void scrollTo(int item); void scrollTo(int item);
void scrollToEnd(); void scrollToEnd();
void enableQuickSelect(bool enable) { _quickSelect = enable; }
String getQuickSelectString() const { return _quickSelectStr; }
void setFilter(const String &filter); void setFilter(const String &filter);

View file

@ -65,7 +65,7 @@ enum {
kLoadGameCmd = 'LOAD', kLoadGameCmd = 'LOAD',
kQuitCmd = 'QUIT', kQuitCmd = 'QUIT',
kSearchCmd = 'SRCH', kSearchCmd = 'SRCH',
kListSearchCmd = 'LSSR',
kCmdGlobalGraphicsOverride = 'OGFX', kCmdGlobalGraphicsOverride = 'OGFX',
kCmdGlobalAudioOverride = 'OSFX', kCmdGlobalAudioOverride = 'OSFX',
@ -523,9 +523,10 @@ LauncherDialog::LauncherDialog()
_searchWidget = new EditTextWidget(this, "Launcher.Search", _search, kSearchCmd); _searchWidget = new EditTextWidget(this, "Launcher.Search", _search, kSearchCmd);
// Add list with game titles // Add list with game titles
_list = new ListWidget(this, "Launcher.GameList"); _list = new ListWidget(this, "Launcher.GameList", kListSearchCmd);
_list->setEditable(false); _list->setEditable(false);
_list->setNumberingMode(kListNumberingOff); _list->setNumberingMode(kListNumberingOff);
_list->enableQuickSelect(false);
// Populate the list // Populate the list
@ -923,6 +924,11 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kSearchCmd: case kSearchCmd:
_list->setFilter(_searchWidget->getEditString()); _list->setFilter(_searchWidget->getEditString());
break; break;
case kListSearchCmd:
_searchWidget->setEditString(_list->getQuickSelectString());
_searchWidget->draw();
_list->setFilter(_list->getQuickSelectString());
break;
default: default:
Dialog::handleCommand(sender, cmd, data); Dialog::handleCommand(sender, cmd, data);
} }