mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 10:49:41 +02:00
When going up a level in the selector, put cursor on old dir
This adds a sense of continuity to the navigation.
This commit is contained in:
parent
bb30dedd09
commit
fe0c7c2e8d
@ -191,10 +191,8 @@ int Selector::exec(int startSelection) {
|
||||
// ...fall through...
|
||||
case InputManager::LEFT:
|
||||
if (showDirectories) {
|
||||
dir = parentDir(dir);
|
||||
selected = 0;
|
||||
selected = goToParentDir(fl);
|
||||
firstElement = 0;
|
||||
prepare(fl);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -204,14 +202,19 @@ int Selector::exec(int startSelection) {
|
||||
file = fl[selected];
|
||||
close = true;
|
||||
} else {
|
||||
dir = dir+fl[selected];
|
||||
char *buf = realpath(dir.c_str(), NULL);
|
||||
dir = (string) buf + '/';
|
||||
free(buf);
|
||||
string subdir = fl[selected];
|
||||
if (subdir == "..") {
|
||||
selected = goToParentDir(fl);
|
||||
} else {
|
||||
dir += subdir;
|
||||
char *buf = realpath(dir.c_str(), NULL);
|
||||
dir = (string) buf + '/';
|
||||
free(buf);
|
||||
|
||||
selected = 0;
|
||||
prepare(fl);
|
||||
selected = 0;
|
||||
}
|
||||
firstElement = 0;
|
||||
prepare(fl);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -235,3 +238,13 @@ bool Selector::prepare(FileLister& fl) {
|
||||
|
||||
return opened;
|
||||
}
|
||||
|
||||
int Selector::goToParentDir(FileLister& fl) {
|
||||
string oldDir = dir;
|
||||
dir = parentDir(dir);
|
||||
prepare(fl);
|
||||
string oldName = oldDir.substr(dir.size(), oldDir.size() - dir.size() - 1);
|
||||
auto& subdirs = fl.getDirectories();
|
||||
auto it = find(subdirs.begin(), subdirs.end(), oldName);
|
||||
return it == subdirs.end() ? 0 : it - subdirs.begin();
|
||||
}
|
||||
|
@ -37,6 +37,12 @@ private:
|
||||
|
||||
bool prepare(FileLister& fl);
|
||||
|
||||
/**
|
||||
* Changes 'dir' to its parent directory.
|
||||
* Returns the index of the old dir in the parent, or 0 if unknown.
|
||||
*/
|
||||
int goToParentDir(FileLister& fl);
|
||||
|
||||
public:
|
||||
Selector(GMenu2X *gmenu2x, LinkApp& link,
|
||||
const std::string &selectorDir = "");
|
||||
|
Loading…
Reference in New Issue
Block a user