Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/foldermodel.cpp
Show First 20 Lines • Show All 638 Lines • ▼ Show 20 Line(s) | 636 | { | |||
---|---|---|---|---|---|
639 | 639 | | |||
640 | m_screen = screen; | 640 | m_screen = screen; | ||
641 | if (m_usedByContainment && !m_screenMapper->sharedDesktops()) { | 641 | if (m_usedByContainment && !m_screenMapper->sharedDesktops()) { | ||
642 | m_screenMapper->addScreen(screen, resolvedUrl()); | 642 | m_screenMapper->addScreen(screen, resolvedUrl()); | ||
643 | } | 643 | } | ||
644 | emit screenChanged(); | 644 | emit screenChanged(); | ||
645 | } | 645 | } | ||
646 | 646 | | |||
647 | bool FolderModel::eventFilter(QObject *watched, QEvent *event) | ||||
648 | { | ||||
649 | Q_UNUSED(watched) | ||||
650 | | ||||
651 | // Catching Shift modifier usage on open context menus to swap the | ||||
652 | // Trash/Delete actions. | ||||
653 | if (event->type() == QEvent::KeyPress) { | ||||
davidedmundson: you delete the menu when the menu isn't open, you won't get any events | |||||
654 | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); | ||||
655 | | ||||
656 | if (keyEvent->key() == Qt::Key_Shift) { | ||||
657 | m_actionCollection.action(QStringLiteral("trash"))->setVisible(false); | ||||
658 | m_actionCollection.action(QStringLiteral("del"))->setVisible(true); | ||||
659 | } | ||||
660 | } else if (event->type() == QEvent::KeyRelease) { | ||||
661 | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); | ||||
662 | | ||||
663 | if (keyEvent->key() == Qt::Key_Shift) { | ||||
664 | m_actionCollection.action(QStringLiteral("trash"))->setVisible(true); | ||||
665 | m_actionCollection.action(QStringLiteral("del"))->setVisible(false); | ||||
666 | } | ||||
667 | } | ||||
668 | | ||||
669 | return false; | ||||
670 | } | ||||
671 | | ||||
647 | KFileItem FolderModel::rootItem() const | 672 | KFileItem FolderModel::rootItem() const | ||
648 | { | 673 | { | ||
649 | return m_dirModel->dirLister()->rootItem(); | 674 | return m_dirModel->dirLister()->rootItem(); | ||
650 | } | 675 | } | ||
651 | 676 | | |||
652 | void FolderModel::up() | 677 | void FolderModel::up() | ||
653 | { | 678 | { | ||
654 | const QUrl &up = KIO::upUrl(resolvedUrl()); | 679 | const QUrl &up = KIO::upUrl(resolvedUrl()); | ||
▲ Show 20 Lines • Show All 1112 Lines • ▼ Show 20 Line(s) | 1770 | } else { | |||
1767 | menu->addAction(m_actionCollection.action(QStringLiteral("rename"))); | 1792 | menu->addAction(m_actionCollection.action(QStringLiteral("rename"))); | ||
1768 | menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash"))); | 1793 | menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash"))); | ||
1769 | 1794 | | |||
1770 | KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); | 1795 | KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); | ||
1771 | KConfigGroup cg(globalConfig, "KDE"); | 1796 | KConfigGroup cg(globalConfig, "KDE"); | ||
1772 | bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false); | 1797 | bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false); | ||
1773 | 1798 | | |||
1774 | menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); | 1799 | menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); | ||
1775 | if (modifiers.testFlag(Qt::ShiftModifier)) { | 1800 | | ||
1776 | showDeleteCommand = true; | 1801 | QAction *trashAction = m_actionCollection.action(QStringLiteral("trash")); | ||
1777 | } else { | | |||
1778 | if (QAction *trashAction = m_actionCollection.action(QStringLiteral("trash"))) { | | |||
1779 | menu->addAction(trashAction); | 1802 | menu->addAction(trashAction); | ||
1780 | if (!trashAction->isVisible()) { | 1803 | trashAction->setVisible(!modifiers.testFlag(Qt::ShiftModifier)); | ||
1781 | showDeleteCommand = true; | | |||
1782 | } | | |||
1783 | } | | |||
1784 | } | | |||
1785 | 1804 | | |||
1786 | if (showDeleteCommand) { | 1805 | QAction *deleteAction = m_actionCollection.action(QStringLiteral("del")); | ||
1787 | menu->addAction(m_actionCollection.action(QStringLiteral("del"))); | 1806 | menu->addAction(deleteAction); | ||
1788 | } | 1807 | | ||
1808 | deleteAction->setVisible(showDeleteCommand || !trashAction->isVisible()); | ||||
1789 | 1809 | | |||
1790 | // "Open with" actions | 1810 | // "Open with" actions | ||
1791 | m_fileItemActions->setItemListProperties(itemProperties); | 1811 | m_fileItemActions->setItemListProperties(itemProperties); | ||
1792 | m_fileItemActions->addOpenWithActionsTo(menu); | 1812 | m_fileItemActions->addOpenWithActionsTo(menu); | ||
1793 | // Service actions | 1813 | // Service actions | ||
1794 | m_fileItemActions->addServiceActionsTo(menu); | 1814 | m_fileItemActions->addServiceActionsTo(menu); | ||
1795 | menu->addSeparator(); | 1815 | menu->addSeparator(); | ||
1796 | // Plugin actions | 1816 | // Plugin actions | ||
Show All 17 Lines | |||||
1814 | } | 1834 | } | ||
1815 | 1835 | | |||
1816 | if (visualParent) { | 1836 | if (visualParent) { | ||
1817 | m_menuPosition = visualParent->mapToGlobal(QPointF(0, visualParent->height())).toPoint(); | 1837 | m_menuPosition = visualParent->mapToGlobal(QPointF(0, visualParent->height())).toPoint(); | ||
1818 | } else { | 1838 | } else { | ||
1819 | m_menuPosition = QCursor::pos(); | 1839 | m_menuPosition = QCursor::pos(); | ||
1820 | } | 1840 | } | ||
1821 | 1841 | | |||
1842 | // Used to monitor Shift modifier usage while the menu is open, to | ||||
1843 | // swap the Trash and Delete actions. | ||||
1844 | menu->installEventFilter(this); | ||||
1822 | 1845 | | |||
1823 | menu->setAttribute(Qt::WA_TranslucentBackground); | 1846 | menu->setAttribute(Qt::WA_TranslucentBackground); | ||
1824 | menu->winId(); //force surface creation before ensurePolish call in menu::Popup which happens before show | 1847 | menu->winId(); //force surface creation before ensurePolish call in menu::Popup which happens before show | ||
1825 | menu->popup(m_menuPosition); | 1848 | menu->popup(m_menuPosition); | ||
1826 | connect(menu, &QMenu::aboutToHide, [menu]() { menu->deleteLater(); }); | 1849 | connect(menu, &QMenu::aboutToHide, [menu]() { menu->deleteLater(); }); | ||
Use four argument connect since now you access this but given you delete the menu anyway, this change probably isn't neccessary to begin with broulik: Use four argument connect since now you access `this` but given you delete the menu anyway… | |||||
1827 | } | 1850 | } | ||
1828 | 1851 | | |||
1829 | void FolderModel::openPropertiesDialog() | 1852 | void FolderModel::openPropertiesDialog() | ||
1830 | { | 1853 | { | ||
1831 | const QModelIndexList indexes = m_selectionModel->selectedIndexes(); | 1854 | const QModelIndexList indexes = m_selectionModel->selectedIndexes(); | ||
1832 | if (indexes.isEmpty()) { | 1855 | if (indexes.isEmpty()) { | ||
1833 | return; | 1856 | return; | ||
1834 | } | 1857 | } | ||
▲ Show 20 Lines • Show All 231 Lines • Show Last 20 Lines |
you delete the menu when the menu isn't open, you won't get any events