Browse Source

draft history navigation

CPP-GTK4
yggverse 3 months ago
parent
commit
769ef576f6
  1. 26
      src/app/browser/main/tab/page/navbar.cpp
  2. 87
      src/app/browser/main/tab/page/navbar/history.cpp
  3. 16
      src/app/browser/main/tab/page/navbar/history.hpp

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

@ -89,12 +89,30 @@ Navbar::Navbar( @@ -89,12 +89,30 @@ Navbar::Navbar(
// Actions
void Navbar::back()
{
navbarHistory->back();
if (navbarHistory->has_memory_back())
{
navbarRequest->set_text(
navbarHistory->make_memory_back_request()
);
navbarHistory->back(); // --
navbarUpdate->activate();
}
}
void Navbar::forward()
{
navbarHistory->forward();
if (navbarHistory->has_memory_forward())
{
navbarRequest->set_text(
navbarHistory->make_memory_forward_request()
);
navbarHistory->forward(); // ++
navbarUpdate->activate();
}
}
void Navbar::push(
@ -121,7 +139,7 @@ void Navbar::refresh() @@ -121,7 +139,7 @@ void Navbar::refresh()
navbarHistory->refresh();
}
// Setters
// Setters @TODO is really wanted?
void Navbar::set_request_text(
const Glib::ustring & VALUE
) {
@ -132,7 +150,7 @@ void Navbar::set_request_text( @@ -132,7 +150,7 @@ void Navbar::set_request_text(
// refresh(); not wanted as on change listener do same @TODO
}
// Getters
// Getters @TODO &
Glib::ustring Navbar::get_request_text()
{
return navbarRequest->get_text();

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

@ -26,12 +26,18 @@ History::History() @@ -26,12 +26,18 @@ History::History()
// Actions
void History::back()
{
historyBack->activate();
if (has_memory_back())
{
index--;
}
}
void History::forward()
{
historyForward->activate();
if (has_memory_forward())
{
index++;
}
}
void History::push(
@ -48,16 +54,89 @@ void History::push( @@ -48,16 +54,89 @@ void History::push(
true
}
);
index = memory.size(); // @TODO
}
}
void History::refresh()
{
historyBack->set_sensitive(
false // @TODO memory.size() > 0
has_memory_back()
);
historyForward->set_sensitive(
false // @TODO memory.size() > 0
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
);
}

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

@ -26,8 +26,13 @@ namespace app::browser::main::tab::page::navbar @@ -26,8 +26,13 @@ namespace app::browser::main::tab::page::navbar
bool permanent; // save in database (on application close) @TODO
};
// Define navigation history storage
std::vector<Memory> memory;
std::vector<Memory>::iterator memory_index;
int index = 0;
// Private helpers
Memory & get_memory_back();
Memory & get_memory_forward();
// Components
history::Back * historyBack;
@ -37,6 +42,7 @@ namespace app::browser::main::tab::page::navbar @@ -37,6 +42,7 @@ namespace app::browser::main::tab::page::navbar
History();
// Actions
void back();
void forward();
@ -45,6 +51,14 @@ namespace app::browser::main::tab::page::navbar @@ -45,6 +51,14 @@ namespace app::browser::main::tab::page::navbar
);
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