From bba16ed7756572db0d17c5f41aa2d61073a979fc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 14 Nov 2002 14:42:39 +0000 Subject: Browser already can display files and navigate down; TOOD: go up, choose svn-id: r5551 --- gui/ListWidget.cpp | 14 ++++++++ gui/ListWidget.h | 1 + gui/browser.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++----- gui/browser.h | 9 ++++- 4 files changed, 111 insertions(+), 9 deletions(-) (limited to 'gui') diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 3b1ff3df70..0af09fbfb5 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -65,6 +65,20 @@ void ListWidget::setList(const StringList& list) scrollBarRecalc(); } +void ListWidget::scrollTo(int item) +{ + int size = _list.size(); + if (item >= size) + item = size - 1; + else if (item < 0) + item = 0; + + if (_currentPos != item) { + _currentPos = item; + scrollBarRecalc(); + } +} + void ListWidget::scrollBarRecalc() { _scrollBar->_numEntries = _list.size(); diff --git a/gui/ListWidget.h b/gui/ListWidget.h index e00896a7f5..aca1d3eabf 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -67,6 +67,7 @@ public: void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; } bool isEditable() const { return _editable; } void setEditable(bool editable) { _editable = editable; } + void scrollTo(int item); virtual void handleTickle(); virtual void handleMouseDown(int x, int y, int button, int clickCount); diff --git a/gui/browser.cpp b/gui/browser.cpp index dd20b6c01c..48f30ee632 100644 --- a/gui/browser.cpp +++ b/gui/browser.cpp @@ -30,22 +30,102 @@ * - others??? */ +enum { + kChooseCmd = 'Chos', + kGoUpCmd = 'GoUp' +}; + BrowserDialog::BrowserDialog(NewGui *gui) - : Dialog(gui, 50, 20, 320-2*50, 200-2*20) + : Dialog(gui, 40, 10, 320-2*40, 200-2*10) { // Headline - TODO: should be customizable during creation time - new StaticTextWidget(this, 10, 10, _w-2*10, kLineHeight, + new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight, "Select directory with game data", kTextAlignCenter); + + // Current path - TODO: handle long paths ? + _currentPath = + new StaticTextWidget(this, 10, 20, _w-2*10, kLineHeight, + "DUMMY", kTextAlignLeft); // Add file list - _fileList = new ListWidget(this, 10, 20, _w-2*10, _h-20-24-10); + _fileList = new ListWidget(this, 10, 34, _w-2*10, _h-34-24-10); + _fileList->setNumberingMode(kListNumberingOff); // Buttons - addButton(10, _h-24, "Go up", kCloseCmd, 0); + addButton(10, _h-24, "Go up", kGoUpCmd, 0); addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0); - addButton(_w-(kButtonWidth+10), _h-24, "Choose", kCloseCmd, 0); + addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0); +} + +void BrowserDialog::open() +{ + // If no node has been set, or the last used one is now invalid, + // go back to the root/default dir. + if (_node == NULL || !_node->isValid()) { + delete _node; + _node = FilesystemNode::getRoot(); + assert(_node != NULL); + } + + // Alway refresh file list + updateListing(); + + // Call super implementation + Dialog::open(); +} + +void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) +{ + FilesystemNode *tmp; + + switch (cmd) { + case kChooseCmd: + // If nothing is selected in the list widget, choose the current dir. + // Else, choose the dir that is selected. + // TODO + close(); + break; + case kGoUpCmd: +/* + tmp = _node->parent(); + delete _node; + _node = tmp; + updateListing(); +*/ + break; + case kListItemDoubleClickedCmd: + tmp = (*_nodeContent)[data].clone(); + delete _node; + _node = tmp; + updateListing(); + break; + default: + Dialog::handleCommand(sender, cmd, data); + } +} + +void BrowserDialog::updateListing() +{ + assert(_node != NULL); - // TODO - populate list item, implement buttons, etc. etc. - // TODO - will the choose button select the directory we are currrently in?!? - // TODO - double clicking an item should traverse into that directory + // Update the path display + _currentPath->setLabel(_node->path()); + + // Read in the data from the file system + delete _nodeContent; + _nodeContent = _node->listDir(); + assert(_nodeContent != NULL); + + // Populate the ListWidget + ScummVM::StringList list; + int size = _nodeContent->size(); + for (int i = 0; i < size; i++) { + list.push_back((*_nodeContent)[i].displayName()); + } + _fileList->setList(list); + _fileList->scrollTo(0); + + // Finally, redraw + draw(); } + diff --git a/gui/browser.h b/gui/browser.h index a07f169eb3..015d0d536a 100644 --- a/gui/browser.h +++ b/gui/browser.h @@ -26,6 +26,8 @@ #include "common/list.h" class ListWidget; +class StaticTextWidget; + class FilesystemNode; class FSList; @@ -35,11 +37,16 @@ class BrowserDialog : public Dialog { public: BrowserDialog(NewGui *gui); + virtual void open(); + virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); + protected: ListWidget *_fileList; + StaticTextWidget*_currentPath; FilesystemNode *_node; - FSList *_content; + FSList *_nodeContent; + void updateListing(); }; #endif -- cgit v1.2.3