dialog:: larger file dialog, automatically set position

This commit is contained in:
Zeno Rogue 2022-11-03 19:32:12 +01:00
parent 2bc0de05a6
commit 320aac6b9a
1 changed files with 27 additions and 13 deletions

View File

@ -1441,7 +1441,7 @@ EX namespace dialog {
} }
sort(v.begin(), v.end(), filecmp); sort(v.begin(), v.end(), filecmp);
dialog::start_list(1500, 1500); dialog::start_list(2000, 2000);
for(auto& vv: v) { for(auto& vv: v) {
dialog::addItem(vv.first, list_fake_key++); dialog::addItem(vv.first, list_fake_key++);
dialog::lastItem().color = vv.second; dialog::lastItem().color = vv.second;
@ -1450,26 +1450,38 @@ EX namespace dialog {
dialog::add_action([vf, dir] { dialog::add_action([vf, dir] {
string& s(*cfileptr); string& s(*cfileptr);
string where = "", what = s, whereparent = "../"; string where = "", what = s, whereparent = "../";
string last = "";
for(int i=0; i<isize(s); i++) for(int i=0; i<isize(s); i++)
if(s[i] == '/') { if(s[i] == '/') {
if(i >= 2 && s.substr(i-2,3) == "../") if(i >= 2 && s.substr(i-2,3) == "../") {
whereparent = s.substr(0, i+1) + "../"; whereparent = s.substr(0, i+1) + "../";
else last = "";
}
else {
last = s.substr(isize(where), i + 1 - isize(where));
whereparent = where; whereparent = where;
}
where = s.substr(0, i+1), what = s.substr(i+1); where = s.substr(0, i+1), what = s.substr(i+1);
} }
string str1; string str1;
if(vf == "../") if(vf == "../") {
str1 = whereparent + what; s = whereparent + what;
else if(dir) find_highlight(last);
str1 = where + vf + what; list_skip = 0;
else }
str1 = where + vf; else if(dir) {
if(s == str1) { s = where + vf + what;
popScreen(); find_highlight("../");
if(!file_action()) pushScreen(drawFileDialog); list_skip = 0;
}
else {
str1 = where + vf;
if(s == str1) {
popScreen();
if(!file_action()) pushScreen(drawFileDialog);
}
s = str1;
} }
s = str1;
}); });
} }
dialog::end_list(); dialog::end_list();
@ -1501,10 +1513,12 @@ EX namespace dialog {
else if(sym == SDLK_BACKSPACE && i) { else if(sym == SDLK_BACKSPACE && i) {
s.erase(i-1, 1); s.erase(i-1, 1);
highlight_text = "//missing"; highlight_text = "//missing";
list_skip = 0;
} }
else if(uni >= 32 && uni < 127) { else if(uni >= 32 && uni < 127) {
s.insert(i, s0 + char(uni)); s.insert(i, s0 + char(uni));
highlight_text = "//missing"; highlight_text = "//missing";
list_skip = 0;
} }
return; return;
} }