X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4822c2cc3bcdc70d73bb76dd627b04312d463265..7d7ecaafb18e85224fcf0b2432f3617edb9e3a2a:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 2a2994086..a36d1aeb0 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,8 @@ #include "views/dolphinview.h" #include "views/viewmodecontroller.h" +K_GLOBAL_STATIC(KModifierKeyInfo, m_keyInfo) + DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const KFileItem& fileInfo, const KUrl& baseUrl) : @@ -65,7 +68,6 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_customActions(), m_popup(new KMenu(m_mainWindow)), m_shiftPressed(false), - m_keyInfo(), m_removeAction(0) { // The context menu either accesses the URLs of the selected items @@ -74,13 +76,14 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_selectedUrls = view->selectedUrls(); m_selectedItems = view->selectedItems(); - if (m_keyInfo.isKeyPressed(Qt::Key_Shift) || m_keyInfo.isKeyLatched(Qt::Key_Shift)) { - m_shiftPressed = true; + if (m_keyInfo != 0) { + 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); connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered())); } @@ -99,7 +102,7 @@ void DolphinContextMenu::setCustomActions(const QList& actions) void DolphinContextMenu::open() { // get the context information - if (m_baseUrl.protocol() == "trash") { + if (m_baseUrl.protocol() == QLatin1String("trash")) { m_context |= TrashContext; } @@ -123,6 +126,14 @@ void DolphinContextMenu::open() } } +void DolphinContextMenu::initializeModifierKeyInfo() +{ + // Access m_keyInfo, so that it gets instantiated by + // K_GLOBAL_STATIC + KModifierKeyInfo* keyInfo = m_keyInfo; + Q_UNUSED(keyInfo); +} + void DolphinContextMenu::slotKeyModifierPressed(Qt::Key key, bool pressed) { m_shiftPressed = (key == Qt::Key_Shift) && pressed; @@ -208,6 +219,7 @@ void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); + QAction* addToPlacesAction = 0; if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) { // setup 'Create New' menu DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow); @@ -226,6 +238,14 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Open in new window' and 'Open in new tab' entries m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window")); m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab")); + + // insert 'Add to Places' entry + if (!placeExists(m_fileInfo.url())) { + addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"), + i18nc("@action:inmenu Add selected folder to places", + "Add to Places")); + } + m_popup->addSeparator(); } addShowMenubarAction(); @@ -244,14 +264,6 @@ void DolphinContextMenu::openItemContextMenu() m_copyToMenu.setItems(m_selectedItems); m_copyToMenu.setReadOnly(!capabilities().supportsWriting()); m_copyToMenu.addActionsTo(m_popup.data()); - m_popup->addSeparator(); - } - - // insert 'Add to Places' entry if exactly one item is selected - QAction* addToPlacesAction = 0; - if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1) && !placeExists(m_fileInfo.url())) { - addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"), - i18nc("@action:inmenu Add selected folder to places", "Add to Places")); } // insert 'Properties...' entry @@ -417,9 +429,7 @@ void DolphinContextMenu::addServiceActions(KFileItemActions& fileItemActions) fileItemActions.addOpenWithActionsTo(m_popup.data(), "DesktopEntryName != 'dolphin'"); // insert 'Actions' sub menu - if (fileItemActions.addServiceActionsTo(m_popup.data())) { - m_popup->addSeparator(); - } + fileItemActions.addServiceActionsTo(m_popup.data()); } void DolphinContextMenu::addVersionControlActions()