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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2002-11-14 13:46:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-02 02:18:16 +00:00
|
|
|
#include "gui/browser.h"
|
2018-01-06 15:13:29 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2018-08-18 06:37:59 +00:00
|
|
|
#include "gui/widgets/edittext.h"
|
2010-11-16 10:11:57 +00:00
|
|
|
#include "gui/widgets/list.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"
|
2018-11-20 02:11:59 +00:00
|
|
|
#if defined(USE_SYSDIALOGS)
|
|
|
|
#include "common/dialogs.h"
|
|
|
|
#endif
|
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',
|
2013-01-27 18:11:20 +00:00
|
|
|
kGoUpCmd = 'GoUp',
|
2018-08-27 04:39:40 +00:00
|
|
|
kHiddenCmd = 'Hidd',
|
|
|
|
kPathEditedCmd = 'Path'
|
2005-04-10 14:49:57 +00:00
|
|
|
};
|
|
|
|
|
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???
|
|
|
|
*/
|
|
|
|
|
2020-06-13 16:42:25 +00:00
|
|
|
BrowserDialog::BrowserDialog(const Common::U32String &title, bool dirBrowser)
|
2008-08-08 15:06:28 +00:00
|
|
|
: Dialog("Browser") {
|
2005-05-16 09:24:28 +00:00
|
|
|
|
2018-11-20 02:11:59 +00:00
|
|
|
_title = title;
|
2005-04-16 17:55:09 +00:00
|
|
|
_isDirBrowser = dirBrowser;
|
2020-01-05 16:48:04 +00:00
|
|
|
_fileList = nullptr;
|
|
|
|
_currentPath = nullptr;
|
2016-08-29 06:03:40 +00:00
|
|
|
_showHidden = false;
|
2003-04-30 13:57:57 +00:00
|
|
|
|
2002-11-14 13:46:35 +00:00
|
|
|
// Headline - TODO: should be customizable during creation time
|
2020-06-11 15:55:05 +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 ?
|
2020-11-15 18:15:58 +00:00
|
|
|
_currentPath = new EditTextWidget(this, "Browser.Path", Common::U32String(), Common::U32String(), 0, kPathEditedCmd);
|
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
|
|
|
|
2013-01-27 18:11:20 +00:00
|
|
|
// Checkbox for the "show hidden files" state.
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
_showHiddenWidget = new CheckboxWidget(this, "Browser.Hidden", _("Show hidden files"), _("Show files marked with the hidden attribute"), kHiddenCmd);
|
2013-01-27 18:11:20 +00:00
|
|
|
|
2002-11-14 13:46:35 +00:00
|
|
|
// Buttons
|
2010-09-12 11:43:51 +00:00
|
|
|
if (g_system->getOverlayWidth() > 320)
|
2020-07-01 18:01:48 +00:00
|
|
|
new ButtonWidget(this, "Browser.Up", _("Go up"), _("Go to previous directory level"), kGoUpCmd);
|
2010-09-12 11:43:51 +00:00
|
|
|
else
|
2020-07-01 18:01:48 +00:00
|
|
|
new ButtonWidget(this, "Browser.Up", _c("Go up", "lowres"), _("Go to previous directory level"), kGoUpCmd);
|
2020-11-15 18:15:58 +00:00
|
|
|
new ButtonWidget(this, "Browser.Cancel", _("Cancel"), Common::U32String(), kCloseCmd);
|
|
|
|
new ButtonWidget(this, "Browser.Choose", _("Choose"), Common::U32String(), kChooseCmd);
|
2002-11-14 14:42:39 +00:00
|
|
|
}
|
|
|
|
|
2018-11-20 02:11:59 +00:00
|
|
|
int BrowserDialog::runModal() {
|
|
|
|
#if defined(USE_SYSDIALOGS)
|
|
|
|
// Try to use the backend browser
|
|
|
|
Common::DialogManager *dialogManager = g_system->getDialogManager();
|
|
|
|
if (dialogManager) {
|
2018-11-22 16:26:04 +00:00
|
|
|
if (ConfMan.getBool("gui_browser_native", Common::ConfigManager::kApplicationDomain)) {
|
2020-07-21 21:32:55 +00:00
|
|
|
Common::DialogManager::DialogResult result = dialogManager->showFileBrowser(_title, _choice, _isDirBrowser);
|
2018-11-22 16:26:04 +00:00
|
|
|
if (result != Common::DialogManager::kDialogError) {
|
|
|
|
return result;
|
|
|
|
}
|
2018-11-20 02:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// If all else fails, use the GUI browser
|
|
|
|
return Dialog::runModal();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2016-08-29 06:03:40 +00:00
|
|
|
_showHidden = ConfMan.getBool("gui_browser_show_hidden", Common::ConfigManager::kApplicationDomain);
|
|
|
|
_showHiddenWidget->setState(_showHidden);
|
|
|
|
|
|
|
|
// At this point the file list has already been refreshed by the kHiddenCmd handler
|
2002-11-14 14:42:39 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2018-08-18 06:37:59 +00:00
|
|
|
//Search for typed-in directory
|
2018-08-27 04:39:40 +00:00
|
|
|
case kPathEditedCmd:
|
2020-06-11 15:55:05 +00:00
|
|
|
_node = Common::FSNode(Common::convertFromU32String(_currentPath->getEditString()));
|
2018-08-18 06:37:59 +00:00
|
|
|
updateListing();
|
|
|
|
break;
|
|
|
|
//Search by text input
|
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;
|
2013-01-27 18:11:20 +00:00
|
|
|
case kHiddenCmd:
|
|
|
|
// Update whether the user wants hidden files to be shown
|
|
|
|
_showHidden = _showHiddenWidget->getState();
|
|
|
|
// We save the state in the application domain to avoid cluttering and
|
|
|
|
// to prevent odd behavior.
|
|
|
|
ConfMan.setBool("gui_browser_show_hidden", _showHidden, Common::ConfigManager::kApplicationDomain);
|
|
|
|
// Update the file listing
|
|
|
|
updateListing();
|
|
|
|
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
|
2018-08-18 06:37:59 +00:00
|
|
|
_currentPath->setEditString(_node.getPath());
|
2006-07-10 11:12:11 +00:00
|
|
|
|
2006-04-28 23:15:43 +00:00
|
|
|
// We memorize the last visited path.
|
2020-02-10 22:54:56 +00:00
|
|
|
// Don't memorize a path that is not a directory
|
|
|
|
if (_node.isDirectory()) {
|
|
|
|
ConfMan.set("browser_lastpath", _node.getPath());
|
|
|
|
}
|
2005-04-10 14:33:44 +00:00
|
|
|
|
|
|
|
// Read in the data from the file system
|
2013-01-27 18:11:20 +00:00
|
|
|
if (!_node.getChildren(_nodeContent, Common::FSNode::kListAll, _showHidden))
|
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
|
2020-06-11 15:55:05 +00:00
|
|
|
ListWidget::U32StringArray 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
|
2018-01-06 15:13:29 +00:00
|
|
|
g_gui.scheduleTopDialogRedraw();
|
2005-04-10 14:33:44 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|