mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 16:56:14 +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...
|
// ...fall through...
|
||||||
case InputManager::LEFT:
|
case InputManager::LEFT:
|
||||||
if (showDirectories) {
|
if (showDirectories) {
|
||||||
dir = parentDir(dir);
|
selected = goToParentDir(fl);
|
||||||
selected = 0;
|
|
||||||
firstElement = 0;
|
firstElement = 0;
|
||||||
prepare(fl);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -204,14 +202,19 @@ int Selector::exec(int startSelection) {
|
|||||||
file = fl[selected];
|
file = fl[selected];
|
||||||
close = true;
|
close = true;
|
||||||
} else {
|
} else {
|
||||||
dir = dir+fl[selected];
|
string subdir = fl[selected];
|
||||||
|
if (subdir == "..") {
|
||||||
|
selected = goToParentDir(fl);
|
||||||
|
} else {
|
||||||
|
dir += subdir;
|
||||||
char *buf = realpath(dir.c_str(), NULL);
|
char *buf = realpath(dir.c_str(), NULL);
|
||||||
dir = (string) buf + '/';
|
dir = (string) buf + '/';
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
selected = 0;
|
|
||||||
firstElement = 0;
|
|
||||||
prepare(fl);
|
prepare(fl);
|
||||||
|
selected = 0;
|
||||||
|
}
|
||||||
|
firstElement = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -235,3 +238,13 @@ bool Selector::prepare(FileLister& fl) {
|
|||||||
|
|
||||||
return opened;
|
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);
|
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:
|
public:
|
||||||
Selector(GMenu2X *gmenu2x, LinkApp& link,
|
Selector(GMenu2X *gmenu2x, LinkApp& link,
|
||||||
const std::string &selectorDir = "");
|
const std::string &selectorDir = "");
|
||||||
|
Loading…
Reference in New Issue
Block a user