X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/41d8b21edef00745ff2f17b6bd54fca29d6cd598..5c163a41c5fdb8d97138cce455c81cb5732263aa:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 79ffdaa2e..e1913a82f 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -22,7 +22,6 @@ #include "dolphinmainwindow.h" #include "dolphinnewfilemenu.h" -#include "settings/dolphinsettings.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" @@ -32,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -51,6 +49,9 @@ #include #include +#include +#include + #include #include #include @@ -61,8 +62,11 @@ K_GLOBAL_STATIC(KModifierKeyInfo, m_keyInfo) DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, + const QPoint& pos, const KFileItem& fileInfo, const KUrl& baseUrl) : + QObject(parent), + m_pos(pos), m_mainWindow(parent), m_fileInfo(fileInfo), m_baseUrl(baseUrl), @@ -86,8 +90,8 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, if (m_keyInfo->isKeyPressed(Qt::Key_Shift) || m_keyInfo->isKeyLatched(Qt::Key_Shift)) { m_shiftPressed = true; } - connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key, bool)), - this, SLOT(slotKeyModifierPressed(Qt::Key, bool))); + connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key,bool)), + this, SLOT(slotKeyModifierPressed(Qt::Key,bool))); } m_removeAction = new QAction(this); @@ -156,10 +160,10 @@ void DolphinContextMenu::slotKeyModifierPressed(Qt::Key key, bool pressed) void DolphinContextMenu::slotRemoveActionTriggered() { const KActionCollection* collection = m_mainWindow->actionCollection(); - if (m_shiftPressed) { - collection->action("delete")->trigger(); - } else { + if (moveToTrash()) { collection->action("move_to_trash")->trigger(); + } else { + collection->action("delete")->trigger(); } } @@ -172,14 +176,6 @@ void DolphinContextMenu::openTrashContextMenu() emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); m_popup->addAction(emptyTrashAction); - QAction* addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"), - i18nc("@action:inmenu Add current folder to places", "Add to Places")); - - // Don't show if url is already in places - if (placeExists(m_mainWindow->activeViewContainer()->url())) { - addToPlacesAction->setVisible(false); - } - addCustomActions(); QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); @@ -187,23 +183,8 @@ void DolphinContextMenu::openTrashContextMenu() addShowMenuBarAction(); - QAction *action = m_popup->exec(QCursor::pos()); - if (action == emptyTrashAction) { - const QString text(i18nc("@info", "Do you really want to empty the Trash? All items will be deleted.")); - const bool del = KMessageBox::warningContinueCancel(m_mainWindow, - text, - QString(), - KGuiItem(i18nc("@action:button", "Empty Trash"), - KIcon("user-trash")) - ) == KMessageBox::Continue; - if (del) { - KonqOperations::emptyTrash(m_mainWindow); - } - } else if (action == addToPlacesAction) { - const KUrl& url = m_mainWindow->activeViewContainer()->url(); - if (url.isValid()) { - DolphinSettings::instance().placesModel()->addPlace(i18nc("@label", "Trash"), url); - } + if (m_popup->exec(m_pos) == emptyTrashAction) { + KonqOperations::emptyTrash(m_mainWindow); } } @@ -221,7 +202,7 @@ void DolphinContextMenu::openTrashItemContextMenu() QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); m_popup->addAction(propertiesAction); - if (m_popup->exec(QCursor::pos()) == restoreAction) { + if (m_popup->exec(m_pos) == restoreAction) { KUrl::List selectedUrls; foreach (const KFileItem &item, m_selectedItems) { selectedUrls.append(item.url()); @@ -243,7 +224,7 @@ void DolphinContextMenu::openItemContextMenu() // setup 'Create New' menu DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow); const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); + newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); newFileMenu->checkUpToDate(); newFileMenu->setPopupFiles(m_fileInfo.url()); newFileMenu->setEnabled(selectedItemsProperties().supportsWriting()); @@ -298,7 +279,7 @@ void DolphinContextMenu::openItemContextMenu() addVersionControlPluginActions(); // insert 'Copy To' and 'Move To' sub menus - if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) { + if (GeneralSettings::showCopyMoveMenu()) { m_copyToMenu.setItems(m_selectedItems); m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting()); m_copyToMenu.addActionsTo(m_popup); @@ -308,13 +289,15 @@ void DolphinContextMenu::openItemContextMenu() QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); m_popup->addAction(propertiesAction); - QAction* activatedAction = m_popup->exec(QCursor::pos()); + QAction* activatedAction = m_popup->exec(m_pos); if (activatedAction) { if (activatedAction == addToPlacesAction) { const KUrl selectedUrl(m_fileInfo.url()); if (selectedUrl.isValid()) { - DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl), - selectedUrl); + PlacesItemModel model; + const QString text = m_mainWindow->activeViewContainer()->placesText(); + PlacesItem* item = model.createPlacesItem(text, selectedUrl); + model.appendItemToGroup(item); } } else if (activatedAction == openParentInNewWindowAction) { m_command = OpenParentFolderInNewWindow; @@ -329,7 +312,7 @@ void DolphinContextMenu::openViewportContextMenu() // setup 'Create New' menu KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); + newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); newFileMenu->checkUpToDate(); newFileMenu->setPopupFiles(m_baseUrl); m_popup->addMenu(newFileMenu->menu()); @@ -370,11 +353,14 @@ void DolphinContextMenu::openViewportContextMenu() addShowMenuBarAction(); - QAction* action = m_popup->exec(QCursor::pos()); + QAction* action = m_popup->exec(m_pos); if (addToPlacesAction && (action == addToPlacesAction)) { - const KUrl url = m_mainWindow->activeViewContainer()->url(); - if (url.isValid()) { - DolphinSettings::instance().placesModel()->addPlace(placesName(url), url); + const DolphinViewContainer* container = m_mainWindow->activeViewContainer(); + if (container->url().isValid()) { + PlacesItemModel model; + PlacesItem* item = model.createPlacesItem(container->placesText(), + container->url()); + model.appendItemToGroup(item); } } } @@ -414,27 +400,18 @@ void DolphinContextMenu::addShowMenuBarAction() } } -QString DolphinContextMenu::placesName(const KUrl& url) const -{ - QString name = url.fileName(); - if (name.isEmpty()) { - name = url.host(); - } - return name; -} - bool DolphinContextMenu::placeExists(const KUrl& url) const { - const KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); - const int count = placesModel->rowCount(); + PlacesItemModel model; + const int count = model.count(); for (int i = 0; i < count; ++i) { - const QModelIndex index = placesModel->index(i, 0); - - if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) { + const KUrl placeUrl = model.placesItem(i)->url(); + if (placeUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { return true; } } + return false; } @@ -455,7 +432,7 @@ QAction* DolphinContextMenu::createPasteAction() return action; } -KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() +KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const { if (!m_selectedItemsProperties) { m_selectedItemsProperties = new KFileItemListProperties(m_selectedItems); @@ -547,13 +524,12 @@ void DolphinContextMenu::addCustomActions() void DolphinContextMenu::updateRemoveAction() { const KActionCollection* collection = m_mainWindow->actionCollection(); - const bool moveToTrash = selectedItemsProperties().isLocal() && !m_shiftPressed; // Using m_removeAction->setText(action->text()) does not apply the &-shortcut. // This is only done until the original action has been shown at least once. To // bypass this issue, the text and &-shortcut is applied manually. const QAction* action = 0; - if (moveToTrash) { + if (moveToTrash()) { action = collection->action("move_to_trash"); m_removeAction->setText(i18nc("@action:inmenu", "&Move to Trash")); } else { @@ -564,4 +540,9 @@ void DolphinContextMenu::updateRemoveAction() m_removeAction->setShortcuts(action->shortcuts()); } +bool DolphinContextMenu::moveToTrash() const +{ + return !m_shiftPressed; +} + #include "dolphincontextmenu.moc"