]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
Improve arrow key navigation in Details View with expanded folders
[dolphin.git] / src / dolphincontextmenu.cpp
index 79ffdaa2eca6451230224aa6be54af5b3624c5fc..ab91a9ba60db94d432fc4c7fbd3b9905b920644f 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "dolphinmainwindow.h"
 #include "dolphinnewfilemenu.h"
-#include "settings/dolphinsettings.h"
 #include "dolphinviewcontainer.h"
 #include "dolphin_generalsettings.h"
 
 K_GLOBAL_STATIC(KModifierKeyInfo, m_keyInfo)
 
 DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
+                                       const QPoint& pos,
                                        const KFileItem& fileInfo,
                                        const KUrl& baseUrl) :
+    QObject(parent),
+    m_pos(pos),
     m_mainWindow(parent),
     m_fileInfo(fileInfo),
     m_baseUrl(baseUrl),
@@ -86,8 +88,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
         if (m_keyInfo->isKeyPressed(Qt::Key_Shift) || m_keyInfo->isKeyLatched(Qt::Key_Shift)) {
             m_shiftPressed = true;
         }
-        connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key, bool)),
-                this, SLOT(slotKeyModifierPressed(Qt::Key, bool)));
+        connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key,bool)),
+                this, SLOT(slotKeyModifierPressed(Qt::Key,bool)));
     }
 
     m_removeAction = new QAction(this);
@@ -156,10 +158,10 @@ void DolphinContextMenu::slotKeyModifierPressed(Qt::Key key, bool pressed)
 void DolphinContextMenu::slotRemoveActionTriggered()
 {
     const KActionCollection* collection = m_mainWindow->actionCollection();
-    if (m_shiftPressed) {
-        collection->action("delete")->trigger();
-    } else {
+    if (moveToTrash()) {
         collection->action("move_to_trash")->trigger();
+    } else {
+        collection->action("delete")->trigger();
     }
 }
 
@@ -172,14 +174,6 @@ void DolphinContextMenu::openTrashContextMenu()
     emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
     m_popup->addAction(emptyTrashAction);
 
-    QAction* addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
-                                                  i18nc("@action:inmenu Add current folder to places", "Add to Places"));
-
-    // Don't show if url is already in places
-    if (placeExists(m_mainWindow->activeViewContainer()->url())) {
-        addToPlacesAction->setVisible(false);
-    }
-
     addCustomActions();
 
     QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
@@ -187,23 +181,8 @@ void DolphinContextMenu::openTrashContextMenu()
 
     addShowMenuBarAction();
 
-    QAction *action = m_popup->exec(QCursor::pos());
-    if (action == emptyTrashAction) {
-        const QString text(i18nc("@info", "Do you really want to empty the Trash? All items will be deleted."));
-        const bool del = KMessageBox::warningContinueCancel(m_mainWindow,
-                                                            text,
-                                                            QString(),
-                                                            KGuiItem(i18nc("@action:button", "Empty Trash"),
-                                                                     KIcon("user-trash"))
-                                                           ) == KMessageBox::Continue;
-        if (del) {
-            KonqOperations::emptyTrash(m_mainWindow);
-        }
-    } else if (action == addToPlacesAction) {
-        const KUrl& url = m_mainWindow->activeViewContainer()->url();
-        if (url.isValid()) {
-            DolphinSettings::instance().placesModel()->addPlace(i18nc("@label", "Trash"), url);
-        }
+    if (m_popup->exec(m_pos) == emptyTrashAction) {
+        KonqOperations::emptyTrash(m_mainWindow);
     }
 }
 
@@ -221,7 +200,7 @@ void DolphinContextMenu::openTrashItemContextMenu()
     QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
     m_popup->addAction(propertiesAction);
 
