]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
disable the 'Create New' entry in the context menu, if the directory does not support...
[dolphin.git] / src / dolphincontextmenu.cpp
index b2ec59e1547e392d662fba90f4773019b639ef8f..107c2b24ac9db54f39764b5b1bb6c2703f03d5b4 100644 (file)
@@ -21,6 +21,7 @@
 #include "dolphincontextmenu.h"
 
 #include "dolphinmainwindow.h"
+#include "dolphinnewmenu.h"
 #include "dolphinsettings.h"
 #include "dolphinview.h"
 #include "dolphinviewcontainer.h"
@@ -172,6 +173,24 @@ void DolphinContextMenu::openItemContextMenu()
     Q_ASSERT(!m_fileInfo.isNull());
 
     KMenu* popup = new KMenu(m_mainWindow);
+    if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) {
+        // setup 'Create New' menu
+        DolphinNewMenu* newMenu = new DolphinNewMenu(popup, m_mainWindow);
+        newMenu->slotCheckUpToDate();
+        newMenu->setPopupFiles(m_fileInfo.url());
+        newMenu->setEnabled(capabilities().supportsWriting());
+        
+        KMenu* menu = newMenu->menu();
+        menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
+        menu->setIcon(KIcon("document-new"));
+        popup->addMenu(newMenu->menu());
+        popup->addSeparator();
+    
+        // insert 'Open in new window' and 'Open in new tab' entries
+        popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+        popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+        popup->addSeparator();
+    }
     addShowMenubarAction(popup);
     insertDefaultItemActions(popup);
 
@@ -264,8 +283,12 @@ void DolphinContextMenu::openViewportContextMenu()
     QAction* action = popup->exec(QCursor::pos());
     if (action == propertiesAction) {
         const KUrl& url = m_mainWindow->activeViewContainer()->url();
-        KPropertiesDialog dialog(url, m_mainWindow);
-        dialog.exec();
+                
+        KPropertiesDialog* dialog = new KPropertiesDialog(url, m_mainWindow);
+        dialog->setAttribute(Qt::WA_DeleteOnClose);
+        dialog->show();
+        dialog->raise();
+        dialog->activateWindow();
     } else if (action == addToPlacesAction) {
         const KUrl& url = m_mainWindow->activeViewContainer()->url();
         if (url.isValid()) {
@@ -296,8 +319,10 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     popup->addAction(renameAction);
 
     // insert 'Move to Trash' and (optionally) 'Delete'
-    KConfigGroup kdeConfig(KGlobal::config(), "KDE");
-    bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
+    KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
+    KConfigGroup configGroup(globalConfig, "KDE");
+    bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);
+    
     const KUrl& url = m_mainWindow->activeViewContainer()->url();
     if (url.isLocalFile()) {
         QAction* moveToTrashAction = collection->action("move_to_trash");
@@ -316,10 +341,6 @@ void DolphinContextMenu::addShowMenubarAction(KMenu* menu)
 {
     KAction* showMenuBar = m_mainWindow->showMenuBarAction();
     if (!m_mainWindow->menuBar()->isVisible()) {
-        // TODO: it should not be necessary to uncheck the menu
-        // bar action, but currently the action states don't get
-        // updated if the menu is disabled
-        showMenuBar->setChecked(false);
         menu->addAction(showMenuBar);
         menu->addSeparator();
     }
@@ -337,7 +358,8 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
 QAction* DolphinContextMenu::createPasteAction()
 {
     QAction* action = 0;
-    if ((m_selectedItems.count() == 1) && m_fileInfo.isDir()) {
+    const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
+    if (isDir && (m_selectedItems.count() == 1)) {
         action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
         const QMimeData* mimeData = QApplication::clipboard()->mimeData();
         const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);