1
//============================================================================
5
// SS tttttt eeee ll ll aaaa
6
// SSSS tt ee ee ll ll aa
7
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8
// SS SS tt ee ll ll aa aa
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
13
// See the file "license" for information on usage and redistribution of
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: BrowserDialog.cxx,v 1.18 2006/03/20 13:23:13 stephena Exp $
18
// Based on code from ScummVM - Scumm Interpreter
19
// Copyright (C) 2002-2004 The ScummVM project
20
//============================================================================
22
#include "OSystem.hxx"
24
#include "StringListWidget.hxx"
27
#include "GuiObject.hxx"
28
#include "GuiUtils.hxx"
29
#include "BrowserDialog.hxx"
33
/* We want to use this as a general directory selector at some point... possible uses
34
* - to select the data dir for a game
35
* - to select the place where save games are stored
37
* TODO - make this dialog font sensitive
40
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41
BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
42
int x, int y, int w, int h)
43
: Dialog(boss->instance(), boss->parent(), x, y, w, h),
48
const int lineHeight = font.getLineHeight(),
49
bwidth = font.getStringWidth("Cancel") + 20,
50
bheight = font.getLineHeight() + 4;
54
_title = new StaticTextWidget(this, font, xpos, ypos,
55
_w - 2 * xpos, lineHeight,
56
"", kTextAlignCenter);
58
// Current path - TODO: handle long paths ?
59
ypos += lineHeight + 4;
60
_currentPath = new StaticTextWidget(this, font, xpos, ypos,
61
_w - 2 * xpos, lineHeight,
62
"DUMMY", kTextAlignLeft);
66
_fileList = new StringListWidget(this, font, xpos, ypos,
67
_w - 2 * xpos, _h - bheight - ypos - 15);
68
_fileList->setNumberingMode(kListNumberingOff);
69
_fileList->setEditable(false);
70
_fileList->setFlags(WIDGET_NODRAW_FOCUS);
71
addFocusWidget(_fileList);
74
xpos = 10; ypos = _h - bheight - 8;
75
_goUpButton = new ButtonWidget(this, font, xpos, ypos, bwidth, bheight,
76
"Go up", kGoUpCmd, 0);
78
xpos = _w - 2 *(bwidth + 10);
79
new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Choose",
82
new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Cancel",
85
xpos = _w - 2 *(bwidth + 10); ypos = _h - bheight - 8;
86
new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Cancel",
89
new ButtonWidget(this, font, xpos, ypos, bwidth, bheight, "Choose",
94
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95
void BrowserDialog::setStartPath(const string& startpath)
97
// If no node has been set, or the last used one is now invalid,
98
// go back to the root/default dir.
99
_choice = FilesystemNode(startpath);
101
if (_choice.isValid())
103
else if (!_node.isValid())
104
_node = FilesystemNode();
106
// Alway refresh file list
110
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111
void BrowserDialog::handleCommand(CommandSender* sender, int cmd,
118
// If nothing is selected in the list widget, choose the current dir.
119
// Else, choose the dir that is selected.
120
int selection = _fileList->getSelected();
121
if (selection >= 0 && selection < (int)_nodeContent.size())
122
_choice = _nodeContent[selection];
126
// Send a signal to the calling class that a selection has been made
127
// Since we aren't derived from a widget, we don't have a 'data' or 'id'
129
sendCommand(_cmd, 0, 0);
136
_node = _node.getParent();
140
case kListItemActivatedCmd:
141
case kListItemDoubleClickedCmd:
142
_node = _nodeContent[data];
147
Dialog::handleCommand(sender, cmd, data, 0);
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
void BrowserDialog::updateListing()
155
// Update the path display
156
_currentPath->setLabel(_node.path());
158
// Read in the data from the file system
159
_nodeContent = _node.listDir();
162
// Populate the ListWidget
164
int size = _nodeContent.size();
165
for (int i = 0; i < size; i++)
167
if(_nodeContent[i].isDirectory())
168
list.push_back(" [" + _nodeContent[i].displayName() + "]");
170
list.push_back(_nodeContent[i].displayName());
173
_fileList->setList(list);
175
_fileList->setSelected(0);
177
// Only hilite the 'up' button if there's a parent directory
178
_goUpButton->setEnabled(_node.hasParent());