]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'release/20.12'
authorNate Graham <nate@kde.org>
Tue, 1 Dec 2020 00:08:46 +0000 (17:08 -0700)
committerNate Graham <nate@kde.org>
Tue, 1 Dec 2020 00:08:46 +0000 (17:08 -0700)
1  2 
src/dolphincontextmenu.cpp

index 9c96130f24cbeb27cd0969dd789def1983c76e4e,283f5256509cd85346d52a3947642b18e8f02730..925951bbf3d8b4f4d27c3e4a872f19adb7c6c61f
@@@ -61,8 -61,6 +61,8 @@@ DolphinContextMenu::DolphinContextMenu(
      // or the items itself. To increase the performance both lists are cached.
      const DolphinView* view = m_mainWindow->activeViewContainer()->view();
      m_selectedItems = view->selectedItems();
 +
 +    installEventFilter(this);
  }
  
  DolphinContextMenu::~DolphinContextMenu()
@@@ -112,28 -110,20 +112,28 @@@ DolphinContextMenu::Command DolphinCont
      return m_command;
  }
  
 -void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
 +void DolphinContextMenu::childEvent(QChildEvent* event)
  {
 -    if (m_removeAction && ev->key() == Qt::Key_Shift) {
 -        m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
 +    if(event->added()) {
 +        event->child()->installEventFilter(this);
      }
 -    QMenu::keyPressEvent(ev);
 +    QMenu::childEvent(event);
  }
  
 -void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
 +bool DolphinContextMenu::eventFilter(QObject* dest, QEvent* event)
  {
 -    if (m_removeAction && ev->key() == Qt::Key_Shift) {
 -        m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
 +    if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
 +        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
 +        if(m_removeAction && keyEvent->key() == Qt::Key_Shift) {
 +            if(event->type() == QEvent::KeyPress) {
 +                m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
 +            } else {
 +                m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
 +            }
 +            return true;
 +        }
      }
 -    QMenu::keyReleaseEvent(ev);
 +    return QMenu::eventFilter(dest, event);
  }
  
  void DolphinContextMenu::openTrashContextMenu()
@@@ -208,7 -198,6 +208,7 @@@ void DolphinContextMenu::addDirectoryIt
       QMenu* menu = newFileMenu->menu();
       menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
       menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
 +     menu->setParent(this, Qt::Popup);
       addMenu(menu);
  
       addSeparator();
@@@ -282,7 -271,21 +282,7 @@@ void DolphinContextMenu::openItemContex
  
      insertDefaultItemActions(selectedItemsProps);
  
 -    // insert 'Add to Places' entry if appropriate
 -    if (m_selectedItems.count() == 1) {
 -        if (m_fileInfo.isDir()) {
 -            if (!placeExists(m_fileInfo.url())) {
 -                addAction(m_mainWindow->actionCollection()->action(QStringLiteral("add_to_places")));
 -            }
 -        }
 -    }
 -
 -    addSeparator();
 -
 -    fileItemActions.addServiceActionsTo(this);
 -    fileItemActions.addPluginActionsTo(this);
 -
 -    addVersionControlPluginActions();
 +    addAdditionalActions(fileItemActions, selectedItemsProps);
  
      // insert 'Copy To' and 'Move To' sub menus
      if (GeneralSettings::showCopyMoveMenu()) {
@@@ -344,7 -347,14 +344,7 @@@ void DolphinContextMenu::openViewportCo
      addAction(m_mainWindow->actionCollection()->action(QStringLiteral("sort")));
      addAction(m_mainWindow->actionCollection()->action(QStringLiteral("view_mode")));
  
 -    addSeparator();
 -
 -    // Insert service actions
 -    fileItemActions.addServiceActionsTo(this);
 -    fileItemActions.addPluginActionsTo(this);
 -
 -    addVersionControlPluginActions();
 -
 +    addAdditionalActions(fileItemActions, baseUrlProperties);
      addCustomActions();
  
      addSeparator();
@@@ -373,20 -383,11 +373,20 @@@ void DolphinContextMenu::insertDefaultI
      }
      addAction(m_mainWindow->actionCollection()->action(QStringLiteral("duplicate")));
  
 -    addSeparator();
 -
      // Insert 'Rename'
      addAction(collection->action(KStandardAction::name(KStandardAction::RenameFile)));
  
 +    // insert 'Add to Places' entry if appropriate
 +    if (m_selectedItems.count() == 1) {
 +        if (m_fileInfo.isDir()) {
 +            if (!placeExists(m_fileInfo.url())) {
 +                addAction(m_mainWindow->actionCollection()->action(QStringLiteral("add_to_places")));
 +            }
 +        }
 +    }
 +
 +    addSeparator();
 +
      // Insert 'Move to Trash' and/or 'Delete'
      const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) ||
                                      !properties.isLocal());
@@@ -432,23 -433,23 +432,23 @@@ QAction* DolphinContextMenu::createPast
  {
      QAction* action = nullptr;
      KFileItem destItem;
-     if (!m_fileInfo.isNull()) {
+     if (!m_fileInfo.isNull() && m_selectedItems.count() <= 1) {
          destItem = m_fileInfo;
      } else {
          destItem = baseFileItem();
      }
  
      if (!destItem.isNull() && destItem.isDir()) {
-         if (m_selectedItems.count() <= 1) {
-             const QMimeData *mimeData = QApplication::clipboard()->mimeData();
-             bool canPaste;
-             const QString text = KIO::pasteActionText(mimeData, &canPaste, destItem);
-             action = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this);
-             if (canPaste) {
+         const QMimeData *mimeData = QApplication::clipboard()->mimeData();
+         bool canPaste;
+         const QString text = KIO::pasteActionText(mimeData, &canPaste, destItem);
+         if (canPaste) {
+             if (destItem == m_fileInfo) {
+                 // if paste destination is a selected folder
+                 action = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this);
                  connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder);
              } else {
-                 // don't add the unavailable action
-                 action = nullptr;
+                 action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
              }
          }
      }
@@@ -484,21 -485,8 +484,21 @@@ void DolphinContextMenu::addOpenWithAct
      fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != '%1'").arg(qApp->desktopFileName()));
  }
  
 -void DolphinContextMenu::addVersionControlPluginActions()
 +void DolphinContextMenu::addCustomActions()
  {
 +    addActions(m_customActions);
 +}
 +
 +void DolphinContextMenu::addAdditionalActions(KFileItemActions &fileItemActions, const KFileItemListProperties &props)
 +{
 +    addSeparator();
 +
 +    QList<QAction *> additionalActions;
 +    if (props.isDirectory() && props.isLocal()) {
 +        additionalActions << m_mainWindow->actionCollection()->action(QStringLiteral("open_terminal"));
 +    }
 +    fileItemActions.addActionsTo(this, KFileItemActions::MenuActionSource::All, additionalActions);
 +
      const DolphinView* view = m_mainWindow->activeViewContainer()->view();
      const QList<QAction*> versionControlActions = view->versionControlActions(m_selectedItems);
      if (!versionControlActions.isEmpty()) {
      }
  }
  
 -void DolphinContextMenu::addCustomActions()
 -{
 -    addActions(m_customActions);
 -}
 -