Yoda/src/app/browser/main/tab/page/navbar/history.cpp
2024-09-04 02:36:30 +03:00

111 lines
No EOL
1.6 KiB
C++

#include "history.hpp"
#include "history/back.hpp"
#include "history/forward.hpp"
using namespace app::browser::main::tab::page::navbar;
History::History()
{
add_css_class(
"linked" // merge children elements
);
historyBack = Gtk::make_managed<history::Back>();
append(
* historyBack
);
historyForward = Gtk::make_managed<history::Forward>();
append(
* historyForward
);
}
// Actions
bool History::try_back(
Memory & match,
bool follow
) {
try
{
match = memory.at(
index - 1
);
if (follow)
{
index--;
}
return true;
}
catch (std::out_of_range)
{
return false;
}
}
bool History::try_forward(
Memory & match,
bool follow
) {
try
{
match = memory.at(
index + 1
);
if (follow)
{
index++;
}
return true;
}
catch (std::out_of_range)
{
return false;
}
}
void History::push(
const Glib::ustring & REQUEST
) {
if (memory.empty() || memory.back().request != REQUEST)
{
memory.push_back(
{
REQUEST,
std::time(
nullptr
),
true
}
);
index = memory.size(); // @TODO
}
}
void History::refresh()
{
Memory match;
historyBack->set_sensitive(
try_back(
match,
false
)
);
historyForward->set_sensitive(
try_forward(
match,
false
)
);
}