mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:17:45 +00:00
Browser: Add title to go back/forward context menu
Adds page title to the context menu for go back/forward.
This commit is contained in:
parent
3f5eb6446b
commit
0aa0e00dd5
3 changed files with 39 additions and 23 deletions
|
@ -13,21 +13,24 @@ void History::dump() const
|
||||||
dbgln("Dump {} items(s)", m_items.size());
|
dbgln("Dump {} items(s)", m_items.size());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto& item : m_items) {
|
for (auto& item : m_items) {
|
||||||
dbgln("[{}] {} {}", i, item, m_current == i ? '*' : ' ');
|
dbgln("[{}] {} '{}' {}", i, item.url, item.title, m_current == i ? '*' : ' ');
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void History::push(const URL& url)
|
void History::push(const URL& url, const String& title)
|
||||||
{
|
{
|
||||||
if (!m_items.is_empty() && m_items[m_current] == url)
|
if (!m_items.is_empty() && m_items[m_current].url == url)
|
||||||
return;
|
return;
|
||||||
m_items.shrink(m_current + 1);
|
m_items.shrink(m_current + 1);
|
||||||
m_items.append(url);
|
m_items.append(URLTitlePair {
|
||||||
|
.url = url,
|
||||||
|
.title = title,
|
||||||
|
});
|
||||||
m_current++;
|
m_current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
URL History::current() const
|
History::URLTitlePair History::current() const
|
||||||
{
|
{
|
||||||
if (m_current == -1)
|
if (m_current == -1)
|
||||||
return {};
|
return {};
|
||||||
|
@ -52,22 +55,27 @@ void History::clear()
|
||||||
m_current = -1;
|
m_current = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<URL> History::get_back_history()
|
void History::update_title(const String& title)
|
||||||
{
|
{
|
||||||
Vector<URL> back_history;
|
m_items[m_current].title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector<StringView> History::get_back_title_history()
|
||||||
|
{
|
||||||
|
Vector<StringView> back_title_history;
|
||||||
for (int i = m_current - 1; i >= 0; i--) {
|
for (int i = m_current - 1; i >= 0; i--) {
|
||||||
back_history.append(m_items[i]);
|
back_title_history.append(m_items[i].title);
|
||||||
}
|
}
|
||||||
return back_history;
|
return back_title_history;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector<URL> History::get_forward_history()
|
const Vector<StringView> History::get_forward_title_history()
|
||||||
{
|
{
|
||||||
Vector<URL> forward_history;
|
Vector<StringView> forward_title_history;
|
||||||
for (int i = m_current + 1; i < static_cast<int>(m_items.size()); i++) {
|
for (int i = m_current + 1; i < static_cast<int>(m_items.size()); i++) {
|
||||||
forward_history.append(m_items[i]);
|
forward_title_history.append(m_items[i].title);
|
||||||
}
|
}
|
||||||
return forward_history;
|
return forward_title_history;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,12 +13,18 @@ namespace Browser {
|
||||||
|
|
||||||
class History {
|
class History {
|
||||||
public:
|
public:
|
||||||
|
struct URLTitlePair {
|
||||||
|
URL url;
|
||||||
|
String title;
|
||||||
|
};
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
void push(const URL&);
|
void push(const URL& url, const String& title);
|
||||||
URL current() const;
|
void update_title(const String& title);
|
||||||
const Vector<URL> get_back_history();
|
URLTitlePair current() const;
|
||||||
const Vector<URL> get_forward_history();
|
|
||||||
|
const Vector<StringView> get_back_title_history();
|
||||||
|
const Vector<StringView> get_forward_title_history();
|
||||||
|
|
||||||
void go_back(int steps = 1);
|
void go_back(int steps = 1);
|
||||||
void go_forward(int steps = 1);
|
void go_forward(int steps = 1);
|
||||||
|
@ -28,7 +34,7 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Vector<URL> m_items;
|
Vector<URLTitlePair> m_items;
|
||||||
int m_current { -1 };
|
int m_current { -1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ Tab::Tab(BrowserWindow& window, Type type)
|
||||||
return;
|
return;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
m_go_back_context_menu = GUI::Menu::construct();
|
m_go_back_context_menu = GUI::Menu::construct();
|
||||||
for (auto& url : m_history.get_back_history()) {
|
for (auto& url : m_history.get_back_title_history()) {
|
||||||
i++;
|
i++;
|
||||||
m_go_back_context_menu->add_action(GUI::Action::create(url.to_string(),
|
m_go_back_context_menu->add_action(GUI::Action::create(url.to_string(),
|
||||||
Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"),
|
Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"),
|
||||||
|
@ -113,7 +113,7 @@ Tab::Tab(BrowserWindow& window, Type type)
|
||||||
return;
|
return;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
m_go_forward_context_menu = GUI::Menu::construct();
|
m_go_forward_context_menu = GUI::Menu::construct();
|
||||||
for (auto& url : m_history.get_forward_history()) {
|
for (auto& url : m_history.get_forward_title_history()) {
|
||||||
i++;
|
i++;
|
||||||
m_go_forward_context_menu->add_action(GUI::Action::create(url.to_string(),
|
m_go_forward_context_menu->add_action(GUI::Action::create(url.to_string(),
|
||||||
Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"),
|
Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"),
|
||||||
|
@ -161,7 +161,7 @@ Tab::Tab(BrowserWindow& window, Type type)
|
||||||
|
|
||||||
// don't add to history if back or forward is pressed
|
// don't add to history if back or forward is pressed
|
||||||
if (!m_is_history_navigation)
|
if (!m_is_history_navigation)
|
||||||
m_history.push(url);
|
m_history.push(url, title());
|
||||||
m_is_history_navigation = false;
|
m_is_history_navigation = false;
|
||||||
|
|
||||||
update_actions();
|
update_actions();
|
||||||
|
@ -231,8 +231,10 @@ Tab::Tab(BrowserWindow& window, Type type)
|
||||||
|
|
||||||
hooks().on_title_change = [this](auto& title) {
|
hooks().on_title_change = [this](auto& title) {
|
||||||
if (title.is_null()) {
|
if (title.is_null()) {
|
||||||
|
m_history.update_title(url().to_string());
|
||||||
m_title = url().to_string();
|
m_title = url().to_string();
|
||||||
} else {
|
} else {
|
||||||
|
m_history.update_title(title);
|
||||||
m_title = title;
|
m_title = title;
|
||||||
}
|
}
|
||||||
if (on_title_change)
|
if (on_title_change)
|
||||||
|
@ -347,14 +349,14 @@ void Tab::go_back(int steps)
|
||||||
{
|
{
|
||||||
m_history.go_back(steps);
|
m_history.go_back(steps);
|
||||||
update_actions();
|
update_actions();
|
||||||
load(m_history.current(), LoadType::HistoryNavigation);
|
load(m_history.current().url, LoadType::HistoryNavigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::go_forward(int steps)
|
void Tab::go_forward(int steps)
|
||||||
{
|
{
|
||||||
m_history.go_forward(steps);
|
m_history.go_forward(steps);
|
||||||
update_actions();
|
update_actions();
|
||||||
load(m_history.current(), LoadType::HistoryNavigation);
|
load(m_history.current().url, LoadType::HistoryNavigation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tab::update_actions()
|
void Tab::update_actions()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue