]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Fix alignment of icons in Places panel and Compact view mode
[dolphin.git] / src / dolphinmainwindow.cpp
index da241e20e5016a845961b646b389425ed9c018a7..d112007bc542a66fc654f2cc973473c0c8cf7125 100644 (file)
@@ -25,6 +25,7 @@
 #include "dolphindockwidget.h"
 #include "dolphincontextmenu.h"
 #include "dolphinnewfilemenu.h"
+#include "dolphinplacesmodelsingleton.h"
 #include "dolphinrecenttabsmenu.h"
 #include "dolphintabwidget.h"
 #include "dolphinviewcontainer.h"
 #include "views/draganddrophelper.h"
 #include "views/viewproperties.h"
 #include "views/dolphinnewfilemenuobserver.h"
-
 #include "dolphin_generalsettings.h"
 
 #include <KActionCollection>
 #include <KActionMenu>
 #include <KAuthorized>
 #include <KConfig>
-#include <kdualaction.h>
+#include <KFileItemListProperties>
+#include <KFilePlacesModel>
 #include <KHelpMenu>
-#include <KJobWidgets>
-#include <QLineEdit>
-#include <KToolBar>
 #include <KIO/JobUiDelegate>
+#include <KIO/OpenFileManagerWindowJob>
+#include <KJobWidgets>
 #include <KLocalizedString>
-#include <KProtocolManager>
-#include <KProtocolInfo>
-#include <QMenu>
 #include <KMessageBox>
-#include <KFilePlacesModel>
-#include <KFileItemListProperties>
+#include <KProtocolInfo>
+#include <KProtocolManager>
 #include <KRun>
 #include <KShell>
 #include <KStandardAction>
 #include <KToggleAction>
-#include <KUrlNavigator>
+#include <KToolBar>
 #include <KToolInvocation>
 #include <KUrlComboBox>
+#include <KUrlNavigator>
 
 #include <QApplication>
-#include <QMenuBar>
 #include <QClipboard>
-#include <QToolButton>
-#include <QTimer>
-#include <QStandardPaths>
-#include <QPushButton>
 #include <QCloseEvent>
-#include <QShowEvent>
 #include <QDialog>
+#include <QFileInfo>
+#include <QLineEdit>
+#include <QMenu>
+#include <QMenuBar>
+#include <QPushButton>
+#include <QShowEvent>
+#include <QStandardPaths>
+#include <QTimer>
+#include <QToolButton>
+#include <kdualaction.h>
 
 namespace {
     // Used for GeneralSettings::version() to determine whether
@@ -356,6 +358,22 @@ void DolphinMainWindow::openInNewWindow()
     }
 }
 
+void DolphinMainWindow::showTarget()
+{
+    const auto link = m_activeViewContainer->view()->selectedItems().at(0);
+    const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
+    auto linkDestination = link.linkDest();
+    if (QFileInfo(linkDestination).isRelative()) {
+        linkDestination = linkLocationDir.filePath(linkDestination);
+    }
+    if (QFileInfo::exists(linkDestination)) {
+        KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
+    } else {
+        m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination),
+                                           DolphinViewContainer::Warning);
+    }
+}
+
 void DolphinMainWindow::showEvent(QShowEvent* event)
 {
     KXmlGuiWindow::showEvent(event);
@@ -411,6 +429,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event)
             case QDialogButtonBox::No:
                 // Close only the current tab
                 m_tabWidget->closeTab();
+                Q_FALLTHROUGH();
             default:
                 event->ignore();
                 return;
@@ -975,8 +994,6 @@ void DolphinMainWindow::tabCountChanged(int count)
 
 void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
 {
-    static KFilePlacesModel s_placesModel;
-
     QString schemePrefix;
     if (!url.isLocalFile()) {
         schemePrefix.append(url.scheme() + " - ");
@@ -991,10 +1008,11 @@ void DolphinMainWindow::setUrlAsCaption(const QUrl& url)
         return;
     }
 
-    const auto& matchedPlaces = s_placesModel.match(s_placesModel.index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
+    KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel();
+    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
 
     if (!matchedPlaces.isEmpty()) {
-        setWindowTitle(s_placesModel.text(matchedPlaces.first()));
+        setWindowTitle(placesModel->text(matchedPlaces.first()));
         return;
     }
 
@@ -1049,19 +1067,19 @@ void DolphinMainWindow::setupActions()
     QAction* newWindow = actionCollection()->addAction(QStringLiteral("new_window"));
     newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
     newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
-    actionCollection()->setDefaultShortcut(newWindow, Qt::CTRL | Qt::Key_N);
+    actionCollection()->setDefaultShortcut(newWindow, Qt::CTRL + Qt::Key_N);
     connect(newWindow, &QAction::triggered, this, &DolphinMainWindow::openNewMainWindow);
 
     QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
     newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
     newTab->setText(i18nc("@action:inmenu File", "New Tab"));
-    actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N});
+    actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
     connect(newTab, &QAction::triggered, this, static_cast<void(DolphinMainWindow::*)()>(&DolphinMainWindow::openNewActivatedTab));
 
     QAction* closeTab = actionCollection()->addAction(QStringLiteral("close_tab"));
     closeTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-close")));
     closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
-    actionCollection()->setDefaultShortcut(closeTab, Qt::CTRL | Qt::Key_W);
+    actionCollection()->setDefaultShortcut(closeTab, Qt::CTRL + Qt::Key_W);
     closeTab->setEnabled(false);
     connect(closeTab, &QAction::triggered, m_tabWidget, static_cast<void(DolphinTabWidget::*)()>(&DolphinTabWidget::closeTab));
 
@@ -1085,12 +1103,14 @@ void DolphinMainWindow::setupActions()
 
     QAction* selectAll = actionCollection()->addAction(QStringLiteral("select_all"));
     selectAll->setText(i18nc("@action:inmenu Edit", "Select All"));
-    actionCollection()->setDefaultShortcut(selectAll, Qt::CTRL | Qt::Key_A);
+    selectAll->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-all")));
+    actionCollection()->setDefaultShortcut(selectAll, Qt::CTRL + Qt::Key_A);
     connect(selectAll, &QAction::triggered, this, &DolphinMainWindow::selectAll);
 
     QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
     invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
-    actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
+    invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
+    actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
     connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
 
     // setup 'View' menu
@@ -1101,7 +1121,7 @@ void DolphinMainWindow::setupActions()
     connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
 
     QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
-    actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S);
+    actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL + Qt::Key_S);
     stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
     stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
     stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
@@ -1128,7 +1148,7 @@ void DolphinMainWindow::setupActions()
 
     QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
     replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
-    actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL | Qt::Key_L);
+    actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL + Qt::Key_L);
     connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
 
     // setup 'Go' menu
@@ -1148,7 +1168,7 @@ void DolphinMainWindow::setupActions()
 
     QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
     undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
-    actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T);
+    actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL + Qt::SHIFT + Qt::Key_T);
     undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
     undoCloseTab->setEnabled(false);
     connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
@@ -1164,7 +1184,7 @@ void DolphinMainWindow::setupActions()
     QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
     showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
     showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
-    actionCollection()->setDefaultShortcut(showFilterBar, Qt::CTRL | Qt::Key_I);
+    actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL + Qt::Key_I, Qt::Key_Slash});
     connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
 
     QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
@@ -1178,7 +1198,7 @@ void DolphinMainWindow::setupActions()
         QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
         openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
         openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
-        actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4);
+        actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
         connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
     }
 #endif
@@ -1191,10 +1211,10 @@ void DolphinMainWindow::setupActions()
 
     // not in menu actions
     QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
-    nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab));
+    nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
 
     QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
-    prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab));
+    prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
 
     QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
     activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
@@ -1211,6 +1231,12 @@ void DolphinMainWindow::setupActions()
     actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
 
     // for context menu
+    QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
+    showTarget->setText(i18nc("@action:inmenu", "Show Target"));
+    showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
+    showTarget->setEnabled(false);
+    connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
+
     QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
     openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
     openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
@@ -1371,11 +1397,12 @@ void DolphinMainWindow::updateEditActions()
         stateChanged(QStringLiteral("has_selection"));
 
         KActionCollection* col = actionCollection();
-        QAction* renameAction      = col->action(KStandardAction::name(KStandardAction::RenameFile));
-        QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
-        QAction* deleteAction      = col->action(KStandardAction::name(KStandardAction::DeleteFile));
-        QAction* cutAction         = col->action(KStandardAction::name(KStandardAction::Cut));
+        QAction* renameAction            = col->action(KStandardAction::name(KStandardAction::RenameFile));
+        QAction* moveToTrashAction       = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
+        QAction* deleteAction            = col->action(KStandardAction::name(KStandardAction::DeleteFile));
+        QAction* cutAction               = col->action(KStandardAction::name(KStandardAction::Cut));
         QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
+        QAction* showTarget              = col->action(QStringLiteral("show_target"));
 
         KFileItemListProperties capabilities(list);
         const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
@@ -1385,6 +1412,7 @@ void DolphinMainWindow::updateEditActions()
         deleteAction->setEnabled(capabilities.supportsDeleting());
         deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
         cutAction->setEnabled(capabilities.supportsMoving());
+        showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
     }
 }