X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/be1298d9aabbcc18c8a2b1c697d2bca5e7c0a9f3..78e9cc506f90eb862f032154199331b5e5e6dffb:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 24e1a1f97..78e489915 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -28,6 +28,7 @@ #include "dolphinnewmenu.h" #include "settings/dolphinsettings.h" #include "settings/dolphinsettingsdialog.h" +#include "dolphinsearchbox.h" #include "dolphinstatusbar.h" #include "dolphinviewcontainer.h" #include "panels/folders/folderspanel.h" @@ -92,7 +93,7 @@ DolphinMainWindow::DolphinMainWindow(int id) : m_tabBar(0), m_activeViewContainer(0), m_centralWidgetLayout(0), - m_searchBar(0), + m_searchBox(0), m_id(id), m_tabIndex(0), m_viewTab(), @@ -265,6 +266,15 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) emit selectionChanged(selection); } +void DolphinMainWindow::slotWheelMoved(int wheelDelta) +{ + if (wheelDelta > 0) { + activatePrevTab(); + } else { + activateNextTab(); + } +} + void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item) { emit requestItemInfo(item); @@ -480,6 +490,35 @@ void DolphinMainWindow::slotUndoAvailable(bool available) } } +void DolphinMainWindow::restoreClosedTab(QAction* action) +{ + //The Clear Recently Closed Tabs List QAction, has it's data set to true, so we can detect it in here, as it's an exception. + if (action->data().toBool() == true) { + // Lets preserve the separator, and the clear action within this menu. + QList actionlist = m_recentTabsMenu->menu()->actions(); + for (int i = 2; i < actionlist.size(); i++) { + m_recentTabsMenu->menu()->removeAction(actionlist.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)); @@ -768,8 +807,8 @@ void DolphinMainWindow::closeTab(int index) // previous tab before closing the tab. m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1); } - - // delete tab + rememberClosedTab(index); + //Delete this tab. m_viewTab[index].primaryView->deleteLater(); if (m_viewTab[index].secondaryView != 0) { m_viewTab[index].secondaryView->deleteLater(); @@ -843,10 +882,9 @@ void DolphinMainWindow::slotTestCanDecode(const QDragMoveEvent* event, bool& can canDecode = KUrl::List::canDecode(event->mimeData()); } -void DolphinMainWindow::searchItems() +void DolphinMainWindow::searchItems(const KUrl& url) { - const QString nepomukString = "nepomuksearch:/" + m_searchBar->text(); - m_activeViewContainer->setUrl(KUrl(nepomukString)); + m_activeViewContainer->setUrl(url); } @@ -885,7 +923,8 @@ void DolphinMainWindow::init() m_actionHandler->setCurrentView(view); m_tabBar = new KTabBar(this); - m_tabBar->setCloseButtonEnabled(true); + m_tabBar->setMovable(true); + m_tabBar->setTabsClosable(true); connect(m_tabBar, SIGNAL(currentChanged(int)), this, SLOT(setActiveTab(int))); connect(m_tabBar, SIGNAL(closeRequest(int)), @@ -896,6 +935,11 @@ void DolphinMainWindow::init() this, SLOT(openNewTab())); connect(m_tabBar, SIGNAL(testCanDecode(const QDragMoveEvent*, bool&)), this, SLOT(slotTestCanDecode(const QDragMoveEvent*, bool&))); + connect(m_tabBar, SIGNAL(wheelDelta(int)), + this, SLOT(slotWheelMoved(int))); + connect(m_tabBar, SIGNAL(mouseMiddleClick(int)), + this, SLOT(closeTab(int))); + m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open QWidget* centralWidget = new QWidget(this); @@ -911,9 +955,8 @@ void DolphinMainWindow::init() setupGUI(Keys | Save | Create | ToolBar); - m_searchBar->setParent(toolBar("searchToolBar")); - m_searchBar->setFont(KGlobalSettings::generalFont()); - m_searchBar->show(); + m_searchBox->setParent(toolBar("searchToolBar")); + m_searchBox->show(); stateChanged("new_file"); @@ -993,10 +1036,10 @@ void DolphinMainWindow::setupActions() KAction* newTab = actionCollection()->addAction("new_tab"); newTab->setIcon(KIcon("tab-new")); newTab->setText(i18nc("@action:inmenu File", "New Tab")); - newTab->setShortcut(KShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_N, Qt::CTRL | Qt::Key_T)); + newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N)); connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab())); - QAction* closeTab = actionCollection()->addAction("close_tab"); + KAction* closeTab = actionCollection()->addAction("close_tab"); closeTab->setIcon(KIcon("tab-close")); closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); closeTab->setShortcut(Qt::CTRL | Qt::Key_W); @@ -1064,6 +1107,19 @@ void DolphinMainWindow::setupActions() backShortcut.setAlternate(Qt::Key_Backspace); backAction->setShortcut(backShortcut); + m_recentTabsMenu = new KActionMenu(i18n("&Recently Closed Tabs"), this); + m_recentTabsMenu->setIcon(KIcon("edit-undo")); + actionCollection()->addAction("closed_tabs", m_recentTabsMenu); + connect(m_recentTabsMenu->menu(), SIGNAL(triggered(QAction *)), + this, SLOT(restoreClosedTab(QAction *))); + + QAction* action = new QAction("&Empty Recently Closed Tabs", m_recentTabsMenu); + action->setIcon(KIcon("edit-clear-list")); + action->setData(QVariant::fromValue(true)); + m_recentTabsMenu->addAction(action); + m_recentTabsMenu->addSeparator(); + m_recentTabsMenu->setEnabled(false); + KStandardAction::forward(this, SLOT(goForward()), actionCollection()); KStandardAction::up(this, SLOT(goUp()), actionCollection()); KStandardAction::home(this, SLOT(goHome()), actionCollection()); @@ -1124,15 +1180,13 @@ void DolphinMainWindow::setupActions() connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow())); // 'Search' toolbar - m_searchBar = new KLineEdit(this); - m_searchBar->setMinimumWidth(150); - m_searchBar->setClearButtonShown(true); - connect(m_searchBar, SIGNAL(returnPressed()), this, SLOT(searchItems())); + m_searchBox = new DolphinSearchBox(this); + connect(m_searchBox, SIGNAL(search(KUrl)), this, SLOT(searchItems(KUrl))); KAction* search = new KAction(this); actionCollection()->addAction("search_bar", search); search->setText(i18nc("@action:inmenu", "Search Bar")); - search->setDefaultWidget(m_searchBar); + search->setDefaultWidget(m_searchBox); search->setShortcutConfigurable(false); } @@ -1279,6 +1333,37 @@ void DolphinMainWindow::updateGoActions() goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } +void DolphinMainWindow::rememberClosedTab(int index) +{ + KMenu* tabsMenu = m_recentTabsMenu->menu(); + + const QString primaryPath = m_viewTab[index].primaryView->url().path(); + const QString iconName = KMimeType::iconNameForUrl(primaryPath); + + QAction* action = new QAction(primaryPath, tabsMenu); + + ClosedTab closedTab; + closedTab.primaryUrl = m_viewTab[index].primaryView->url(); + + if (m_viewTab[index].secondaryView != 0) { + closedTab.secondaryUrl = m_viewTab[index].secondaryView->url(); + closedTab.isSplit = true; + } else { + closedTab.isSplit = false; + } + + action->setData(QVariant::fromValue(closedTab)); + action->setIcon(KIcon(iconName)); + + //Add our action at the first element, but only do that if it isn't empty, else just append + if (tabsMenu->actions().isEmpty()) { + tabsMenu->addAction(action); + } else { + tabsMenu->insertAction(tabsMenu->actions().first() + 2, action); + } + actionCollection()->action("closed_tabs")->setEnabled(true); +} + void DolphinMainWindow::clearStatusBar() { m_activeViewContainer->statusBar()->clear(); @@ -1334,6 +1419,10 @@ QString DolphinMainWindow::tabName(const KUrl& url) const name = url.fileName(); if (name.isEmpty()) { name = url.protocol(); + } else { + // Make sure that a '&' inside the directory name is displayed correctly + // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() + name.replace('&', "&&"); } } return name;