refactored file navigation bar into own class

enhanced BrowserDialog
This commit is contained in:
Thomas Jentzsch 2021-12-13 15:38:59 +01:00
parent 143cf9fa13
commit 1e0da2177d
9 changed files with 136 additions and 171 deletions

View File

@ -23,6 +23,7 @@
#include "FrameBuffer.hxx"
#include "EditTextWidget.hxx"
#include "FileListWidget.hxx"
#include "NavigationWidget.hxx"
#include "Widget.hxx"
#include "Font.hxx"
#include "BrowserDialog.hxx"
@ -51,10 +52,7 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
xpos = HBORDER; ypos = VBORDER + _th;
// Current path - TODO: handle long paths ?
StaticTextWidget* t = new StaticTextWidget(this, font, xpos, ypos + 2, "Path ");
_currentPath = new EditTextWidget(this, font, xpos + t->getWidth(), ypos,
_w - t->getWidth() - 2 * xpos, lineHeight);
_currentPath->setEditable(false);
_navigationBar = new NavigationWidget(this, font, xpos, ypos, _w - HBORDER * 2, lineHeight);
xpos = _w - (HBORDER + _font.getStringWidth("Save") + CheckboxWidget::prefixSize(_font));
_savePathBox = new CheckboxWidget(this, font, xpos, ypos + 2, "Save");
@ -66,6 +64,7 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
_h - selectHeight - buttonHeight - ypos - VBORDER * 2);
_fileList->setEditable(false);
addFocusWidget(_fileList);
_navigationBar->setList(_fileList);
// Add currently selected item
ypos += _fileList->getHeight() + VGAP * 2;
@ -183,8 +182,8 @@ void BrowserDialog::show(const string& startpath,
_fileList->setListMode(FilesystemNode::ListMode::All);
_fileList->setNameFilter(namefilter);
_fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop());
_currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth);
// Show "save" checkbox
_navigationBar->setWidth(_savePathBox->getLeft() - _navigationBar->getLeft() - fontWidth);
_savePathBox->setEnabled(true);
_savePathBox->clearFlags(Widget::FLAG_INVISIBLE);
_savePathBox->setState(instance().settings().getBool("saveuserdir"));
@ -200,8 +199,8 @@ void BrowserDialog::show(const string& startpath,
_fileList->setListMode(FilesystemNode::ListMode::All);
_fileList->setNameFilter(namefilter);
_fileList->setHeight(_selected->getTop() - VGAP * 2 - _fileList->getTop());
_currentPath->setWidth(_savePathBox->getLeft() - _currentPath->getLeft() - fontWidth);
// Show "save" checkbox
_navigationBar->setWidth(_savePathBox->getLeft() - _navigationBar->getLeft() - fontWidth);
_savePathBox->setEnabled(true);
_savePathBox->clearFlags(Widget::FLAG_INVISIBLE);
_savePathBox->setState(instance().settings().getBool("saveuserdir"));
@ -220,8 +219,8 @@ void BrowserDialog::show(const string& startpath,
_fileList->setNameFilter([](const FilesystemNode&) { return true; });
// TODO: scrollbar affected too!
_fileList->setHeight(_selected->getBottom() - _fileList->getTop());
_currentPath->setWidth(_savePathBox->getRight() - _currentPath->getLeft());
// Hide "save" checkbox
_navigationBar->setWidth(_savePathBox->getRight() - _navigationBar->getLeft());
_savePathBox->setEnabled(false);
_savePathBox->setFlags(Widget::FLAG_INVISIBLE);
@ -259,6 +258,16 @@ const FilesystemNode& BrowserDialog::getResult() const
return _fileList->currentDir();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BrowserDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
{
// Grab the key before passing it to the actual dialog and check for
// file list navigation keys
// Required because BrowserDialog does not want raw input
if(repeated || !_fileList->handleKeyDown(key, mod))
Dialog::handleKeyDown(key, mod, repeated);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void BrowserDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)
@ -320,7 +329,7 @@ void BrowserDialog::updateUI(bool fileSelected)
_goUpButton->setEnabled(_fileList->currentDir().hasParent());
// Update the path display
_currentPath->setText(_fileList->currentDir().getShortPath());
_navigationBar->updateUI();
// Enable/disable OK button based on current mode and status
bool enable = true;

View File

@ -22,6 +22,7 @@ class GuiObject;
class ButtonWidget;
class EditTextWidget;
class FileListWidget;
class NavigationWidget;
class StaticTextWidget;
#include "Dialog.hxx"
@ -103,6 +104,7 @@ class BrowserDialog : public Dialog
/** Get resulting file node (called after receiving kChooseCmd) */
const FilesystemNode& getResult() const;
void handleKeyDown(StellaKey key, StellaMod mod, bool repeated) override;
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
void updateUI(bool fileSelected);
@ -119,7 +121,7 @@ class BrowserDialog : public Dialog
Command _command{[](bool, const FilesystemNode&){}};
FileListWidget* _fileList{nullptr};
EditTextWidget* _currentPath{nullptr};
NavigationWidget* _navigationBar{nullptr};
StaticTextWidget* _name{nullptr};
EditTextWidget* _selected{nullptr};
ButtonWidget* _goUpButton{nullptr};

View File

@ -76,8 +76,6 @@ void FileListWidget::setDirectory(const FilesystemNode& node,
void FileListWidget::setLocation(const FilesystemNode& node,
const string select)
{
cerr << node.getPath() << " : " << select << endl;
progress().resetProgress();
progress().open();
FilesystemNode::CancelCheck isCancelled = [this]() {
@ -286,6 +284,47 @@ void FileListWidget::incProgress()
progress().incProgress();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FileListWidget::handleKeyDown(StellaKey key, StellaMod mod)
{
// Grab the key before passing it to the actual dialog and check for
// file list navigation keys
bool handled = false;
if(StellaModTest::isAlt(mod))
{
handled = true;
cerr << " " << mod << ", " << key << endl;
switch(key)
{
case KBDK_HOME:
sendCommand(kHomeDirCmd, 0, 0);
break;
case KBDK_LEFT:
sendCommand(kPrevDirCmd, 0, 0);
break;
case KBDK_RIGHT:
sendCommand(kNextDirCmd, 0, 0);
break;
case KBDK_UP:
sendCommand(kParentDirCmd, 0, 0);
break;
case KBDK_DOWN:
sendCommand(kActivatedCmd, _selected, 0);
break;
default:
handled = false;
break;
}
}
return handled;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool FileListWidget::handleText(char text)
{

View File

@ -57,6 +57,8 @@ class FileListWidget : public StringListWidget
int x, int y, int w, int h);
~FileListWidget() override = default;
bool handleKeyDown(StellaKey key, StellaMod mod) override;
string getToolTip(const Common::Point& pos) const override;
/** Determines how to display files/folders; either setDirectory or reload

View File

@ -24,6 +24,7 @@
#include "EditTextWidget.hxx"
#include "FileListWidget.hxx"
#include "LauncherFileListWidget.hxx"
#include "NavigationWidget.hxx"
#include "FSNode.hxx"
#include "MD5.hxx"
#include "OptionsDialog.hxx"
@ -79,6 +80,7 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
addRomWidgets(ypos, wid);
if(!myUseMinimalUI && bottomButtons)
addButtonWidgets(ypos, wid);
myNavigationBar->setList(myList);
tooltip().setFont(_font);
@ -213,58 +215,22 @@ void LauncherDialog::addPathWidgets(int& ypos, WidgetArray& wid)
LBL_GAP = fontWidth,
BTN_GAP = fontWidth / 4;
const bool smallIcon = lineHeight < 26;
const int iconGap = (fontWidth + 1) & ~0b1; // round up to next even
const string lblFound = "12345 items";
const int lwFound = _font.getStringWidth(lblFound);
const GUI::Icon& reloadIcon = smallIcon ? GUI::icon_reload_small : GUI::icon_reload_large;
const int iconWidth = reloadIcon.width();
const int buttonWidth = iconWidth + ((fontWidth + 1) & ~0b1) - 1; // round up to next odd
const int buttonHeight = lineHeight + 2;
const int wNav = _w - HBORDER * 2 - (myUseMinimalUI ? lwFound + LBL_GAP : buttonWidth + BTN_GAP);
int xpos = HBORDER;
myNavigationBar = new NavigationWidget(this, _font, xpos, ypos, wNav, buttonHeight);
if(!myUseMinimalUI)
{
const GUI::Icon& prevIcon = smallIcon ? GUI::icon_prev_small : GUI::icon_prev_large;
const GUI::Icon& nextIcon = smallIcon ? GUI::icon_next_small : GUI::icon_next_large;
const GUI::Icon& homeIcon = smallIcon ? GUI::icon_home_small : GUI::icon_home_large;
const GUI::Icon& upIcon = smallIcon ? GUI::icon_up_small : GUI::icon_up_large;
myHomeButton = new ButtonWidget(this, _font, xpos, ypos,
iconWidth + iconGap - 1, lineHeight + 2, homeIcon, FileListWidget::kHomeDirCmd);
myHomeButton->setToolTip("Go back to Stella's ROM directory.");
wid.push_back(myHomeButton);
xpos = myHomeButton->getRight() + BTN_GAP;
myPrevButton = new ButtonWidget(this, _font, xpos, ypos,
iconWidth + iconGap - 1, lineHeight + 2, prevIcon, FileListWidget::kPrevDirCmd);
myPrevButton->setToolTip("Go back in directory history.");
wid.push_back(myPrevButton);
xpos = myPrevButton->getRight() + BTN_GAP;
myNextButton = new ButtonWidget(this, _font, xpos, ypos,
iconWidth + iconGap - 1, lineHeight + 2, nextIcon, FileListWidget::kNextDirCmd);
myNextButton->setToolTip("Go forward in directory history.");
wid.push_back(myNextButton);
xpos = myNextButton->getRight() + BTN_GAP;
myUpButton = new ButtonWidget(this, _font, xpos, ypos,
iconWidth + iconGap - 1, lineHeight + 2, upIcon, ListWidget::kParentDirCmd);
myUpButton->setToolTip("Go Up");
wid.push_back(myUpButton);
xpos = myUpButton->getRight() + BTN_GAP;
}
myDir = new EditTextWidget(this, _font, xpos, ypos,
_w - xpos - (myUseMinimalUI
? lwFound + LBL_GAP
: (iconWidth + iconGap + BTN_GAP))
- HBORDER, lineHeight, "");
myDir->setEditable(false, true);
myDir->clearFlags(Widget::FLAG_RETAIN_FOCUS);
if(!myUseMinimalUI)
{
xpos = myDir->getRight() + BTN_GAP;
xpos = myNavigationBar->getRight() + BTN_GAP;
myReloadButton = new ButtonWidget(this, _font, xpos, ypos,
iconWidth + iconGap - 1, lineHeight + 2, reloadIcon, kReloadCmd);
buttonWidth, buttonHeight, reloadIcon, kReloadCmd);
myReloadButton->setToolTip("Reload listing");
wid.push_back(myReloadButton);
}
@ -276,7 +242,7 @@ void LauncherDialog::addPathWidgets(int& ypos, WidgetArray& wid)
myRomCount = new StaticTextWidget(this, _font, xpos, ypos + 2,
lwFound, fontHeight, "", TextAlign::Right);
EditTextWidget* e = new EditTextWidget(this, _font, myDir->getRight() - 1, ypos,
EditTextWidget* e = new EditTextWidget(this, _font, myNavigationBar->getRight() - 1, ypos,
lwFound + LBL_GAP + 1, lineHeight, "");
e->setEditable(false, true);
}
@ -522,17 +488,7 @@ void LauncherDialog::updateUI()
if(myGoUpButton)
myGoUpButton->setEnabled(myList->currentDir().hasParent());
// Only enable the navigation buttons if function is available
if(myHomeButton)
myHomeButton->setEnabled(myList->hasPrevHistory());
if(myPrevButton)
myPrevButton->setEnabled(myList->hasPrevHistory());
if(myNextButton)
myNextButton->setEnabled(myList->hasNextHistory());
if(myUpButton)
myUpButton->setEnabled(myList->currentDir().hasParent());
// Show current directory
myDir->setText(myList->currentDir().getShortPath());
myNavigationBar->updateUI();
// Indicate how many files were found
ostringstream buf;
@ -781,8 +737,6 @@ void LauncherDialog::handleContextMenu()
reload();
else if(cmd == "options")
openSettings();
//else if(cmd == "quit")
// handleQuit();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -809,91 +763,59 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
// context menu keys
bool handled = false;
if(!(myPattern->isHighlighted()
&& instance().eventHandler().eventForKey(EventMode::kEditMode, key, mod) != Event::NoType))
if(StellaModTest::isControl(mod) &&
!(myPattern && myPattern->isHighlighted()
&& instance().eventHandler().eventForKey(EventMode::kEditMode, key, mod) != Event::NoType))
{
if(StellaModTest::isAlt(mod))
handled = true;
switch(key)
{
handled = true;
switch(key)
{
case KBDK_HOME:
sendCommand(FileListWidget::kHomeDirCmd, 0, 0);
break;
case KBDK_A:
sendCommand(kAllfilesCmd, 0, 0);
toggleShowAll();
break;
case KBDK_LEFT:
sendCommand(FileListWidget::kPrevDirCmd, 0, 0);
break;
case KBDK_D:
sendCommand(kSubDirsCmd, 0, 0);
break;
case KBDK_RIGHT:
sendCommand(FileListWidget::kNextDirCmd, 0, 0);
break;
case KBDK_E:
toggleExtensions();
break;
case KBDK_UP:
sendCommand(ListWidget::kParentDirCmd, 0, 0);
break;
case KBDK_F:
myList->toggleUserFavorite();
break;
case KBDK_DOWN:
sendCommand(kLoadROMCmd, 0, 0);
break;
case KBDK_H:
if(instance().highScores().enabled())
openHighScores();
break;
default:
handled = false;
break;
}
}
else if(StellaModTest::isControl(mod))
{
handled = true;
switch(key)
{
case KBDK_A:
sendCommand(kAllfilesCmd, 0, 0);
toggleShowAll();
break;
case KBDK_O:
openSettings();
break;
case KBDK_D:
sendCommand(kSubDirsCmd, 0, 0);
break;
case KBDK_P:
openGlobalProps();
break;
case KBDK_E:
toggleExtensions();
break;
case KBDK_R:
reload();
break;
case KBDK_F:
myList->toggleUserFavorite();
break;
case KBDK_S:
toggleSorting();
break;
case KBDK_H:
if(instance().highScores().enabled())
openHighScores();
break;
case KBDK_X:
myList->removeFavorite();
reload();
break;
case KBDK_O:
openSettings();
break;
case KBDK_P:
openGlobalProps();
break;
case KBDK_R:
reload();
break;
case KBDK_S:
toggleSorting();
break;
case KBDK_X:
myList->removeFavorite();
reload();
break;
default:
handled = false;
break;
}
default:
handled = false;
break;
}
}
if(!handled)
@ -923,7 +845,9 @@ void LauncherDialog::handleKeyDown(StellaKey key, StellaMod mod, bool repeated)
break;
}
#else
Dialog::handleKeyDown(key, mod);
// Required because BrowserDialog does not want raw input
if(repeated || !myList->handleKeyDown(key, mod))
Dialog::handleKeyDown(key, mod, repeated);
#endif
}
@ -997,7 +921,7 @@ void LauncherDialog::handleMouseUp(int x, int y, MouseButton b, int clickCount)
void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)
{
switch (cmd)
switch(cmd)
{
case kAllfilesCmd:
toggleShowAll();
@ -1007,22 +931,6 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
toggleSubDirs();
break;
case FileListWidget::kHomeDirCmd:
myList->sendCommand(FileListWidget::kHomeDirCmd, 0, 0);
break;
case FileListWidget::kPrevDirCmd:
myList->sendCommand(FileListWidget::kPrevDirCmd, 0, 0);
break;
case FileListWidget::kNextDirCmd:
myList->sendCommand(FileListWidget::kNextDirCmd, 0, 0);
break;
case ListWidget::kParentDirCmd:
myList->sendCommand(ListWidget::kParentDirCmd, 0, 0);
break;
case kLoadROMCmd:
if(myList->isDirectory(myList->selected()))
{
@ -1242,7 +1150,6 @@ void LauncherDialog::openContextMenu(int x, int y)
//if(!instance().settings().getBool("launcherbuttons"))
//{
// items.push_back(ContextItem("Options" + ELLIPSIS, "Ctrl+O", "options"));
// items.push_back(ContextItem("Quit", "Ctrl+Q", "quit"));
//}
}

View File

@ -25,6 +25,7 @@ class DialogContainer;
class OSystem;
class Properties;
class EditTextWidget;
class NavigationWidget;
class LauncherFileListWidget;
class RomInfoWidget;
class StaticTextWidget;
@ -199,14 +200,10 @@ class LauncherDialog : public Dialog, CommandSender
ButtonWidget* mySubDirsButton{nullptr};
StaticTextWidget* myRomCount{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myPrevButton{nullptr};
ButtonWidget* myNextButton{nullptr};
ButtonWidget* myUpButton{nullptr};
EditTextWidget* myDir{nullptr};
NavigationWidget* myNavigationBar{nullptr};
ButtonWidget* myReloadButton{nullptr};
LauncherFileListWidget* myList{nullptr};
LauncherFileListWidget* myList{nullptr};
ButtonWidget* myStartButton{nullptr};
ButtonWidget* myGoUpButton{nullptr};

View File

@ -35,11 +35,12 @@ MODULE_OBJS := \
src/gui/MessageBox.o \
src/gui/MessageDialog.o \
src/gui/MessageMenu.o \
src/gui/MinUICommandDialog.o\
src/gui/MinUICommandDialog.o \
src/gui/NavigationWidget.o \
src/gui/OptionsDialog.o \
src/gui/OptionsMenu.o \
src/gui/PlusRomsMenu.o\
src/gui/PlusRomsSetupDialog.o\
src/gui/PlusRomsSetupDialog.o \
src/gui/PopUpWidget.o \
src/gui/ProgressDialog.o \
src/gui/QuadTariDialog.o \

View File

@ -913,6 +913,7 @@
<ClCompile Include="..\gui\HighScoresDialog.cxx" />
<ClCompile Include="..\gui\HighScoresMenu.cxx" />
<ClCompile Include="..\gui\LauncherFileListWidget.cxx" />
<ClCompile Include="..\gui\NavigationWidget.cxx" />
<ClCompile Include="..\gui\PlusRomsMenu.cxx" />
<ClCompile Include="..\gui\JoystickDialog.cxx" />
<ClCompile Include="..\gui\LoggerDialog.cxx" />
@ -2120,6 +2121,7 @@
<ClInclude Include="..\gui\HighScoresMenu.hxx" />
<ClInclude Include="..\gui\Icon.hxx" />
<ClInclude Include="..\gui\LauncherFileListWidget.hxx" />
<ClInclude Include="..\gui\NavigationWidget.hxx" />
<ClInclude Include="..\gui\PlusRomsMenu.hxx" />
<ClInclude Include="..\gui\JoystickDialog.hxx" />
<ClInclude Include="..\gui\LoggerDialog.hxx" />

View File

@ -1125,6 +1125,9 @@
<ClCompile Include="..\gui\FavoritesManager.cxx">
<Filter>Source Files\gui</Filter>
</ClCompile>
<ClCompile Include="..\gui\NavigationWidget.cxx">
<Filter>Source Files\gui</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\bspf.hxx">
@ -2318,6 +2321,9 @@
<ClInclude Include="..\gui\Icons.hxx">
<Filter>Header Files\gui</Filter>
</ClInclude>
<ClInclude Include="..\gui\NavigationWidget.hxx">
<Filter>Header Files\gui</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="stella.ico">