Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create DnD menu only with supported actions #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/dndactionmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@

namespace Fm {

DndActionMenu::DndActionMenu(QWidget* parent): QMenu(parent) {
copyAction = addAction(QIcon::fromTheme("edit-copy"), tr("Copy here"));
moveAction = addAction(tr("Move here"));
linkAction = addAction(tr("Create symlink here"));
DndActionMenu::DndActionMenu(Qt::DropActions possibleActions, QWidget* parent)
: QMenu(parent)
, copyAction(nullptr)
, moveAction(nullptr)
, linkAction(nullptr)
, cancelAction(nullptr)
{
if (possibleActions.testFlag(Qt::CopyAction))
copyAction = addAction(QIcon::fromTheme("edit-copy"), tr("Copy here"));
if (possibleActions.testFlag(Qt::MoveAction))
moveAction = addAction(tr("Move here"));
if (possibleActions.testFlag(Qt::LinkAction))
linkAction = addAction(tr("Create symlink here"));
addSeparator();
cancelAction = addAction(tr("Cancel"));
}
Expand All @@ -34,18 +43,19 @@ DndActionMenu::~DndActionMenu() {

}

Qt::DropAction DndActionMenu::askUser(QPoint pos) {
Qt::DropAction result;
DndActionMenu menu;
Qt::DropAction DndActionMenu::askUser(Qt::DropActions possibleActions, QPoint pos) {
Qt::DropAction result = Qt::IgnoreAction;
DndActionMenu menu{possibleActions};
QAction* action = menu.exec(pos);
if(action == menu.copyAction)
result = Qt::CopyAction;
else if(action == menu.moveAction)
result = Qt::MoveAction;
else if(action == menu.linkAction)
result = Qt::LinkAction;
else
result = Qt::IgnoreAction;
if (nullptr != action)
{
if(action == menu.copyAction)
result = Qt::CopyAction;
else if(action == menu.moveAction)
result = Qt::MoveAction;
else if(action == menu.linkAction)
result = Qt::LinkAction;
}
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/dndactionmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace Fm {
class DndActionMenu : public QMenu {
Q_OBJECT
public:
explicit DndActionMenu(QWidget* parent = 0);
explicit DndActionMenu(Qt::DropActions possibleActions, QWidget* parent = 0);
virtual ~DndActionMenu();

static Qt::DropAction askUser(QPoint pos);
static Qt::DropAction askUser(Qt::DropActions possibleActions, QPoint pos);

private:
QAction* copyAction;
Expand Down
2 changes: 1 addition & 1 deletion src/folderview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ void FolderView::childDropEvent(QDropEvent* e) {
if(e->keyboardModifiers() == Qt::NoModifier) {
// if no key modifiers are used, popup a menu
// to ask the user for the action he/she wants to perform.
Qt::DropAction action = DndActionMenu::askUser(QCursor::pos());
Qt::DropAction action = DndActionMenu::askUser(e->possibleActions(), QCursor::pos());
e->setDropAction(action);
}
}
Expand Down