mirror of https://github.com/stella-emu/stella.git
Fixed selection of previous dir in FileListWidget.
I was going to have it remember descending directories too, but it's just too much fooling around for a minor feature. Maybe someone else can take a stab at it ...
This commit is contained in:
parent
98267b7ab3
commit
a8c1cd3730
|
@ -266,7 +266,6 @@ class LinkedObjectPool
|
|||
for(const auto& i: p.myList)
|
||||
os << i << (p.current() == i ? "* " : " ");
|
||||
return os;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -49,6 +49,13 @@ class FixedStack
|
|||
T pop() { return std::move(_stack[--_size]); }
|
||||
uInt32 size() const { return _size; }
|
||||
|
||||
// Reverse the contents of the stack
|
||||
// This operation isn't needed very often, but it's handy to have
|
||||
void reverse() {
|
||||
for(uInt32 i = 0, j = _size - 1; i < j; ++i, --j)
|
||||
std::swap(_stack[i], _stack[j]);
|
||||
}
|
||||
|
||||
// Apply the given function to every item in the stack
|
||||
// We do it this way so the stack API can be preserved,
|
||||
// and no access to individual elements is allowed outside
|
||||
|
@ -58,6 +65,12 @@ class FixedStack
|
|||
func(_stack[i]);
|
||||
}
|
||||
|
||||
friend ostream& operator<<(ostream& os, const FixedStack<T>& s) {
|
||||
for(uInt32 pos = 0; pos < s._size; ++pos)
|
||||
os << s._stack[pos] << " ";
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
FixedStack(const FixedStack&) = delete;
|
||||
|
|
|
@ -50,6 +50,31 @@ void FileListWidget::setDirectory(const FilesystemNode& node, string select)
|
|||
_node = _node.getParent();
|
||||
}
|
||||
|
||||
// Initialize history
|
||||
FilesystemNode tmp = _node;
|
||||
while(tmp.hasParent())
|
||||
{
|
||||
string name = tmp.getName();
|
||||
if(name.back() == '/' || name.back() == '\\')
|
||||
name.pop_back();
|
||||
if(!BSPF::startsWithIgnoreCase(name, " ["))
|
||||
name = " [" + name + "]";
|
||||
|
||||
_history.push(name);
|
||||
tmp = tmp.getParent();
|
||||
}
|
||||
// History is in reverse order; we need to fix that
|
||||
_history.reverse();
|
||||
|
||||
// Finally, go to this location
|
||||
setLocation(_node, select);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void FileListWidget::setLocation(const FilesystemNode& node, const string& select)
|
||||
{
|
||||
_node = node;
|
||||
|
||||
// Read in the data from the file system (start with an empty list)
|
||||
_fileList.clear();
|
||||
_fileList.reserve(512);
|
||||
|
@ -67,9 +92,10 @@ void FileListWidget::setDirectory(const FilesystemNode& node, string select)
|
|||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void FileListWidget::setLocation(const FilesystemNode& node, string select)
|
||||
void FileListWidget::selectDirectory()
|
||||
{
|
||||
setDirectory(node, select);
|
||||
_history.push(selected().getName());
|
||||
setLocation(selected());
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -77,13 +103,7 @@ void FileListWidget::selectParent()
|
|||
{
|
||||
if(_node.hasParent())
|
||||
{
|
||||
// Make sure 'selected' has the proper directory naming scheme
|
||||
string select = _node.getName();
|
||||
if(select.back() == '/' || select.back() == '\\')
|
||||
select.pop_back();
|
||||
if(!BSPF::startsWithIgnoreCase(select, " ["))
|
||||
select = " [" + select + "]";
|
||||
|
||||
const string& select = !_history.empty() ? _history.pop() : EmptyString;
|
||||
setLocation(_node.getParent(), select);
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +135,7 @@ void FileListWidget::handleCommand(CommandSender* sender, int cmd, int data, int
|
|||
if(selected().isDirectory())
|
||||
{
|
||||
cmd = ItemChanged;
|
||||
setLocation(selected(), "");
|
||||
selectDirectory();
|
||||
}
|
||||
else
|
||||
cmd = ItemActivated;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
class CommandSender;
|
||||
|
||||
#include "FSNode.hxx"
|
||||
#include "LinkedObjectPool.hxx"
|
||||
#include "Stack.hxx"
|
||||
#include "StringListWidget.hxx"
|
||||
|
||||
/**
|
||||
|
@ -74,7 +74,10 @@ class FileListWidget : public StringListWidget
|
|||
|
||||
private:
|
||||
/** Very similar to setDirectory(), but also updates the history */
|
||||
void setLocation(const FilesystemNode& node, string select);
|
||||
void setLocation(const FilesystemNode& node, const string& select = EmptyString);
|
||||
|
||||
/** Descend into currently selected directory */
|
||||
void selectDirectory();
|
||||
|
||||
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
|
||||
|
||||
|
@ -83,7 +86,7 @@ class FileListWidget : public StringListWidget
|
|||
FilesystemNode _node;
|
||||
FSList _fileList;
|
||||
|
||||
Common::LinkedObjectPool<string> _history;
|
||||
Common::FixedStack<string> _history;
|
||||
|
||||
string _extension;
|
||||
uInt32 _selected;
|
||||
|
|
Loading…
Reference in New Issue