add new system navigation
This commit is contained in:
@@ -17,7 +17,9 @@ namespace rrr
|
||||
{
|
||||
nav.fill(PWD);
|
||||
his.fill(PWD);
|
||||
prev.fill(nav.store[PWD].at(cursor_position).path);
|
||||
prev.fill(nav.data.at(navigation_cursor_position).path);
|
||||
|
||||
hack::log()(prev.data.size());
|
||||
}
|
||||
|
||||
files* content::get(TYPE_WIN type)
|
||||
@@ -28,7 +30,7 @@ namespace rrr
|
||||
return &his.data;
|
||||
break;
|
||||
case TYPE_WIN::NAVIGATION:
|
||||
return &nav.store[PWD];
|
||||
return &nav.data;
|
||||
break;
|
||||
case TYPE_WIN::PREVIEW:
|
||||
return &prev.data;
|
||||
@@ -39,46 +41,55 @@ namespace rrr
|
||||
}
|
||||
}
|
||||
|
||||
int content::get_cursor_position(TYPE_WIN type)
|
||||
file content::get_selected_file(TYPE_WIN type)
|
||||
{
|
||||
file f;
|
||||
switch (type)
|
||||
{
|
||||
case TYPE_WIN::HISTORY:
|
||||
return get_history_cursor_position();
|
||||
try
|
||||
{
|
||||
set_history_cursor_position();
|
||||
f = his.data.at(history_cursor_position);
|
||||
}
|
||||
catch(...) { hack::error()("Dont set history"); }
|
||||
break;
|
||||
case TYPE_WIN::NAVIGATION:
|
||||
return cursor_position;
|
||||
try
|
||||
{
|
||||
f = nav.data.at(navigation_cursor_position);
|
||||
}
|
||||
catch(...) { hack::error()("Dont set navigation"); }
|
||||
break;
|
||||
case TYPE_WIN::PREVIEW:
|
||||
return get_preview_cursor_position();
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
try
|
||||
{
|
||||
set_preview_cursor_position();
|
||||
f = prev.data.at(preview_cursor_position);
|
||||
}
|
||||
catch(...) { hack::error()("Dont set preview"); }
|
||||
break;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
int content::get_history_cursor_position() const
|
||||
void content::set_history_cursor_position()
|
||||
{
|
||||
int history_cursor_position = 0;
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, his.data.size()), [&](tbb::blocked_range<int> r)
|
||||
{
|
||||
for (int i = r.begin(); i < r.end(); ++i)
|
||||
if (his.data.at(i).path == PWD)
|
||||
history_cursor_position = i;
|
||||
});
|
||||
|
||||
return history_cursor_position;
|
||||
}
|
||||
|
||||
int content::get_preview_cursor_position()
|
||||
void content::set_preview_cursor_position()
|
||||
{
|
||||
int preview_cursor_position = 0;
|
||||
|
||||
if (std::filesystem::is_empty(PWD))
|
||||
return preview_cursor_position;
|
||||
return;
|
||||
|
||||
auto pwd = nav.store[PWD].at(cursor_position).path;
|
||||
auto pwd = nav.data.at(navigation_cursor_position).path;
|
||||
|
||||
if (buffer::state.contains(pwd))
|
||||
{
|
||||
@@ -89,13 +100,11 @@ namespace rrr
|
||||
preview_cursor_position = i;
|
||||
});
|
||||
}
|
||||
|
||||
return preview_cursor_position;
|
||||
}
|
||||
|
||||
void content::increment_position(int step)
|
||||
{
|
||||
cursor_position += step;
|
||||
navigation_cursor_position += step;
|
||||
check_cursor_position();
|
||||
|
||||
// в зависимости от того пустаая ли директория
|
||||
@@ -103,14 +112,14 @@ namespace rrr
|
||||
if (std::filesystem::is_empty(PWD))
|
||||
prev.data.clear();
|
||||
else
|
||||
prev.fill(nav.store[PWD].at(cursor_position).path);
|
||||
prev.fill(nav.data.at(navigation_cursor_position).path);
|
||||
}
|
||||
|
||||
void content::check_cursor_position()
|
||||
{
|
||||
if (cursor_position == (int)nav.store[PWD].size()) cursor_position = (int)nav.store[PWD].size() - 1;
|
||||
else if (cursor_position < 0) cursor_position = 0;
|
||||
else if (cursor_position > (int)nav.store[PWD].size()) cursor_position = 0;
|
||||
if (navigation_cursor_position == (int)nav.data.size()) navigation_cursor_position = (int)nav.data.size() - 1;
|
||||
else if (navigation_cursor_position < 0) navigation_cursor_position = 0;
|
||||
else if (navigation_cursor_position > (int)nav.data.size()) navigation_cursor_position = 0;
|
||||
}
|
||||
|
||||
void content::navigation_right()
|
||||
@@ -118,7 +127,7 @@ namespace rrr
|
||||
if (std::filesystem::is_empty(PWD)) return;
|
||||
|
||||
// ставим новый pwd и заполняем навигацию и историю
|
||||
PWD = PWD / nav.store[PWD].at(cursor_position).path.filename();
|
||||
PWD = PWD / nav.data.at(navigation_cursor_position).path.filename();
|
||||
|
||||
nav.fill(PWD);
|
||||
his.fill(PWD);
|
||||
@@ -129,16 +138,16 @@ namespace rrr
|
||||
if (buffer::state.contains(PWD))
|
||||
{
|
||||
auto f = buffer::state[PWD];
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, nav.store[PWD].size()), [&](tbb::blocked_range<int> r)
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, nav.data.size()), [&](tbb::blocked_range<int> r)
|
||||
{
|
||||
for (int i = r.begin(); i < r.end(); ++i)
|
||||
if (nav.store[PWD].at(i).path == f.path)
|
||||
cursor_position = i;
|
||||
if (nav.data.at(i).path == f.path)
|
||||
navigation_cursor_position = i;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
cursor_position = 0;
|
||||
navigation_cursor_position = 0;
|
||||
}
|
||||
|
||||
// и исходя из позиции курсора заполняем окно предварительного просмотра
|
||||
@@ -146,7 +155,7 @@ namespace rrr
|
||||
if (std::filesystem::is_empty(PWD))
|
||||
prev.data.clear();
|
||||
else
|
||||
prev.fill(nav.store[PWD].at(cursor_position).path);
|
||||
prev.fill(nav.data.at(navigation_cursor_position).path);
|
||||
}
|
||||
|
||||
void content::navigation_left()
|
||||
@@ -154,26 +163,28 @@ namespace rrr
|
||||
// буфер заполняется только когда отсюда уходишь
|
||||
// типа я тут был
|
||||
if (std::filesystem::is_empty(PWD))
|
||||
buffer::state[PWD] = nav.store[PWD.parent_path()].at(cursor_position);
|
||||
// buffer::state[PWD] = nav.store[PWD.parent_path()].at(cursor_position);
|
||||
buffer::state[PWD] = nav.data.at(navigation_cursor_position);
|
||||
else
|
||||
buffer::state[PWD] = nav.store[PWD].at(cursor_position);
|
||||
buffer::state[PWD] = nav.data.at(navigation_cursor_position);
|
||||
|
||||
auto from = PWD;
|
||||
|
||||
nav.fill(PWD.parent_path());
|
||||
his.fill(PWD.parent_path());
|
||||
prev.fill(PWD);
|
||||
|
||||
// ставим новый pwd и заполняем навигацию и историю
|
||||
PWD = PWD.parent_path();
|
||||
nav.fill(PWD);
|
||||
his.fill(PWD);
|
||||
prev.fill(from);
|
||||
|
||||
// тут всегда есть место откуда ты пришел
|
||||
// т.е. нет возмолжности придти неоткуда
|
||||
// соответственно находим это место
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, nav.store[PWD].size()), [&](tbb::blocked_range<int> r)
|
||||
tbb::parallel_for(tbb::blocked_range<int>(0, nav.data.size()), [&](tbb::blocked_range<int> r)
|
||||
{
|
||||
for (int i = r.begin(); i < r.end(); ++i)
|
||||
if (nav.store[PWD].at(i).path == from)
|
||||
cursor_position = i;
|
||||
if (nav.data.at(i).path == from)
|
||||
navigation_cursor_position = i;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user