mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
The paste operation should ignore the current selection to behave similar as Konqueror and other file managers. Only if a context menu for a folder is opened, a pasting should be done into this folder.
Some internal cleanups are still required (see TODO comments), so that after finishing the operation an indication can be given to the user in the statusbar (must go for breakfast now, otherwise I'll eat my keyboard...). BUG: 159862 svn path=/trunk/KDE/kdebase/apps/; revision=791354
This commit is contained in:
parent
2fdeb4f5bb
commit
fc15039860
|
@ -95,6 +95,24 @@ void DolphinContextMenu::open()
|
|||
}
|
||||
}
|
||||
|
||||
void DolphinContextMenu::pasteIntoFolder()
|
||||
{
|
||||
// TODO: this method should go into DolphinView (see DolphinContextMenu::createPasteAction())
|
||||
Q_ASSERT(m_selectedItems.count() == 1);
|
||||
Q_ASSERT(m_fileInfo.isDir());
|
||||
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
const QMimeData* mimeData = clipboard->mimeData();
|
||||
|
||||
const KUrl::List source = KUrl::List::fromMimeData(mimeData);
|
||||
const KUrl& dest = m_fileInfo.url();
|
||||
if (KonqMimeData::decodeIsCutSelection(mimeData)) {
|
||||
KonqOperations::copy(m_mainWindow, KonqOperations::MOVE, source, dest);
|
||||
clipboard->clear();
|
||||
} else {
|
||||
KonqOperations::copy(m_mainWindow, KonqOperations::COPY, source, dest);
|
||||
}
|
||||
}
|
||||
|
||||
void DolphinContextMenu::openTrashContextMenu()
|
||||
{
|
||||
|
@ -230,7 +248,7 @@ void DolphinContextMenu::openViewportContextMenu()
|
|||
popup->addMenu(newMenu->menu());
|
||||
popup->addSeparator();
|
||||
|
||||
QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
|
||||
QAction* pasteAction = createPasteAction();
|
||||
popup->addAction(pasteAction);
|
||||
|
||||
// setup 'View Mode' menu
|
||||
|
@ -281,7 +299,7 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
|
|||
// insert 'Cut', 'Copy' and 'Paste'
|
||||
QAction* cutAction = collection->action(KStandardAction::name(KStandardAction::Cut));
|
||||
QAction* copyAction = collection->action(KStandardAction::name(KStandardAction::Copy));
|
||||
QAction* pasteAction = collection->action(KStandardAction::name(KStandardAction::Paste));
|
||||
QAction* pasteAction = createPasteAction();
|
||||
|
||||
popup->addAction(cutAction);
|
||||
popup->addAction(copyAction);
|
||||
|
@ -415,4 +433,21 @@ QString DolphinContextMenu::placesName(const KUrl& url) const
|
|||
return name;
|
||||
}
|
||||
|
||||
QAction* DolphinContextMenu::createPasteAction()
|
||||
{
|
||||
// TODO: move this method as QAction* action pasteAction() into DolphinMainWindow
|
||||
QAction* action = 0;
|
||||
if ((m_selectedItems.count() == 1) && m_fileInfo.isDir()) {
|
||||
action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
|
||||
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
|
||||
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
|
||||
action->setEnabled(!pasteData.isEmpty());
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(pasteIntoFolder()));
|
||||
} else {
|
||||
action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
#include "dolphincontextmenu.moc"
|
||||
|
|
|
@ -69,6 +69,9 @@ public:
|
|||
/** Opens the context menu model. */
|
||||
void open();
|
||||
|
||||
private slots:
|
||||
void pasteIntoFolder();
|
||||
|
||||
private:
|
||||
void openTrashContextMenu();
|
||||
void openTrashItemContextMenu();
|
||||
|
@ -108,6 +111,8 @@ private:
|
|||
*/
|
||||
QString placesName(const KUrl& url) const;
|
||||
|
||||
QAction* createPasteAction();
|
||||
|
||||
private:
|
||||
struct Entry
|
||||
{
|
||||
|
|
|
@ -1102,41 +1102,12 @@ void DolphinView::paste()
|
|||
const QMimeData* mimeData = clipboard->mimeData();
|
||||
|
||||
const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
|
||||
|
||||
// per default the pasting is done into the current URL of the view
|
||||
KUrl destUrl = url();
|
||||
|
||||
// check whether the pasting should be done into a selected directory
|
||||
const KUrl::List selectedUrls = this->selectedUrls();
|
||||
if (selectedUrls.count() == 1) {
|
||||
const KFileItem fileItem(S_IFDIR,
|
||||
KFileItem::Unknown,
|
||||
selectedUrls.first(),
|
||||
true);
|
||||
if (fileItem.isDir()) {
|
||||
// only one item is selected which is a directory, hence paste
|
||||
// into this directory
|
||||
destUrl = selectedUrls.first();
|
||||
if (sourceUrls.contains(destUrl)) {
|
||||
const QString text = i18nc("@info", "The folder <filename>%1</filename> is pasted into itself. Is this intended?", fileItem.name());
|
||||
int result = KMessageBox::questionYesNo(window(),
|
||||
text,
|
||||
i18nc("@title:window", "Paste into Folder"),
|
||||
KGuiItem(i18nc("@action:button", "Paste"), "dialog-ok"),
|
||||
KGuiItem(i18nc("@action:button", "Cancel"), "dialog-cancel"));
|
||||
if (result == KMessageBox::No) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (KonqMimeData::decodeIsCutSelection(mimeData)) {
|
||||
KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, destUrl);
|
||||
KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url());
|
||||
emit doingOperation(KonqFileUndoManager::MOVE);
|
||||
clipboard->clear();
|
||||
} else {
|
||||
KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, destUrl);
|
||||
KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url());
|
||||
emit doingOperation(KonqFileUndoManager::COPY);
|
||||
}
|
||||
}
|
||||
|
@ -1163,19 +1134,6 @@ QPair<bool, QString> DolphinView::pasteInfo() const
|
|||
ret.second = i18nc("@action:inmenu", "Paste");
|
||||
}
|
||||
|
||||
if (ret.first) {
|
||||
const KFileItemList items = selectedItems();
|
||||
const uint count = items.count();
|
||||
if (count > 1) {
|
||||
// pasting should not be allowed when more than one file
|
||||
// is selected
|
||||
ret.first = false;
|
||||
} else if (count == 1) {
|
||||
// Only one file is selected. Pasting is only allowed if this
|
||||
// file is a directory.
|
||||
ret.first = items.first().isDir();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue