]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
Do a custom error handling in for the 'Create New...' submenu. Thanks to David for...
[dolphin.git] / src / dolphincontextmenu.cpp
index ddc8c9155caf92b2ee5314d2a18f2335576b63f6..8cc79e9554363e64ef1683a48a192d21f233555d 100644 (file)
@@ -36,6 +36,7 @@
 #include <kio/netaccess.h>
 #include <kmenu.h>
 #include <kmimetypetrader.h>
+#include <knewmenu.h>
 #include <klocale.h>
 #include <kpropertiesdialog.h>
 #include <krun.h>
@@ -69,35 +70,19 @@ DolphinContextMenu::~DolphinContextMenu()
 
 void DolphinContextMenu::openViewportContextMenu()
 {
-    // Parts of the following code have been taken
-    // from the class KonqOperations located in
-    // libqonq/konq_operations.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>)
-
     assert(m_fileInfo == 0);
-
     DolphinMainWindow* dolphin = m_dolphinView->mainWindow();
     KMenu* popup = new KMenu(m_dolphinView);
 
     // setup 'Create New' menu
-    KMenu* createNewMenu = new KMenu(i18n("Create New"));
-    createNewMenu->setIcon(SmallIcon("filenew"));
-
-    QAction* createFolderAction = dolphin->actionCollection()->action("create_folder");
-    if (createFolderAction != 0) {
-        createNewMenu->addAction(createFolderAction);
-    }
-
-    QLinkedListIterator<QAction*> fileGrouptIt(dolphin->fileGroupActions());
-    while (fileGrouptIt.hasNext()) {
-        createNewMenu->addAction(fileGrouptIt.next());
-    }
-
-    popup->addMenu(createNewMenu);
+    KNewMenu* newMenu = dolphin->newMenu();
+    newMenu->slotCheckUpToDate();
+    newMenu->setPopupFiles(m_dolphinView->url());
+    popup->addMenu(newMenu->menu());
+    popup->addSeparator();
 
     QAction* pasteAction = dolphin->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
     popup->addAction(pasteAction);
-    popup->insertSeparator(pasteAction);
 
     // setup 'View Mode' menu
     KMenu* viewModeMenu = new KMenu(i18n("View Mode"));
@@ -112,12 +97,12 @@ void DolphinContextMenu::openViewportContextMenu()
     viewModeMenu->addAction(previewsMode);
 
     popup->addMenu(viewModeMenu);
+    popup->addSeparator();
 
     QAction* bookmarkAction = popup->addAction(i18n("Bookmark this folder"));
-    popup->insertSeparator(bookmarkAction);
+    popup->addSeparator();
 
     QAction* propertiesAction = popup->addAction(i18n("Properties..."));
-    popup->insertSeparator(propertiesAction);
 
     QAction* activatedAction = popup->exec(m_pos);
     if (activatedAction == propertiesAction) {
@@ -142,11 +127,6 @@ void DolphinContextMenu::openViewportContextMenu()
 
 void DolphinContextMenu::openItemContextMenu()
 {
-    // Parts of the following code have been taken
-    // from the class KonqOperations located in
-    // libkonq/konq_operations.h of Konqueror.
-    // (Copyright (C) 2000  David Faure <faure@kde.org>)
-
     assert(m_fileInfo != 0);
 
     KMenu* popup = new KMenu(m_dolphinView);
@@ -167,11 +147,11 @@ void DolphinContextMenu::openItemContextMenu()
             popup->addAction(action);
         }
     }
+    popup->addSeparator();
 
     // insert 'Rename'
     QAction* renameAction = dolphin->actionCollection()->action("rename");
     popup->addAction(renameAction);
-    popup->insertSeparator(renameAction);
 
     // insert 'Move to Trash' for local Urls, otherwise insert 'Delete'
     const KUrl& url = dolphin->activeView()->url();
@@ -199,11 +179,11 @@ void DolphinContextMenu::openItemContextMenu()
     // Insert 'Actions' sub menu
     QVector<KDEDesktopMimeType::Service> actionsVector;
     const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
+    popup->addSeparator();
 
     // insert 'Properties...' entry
     QAction* propertiesAction = dolphin->actionCollection()->action("properties");
     popup->addAction(propertiesAction);
-    popup->insertSeparator(propertiesAction);
 
     QAction* activatedAction = popup->exec(m_pos);
 
@@ -246,6 +226,11 @@ void DolphinContextMenu::openItemContextMenu()
 QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
                                                         QVector<KService::Ptr>& openWithVector)
 {
+    // Parts of the following code have been taken
+    // from the class KonqOperations located in
+    // libqonq/konq_operations.h of Konqueror.
+    // (Copyright (C) 2000  David Faure <faure@kde.org>)
+
     // Prepare 'Open With' sub menu. Usually a sub menu is created, where all applications
     // are listed which are registered to open the item. As last entry "Other..." will be
     // attached which allows to select a custom application. If no applications are registered
@@ -253,11 +238,7 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
     const KFileItemList list = m_dolphinView->selectedItems();
 
     bool insertOpenWithItems = true;
-
-    // TODO: a crash occurs in KFileItem although m_fileInfo seems to be valid. Temporary
-    // commented out the following command, otherwise it won't be possible to open a context menu:
-    //const QString contextMimeType(m_fileInfo->mimetype());
-    const QString contextMimeType;
+    const QString contextMimeType(m_fileInfo->mimetype());
 
     QListIterator<KFileItem*> mimeIt(list);
     while (insertOpenWithItems && mimeIt.hasNext()) {
@@ -266,7 +247,6 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
     }
 
     QList<QAction*> openWithActions;
-
     if (insertOpenWithItems) {
         // fill the 'Open with' sub menu with application types
         const KMimeType::Ptr mimePtr = KMimeType::findByUrl(m_fileInfo->url());
@@ -290,10 +270,11 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
                 }
             }
 
+            openWithMenu->addSeparator();
             QAction* action = openWithMenu->addAction(i18n("&Other..."));
-            openWithMenu->insertSeparator(action);
 
             openWithActions << action;
+            popup->addSeparator();
             popup->addMenu(openWithMenu);
         }
         else {
@@ -307,8 +288,8 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
     else {
         // At least one of the selected items has a different MIME type. In this case
         // just show a disabled "Open With..." entry.
+        popup->addSeparator();
         QAction* action = popup->addAction(i18n("Open With..."));
-        popup->insertSeparator(action);
         action->setEnabled(false);
     }
 
@@ -318,6 +299,11 @@ QList<QAction*> DolphinContextMenu::insertOpenWithItems(KMenu* popup,
 QList<QAction*> DolphinContextMenu::insertActionItems(KMenu* popup,
                                                       QVector<KDEDesktopMimeType::Service>& actionsVector)
 {
+    // Parts of the following code have been taken
+    // from the class KonqOperations located in
+    // libqonq/konq_operations.h of Konqueror.
+    // (Copyright (C) 2000  David Faure <faure@kde.org>)
+
     KMenu* actionsMenu = new KMenu(i18n("Actions"));
 
     QList<QAction*> serviceActions;