Browse Source

simplify history navigation api

CPP-GTK4
yggverse 3 months ago
parent
commit
43e89716ae
  1. 16
      src/app/browser/main/tab/page/navbar.cpp
  2. 131
      src/app/browser/main/tab/page/navbar/history.cpp
  3. 48
      src/app/browser/main/tab/page/navbar/history.hpp

16
src/app/browser/main/tab/page/navbar.cpp

@ -89,28 +89,28 @@ Navbar::Navbar( @@ -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();
}
}

131
src/app/browser/main/tab/page/navbar/history.cpp

@ -24,19 +24,51 @@ History::History() @@ -24,19 +24,51 @@ History::History()
}
// Actions
void History::back()
{
if (has_memory_back())
bool History::back(
Memory & match,
bool follow
) {
try
{
match = memory.at(
index - 1
);
if (follow)
{
index--;
}
return true;
}
catch (std::out_of_range)
{
index--;
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( @@ -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
)
);
}

48
src/app/browser/main/tab/page/navbar/history.hpp

@ -18,47 +18,43 @@ namespace app::browser::main::tab::page::navbar @@ -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…
Cancel
Save