]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'release/20.12'
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Tue, 15 Dec 2020 22:28:15 +0000 (23:28 +0100)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Tue, 15 Dec 2020 22:28:15 +0000 (23:28 +0100)
1  2 
src/dolphincontextmenu.cpp

index f95701e4f56df58bd22041b1e456dfcc03529fb5,91e9d8238d5c7834f80ce09f77b99cf729c3f228..eabd81e225080999c57e7328f9e0a9fc717c8aff
@@@ -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()
@@@ -105,35 -103,26 +105,34 @@@ DolphinContextMenu::Command DolphinCont
      } else if (m_context & ItemContext) {
          openItemContextMenu();
      } else {
-         Q_ASSERT(m_context == NoContext);
          openViewportContextMenu();
      }
  
      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 -197,6 +207,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();
@@@ -224,7 -212,7 +223,7 @@@ void DolphinContextMenu::openItemContex
      const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
  
      KFileItemActions fileItemActions;
 -    fileItemActions.setParentWidget(m_mainWindow);
 +    fileItemActions.setParentWidget(this);
      fileItemActions.setItemListProperties(selectedItemsProps);
  
      if (m_selectedItems.count() == 1) {
  
      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 -346,14 +343,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 -382,11 +372,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());
@@@ -484,21 -484,8 +483,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);
 -}
 -