#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"
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),
}
}
-void DolphinMainWindow::restoreClosedTab(QAction* action)
-{
- if (action->data().toBool()) {
- // clear all actions except the "Empty Recently Closed Tabs"
- // action and the separator
- QList<QAction*> 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<ClosedTab>();
- 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));
// 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();
}
}
+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);
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);
+ 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)));
KStandardAction::forward(this, SLOT(goForward()), actionCollection());
KStandardAction::up(this, SLOT(goUp()), actionCollection());
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);