mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
Ladybird: Allow browser tabs to be closed
This is a small patch which wires up the tab close button.
This commit is contained in:
parent
8af5b49cba
commit
67ab6dd2e6
2 changed files with 14 additions and 2 deletions
|
@ -29,6 +29,7 @@ BrowserWindow::BrowserWindow(Core::EventLoop& event_loop)
|
||||||
setWindowTitle(m_tabs_container->tabText(index));
|
setWindowTitle(m_tabs_container->tabText(index));
|
||||||
setWindowIcon(m_tabs_container->tabIcon(index));
|
setWindowIcon(m_tabs_container->tabIcon(index));
|
||||||
});
|
});
|
||||||
|
QObject::connect(m_tabs_container, &QTabWidget::tabCloseRequested, this, &BrowserWindow::close_tab);
|
||||||
|
|
||||||
new_tab();
|
new_tab();
|
||||||
|
|
||||||
|
@ -46,11 +47,21 @@ void BrowserWindow::new_tab()
|
||||||
}
|
}
|
||||||
|
|
||||||
m_tabs_container->addTab(tab_ptr, "New Tab");
|
m_tabs_container->addTab(tab_ptr, "New Tab");
|
||||||
|
m_tabs_container->setCurrentWidget(tab_ptr);
|
||||||
|
|
||||||
QObject::connect(tab_ptr, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
|
QObject::connect(tab_ptr, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
|
||||||
QObject::connect(tab_ptr, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
|
QObject::connect(tab_ptr, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::close_tab(int index)
|
||||||
|
{
|
||||||
|
auto* tab = m_tabs_container->widget(index);
|
||||||
|
m_tabs_container->removeTab(index);
|
||||||
|
m_tabs.remove_first_matching([&](auto& entry) {
|
||||||
|
return entry == tab;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
int BrowserWindow::tab_index(Tab* tab)
|
int BrowserWindow::tab_index(Tab* tab)
|
||||||
{
|
{
|
||||||
return m_tabs_container->indexOf(tab);
|
return m_tabs_container->indexOf(tab);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Tab.h"
|
#include "Tab.h"
|
||||||
#include <AK/Vector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <LibCore/Forward.h>
|
#include <LibCore/Forward.h>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
@ -33,10 +33,11 @@ public slots:
|
||||||
void tab_title_changed(int index, QString const&);
|
void tab_title_changed(int index, QString const&);
|
||||||
void tab_favicon_changed(int index, QIcon icon);
|
void tab_favicon_changed(int index, QIcon icon);
|
||||||
void new_tab();
|
void new_tab();
|
||||||
|
void close_tab(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget* m_tabs_container { nullptr };
|
QTabWidget* m_tabs_container { nullptr };
|
||||||
Vector<NonnullOwnPtr<Tab>> m_tabs;
|
NonnullOwnPtrVector<Tab> m_tabs;
|
||||||
Tab* m_current_tab { nullptr };
|
Tab* m_current_tab { nullptr };
|
||||||
|
|
||||||
Core::EventLoop& m_event_loop;
|
Core::EventLoop& m_event_loop;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue