]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
Whitespace cleanups and documentation fixes
[dolphin.git] / src / dolphincontextmenu.cpp
index 617189715d0977db11a46a4ccf77446eee5b6ac8..286d304c5217cf4034fe835b6413c655c2925cdb 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "dolphinmainwindow.h"
 #include "dolphinnewfilemenu.h"
-#include "settings/dolphinsettings.h"
 #include "dolphinviewcontainer.h"
 #include "dolphin_generalsettings.h"
 
 #include <QClipboard>
 #include <QDir>
 
+#include "views/dolphinplacesmodel.h"
 #include "views/dolphinview.h"
 #include "views/viewmodecontroller.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),
@@ -156,10 +159,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();
     }
 }
 
@@ -187,13 +190,13 @@ void DolphinContextMenu::openTrashContextMenu()
 
     addShowMenuBarAction();
 
-    QAction *action = m_popup->exec(QCursor::pos());
+    QAction *action = m_popup->exec(m_pos);
     if (action == emptyTrashAction) {
         KonqOperations::emptyTrash(m_mainWindow);
     } else if (action == addToPlacesAction) {
-        const KUrl& url = m_mainWindow->activeViewContainer()->url();
+        const KUrl url = m_mainWindow->activeViewContainer()->url();
         if (url.isValid()) {
-            DolphinSettings::instance().placesModel()->addPlace(i18nc("@label", "Trash"), url);
+            DolphinPlacesModel::instance()->addPlace(i18nc("@label", "Trash"), url);
         }
     }
 }
@@ -212,7 +215,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());
@@ -289,7 +292,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);
@@ -299,13 +302,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);
+                DolphinPlacesModel::instance()->addPlace(placesName(selectedUrl),
+                                                         selectedUrl);
             }
         } else if (activatedAction == openParentInNewWindowAction) {
             m_command = OpenParentFolderInNewWindow;
@@ -361,11 +364,11 @@ 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);
+            DolphinPlacesModel::instance()->addPlace(placesName(url), url);
         }
     }
 }
@@ -416,7 +419,7 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
 
 bool DolphinContextMenu::placeExists(const KUrl& url) const
 {
-    const KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
+    const KFilePlacesModel* placesModel = DolphinPlacesModel::instance();
     const int count = placesModel->rowCount();
 
     for (int i = 0; i < count; ++i) {
@@ -446,7 +449,7 @@ QAction* DolphinContextMenu::createPasteAction()
     return action;
 }
 
-KFileItemListProperties& DolphinContextMenu::selectedItemsProperties()
+KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const
 {
     if (!m_selectedItemsProperties) {
         m_selectedItemsProperties = new KFileItemListProperties(m_selectedItems);
@@ -538,13 +541,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 {
@@ -555,4 +557,9 @@ void DolphinContextMenu::updateRemoveAction()
     m_removeAction->setShortcuts(action->shortcuts());
 }
 
+bool DolphinContextMenu::moveToTrash() const
+{
+    return selectedItemsProperties().isLocal() && !m_shiftPressed;
+}
+
 #include "dolphincontextmenu.moc"