mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-06 00:14:13 +00:00
simplify history navigation api
This commit is contained in:
parent
769ef576f6
commit
43e89716ae
@ -89,28 +89,28 @@ Navbar::Navbar(
|
||||
// Actions
|
||||
void Navbar::back()
|
||||
{
|
||||
if (navbarHistory->has_memory_back())
|
||||
navbar::History::Memory match;
|
||||
|
||||
if (navbarHistory->back(match))
|
||||
{
|
||||
navbarRequest->set_text(
|
||||
navbarHistory->make_memory_back_request()
|
||||
match.request
|
||||
);
|
||||
|
||||
navbarHistory->back(); // --
|
||||
|
||||
navbarUpdate->activate();
|
||||
}
|
||||
}
|
||||
|
||||
void Navbar::forward()
|
||||
{
|
||||
if (navbarHistory->has_memory_forward())
|
||||
navbar::History::Memory match;
|
||||
|
||||
if (navbarHistory->forward(match))
|
||||
{
|
||||
navbarRequest->set_text(
|
||||
navbarHistory->make_memory_forward_request()
|
||||
match.request
|
||||
);
|
||||
|
||||
navbarHistory->forward(); // ++
|
||||
|
||||
navbarUpdate->activate();
|
||||
}
|
||||
}
|
||||
|
@ -24,19 +24,51 @@ History::History()
|
||||
}
|
||||
|
||||
// Actions
|
||||
void History::back()
|
||||
{
|
||||
if (has_memory_back())
|
||||
bool History::back(
|
||||
Memory & match,
|
||||
bool follow
|
||||
) {
|
||||
try
|
||||
{
|
||||
index--;
|
||||
match = memory.at(
|
||||
index - 1
|
||||
);
|
||||
|
||||
if (follow)
|
||||
{
|
||||
index--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void History::forward()
|
||||
{
|
||||
if (has_memory_forward())
|
||||
bool History::forward(
|
||||
Memory & match,
|
||||
bool follow
|
||||
) {
|
||||
try
|
||||
{
|
||||
index++;
|
||||
match = memory.at(
|
||||
index + 1
|
||||
);
|
||||
|
||||
if (follow)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,82 +93,19 @@ void History::push(
|
||||
|
||||
void History::refresh()
|
||||
{
|
||||
Memory match;
|
||||
|
||||
historyBack->set_sensitive(
|
||||
has_memory_back()
|
||||
back(
|
||||
match,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
historyForward->set_sensitive(
|
||||
has_memory_forward()
|
||||
);
|
||||
}
|
||||
|
||||
// Getters
|
||||
bool History::has_memory_back() // @TODO & MEMORY
|
||||
{
|
||||
try
|
||||
{
|
||||
const History::Memory & MEMORY = get_memory_back();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (const std::out_of_range & EXCEPTION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool History::has_memory_forward() // @TODO & MEMORY
|
||||
{
|
||||
try
|
||||
{
|
||||
const History::Memory & MEMORY = get_memory_forward();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
catch (const std::out_of_range & EXCEPTION)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Copying getters
|
||||
Glib::ustring History::make_memory_back_request()
|
||||
{
|
||||
Glib::ustring request;
|
||||
|
||||
if (has_memory_back())
|
||||
{
|
||||
request = get_memory_back().request;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
Glib::ustring History::make_memory_forward_request()
|
||||
{
|
||||
Glib::ustring request;
|
||||
|
||||
if (has_memory_forward())
|
||||
{
|
||||
request = get_memory_forward().request;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
// Private helpers
|
||||
History::Memory & History::get_memory_back()
|
||||
{
|
||||
return memory.at(
|
||||
index - 1
|
||||
);
|
||||
}
|
||||
|
||||
History::Memory & History::get_memory_forward()
|
||||
{
|
||||
return memory.at(
|
||||
index + 1
|
||||
forward(
|
||||
match,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
@ -18,47 +18,43 @@ namespace app::browser::main::tab::page::navbar
|
||||
|
||||
class History : public Gtk::Box
|
||||
{
|
||||
// Extras
|
||||
struct Memory
|
||||
{
|
||||
Glib::ustring request;
|
||||
std::time_t time; // event unix time
|
||||
bool permanent; // save in database (on application close) @TODO
|
||||
};
|
||||
|
||||
// Define navigation history storage
|
||||
std::vector<Memory> memory;
|
||||
int index = 0;
|
||||
|
||||
// Private helpers
|
||||
Memory & get_memory_back();
|
||||
Memory & get_memory_forward();
|
||||
|
||||
// Components
|
||||
history::Back * historyBack;
|
||||
history::Forward * historyForward;
|
||||
|
||||
int index = 0;
|
||||
|
||||
public:
|
||||
|
||||
// Extras
|
||||
struct Memory
|
||||
{
|
||||
Glib::ustring request;
|
||||
std::time_t time; // event unix time
|
||||
bool permanent; // save in database (on application close) @TODO
|
||||
};
|
||||
|
||||
// Define navigation history storage
|
||||
std::vector<Memory> memory;
|
||||
|
||||
History();
|
||||
|
||||
// Actions
|
||||
void back();
|
||||
void forward();
|
||||
bool back(
|
||||
Memory & match,
|
||||
bool follow = true
|
||||
);
|
||||
|
||||
bool forward(
|
||||
Memory & match,
|
||||
bool follow = true
|
||||
);
|
||||
|
||||
void push(
|
||||
const Glib::ustring & REQUEST
|
||||
);
|
||||
|
||||
void refresh();
|
||||
|
||||
// Getters
|
||||
bool has_memory_back();
|
||||
bool has_memory_forward();
|
||||
|
||||
// Copying getters (to keep private members encapsulation)
|
||||
Glib::ustring make_memory_back_request();
|
||||
Glib::ustring make_memory_forward_request();
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user