Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/plugins/folder/foldermodel.cpp
Show First 20 Lines • Show All 1251 Lines • ▼ Show 20 Line(s) | 1242 | { | |||
---|---|---|---|---|---|
1252 | 1252 | | |||
1253 | if (!m_selectionModel->hasSelection()) { | 1253 | if (!m_selectionModel->hasSelection()) { | ||
1254 | clearDragImages(); | 1254 | clearDragImages(); | ||
1255 | } else { | 1255 | } else { | ||
1256 | foreach (const QModelIndex &idx, deselected.indexes()) { | 1256 | foreach (const QModelIndex &idx, deselected.indexes()) { | ||
1257 | delete m_dragImages.take(idx.row()); | 1257 | delete m_dragImages.take(idx.row()); | ||
1258 | } | 1258 | } | ||
1259 | } | 1259 | } | ||
1260 | | ||||
1261 | updateActions(); | ||||
1260 | } | 1262 | } | ||
1261 | 1263 | | |||
1262 | bool FolderModel::isBlank(int row) const | 1264 | bool FolderModel::isBlank(int row) const | ||
1263 | { | 1265 | { | ||
1264 | if (row < 0) { | 1266 | if (row < 0) { | ||
1265 | return true; | 1267 | return true; | ||
1266 | } | 1268 | } | ||
1267 | 1269 | | |||
▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Line(s) | |||||
1608 | 1610 | | |||
1609 | QObject* FolderModel::newMenu() const | 1611 | QObject* FolderModel::newMenu() const | ||
1610 | { | 1612 | { | ||
1611 | return m_newMenu->menu(); | 1613 | return m_newMenu->menu(); | ||
1612 | } | 1614 | } | ||
1613 | 1615 | | |||
1614 | void FolderModel::updateActions() | 1616 | void FolderModel::updateActions() | ||
1615 | { | 1617 | { | ||
1618 | const QModelIndexList indexes = m_selectionModel->selectedIndexes(); | ||||
1619 | | ||||
1620 | KFileItemList items; | ||||
1621 | QList<QUrl> urls; | ||||
1622 | bool hasRemoteFiles = false; | ||||
1623 | bool isTrashLink = false; | ||||
1624 | const bool isTrash = (resolvedUrl().scheme() == QLatin1String("trash")); | ||||
1625 | | ||||
1626 | if (indexes.isEmpty()) { | ||||
1627 | items << rootItem(); | ||||
1628 | } else { | ||||
1629 | items.reserve(indexes.count()); | ||||
1630 | urls.reserve(indexes.count()); | ||||
1631 | for (const QModelIndex &index : indexes) { | ||||
1632 | KFileItem item = itemForIndex(index); | ||||
1633 | if (!item.isNull()) { | ||||
1634 | hasRemoteFiles |= item.localPath().isEmpty(); | ||||
1635 | items.append(item); | ||||
1636 | urls.append(item.url()); | ||||
1637 | } | ||||
1638 | } | ||||
1639 | } | ||||
1640 | | ||||
1641 | KFileItemListProperties itemProperties(items); | ||||
1642 | // Check if we're showing the menu for the trash link | ||||
1643 | if (items.count() == 1 && items.at(0).isDesktopFile()) { | ||||
1644 | KDesktopFile file(items.at(0).localPath()); | ||||
1645 | if (file.hasLinkType() && file.readUrl() == QLatin1String("trash:/")) { | ||||
1646 | isTrashLink = true; | ||||
1647 | } | ||||
1648 | } | ||||
1649 | | ||||
1616 | if (m_newMenu) { | 1650 | if (m_newMenu) { | ||
1617 | m_newMenu->checkUpToDate(); | 1651 | m_newMenu->checkUpToDate(); | ||
1618 | m_newMenu->setPopupFiles(m_dirModel->dirLister()->url()); | 1652 | m_newMenu->setPopupFiles(m_dirModel->dirLister()->url()); | ||
1619 | // we need to set here as well, when the menu is shown via AppletInterface::eventFilter | 1653 | // we need to set here as well, when the menu is shown via AppletInterface::eventFilter | ||
1620 | m_menuPosition = QCursor::pos(); | 1654 | m_menuPosition = QCursor::pos(); | ||
1621 | } | | |||
1622 | 1655 | | |||
1623 | const bool isTrash = (resolvedUrl().scheme() == QLatin1String("trash")); | 1656 | if (QAction *newMenuAction = m_actionCollection.action(QStringLiteral("newMenu"))) { | ||
1624 | 1657 | newMenuAction->setEnabled(itemProperties.supportsWriting()); | |||
1625 | QAction *emptyTrash = m_actionCollection.action(QStringLiteral("emptyTrash")); | 1658 | newMenuAction->setVisible(!isTrash); | ||
1659 | } | ||||
1660 | } | ||||
1626 | 1661 | | |||
1627 | if (emptyTrash) { | 1662 | if (QAction *emptyTrash = m_actionCollection.action(QStringLiteral("emptyTrash"))) { | ||
1628 | if (isTrash) { | 1663 | if (isTrash || isTrashLink) { | ||
1629 | emptyTrash->setVisible(true); | 1664 | emptyTrash->setVisible(true); | ||
1630 | emptyTrash->setEnabled(!isTrashEmpty()); | 1665 | emptyTrash->setEnabled(!isTrashEmpty()); | ||
1631 | } else { | 1666 | } else { | ||
1632 | emptyTrash->setVisible(false); | 1667 | emptyTrash->setVisible(false); | ||
1633 | } | 1668 | } | ||
1634 | } | 1669 | } | ||
1635 | 1670 | | |||
1636 | if (QAction *restoreFromTrash = m_actionCollection.action(QStringLiteral("restoreFromTrash"))) { | 1671 | if (QAction *restoreFromTrash = m_actionCollection.action(QStringLiteral("restoreFromTrash"))) { | ||
1637 | restoreFromTrash->setVisible(isTrash); | 1672 | restoreFromTrash->setVisible(isTrash); | ||
1638 | } | 1673 | } | ||
1639 | 1674 | | |||
1640 | QAction *paste = m_actionCollection.action(QStringLiteral("paste")); | 1675 | if (QAction *moveToTrash = m_actionCollection.action(QStringLiteral("trash"))) { | ||
1676 | moveToTrash->setVisible(!hasRemoteFiles && itemProperties.supportsMoving()); | ||||
1677 | } | ||||
1678 | | ||||
1679 | if (QAction *del = m_actionCollection.action(QStringLiteral("del"))) { | ||||
1680 | del->setVisible(itemProperties.supportsDeleting()); | ||||
1681 | } | ||||
1641 | 1682 | | |||
1642 | if (paste) { | 1683 | if (QAction *cut = m_actionCollection.action(QStringLiteral("cut"))) { | ||
1684 | cut->setEnabled(itemProperties.supportsDeleting()); | ||||
1685 | cut->setVisible(!isTrash); | ||||
1686 | } | ||||
1687 | | ||||
1688 | if (QAction *paste = m_actionCollection.action(QStringLiteral("paste"))) { | ||||
1643 | bool enable = false; | 1689 | bool enable = false; | ||
1644 | 1690 | | |||
1645 | const QString pasteText = KIO::pasteActionText(QApplication::clipboard()->mimeData(), | 1691 | const QString pasteText = KIO::pasteActionText(QApplication::clipboard()->mimeData(), | ||
1646 | &enable, rootItem()); | 1692 | &enable, rootItem()); | ||
1647 | 1693 | | |||
1648 | if (enable) { | 1694 | if (enable) { | ||
1649 | paste->setText(pasteText); | 1695 | paste->setText(pasteText); | ||
1650 | paste->setEnabled(true); | 1696 | paste->setEnabled(true); | ||
1651 | } else { | 1697 | } else { | ||
1652 | paste->setText(i18n("&Paste")); | 1698 | paste->setText(i18n("&Paste")); | ||
1653 | paste->setEnabled(false); | 1699 | paste->setEnabled(false); | ||
1654 | } | 1700 | } | ||
1655 | 1701 | | |||
1656 | QAction* pasteTo = m_actionCollection.action(QStringLiteral("pasteto")); | 1702 | if (QAction *pasteTo = m_actionCollection.action(QStringLiteral("pasteto"))) { | ||
1657 | 1703 | pasteTo->setVisible(itemProperties.isDirectory() && itemProperties.supportsWriting()); | |||
1658 | if (pasteTo) { | | |||
1659 | pasteTo->setEnabled(paste->isEnabled()); | 1704 | pasteTo->setEnabled(paste->isEnabled()); | ||
1660 | pasteTo->setText(paste->text()); | 1705 | pasteTo->setText(paste->text()); | ||
1661 | } | 1706 | } | ||
1662 | } | 1707 | } | ||
1708 | | ||||
1709 | if (QAction *rename = m_actionCollection.action(QStringLiteral("rename"))) { | ||||
1710 | qDebug() << "RIENÄIM" << itemProperties.supportsMoving() << itemProperties.urlList(); | ||||
1711 | rename->setEnabled(itemProperties.supportsMoving()); | ||||
1712 | rename->setVisible(!isTrash); | ||||
1713 | } | ||||
1663 | } | 1714 | } | ||
1664 | 1715 | | |||
1665 | void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifiers modifiers) | 1716 | void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifiers modifiers) | ||
1666 | { | 1717 | { | ||
1667 | QModelIndexList indexes = m_selectionModel->selectedIndexes(); | | |||
1668 | | ||||
1669 | if (m_usedByContainment && !KAuthorized::authorize(QStringLiteral("action/kdesktop_rmb"))) { | 1718 | if (m_usedByContainment && !KAuthorized::authorize(QStringLiteral("action/kdesktop_rmb"))) { | ||
1670 | return; | 1719 | return; | ||
1671 | } | 1720 | } | ||
1672 | 1721 | | |||
1673 | updateActions(); | 1722 | updateActions(); | ||
1674 | 1723 | | |||
1724 | const QModelIndexList indexes = m_selectionModel->selectedIndexes(); | ||||
1725 | | ||||
1675 | QMenu *menu = new QMenu(); | 1726 | QMenu *menu = new QMenu(); | ||
1676 | if (!m_fileItemActions) { | 1727 | if (!m_fileItemActions) { | ||
1677 | m_fileItemActions = new KFileItemActions(this); | 1728 | m_fileItemActions = new KFileItemActions(this); | ||
1678 | m_fileItemActions->setParentWidget(QApplication::desktop()); | 1729 | m_fileItemActions->setParentWidget(QApplication::desktop()); | ||
1679 | } | 1730 | } | ||
1680 | 1731 | | |||
1681 | if (indexes.isEmpty()) { | 1732 | if (indexes.isEmpty()) { | ||
1682 | menu->addAction(m_actionCollection.action(QStringLiteral("newMenu"))); | 1733 | menu->addAction(m_actionCollection.action(QStringLiteral("newMenu"))); | ||
1683 | menu->addSeparator(); | 1734 | menu->addSeparator(); | ||
1684 | menu->addAction(m_actionCollection.action(QStringLiteral("paste"))); | 1735 | menu->addAction(m_actionCollection.action(QStringLiteral("paste"))); | ||
1685 | menu->addAction(m_actionCollection.action(QStringLiteral("undo"))); | 1736 | menu->addAction(m_actionCollection.action(QStringLiteral("undo"))); | ||
1686 | menu->addAction(m_actionCollection.action(QStringLiteral("refresh"))); | 1737 | menu->addAction(m_actionCollection.action(QStringLiteral("refresh"))); | ||
1687 | menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); | 1738 | menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); | ||
1688 | menu->addSeparator(); | 1739 | menu->addSeparator(); | ||
1689 | 1740 | | |||
1690 | KFileItemListProperties itemProperties(KFileItemList() << rootItem()); | 1741 | KFileItemListProperties itemProperties(KFileItemList() << rootItem()); | ||
1691 | m_fileItemActions->setItemListProperties(itemProperties); | 1742 | m_fileItemActions->setItemListProperties(itemProperties); | ||
1692 | 1743 | | |||
1693 | menu->addAction(m_fileItemActions->preferredOpenWithAction(QString())); | 1744 | menu->addAction(m_fileItemActions->preferredOpenWithAction(QString())); | ||
1694 | } else { | 1745 | } else { | ||
1695 | KFileItemList items; | 1746 | KFileItemList items; | ||
1696 | QList<QUrl> urls; | 1747 | QList<QUrl> urls; | ||
1697 | bool hasRemoteFiles = false; | | |||
1698 | bool isTrashLink = false; | | |||
1699 | 1748 | | |||
1700 | items.reserve(indexes.count()); | 1749 | items.reserve(indexes.count()); | ||
1701 | urls.reserve(indexes.count()); | 1750 | urls.reserve(indexes.count()); | ||
1702 | foreach (const QModelIndex &index, indexes) { | 1751 | for (const QModelIndex &index : indexes) { | ||
1703 | KFileItem item = itemForIndex(index); | 1752 | KFileItem item = itemForIndex(index); | ||
1704 | if (!item.isNull()) { | 1753 | if (!item.isNull()) { | ||
1705 | hasRemoteFiles |= item.localPath().isEmpty(); | | |||
1706 | items.append(item); | 1754 | items.append(item); | ||
1707 | urls.append(item.url()); | 1755 | urls.append(item.url()); | ||
1708 | } | 1756 | } | ||
1709 | } | 1757 | } | ||
1710 | KFileItemListProperties itemProperties(items); | | |||
1711 | 1758 | | |||
1712 | // Check if we're showing the menu for the trash link | 1759 | KFileItemListProperties itemProperties(items); | ||
1713 | if (items.count() == 1 && items.at(0).isDesktopFile()) { | | |||
1714 | KDesktopFile file(items.at(0).localPath()); | | |||
1715 | if (file.hasLinkType() && file.readUrl() == QLatin1String("trash:/")) { | | |||
1716 | isTrashLink = true; | | |||
1717 | } | | |||
1718 | } | | |||
1719 | 1760 | | |||
1720 | // Start adding the actions: | 1761 | // Start adding the actions: | ||
1721 | menu->addAction(m_actionCollection.action(QStringLiteral("open"))); | 1762 | menu->addAction(m_actionCollection.action(QStringLiteral("open"))); | ||
1722 | menu->addSeparator(); | 1763 | menu->addSeparator(); | ||
1723 | if (itemProperties.supportsDeleting()) { | | |||
1724 | menu->addAction(m_actionCollection.action(QStringLiteral("cut"))); | 1764 | menu->addAction(m_actionCollection.action(QStringLiteral("cut"))); | ||
1725 | } | | |||
1726 | menu->addAction(m_actionCollection.action(QStringLiteral("copy"))); | 1765 | menu->addAction(m_actionCollection.action(QStringLiteral("copy"))); | ||
1727 | | ||||
1728 | if (itemProperties.isDirectory() && itemProperties.supportsWriting()) { | | |||
1729 | menu->addAction(m_actionCollection.action(QStringLiteral("pasteto"))); | 1766 | menu->addAction(m_actionCollection.action(QStringLiteral("pasteto"))); | ||
1730 | } | | |||
1731 | | ||||
1732 | menu->addAction(m_actionCollection.action(QStringLiteral("rename"))); | 1767 | menu->addAction(m_actionCollection.action(QStringLiteral("rename"))); | ||
1733 | menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash"))); | 1768 | menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash"))); | ||
1734 | 1769 | | |||
1735 | KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); | 1770 | KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals); | ||
1736 | KConfigGroup cg(globalConfig, "KDE"); | 1771 | KConfigGroup cg(globalConfig, "KDE"); | ||
1737 | bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false); | 1772 | bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false); | ||
1738 | 1773 | | |||
1739 | // When we're showing the menu for the trash link, offer "Empty Trash" instead | 1774 | menu->addAction(m_actionCollection.action(QStringLiteral("emptyTrash"))); | ||
1740 | // of the "Move to Trash" action. | 1775 | if (modifiers.testFlag(Qt::ShiftModifier)) { | ||
1741 | if (isTrashLink) { | 1776 | showDeleteCommand = true; | ||
1742 | QAction *emptyTrashAction = m_actionCollection.action(QStringLiteral("emptyTrash")); | | |||
1743 | if (emptyTrashAction) { | | |||
1744 | // We explicitly force the action visible here, as it relies on the KFileItemList | | |||
1745 | // we collected above. In updateActions() we don't have it and since this is always | | |||
1746 | // called before we open the menu, it would correct visibility again when opening | | |||
1747 | // the context menu for other items later. | | |||
1748 | emptyTrashAction->setVisible(true); | | |||
1749 | emptyTrashAction->setEnabled(!isTrashEmpty()); | | |||
1750 | menu->addAction(emptyTrashAction); | | |||
1751 | } | | |||
1752 | } else { | | |||
1753 | if (!modifiers.testFlag(Qt::ShiftModifier) && !hasRemoteFiles && itemProperties.supportsMoving()) { | | |||
1754 | menu->addAction(m_actionCollection.action(QStringLiteral("trash"))); | | |||
1755 | } else { | 1777 | } else { | ||
1778 | if (QAction *trashAction = m_actionCollection.action(QStringLiteral("trash"))) { | ||||
1779 | menu->addAction(trashAction); | ||||
1780 | if (!trashAction->isVisible()) { | ||||
1756 | showDeleteCommand = true; | 1781 | showDeleteCommand = true; | ||
1757 | } | 1782 | } | ||
1758 | } | 1783 | } | ||
1784 | } | ||||
1759 | 1785 | | |||
1760 | if (showDeleteCommand && itemProperties.supportsDeleting()) { | 1786 | if (showDeleteCommand) { | ||
1761 | menu->addAction(m_actionCollection.action(QStringLiteral("del"))); | 1787 | menu->addAction(m_actionCollection.action(QStringLiteral("del"))); | ||
1762 | } | 1788 | } | ||
1763 | 1789 | | |||
1764 | // "Open with" actions | 1790 | // "Open with" actions | ||
1765 | m_fileItemActions->setItemListProperties(itemProperties); | 1791 | m_fileItemActions->setItemListProperties(itemProperties); | ||
1766 | m_fileItemActions->addOpenWithActionsTo(menu); | 1792 | m_fileItemActions->addOpenWithActionsTo(menu); | ||
1767 | // Service actions | 1793 | // Service actions | ||
1768 | m_fileItemActions->addServiceActionsTo(menu); | 1794 | m_fileItemActions->addServiceActionsTo(menu); | ||
Show All 11 Lines | |||||
1780 | } | 1806 | } | ||
1781 | 1807 | | |||
1782 | // Properties | 1808 | // Properties | ||
1783 | if (KPropertiesDialog::canDisplay(items)) { | 1809 | if (KPropertiesDialog::canDisplay(items)) { | ||
1784 | QAction *act = new QAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("&Properties"), menu); | 1810 | QAction *act = new QAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("&Properties"), menu); | ||
1785 | QObject::connect(act, &QAction::triggered, this, &FolderModel::openPropertiesDialog); | 1811 | QObject::connect(act, &QAction::triggered, this, &FolderModel::openPropertiesDialog); | ||
1786 | menu->addAction(act); | 1812 | menu->addAction(act); | ||
1787 | } | 1813 | } | ||
1788 | | ||||
1789 | } | 1814 | } | ||
1790 | 1815 | | |||
1791 | if (visualParent) { | 1816 | if (visualParent) { | ||
1792 | m_menuPosition = visualParent->mapToGlobal(QPointF(0, visualParent->height())).toPoint(); | 1817 | m_menuPosition = visualParent->mapToGlobal(QPointF(0, visualParent->height())).toPoint(); | ||
1793 | } else { | 1818 | } else { | ||
1794 | m_menuPosition = QCursor::pos(); | 1819 | m_menuPosition = QCursor::pos(); | ||
1795 | } | 1820 | } | ||
1796 | menu->winId(); //force surface creation before ensurePolish call in menu::Popup which happens before show | 1821 | menu->winId(); //force surface creation before ensurePolish call in menu::Popup which happens before show | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
1842 | } | 1867 | } | ||
1843 | 1868 | | |||
1844 | void FolderModel::copy() | 1869 | void FolderModel::copy() | ||
1845 | { | 1870 | { | ||
1846 | if (!m_selectionModel->hasSelection()) { | 1871 | if (!m_selectionModel->hasSelection()) { | ||
1847 | return; | 1872 | return; | ||
1848 | } | 1873 | } | ||
1849 | 1874 | | |||
1875 | if (QAction *action = m_actionCollection.action(QStringLiteral("copy"))) { | ||||
1876 | if (!action->isEnabled()) { | ||||
1877 | return; | ||||
1878 | } | ||||
1879 | } | ||||
1880 | | ||||
1850 | QMimeData *mimeData = QSortFilterProxyModel::mimeData(m_selectionModel->selectedIndexes()); | 1881 | QMimeData *mimeData = QSortFilterProxyModel::mimeData(m_selectionModel->selectedIndexes()); | ||
1851 | QApplication::clipboard()->setMimeData(mimeData); | 1882 | QApplication::clipboard()->setMimeData(mimeData); | ||
1852 | } | 1883 | } | ||
1853 | 1884 | | |||
1854 | void FolderModel::cut() | 1885 | void FolderModel::cut() | ||
1855 | { | 1886 | { | ||
1856 | if (!m_selectionModel->hasSelection()) { | 1887 | if (!m_selectionModel->hasSelection()) { | ||
1857 | return; | 1888 | return; | ||
1858 | } | 1889 | } | ||
1859 | 1890 | | |||
1891 | if (QAction *action = m_actionCollection.action(QStringLiteral("cut"))) { | ||||
1892 | if (!action->isEnabled()) { | ||||
1893 | return; | ||||
1894 | } | ||||
1895 | } | ||||
1896 | | ||||
1860 | QMimeData *mimeData = QSortFilterProxyModel::mimeData(m_selectionModel->selectedIndexes()); | 1897 | QMimeData *mimeData = QSortFilterProxyModel::mimeData(m_selectionModel->selectedIndexes()); | ||
1861 | KIO::setClipboardDataCut(mimeData, true); | 1898 | KIO::setClipboardDataCut(mimeData, true); | ||
1862 | QApplication::clipboard()->setMimeData(mimeData); | 1899 | QApplication::clipboard()->setMimeData(mimeData); | ||
1863 | } | 1900 | } | ||
1864 | 1901 | | |||
1865 | void FolderModel::paste() | 1902 | void FolderModel::paste() | ||
1866 | { | 1903 | { | ||
1904 | if (QAction *action = m_actionCollection.action(QStringLiteral("paste"))) { | ||||
1905 | if (!action->isEnabled()) { | ||||
1906 | return; | ||||
1907 | } | ||||
1908 | } | ||||
1909 | | ||||
1867 | KIO::paste(QApplication::clipboard()->mimeData(), m_dirModel->dirLister()->url()); | 1910 | KIO::paste(QApplication::clipboard()->mimeData(), m_dirModel->dirLister()->url()); | ||
1868 | } | 1911 | } | ||
1869 | 1912 | | |||
1870 | void FolderModel::pasteTo() | 1913 | void FolderModel::pasteTo() | ||
1871 | { | 1914 | { | ||
1872 | const QList<QUrl> urls = selectedUrls(); | 1915 | const QList<QUrl> urls = selectedUrls(); | ||
1873 | Q_ASSERT(urls.count() == 1); | 1916 | Q_ASSERT(urls.count() == 1); | ||
1874 | KIO::paste(QApplication::clipboard()->mimeData(), urls.first()); | 1917 | KIO::paste(QApplication::clipboard()->mimeData(), urls.first()); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
1917 | } | 1960 | } | ||
1918 | 1961 | | |||
1919 | void FolderModel::moveSelectedToTrash() | 1962 | void FolderModel::moveSelectedToTrash() | ||
1920 | { | 1963 | { | ||
1921 | if (!m_selectionModel->hasSelection()) { | 1964 | if (!m_selectionModel->hasSelection()) { | ||
1922 | return; | 1965 | return; | ||
1923 | } | 1966 | } | ||
1924 | 1967 | | |||
1968 | if (QAction *action = m_actionCollection.action(QStringLiteral("trash"))) { | ||||
1969 | if (!action->isEnabled()) { | ||||
1970 | return; | ||||
1971 | } | ||||
1972 | } | ||||
1973 | | ||||
1925 | const QList<QUrl> urls = selectedUrls(); | 1974 | const QList<QUrl> urls = selectedUrls(); | ||
1926 | KIO::JobUiDelegate uiDelegate; | 1975 | KIO::JobUiDelegate uiDelegate; | ||
1927 | 1976 | | |||
1928 | if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { | 1977 | if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Trash, KIO::JobUiDelegate::DefaultConfirmation)) { | ||
1929 | KIO::Job* job = KIO::trash(urls); | 1978 | KIO::Job* job = KIO::trash(urls); | ||
1930 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 1979 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
1931 | KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, urls, QUrl(QStringLiteral("trash:/")), job); | 1980 | KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, urls, QUrl(QStringLiteral("trash:/")), job); | ||
1932 | } | 1981 | } | ||
1933 | } | 1982 | } | ||
1934 | 1983 | | |||
1935 | void FolderModel::deleteSelected() | 1984 | void FolderModel::deleteSelected() | ||
1936 | { | 1985 | { | ||
1937 | if (!m_selectionModel->hasSelection()) { | 1986 | if (!m_selectionModel->hasSelection()) { | ||
1938 | return; | 1987 | return; | ||
1939 | } | 1988 | } | ||
1940 | 1989 | | |||
1990 | if (QAction *action = m_actionCollection.action(QStringLiteral("del"))) { | ||||
1991 | if (!action->isEnabled()) { | ||||
1992 | return; | ||||
1993 | } | ||||
1994 | } | ||||
1995 | | ||||
1941 | const QList<QUrl> urls = selectedUrls(); | 1996 | const QList<QUrl> urls = selectedUrls(); | ||
1942 | KIO::JobUiDelegate uiDelegate; | 1997 | KIO::JobUiDelegate uiDelegate; | ||
1943 | 1998 | | |||
1944 | if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { | 1999 | if (uiDelegate.askDeleteConfirmation(urls, KIO::JobUiDelegate::Delete, KIO::JobUiDelegate::DefaultConfirmation)) { | ||
1945 | KIO::Job* job = KIO::del(urls); | 2000 | KIO::Job* job = KIO::del(urls); | ||
1946 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | 2001 | job->uiDelegate()->setAutoErrorHandlingEnabled(true); | ||
1947 | } | 2002 | } | ||
1948 | } | 2003 | } | ||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |