X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c7d607a7fc1c9e027d6abdb5adcc7c542bbaa268..81b84a1eaf9fcfc3c2318b7ab4d30c7c578e9680:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 924354b4b..75cc12f46 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,6 +25,7 @@ #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" +#include "dolphinrecenttabsmenu.h" #include "dolphinviewcontainer.h" #include "panels/folders/folderspanel.h" #include "panels/places/placespanel.h" @@ -96,19 +97,6 @@ namespace { const int CurrentDolphinVersion = 200; }; -/* - * Remembers the tab configuration if a tab has been closed. - * Each closed tab can be restored by the menu - * "Go -> Recently Closed Tabs". - */ -struct ClosedTab -{ - KUrl primaryUrl; - KUrl secondaryUrl; - bool isSplit; -}; -Q_DECLARE_METATYPE(ClosedTab) - DolphinMainWindow::DolphinMainWindow() : KXmlGuiWindow(0), m_newFileMenu(0), @@ -743,35 +731,6 @@ void DolphinMainWindow::slotUndoAvailable(bool available) } } -void DolphinMainWindow::restoreClosedTab(QAction* action) -{ - if (action->data().toBool()) { - // clear all actions except the "Empty Recently Closed Tabs" - // action and the separator - QList actions = m_recentTabsMenu->menu()->actions(); - const int count = actions.size(); - for (int i = 2; i < count; ++i) { - m_recentTabsMenu->menu()->removeAction(actions.at(i)); - } - } else { - const ClosedTab closedTab = action->data().value(); - openNewTab(closedTab.primaryUrl); - m_tabBar->setCurrentIndex(m_viewTab.count() - 1); - - if (closedTab.isSplit) { - // create secondary view - toggleSplitView(); - m_viewTab[m_tabIndex].secondaryView->setUrl(closedTab.secondaryUrl); - } - - m_recentTabsMenu->removeAction(action); - } - - if (m_recentTabsMenu->menu()->actions().count() == 2) { - m_recentTabsMenu->setEnabled(false); - } -} - void DolphinMainWindow::slotUndoTextChanged(const QString& text) { QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); @@ -1140,7 +1099,10 @@ void DolphinMainWindow::closeTab(int index) // previous tab before closing the tab. m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1); } - rememberClosedTab(index); + + const KUrl primaryUrl(m_viewTab[index].primaryView->url()); + const KUrl secondaryUrl(m_viewTab[index].secondaryView ? m_viewTab[index].secondaryView->url() : KUrl()); + emit rememberClosedTab(primaryUrl, secondaryUrl); // delete tab m_viewTab[index].primaryView->deleteLater(); @@ -1439,6 +1401,18 @@ void DolphinMainWindow::slotPlaceActivated(const KUrl& url) } } +void DolphinMainWindow::restoreClosedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl) +{ + openNewActivatedTab(primaryUrl); + + if (!secondaryUrl.isEmpty() && secondaryUrl.isValid()) { + const int index = m_tabBar->currentIndex(); + createSecondaryView(index); + setActiveViewContainer(m_viewTab[index].secondaryView); + m_viewTab[index].secondaryView->setUrl(secondaryUrl); + } +} + void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { Q_ASSERT(viewContainer); @@ -1582,33 +1556,20 @@ void DolphinMainWindow::setupActions() // setup 'Go' menu QAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection()); - connect(backAction, &QAction::triggered, this, static_cast(&DolphinMainWindow::goBack)); auto backShortcuts = backAction->shortcuts(); backShortcuts.append(QKeySequence(Qt::Key_Backspace)); backAction->setShortcuts(backShortcuts); - m_recentTabsMenu = new KActionMenu(i18n("Recently Closed Tabs"), this); - m_recentTabsMenu->setIcon(QIcon::fromTheme("edit-undo")); - m_recentTabsMenu->setDelayed(false); - actionCollection()->addAction("closed_tabs", m_recentTabsMenu); - connect(m_recentTabsMenu->menu(), &QMenu::triggered, - this, &DolphinMainWindow::restoreClosedTab); - - QAction* action = new QAction(i18n("Empty Recently Closed Tabs"), m_recentTabsMenu); - action->setIcon(QIcon::fromTheme("edit-clear-list")); - action->setData(QVariant::fromValue(true)); - m_recentTabsMenu->addAction(action); - m_recentTabsMenu->addSeparator(); - m_recentTabsMenu->setEnabled(false); - - QAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection()); - connect(forwardAction, &QAction::triggered, this, static_cast(&DolphinMainWindow::goForward)); + DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this); + actionCollection()->addAction("closed_tabs", recentTabsMenu); + connect(this, SIGNAL(rememberClosedTab(KUrl,KUrl)), + recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl))); + connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)), + this, SLOT(restoreClosedTab(KUrl,KUrl))); - QAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection()); - connect(upAction, &QAction::triggered, this, static_cast(&DolphinMainWindow::goUp)); - - QAction* homeAction = KStandardAction::home(this, SLOT(goHome()), actionCollection()); - connect(homeAction, &QAction::triggered, this, static_cast(&DolphinMainWindow::goHome)); + KStandardAction::forward(this, SLOT(goForward()), actionCollection()); + KStandardAction::up(this, SLOT(goUp()), actionCollection()); + KStandardAction::home(this, SLOT(goHome()), actionCollection()); // setup 'Tools' menu QAction* showFilterBar = actionCollection()->addAction("show_filter_bar"); @@ -1908,44 +1869,6 @@ bool DolphinMainWindow::addActionToMenu(QAction* action, KMenu* menu) return true; } -void DolphinMainWindow::rememberClosedTab(int index) -{ - QMenu* tabsMenu = m_recentTabsMenu->menu(); - - const QString primaryPath = m_viewTab[index].primaryView->url().path(); - const QString iconName = KIO::iconNameForUrl(primaryPath); - - QAction* action = new QAction(squeezedText(primaryPath), tabsMenu); - - ClosedTab closedTab; - closedTab.primaryUrl = m_viewTab[index].primaryView->url(); - - if (m_viewTab[index].secondaryView) { - closedTab.secondaryUrl = m_viewTab[index].secondaryView->url(); - closedTab.isSplit = true; - } else { - closedTab.isSplit = false; - } - - action->setData(QVariant::fromValue(closedTab)); - action->setIcon(QIcon::fromTheme(iconName)); - - // add the closed tab menu entry after the separator and - // "Empty Recently Closed Tabs" entry - if (tabsMenu->actions().size() == 2) { - tabsMenu->addAction(action); - } else { - tabsMenu->insertAction(tabsMenu->actions().at(2), action); - } - - // assure that only up to 8 closed tabs are shown in the menu - if (tabsMenu->actions().size() > 8) { - tabsMenu->removeAction(tabsMenu->actions().last()); - } - actionCollection()->action("closed_tabs")->setEnabled(true); - KAcceleratorManager::manage(tabsMenu); -} - void DolphinMainWindow::refreshViews() { Q_ASSERT(m_viewTab[m_tabIndex].primaryView); @@ -2161,4 +2084,3 @@ void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) } } -#include "dolphinmainwindow.moc"