2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-11-14 13:46:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-14 13:46:35 +00:00
|
|
|
*
|
2006-02-11 10:08:56 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-11-14 13:46:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-02 02:18:16 +00:00
|
|
|
#include "gui/browser.h"
|
2009-01-02 03:21:40 +00:00
|
|
|
#include "gui/GuiManager.h"
|
2003-11-02 02:18:16 +00:00
|
|
|
#include "gui/ListWidget.h"
|
2002-11-14 13:46:35 +00:00
|
|
|
|
2006-04-28 23:15:43 +00:00
|
|
|
#include "common/config-manager.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2007-05-23 12:02:31 +00:00
|
|
|
#include "common/algorithm.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
|
2010-06-15 10:44:51 +00:00
|
|
|
#include "common/translation.h"
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2005-04-10 14:49:57 +00:00
|
|
|
enum {
|
|
|
|
kChooseCmd = 'Chos',
|
|
|
|
kGoUpCmd = 'GoUp'
|
|
|
|
};
|
|
|
|
|
2002-11-14 13:46:35 +00:00
|
|
|
/* We want to use this as a general directory selector at some point... possible uses
|
|
|
|
* - to select the data dir for a game
|
|
|
|
* - to select the place where save games are stored
|
|
|
|
* - others???
|
|
|
|
*/
|
|
|
|
|
2005-04-16 17:55:09 +00:00
|
|
|
BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
|
2008-08-08 15:06:28 +00:00
|
|
|
: Dialog("Browser") {
|
2005-05-16 09:24:28 +00:00
|
|
|
|
2005-04-16 17:55:09 +00:00
|
|
|
_isDirBrowser = dirBrowser;
|
2003-04-30 13:57:57 +00:00
|
|
|
_fileList = NULL;
|
|
|
|
_currentPath = NULL;
|
|
|
|
|
2002-11-14 13:46:35 +00:00
|
|
|
// Headline - TODO: should be customizable during creation time
|
2008-08-08 15:06:28 +00:00
|
|
|
new StaticTextWidget(this, "Browser.Headline", title);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-11-14 14:42:39 +00:00
|
|
|
// Current path - TODO: handle long paths ?
|
2008-08-08 15:06:28 +00:00
|
|
|
_currentPath = new StaticTextWidget(this, "Browser.Path", "DUMMY");
|
2002-11-14 13:46:35 +00:00
|
|
|
|
|
|
|
// Add file list
|
2008-08-08 15:06:28 +00:00
|
|
|
_fileList = new ListWidget(this, "Browser.List");
|
2002-11-14 14:42:39 +00:00
|
|
|
_fileList->setNumberingMode(kListNumberingOff);
|
2004-11-21 13:39:54 +00:00
|
|
|
_fileList->setEditable(false);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2008-11-10 11:24:55 +00:00
|
|
|
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
|
2006-05-27 05:46:04 +00:00
|
|
|
|
2002-11-14 13:46:35 +00:00
|
|
|
// Buttons
|
2010-06-15 10:52:35 +00:00
|
|
|
new ButtonWidget(this, "Browser.Up", _("Go up"), _("Go to previous directory level"), kGoUpCmd);
|
|
|
|
new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
|
|
|
|
new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
|
2002-11-14 14:42:39 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 17:55:09 +00:00
|
|
|
void BrowserDialog::open() {
|
2009-01-10 22:31:15 +00:00
|
|
|
// Call super implementation
|
|
|
|
Dialog::open();
|
|
|
|
|
2006-04-28 23:15:43 +00:00
|
|
|
if (ConfMan.hasKey("browser_lastpath"))
|
2008-10-02 16:58:59 +00:00
|
|
|
_node = Common::FSNode(ConfMan.get("browser_lastpath"));
|
2006-05-04 03:44:50 +00:00
|
|
|
if (!_node.isDirectory())
|
2008-10-02 16:58:59 +00:00
|
|
|
_node = Common::FSNode(".");
|
2002-11-14 14:42:39 +00:00
|
|
|
|
|
|
|
// Alway refresh file list
|
|
|
|
updateListing();
|
|
|
|
}
|
|
|
|
|
2005-04-16 17:55:09 +00:00
|
|
|
void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2002-11-14 14:42:39 +00:00
|
|
|
switch (cmd) {
|
2005-04-16 17:55:09 +00:00
|
|
|
case kChooseCmd:
|
|
|
|
if (_isDirBrowser) {
|
2002-11-19 01:36:47 +00:00
|
|
|
// If nothing is selected in the list widget, choose the current dir.
|
|
|
|
// Else, choose the dir that is selected.
|
|
|
|
int selection = _fileList->getSelected();
|
2009-12-09 16:48:33 +00:00
|
|
|
if (selection >= 0)
|
2004-11-20 21:35:49 +00:00
|
|
|
_choice = _nodeContent[selection];
|
2009-12-09 16:48:33 +00:00
|
|
|
else
|
2004-11-20 21:35:49 +00:00
|
|
|
_choice = _node;
|
2002-11-19 01:36:47 +00:00
|
|
|
setResult(1);
|
|
|
|
close();
|
2005-04-16 17:55:09 +00:00
|
|
|
} else {
|
2005-04-10 14:33:44 +00:00
|
|
|
int selection = _fileList->getSelected();
|
|
|
|
if (selection < 0)
|
|
|
|
break;
|
|
|
|
if (_nodeContent[selection].isDirectory()) {
|
|
|
|
_node = _nodeContent[selection];
|
|
|
|
updateListing();
|
|
|
|
} else {
|
|
|
|
_choice = _nodeContent[selection];
|
|
|
|
setResult(1);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kGoUpCmd:
|
|
|
|
_node = _node.getParent();
|
|
|
|
updateListing();
|
|
|
|
break;
|
|
|
|
case kListItemActivatedCmd:
|
|
|
|
case kListItemDoubleClickedCmd:
|
|
|
|
if (_nodeContent[data].isDirectory()) {
|
|
|
|
_node = _nodeContent[data];
|
|
|
|
updateListing();
|
2009-12-09 16:48:33 +00:00
|
|
|
} else if (!_isDirBrowser) {
|
2005-04-10 14:33:44 +00:00
|
|
|
_choice = _nodeContent[data];
|
|
|
|
setResult(1);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
break;
|
2009-12-09 16:48:33 +00:00
|
|
|
case kListSelectionChangedCmd:
|
|
|
|
// We do not allow selecting directories in directory
|
|
|
|
// browser mode, thus we will invalidate the selection
|
|
|
|
// when the user selects an directory over here.
|
|
|
|
if (data != (uint32)-1 && _isDirBrowser && !_nodeContent[data].isDirectory())
|
|
|
|
_fileList->setSelected(-1);
|
|
|
|
break;
|
2005-04-10 14:33:44 +00:00
|
|
|
default:
|
|
|
|
Dialog::handleCommand(sender, cmd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 17:55:09 +00:00
|
|
|
void BrowserDialog::updateListing() {
|
2005-04-10 14:33:44 +00:00
|
|
|
// Update the path display
|
2007-06-05 21:02:35 +00:00
|
|
|
_currentPath->setLabel(_node.getPath());
|
2006-07-10 11:12:11 +00:00
|
|
|
|
2006-04-28 23:15:43 +00:00
|
|
|
// We memorize the last visited path.
|
2007-06-05 21:02:35 +00:00
|
|
|
ConfMan.set("browser_lastpath", _node.getPath());
|
2005-04-10 14:33:44 +00:00
|
|
|
|
|
|
|
// Read in the data from the file system
|
2009-12-09 16:48:33 +00:00
|
|
|
if (!_node.getChildren(_nodeContent, Common::FSNode::kListAll))
|
2006-07-10 11:12:11 +00:00
|
|
|
_nodeContent.clear();
|
2009-12-09 16:48:33 +00:00
|
|
|
else
|
2006-07-10 11:12:11 +00:00
|
|
|
Common::sort(_nodeContent.begin(), _nodeContent.end());
|
2005-04-10 14:33:44 +00:00
|
|
|
|
|
|
|
// Populate the ListWidget
|
2010-03-18 15:09:24 +00:00
|
|
|
ListWidget::StringArray list;
|
2009-12-09 16:48:33 +00:00
|
|
|
ListWidget::ColorList colors;
|
2008-09-03 11:22:51 +00:00
|
|
|
for (Common::FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) {
|
2009-12-09 16:48:33 +00:00
|
|
|
if (i->isDirectory())
|
2007-06-05 21:02:35 +00:00
|
|
|
list.push_back(i->getDisplayName() + "/");
|
2005-04-10 14:33:44 +00:00
|
|
|
else
|
2007-06-05 21:02:35 +00:00
|
|
|
list.push_back(i->getDisplayName());
|
2009-12-09 16:48:33 +00:00
|
|
|
|
|
|
|
if (_isDirBrowser) {
|
|
|
|
if (i->isDirectory())
|
|
|
|
colors.push_back(ThemeEngine::kFontColorNormal);
|
|
|
|
else
|
|
|
|
colors.push_back(ThemeEngine::kFontColorAlternate);
|
|
|
|
}
|
2005-04-10 14:33:44 +00:00
|
|
|
}
|
2009-12-09 16:48:33 +00:00
|
|
|
|
|
|
|
if (_isDirBrowser)
|
|
|
|
_fileList->setList(list, &colors);
|
|
|
|
else
|
|
|
|
_fileList->setList(list);
|
2005-04-10 14:33:44 +00:00
|
|
|
_fileList->scrollTo(0);
|
|
|
|
|
|
|
|
// Finally, redraw
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|