-    if (m_popup->exec(QCursor::pos()) == restoreAction) {
+    if (m_popup->exec(m_pos) == restoreAction) {
         KUrl::List selectedUrls;
         foreach (const KFileItem &item, m_selectedItems) {
             selectedUrls.append(item.url());
@@ -243,7 +222,7 @@ void DolphinContextMenu::openItemContextMenu()
             // setup 'Create New' menu
             DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow);
             const DolphinView* view = m_mainWindow->activeViewContainer()->view();
-            newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
+            newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
             newFileMenu->checkUpToDate();
             newFileMenu->setPopupFiles(m_fileInfo.url());
             newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
@@ -298,7 +277,7 @@ void DolphinContextMenu::openItemContextMenu()
     addVersionControlPluginActions();
 
     // insert 'Copy To' and 'Move To' sub menus
-    if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) {
+    if (GeneralSettings::showCopyMoveMenu()) {
         m_copyToMenu.setItems(m_selectedItems);
         m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting());
         m_copyToMenu.addActionsTo(m_popup);
@@ -308,13 +287,13 @@ void DolphinContextMenu::openItemContextMenu()
     QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
     m_popup->addAction(propertiesAction);
 
-    QAction* activatedAction = m_popup->exec(QCursor::pos());
+    QAction* activatedAction = m_popup->exec(m_pos);
     if (activatedAction) {
         if (activatedAction == addToPlacesAction) {
             const KUrl selectedUrl(m_fileInfo.url());
             if (selectedUrl.isValid()) {
-                DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
-                                                                    selectedUrl);
+                KFilePlacesModel model;
+                model.addPlace(placesName(selectedUrl), selectedUrl);
             }
         } else if (activatedAction == openParentInNewWindowAction) {
             m_command = OpenParentFolderInNewWindow;
@@ -329,7 +308,7 @@ void DolphinContextMenu::openViewportContextMenu()
     // setup 'Create New' menu
     KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu();
     const DolphinView* view = m_mainWindow->activeViewContainer()->view();
-    newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
+    newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
     newFileMenu->checkUpToDate();
     newFileMenu->setPopupFiles(m_baseUrl);
     m_popup->addMenu(newFileMenu->menu());
@@ -370,11 +349,12 @@ void DolphinContextMenu::openViewportContextMenu()
 
     addShowMenuBarAction();
 
-    QAction* action = m_popup->exec(QCursor::pos());
+    QAction* action = m_popup->exec(m_pos);
     if (addToPlacesAction && (action == addToPlacesAction)) {
         const KUrl url = m_mainWindow->activeViewContainer()->url();
         if (url.isValid()) {
-            DolphinSettings::instance().placesModel()->addPlace(placesName(url), url);
+            KFilePlacesModel model;
+            model.addPlace(placesName(url), url);
         }
     }
 }
@@ -425,13 +405,12 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
 
 bool DolphinContextMenu::placeExists(const KUrl& url) const
 {
-    const KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
-    const int count = placesModel->rowCount();
+    KFilePlacesModel model;
 
+    const int count = model.rowCount();
     for (int i = 0; i < count; ++i) {
-        const QModelIndex index = placesModel->index(i, 0);
-
-        if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
+        const QModelIndex index = model.index(i, 0);
+        if (url.equals(model.url(index), KUrl::CompareWithoutTrailingSlash)) {
             return true;
         }
     }
@@ -455,7 +434,7 @@ QAction* DolphinContextMenu::createPasteAction()
     return action;
 }
 
-KFileItemListProperties& DolphinContextMenu::selectedItemsProperties()
+KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const
 {
     if (!m_selectedItemsProperties) {
         m_selectedItemsProperties = new KFileItemListProperties(m_selectedItems);
@@ -547,13 +526,12 @@ void DolphinContextMenu::addCustomActions()
 void DolphinContextMenu::updateRemoveAction()
 {
     const KActionCollection* collection = m_mainWindow->actionCollection();
-    const bool moveToTrash = selectedItemsProperties().isLocal() && !m_shiftPressed;
 
     // Using m_removeAction->setText(action->text()) does not apply the &-shortcut.
     // This is only done until the original action has been shown at least once. To
     // bypass this issue, the text and &-shortcut is applied manually.
     const QAction* action = 0;
-    if (moveToTrash) {
+    if (moveToTrash()) {
         action = collection->action("move_to_trash");
         m_removeAction->setText(i18nc("@action:inmenu", "&Move to Trash"));
     } else {
@@ -564,4 +542,9 @@ void DolphinContextMenu::updateRemoveAction()
     m_removeAction->setShortcuts(action->shortcuts());
 }
 
+bool DolphinContextMenu::moveToTrash() const
+{
+    return !m_shiftPressed;
+}
+
 #include "dolphincontextmenu.moc"