]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
Use the actions "new_tab" and "new_window" for the viewport-contextmenu instead of...
[dolphin.git] / src / dolphincontextmenu.cpp
index da76e56fefb9e1ce55653760aa8d804b544682c3..ae5bf8698aff97562b840220e7b28b60dc0ab36c 100644 (file)
@@ -67,6 +67,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
     m_copyToMenu(parent),
     m_customActions(),
     m_popup(new KMenu(m_mainWindow)),
+    m_command(None),
     m_shiftPressed(false),
     m_removeAction(0)
 {
@@ -99,10 +100,10 @@ void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
     m_customActions = actions;
 }
 
-void DolphinContextMenu::open()
+DolphinContextMenu::Command DolphinContextMenu::open()
 {
     // get the context information
-    if (m_baseUrl.protocol() == "trash") {
+    if (m_baseUrl.protocol() == QLatin1String("trash")) {
         m_context |= TrashContext;
     }
 
@@ -124,6 +125,8 @@ void DolphinContextMenu::open()
         Q_ASSERT(m_context == NoContext);
         openViewportContextMenu();
     }
+
+    return m_command;
 }
 
 void DolphinContextMenu::initializeModifierKeyInfo()
@@ -219,26 +222,54 @@ void DolphinContextMenu::openItemContextMenu()
 {
     Q_ASSERT(!m_fileInfo.isNull());
 
-    if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) {
-        // setup 'Create New' menu
-        DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow);
-        const DolphinView* view = m_mainWindow->activeViewContainer()->view();
-        newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
-        newFileMenu->checkUpToDate();
-        newFileMenu->setPopupFiles(m_fileInfo.url());
-        newFileMenu->setEnabled(capabilities().supportsWriting());
-
-        KMenu* menu = newFileMenu->menu();
-        menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
-        menu->setIcon(KIcon("document-new"));
-        m_popup->addMenu(menu);
-        m_popup->addSeparator();
-
-        // insert 'Open in new window' and 'Open in new tab' entries
-        m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
-        m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
-        m_popup->addSeparator();
+    QAction* openParentInNewWindowAction = 0;
+    QAction* openParentInNewTabAction = 0;
+    QAction* addToPlacesAction = 0;
+    if (m_selectedUrls.count() == 1) {
+        if (m_fileInfo.isDir()) {
+            // setup 'Create New' menu
+            DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow);
+            const DolphinView* view = m_mainWindow->activeViewContainer()->view();
+            newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
+            newFileMenu->checkUpToDate();
+            newFileMenu->setPopupFiles(m_fileInfo.url());
+            newFileMenu->setEnabled(capabilities().supportsWriting());
+
+            KMenu* menu = newFileMenu->menu();
+            menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
+            menu->setIcon(KIcon("document-new"));
+            m_popup->addMenu(menu);
+            m_popup->addSeparator();
+
+            // insert 'Open in new window' and 'Open in new tab' entries
+            m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+            m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+
+            // insert 'Add to Places' entry
+            if (!placeExists(m_fileInfo.url())) {
+                addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
+                                                       i18nc("@action:inmenu Add selected folder to places",
+                                                             "Add to Places"));
+            }
+
+            m_popup->addSeparator();
+        } else if (m_baseUrl.protocol().contains("search")) {
+            openParentInNewWindowAction = new QAction(KIcon("window-new"),
+                                                    i18nc("@action:inmenu",
+                                                          "Open Path in New Window"),
+                                                    this);
+            m_popup->addAction(openParentInNewWindowAction);
+
+            openParentInNewTabAction = new QAction(KIcon("tab-new"),
+                                                   i18nc("@action:inmenu",
+                                                         "Open Path in New Tab"),
+                                                   this);
+            m_popup->addAction(openParentInNewTabAction);
+
+            m_popup->addSeparator();
+        }
     }
+
     addShowMenubarAction();
     insertDefaultItemActions();
 
@@ -255,14 +286,6 @@ void DolphinContextMenu::openItemContextMenu()
         m_copyToMenu.setItems(m_selectedItems);
         m_copyToMenu.setReadOnly(!capabilities().supportsWriting());
         m_copyToMenu.addActionsTo(m_popup.data());
-        m_popup->addSeparator();
-    }
-
-    // insert 'Add to Places' entry if exactly one item is selected
-    QAction* addToPlacesAction = 0;
-    if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1) && !placeExists(m_fileInfo.url())) {
-        addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
-                                             i18nc("@action:inmenu Add selected folder to places", "Add to Places"));
     }
 
     // insert 'Properties...' entry
@@ -270,12 +293,17 @@ void DolphinContextMenu::openItemContextMenu()
     m_popup->addAction(propertiesAction);
 
     QAction* activatedAction = m_popup->exec(QCursor::pos());
-
-    if ((addToPlacesAction != 0) && (activatedAction == addToPlacesAction)) {
-        const KUrl selectedUrl(m_fileInfo.url());
-        if (selectedUrl.isValid()) {
-            DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
-                                                                selectedUrl);
+    if (activatedAction != 0) {
+        if (activatedAction == addToPlacesAction) {
+            const KUrl selectedUrl(m_fileInfo.url());
+            if (selectedUrl.isValid()) {
+                DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
+                                                                    selectedUrl);
+            }
+        } else if (activatedAction == openParentInNewWindowAction) {
+            m_command = OpenParentFolderInNewWindow;
+        } else if (activatedAction == openParentInNewTabAction) {
+            m_command = OpenParentFolderInNewTab;
         }
     }
 }
@@ -293,9 +321,10 @@ void DolphinContextMenu::openViewportContextMenu()
     m_popup->addMenu(newFileMenu->menu());
     m_popup->addSeparator();
 
-    // insert 'Open in new window' and 'Open in new tab' entries
-    m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
-    m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+    // Insert 'New Window' and 'New Tab' entries. Don't use "open_in_new_window" and
+    // "open_in_new_tab" here, as the current selection should get ignored.
+    m_popup->addAction(m_mainWindow->actionCollection()->action("new_window"));
+    m_popup->addAction(m_mainWindow->actionCollection()->action("new_tab"));
     m_popup->addSeparator();
 
     QAction* pasteAction = createPasteAction();
@@ -428,9 +457,7 @@ void DolphinContextMenu::addServiceActions(KFileItemActions& fileItemActions)
     fileItemActions.addOpenWithActionsTo(m_popup.data(), "DesktopEntryName != 'dolphin'");
 
     // insert 'Actions' sub menu
-    if (fileItemActions.addServiceActionsTo(m_popup.data())) {
-        m_popup->addSeparator();
-    }
+    fileItemActions.addServiceActionsTo(m_popup.data());
 }
 
 void DolphinContextMenu::addVersionControlActions()