added home button

fixed virtual directories missing issue (see #848)
This commit is contained in:
Thomas Jentzsch 2021-12-03 14:06:35 +01:00
parent f13862c19e
commit c2d120ce0c
6 changed files with 128 additions and 23 deletions

View File

@ -43,8 +43,8 @@ void FavoritesManager::load()
for(const auto& u : jUser)
{
const string& path = u.get<string>();
//FilesystemNode node(path);
//if(node.exists())
FilesystemNode node(path);
if(node.exists())
addUser(path);
}
}
@ -60,8 +60,8 @@ void FavoritesManager::load()
for(const auto& r : jRecent)
{
const string& path = r.get<string>();
//FilesystemNode node(path);
//if(node.exists())
FilesystemNode node(path);
if(node.exists())
addRecent(path);
}
}
@ -77,8 +77,8 @@ void FavoritesManager::load()
{
const string& path = p[0].get<string>();
const uInt32 count = p[1].get<uInt32>();
//FilesystemNode node(path);
//if(node.exists())
FilesystemNode node(path);
if(node.exists())
myPopularMap.emplace(path, count);
}
}

View File

@ -212,6 +212,11 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
if(romWidth > 0) romWidth += HBORDER;
int listWidth = _w - (romWidth > 0 ? romWidth + fontWidth : 0) - HBORDER * 2;
xpos = HBORDER; ypos += lineHeight + VGAP;
// remember initial ROM directory for returning there via home button
string romDir = getRomDir();
instance().settings().setValue("startromdir", getRomDir());
cerr << instance().settings().getString("romdir") << endl;
myList = new LauncherFileListWidget(this, _font, xpos, ypos, listWidth, listHeight);
myList->setEditable(false);
myList->setListMode(FilesystemNode::ListMode::All);
@ -238,9 +243,76 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent,
// Add textfield to show current directory
xpos = HBORDER;
ypos += myList->getHeight() + VGAP;
// Home button
static const uIntArray home_small = {
0b0000001000000,
0b0000011100000,
0b0000110110000,
0b0001101011000,
0b0011011101100,
0b0110111110110,
0b1101111111011,
0b1011111111101,
0b0011110111100,
0b0011100011100,
0b0011100011100,
0b0011100011100,
0b0011100011100,
0b0011100011100
//0b000000010000000,
//0b000000111000000,
//0b000001101100000,
//0b000011010110000,
//0b000110111011000,
//0b001101111101100,
//0b011011111110110,
//0b110111111111011,
//0b101111111111101,
//0b001111101111100,
//0b001111000111100,
//0b001111000111100,
//0b001111000111100,
//0b001111000111100,
//0b001111000111100,
};
static const uIntArray home_large = {
0b0000000001000000000,
0b0000000011100000000,
0b0000000110110000000,
0b0000001101011000000,
0b0000011011101100000,
0b0000110111110110000,
0b0001101111111011000,
0b0011011111111101100,
0b0110111111111110110,
0b1101111111111111011,
0b1001111111111111001,
0b0001111100011111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000,
0b0001111000001111000
};
const bool smallIcon = lineHeight < 26;
const uIntArray* icon = smallIcon ? &home_small : &home_large;
const int iconWidth = smallIcon ? 13 : 19;
const int iconGap = fontWidth & ~0b1; // make even
myHomeButton = new ButtonWidget(this, _font, xpos, ypos, iconWidth + iconGap, lineHeight + 2,
icon->data(), iconWidth, int(icon->size()), kHomeDirCmd);
myHomeButton->setToolTip("Go back to Stella's ROM directory.");
wid.push_back(myHomeButton);
xpos = myHomeButton->getRight() + LBL_GAP;
// Path display
lwSelect = _font.getStringWidth("Path") + LBL_GAP;
myDirLabel = new StaticTextWidget(this, _font, xpos, ypos+2, lwSelect, fontHeight,
"Path", TextAlign::Left);
myDirLabel = new StaticTextWidget(this, _font, xpos, ypos+2, lwSelect, fontHeight, "Path");
xpos += lwSelect;
myDir = new EditTextWidget(this, _font, xpos, ypos, _w - xpos - HBORDER, lineHeight, "");
myDir->setEditable(false, true);
@ -374,9 +446,7 @@ void LauncherDialog::loadConfig()
// Should we use a temporary directory specified on the commandline, or the
// default one specified by the settings?
Settings& settings = instance().settings();
const string& tmpromdir = settings.getString("tmpromdir");
const string& romdir = tmpromdir != "" ? tmpromdir :
settings.getString("romdir");
const string& romdir = getRomDir();
const string& version = settings.getString("stella.version");
// Show "What's New" message when a new version of Stella is run for the first time
@ -448,6 +518,15 @@ void LauncherDialog::updateUI()
loadRomInfo();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string LauncherDialog::getRomDir()
{
Settings& settings = instance().settings();
const string& tmpromdir = settings.getString("tmpromdir");
return tmpromdir != EmptyString ? tmpromdir : settings.getString("romdir");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t LauncherDialog::matchWithJoker(const string& str, const string& pattern)
{
@ -845,6 +924,20 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
reload();
break;
case kHomeDirCmd:
{
if(myList->currentDir().getPath() != instance().settings().getString("startromdir"))
{
FilesystemNode node(instance().settings().getString("startromdir"));
if(!myList->isDirectory(node))
node = FilesystemNode("~");
myList->setDirectory(node);
reload();
}
break;
}
case kLoadROMCmd:
if(myList->isDirectory(myList->selected()))
{
@ -904,7 +997,7 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
case kRomDirChosenCmd:
{
string romDir = instance().settings().getString("romdir");
const string romDir = instance().settings().getString("romdir");
if(myList->currentDir().getPath() != romDir)
{
@ -915,6 +1008,11 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
myList->setDirectory(node);
}
if(romDir != instance().settings().getString("startromdir"))
{
instance().settings().setValue("startromdir", romDir);
reload();
}
break;
}
@ -961,12 +1059,6 @@ void LauncherDialog::loadRom()
instance().frameBuffer().showTextMessage(result, MessagePosition::MiddleCenter, true);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::setDefaultDir()
{
instance().settings().setValue("romdir", myList->currentDir().getShortPath());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherDialog::toggleShowAll()
{

View File

@ -51,7 +51,8 @@ class LauncherDialog : public Dialog
enum {
kLoadROMCmd = 'STRT', // load currently selected ROM
kRomDirChosenCmd = 'romc', // ROM dir chosen
kExtChangedCmd = 'extc' // File extension display changed
kExtChangedCmd = 'extc', // File extension display changed
kHomeDirCmd = 'homc', // goto Home directory
};
using FileList = std::unordered_set<string>;
@ -114,6 +115,7 @@ class LauncherDialog : public Dialog
void loadConfig() override;
void saveConfig() override;
void updateUI();
string getRomDir();
/**
Search if string contains pattern including wildcard '*'
@ -156,7 +158,6 @@ class LauncherDialog : public Dialog
void loadRomInfo();
void handleContextMenu();
void showOnlyROMs(bool state);
void setDefaultDir();
void toggleShowAll();
void toggleSubDirs();
void toggleExtensions();
@ -186,6 +187,7 @@ class LauncherDialog : public Dialog
StaticTextWidget* myDirLabel{nullptr};
EditTextWidget* myDir{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myStartButton{nullptr};
ButtonWidget* myPrevDirButton{nullptr};
ButtonWidget* myOptionsButton{nullptr};

View File

@ -31,7 +31,7 @@ LauncherFileListWidget::LauncherFileListWidget(GuiObject* boss, const GUI::Font&
// This widget is special, in that it catches signals and redirects them
setTarget(this);
myFavorites = make_unique<FavoritesManager>(instance().settings());
myRomDir = instance().settings().getString("romdir");
myRomDir = startRomDir();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -124,15 +124,24 @@ void LauncherFileListWidget::addFolder(StringList& list, int& offset, const stri
++offset;
}
string LauncherFileListWidget::startRomDir()
{
string romDir = instance().settings().getString("startromdir");
FilesystemNode node(romDir);
return node.getPath();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void LauncherFileListWidget::extendLists(StringList& list)
{
// Only show virtual dirs in "romdir". Except if
// "romdir" is virtual or "romdir" is a ZIP
// Then show virtual dirs in parent dir of "romdir".
if(myRomDir == instance().settings().getString("romdir")
if(myRomDir == startRomDir()
&& (myInVirtualDir || BSPF::endsWithIgnoreCase(_node.getPath(), ".zip")))
myRomDir = _node.getParent().getPath();
else
myRomDir = startRomDir();
if(_node.getPath() == myRomDir)
{

View File

@ -66,6 +66,7 @@ class LauncherFileListWidget : public FileListWidget
string myRomDir;
private:
string startRomDir();
void getChildren(const FilesystemNode::CancelCheck& isCancelled) override;
void userFavor(const string& path);
void addFolder(StringList& list, int& offset, const string& name, IconType icon);

View File

@ -549,7 +549,8 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id)
case GuiObject::kOKCmd:
{
bool informPath = myIsGlobal &&
myRomPath->getText() != instance().settings().getString("romdir");
(myRomPath->getText() != instance().settings().getString("romdir")
|| myRomPath->getText() != instance().settings().getString("startromdir"));
bool informExt = myIsGlobal &&
myLauncherExtensionsWidget->getState() != instance().settings().getBool("launcherextensions");
saveConfig();