#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"
#include "views/dolphinremoteencoding.h"
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
+#include "views/dolphinnewfilemenuobserver.h"
#ifndef Q_OS_WIN
#include "panels/terminal/terminalpanel.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),
m_updateToolBarTimer(0),
m_lastHandleUrlStatJob(0)
{
- // Workaround for a X11-issue in combination with KModifierInfo
- // (see DolphinContextMenu::initializeModifierKeyInfo() for
- // more information):
- DolphinContextMenu::initializeModifierKeyInfo();
-
setObjectName("Dolphin#");
m_viewTab.append(ViewTab());
ViewTab& viewTab = m_viewTab[m_tabIndex];
viewTab.wasActive = true; // The first opened tab is automatically active
+ connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString)),
+ this, SLOT(showErrorMessage(QString)));
+
KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
undoManager->setUiInterface(new UndoUiInterface());
toggleSplitView();
}
updateEditActions();
+ updatePasteAction();
updateViewActions();
updateGoActions();
// Open each directory inside a new tab. If the "split view" option has been enabled,
// always show two directories within one tab.
- QList<KUrl>::const_iterator it = dirs.begin();
- while (it != dirs.end()) {
+ QList<KUrl>::const_iterator it = dirs.constBegin();
+ while (it != dirs.constEnd()) {
openNewTab(*it);
++it;
- if (hasSplitView && (it != dirs.end())) {
+ if (hasSplitView && (it != dirs.constEnd())) {
const int tabIndex = m_viewTab.count() - 1;
m_viewTab[tabIndex].secondaryView->setUrl(*it);
++it;
if (view) {
view->setUrl(url);
updateEditActions();
+ updatePasteAction();
updateViewActions();
updateGoActions();
setUrlAsCaption(url);
m_viewTab.append(viewTab);
actionCollection()->action("close_tab")->setEnabled(true);
+ actionCollection()->action("activate_prev_tab")->setEnabled(true);
+ actionCollection()->action("activate_next_tab")->setEnabled(true);
// Provide a split view, if the startup settings are set this way
if (GeneralSettings::splitView()) {
void DolphinMainWindow::openInNewTab()
{
- const KFileItemList list = m_activeViewContainer->view()->selectedItems();
+ const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
if (list.isEmpty()) {
openNewTab(m_activeViewContainer->url());
- } else if ((list.count() == 1) && list[0].isDir()) {
- openNewTab(list[0].url());
+ } else {
+ foreach (const KFileItem& item, list) {
+ const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+ if (!url.isEmpty()) {
+ openNewTab(url);
+ }
+ }
}
}
const KFileItemList list = m_activeViewContainer->view()->selectedItems();
if (list.isEmpty()) {
newWindowUrl = m_activeViewContainer->url();
- } else if ((list.count() == 1) && list[0].isDir()) {
- newWindowUrl = list[0].url();
+ } else if (list.count() == 1) {
+ const KFileItem& item = list.first();
+ newWindowUrl = DolphinView::openItemAsFolderUrl(item);
}
if (!newWindowUrl.isEmpty()) {
break;
case KDialog::No:
// Close only the current tab
- closeTab();
+ closeTab();
default:
event->ignore();
return;
Q_ASSERT(cont);
}
+ // The right view must be activated before the URL is set. Changing
+ // the URL in the right view will emit the right URL navigator's
+ // urlChanged(KUrl) signal, which is connected to the changeUrl(KUrl)
+ // slot. That slot will change the URL in the left view if it is still
+ // active. See https://bugs.kde.org/show_bug.cgi?id=330047.
+ setActiveViewContainer(cont);
+
cont->setUrl(secondaryUrl);
const bool editable = group.readEntry(tabProperty("Secondary Editable", i), false);
cont->urlNavigator()->setUrlEditable(editable);
// openNewTab() needs to be called only tabCount - 1 times
if (i != tabCount - 1) {
- openNewTab();
+ openNewTab();
}
}
}
}
-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));
void DolphinMainWindow::compareFiles()
{
- // The method is only invoked if exactly 2 files have
- // been selected. The selected files may be:
- // - both in the primary view
- // - both in the secondary view
- // - one in the primary view and the other in the secondary
- // view
- Q_ASSERT(m_viewTab[m_tabIndex].primaryView);
-
- KUrl urlA;
- KUrl urlB;
-
- KFileItemList items = m_viewTab[m_tabIndex].primaryView->view()->selectedItems();
+ const DolphinViewContainer* primaryViewContainer = m_viewTab[m_tabIndex].primaryView;
+ Q_ASSERT(primaryViewContainer);
+ KFileItemList items = primaryViewContainer->view()->selectedItems();
- switch (items.count()) {
- case 0: {
- Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
- items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
- Q_ASSERT(items.count() == 2);
- urlA = items[0].url();
- urlB = items[1].url();
- break;
- }
-
- case 1: {
- urlA = items[0].url();
- Q_ASSERT(m_viewTab[m_tabIndex].secondaryView);
- items = m_viewTab[m_tabIndex].secondaryView->view()->selectedItems();
- Q_ASSERT(items.count() == 1);
- urlB = items[0].url();
- break;
+ const DolphinViewContainer* secondaryViewContainer = m_viewTab[m_tabIndex].secondaryView;
+ if (secondaryViewContainer) {
+ items.append(secondaryViewContainer->view()->selectedItems());
}
- case 2: {
- urlA = items[0].url();
- urlB = items[1].url();
- break;
+ if (items.count() != 2) {
+ // The action is disabled in this case, but it could have been triggered
+ // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
+ return;
}
- default: {
- // may not happen: compareFiles may only get invoked if 2
- // files are selected
- Q_ASSERT(false);
- }
- }
+ KUrl urlA = items.at(0).url();
+ KUrl urlB = items.at(1).url();
QString command("kompare -c \"");
command.append(urlA.pathOrUrl());
// 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();
if (m_viewTab.count() == 1) {
m_tabBar->removeTab(0);
actionCollection()->action("close_tab")->setEnabled(false);
+ actionCollection()->action("activate_prev_tab")->setEnabled(false);
+ actionCollection()->action("activate_next_tab")->setEnabled(false);
} else {
m_tabBar->blockSignals(false);
}
const ViewTab& viewTab = m_viewTab[tab];
const DolphinView* view = viewTab.isPrimaryViewActive ? viewTab.primaryView->view()
: viewTab.secondaryView->view();
- const QString error = DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event);
+ QString error;
+ DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event, error);
if (!error.isEmpty()) {
activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
}
activeViewContainer()->showMessage(error, DolphinViewContainer::Error);
}
+void DolphinMainWindow::slotPlaceActivated(const KUrl& url)
+{
+ DolphinViewContainer* view = activeViewContainer();
+
+ if (view->url() == url) {
+ // We can end up here if the user clicked a device in the Places Panel
+ // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
+ reloadView();
+ } else {
+ changeUrl(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);
updateHistory();
updateEditActions();
+ updatePasteAction();
updateViewActions();
updateGoActions();
void DolphinMainWindow::setupActions()
{
// setup 'File' menu
- m_newFileMenu = new DolphinNewFileMenu(this);
+ m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
KMenu* menu = m_newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
menu->setIcon(KIcon("document-new"));
+ m_newFileMenu->setDelayed(false);
connect(menu, SIGNAL(aboutToShow()),
this, SLOT(updateNewMenu()));
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(i18n("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);
+ 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)));
KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection());
connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons)));
prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
KAction* activateNextTab = actionCollection()->addAction("activate_next_tab");
+ activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
+ activateNextTab->setEnabled(false);
connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab()));
activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys);
KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab");
+ activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
+ activatePrevTab->setEnabled(false);
connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab()));
activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys);
openInNewTab->setIcon(KIcon("tab-new"));
connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab()));
+ KAction* openInNewTabs = actionCollection()->addAction("open_in_new_tabs");
+ openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
+ openInNewTabs->setIcon(KIcon("tab-new"));
+ connect(openInNewTabs, SIGNAL(triggered()), this, SLOT(openInNewTab()));
+
KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window");
openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
openInNewWindow->setIcon(KIcon("window-new"));
addDockWidget(Qt::LeftDockWidgetArea, placesDock);
connect(placesPanel, SIGNAL(placeActivated(KUrl)),
- this, SLOT(changeUrl(KUrl)));
+ this, SLOT(slotPlaceActivated(KUrl)));
connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)),
this, SLOT(openNewTab(KUrl)));
connect(placesPanel, SIGNAL(errorMessage(QString)),
deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
cutAction->setEnabled(capabilities.supportsMoving());
}
- updatePasteAction();
}
void DolphinMainWindow::updateViewActions()
return true;
}
-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(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(KIcon(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);
const int newWidth = (viewTab.primaryView->width() - splitter->handleWidth()) / 2;
const DolphinView* view = viewTab.primaryView->view();
- viewTab.secondaryView = createViewContainer(view->url(), 0);
+ // The final parent of the new view container will be set by adding it
+ // to the splitter. However, we must make sure that the DolphinMainWindow
+ // is a parent of the view container already when it is constructed
+ // because this enables the container's KFileItemModel to assign its
+ // dir lister to the right main window. The dir lister can then cache
+ // authentication data.
+ viewTab.secondaryView = createViewContainer(view->url(), this);
splitter->addWidget(viewTab.secondaryView);
splitter->setSizes(QList<int>() << newWidth << newWidth);