X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b6cf6cc6846755f11b1c8ebce28ea7f8b7c6e77d..c8ad5fd5b615f7d1a5ed1e793bfc367f7d3966b3:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index e1cc13095..0523085ae 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -397,15 +397,19 @@ void DolphinMainWindow::openNewTab() void DolphinMainWindow::openNewTab(const KUrl& url) { - const KIcon icon = KIcon(KMimeType::iconNameForUrl(m_activeViewContainer->url())); + QWidget* focusWidget = QApplication::focusWidget(); + if (m_viewTab.count() == 1) { // Only one view is open currently and hence no tab is shown at // all. Before creating a tab for 'url', provide a tab for the current URL. - m_tabBar->addTab(icon, squeezedText(tabName(m_activeViewContainer->url()))); + const KUrl currentUrl = m_activeViewContainer->url(); + m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(currentUrl)), + squeezedText(tabName(currentUrl))); m_tabBar->blockSignals(false); } - m_tabBar->addTab(icon, squeezedText(tabName(url))); + m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(url)), + squeezedText(tabName(url))); ViewTab viewTab; viewTab.splitter = new QSplitter(this); @@ -427,6 +431,12 @@ void DolphinMainWindow::openNewTab(const KUrl& url) m_viewTab[tabIndex].secondaryView->setActive(true); m_viewTab[tabIndex].isPrimaryViewActive = false; } + + if (focusWidget != 0) { + // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened + // in background, assure that the previous focused widget gets the focus back. + focusWidget->setFocus(); + } } void DolphinMainWindow::activateNextTab() @@ -485,6 +495,14 @@ void DolphinMainWindow::toggleActiveView() setActiveViewContainer(m_activeViewContainer == right ? left : right); } +void DolphinMainWindow::showEvent(QShowEvent* event) +{ + KXmlGuiWindow::showEvent(event); + if (!event->spontaneous()) { + m_activeViewContainer->view()->setFocus(); + } +} + void DolphinMainWindow::closeEvent(QCloseEvent* event) { DolphinSettings& settings = DolphinSettings::instance();