m_lastViewedTab(0)
{
connect(this, &DolphinTabWidget::tabCloseRequested,
- this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::closeTab));
+ this, QOverload<int>::of(&DolphinTabWidget::closeTab));
connect(this, &DolphinTabWidget::currentChanged,
this, &DolphinTabWidget::currentTabChanged);
DolphinTabBar* tabBar = new DolphinTabBar(this);
connect(tabBar, &DolphinTabBar::openNewActivatedTab,
- this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::openNewActivatedTab));
+ this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
connect(tabBar, &DolphinTabBar::tabDropEvent,
this, &DolphinTabWidget::tabDropEvent);
connect(tabBar, &DolphinTabBar::tabDetachRequested,
{
const int tabCount = count();
for (int i = 0; i < tabCount; ++i) {
+ tabBar()->setTabText(i, tabName(tabPageAt(i)));
tabPageAt(i)->refreshViews();
}
}
// The URL navigator of the new tab should have the same editable state
// as the current tab
- KUrlNavigator* navigator = newActiveViewContainer->urlNavigator();
- navigator->setUrlEditable(isUrlEditable);
+ newActiveViewContainer->urlNavigator()->setUrlEditable(isUrlEditable);
- if (isUrlEditable) {
- // If a new tab is opened and the URL is editable, assure that
- // the user can edit the URL without manually setting the focus
- navigator->setFocus();
- }
+ // Always focus the new tab's view
+ newActiveViewContainer->view()->setFocus();
}
void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
setCurrentIndex(count() - 1);
}
-void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
+void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement)
{
QWidget* focusWidget = QApplication::focusWidget();
this, &DolphinTabWidget::activeViewChanged);
connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
this, &DolphinTabWidget::tabUrlChanged);
- addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(primaryUrl));
+ int newTabIndex = -1;
+ if (tabPlacement == AfterCurrentTab) {
+ newTabIndex = currentIndex() + 1;
+ }
+ insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
if (focusWidget) {
// The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
Q_ASSERT(index < count());
if (count() < 2) {
- // Never close the last tab.
+ // Close Dolphin when closing the last tab.
+ parentWidget()->close();
return;
}
{
const int index = indexOf(qobject_cast<QWidget*>(sender()));
if (index >= 0) {
- tabBar()->setTabText(index, tabName(url));
+ tabBar()->setTabText(index, tabName(tabPageAt(index)));
tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
// Emit the currentUrlChanged signal if the url of the current tab has been changed.
emit tabCountChanged(count());
}
-QString DolphinTabWidget::tabName(const QUrl& url) const
+QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
{
- QString name;
- if (url == QUrl(QStringLiteral("file:///"))) {
- name = '/';
- } else {
- name = url.adjusted(QUrl::StripTrailingSlash).fileName();
- if (name.isEmpty()) {
- name = url.scheme();
- } else {
- // Make sure that a '&' inside the directory name is displayed correctly
- // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
- name.replace('&', QLatin1String("&&"));
- }
+ if (!tabPage) {
+ return QString();
}
- return name;
+ QString name = tabPage->activeViewContainer()->caption();
+ // Make sure that a '&' inside the directory name is displayed correctly
+ // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
+ return name.replace('&', QLatin1String("&&"));
}