If the context-menu is opened for a file shown as search result, offer the actions "Open Parent Folder in New Window" and "Open Parent Folder in New Tab"

svn path=/trunk/KDE/kdebase/apps/; revision=1178362
This commit is contained in:
Peter Penz 2010-09-22 20:24:49 +00:00
parent 308c517487
commit 9b6e353dad
3 changed files with 93 additions and 33 deletions

View file

@ -67,6 +67,7 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
m_copyToMenu(parent),
m_customActions(),
m_popup(new KMenu(m_mainWindow)),
m_command(None),
m_shiftPressed(false),
m_removeAction(0)
{
@ -99,7 +100,7 @@ void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
m_customActions = actions;
}
void DolphinContextMenu::open()
DolphinContextMenu::Command DolphinContextMenu::open()
{
// get the context information
if (m_baseUrl.protocol() == QLatin1String("trash")) {
@ -124,6 +125,8 @@ void DolphinContextMenu::open()
Q_ASSERT(m_context == NoContext);
openViewportContextMenu();
}
return m_command;
}
void DolphinContextMenu::initializeModifierKeyInfo()
@ -219,35 +222,54 @@ void DolphinContextMenu::openItemContextMenu()
{
Q_ASSERT(!m_fileInfo.isNull());
QAction* openParentInNewWindowAction = 0;
QAction* openParentInNewTabAction = 0;
QAction* addToPlacesAction = 0;
if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) {
// setup 'Create New' menu
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow);
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_fileInfo.url());
newFileMenu->setEnabled(capabilities().supportsWriting());
if (m_selectedUrls.count() == 1) {
if (m_fileInfo.isDir()) {
// setup 'Create New' menu
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow);
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
newFileMenu->checkUpToDate();
newFileMenu->setPopupFiles(m_fileInfo.url());
newFileMenu->setEnabled(capabilities().supportsWriting());
KMenu* menu = newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
menu->setIcon(KIcon("document-new"));
m_popup->addMenu(menu);
m_popup->addSeparator();
KMenu* menu = newFileMenu->menu();
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
menu->setIcon(KIcon("document-new"));
m_popup->addMenu(menu);
m_popup->addSeparator();
// 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 '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"));
// 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();
} else if (m_baseUrl.protocol().contains("search")) {
openParentInNewWindowAction = new QAction(KIcon("window-new"),
i18nc("@action:inmenu",
"Open Parent Folder in New Window"),
this);
m_popup->addAction(openParentInNewWindowAction);
openParentInNewTabAction = new QAction(KIcon("tab-new"),
i18nc("@action:inmenu",
"Open Parent Folder in New Tab"),
this);
m_popup->addAction(openParentInNewTabAction);
m_popup->addSeparator();
}
m_popup->addSeparator();
}
addShowMenubarAction();
insertDefaultItemActions();
@ -271,12 +293,17 @@ void DolphinContextMenu::openItemContextMenu()
m_popup->addAction(propertiesAction);
QAction* activatedAction = m_popup->exec(QCursor::pos());
if ((addToPlacesAction != 0) && (activatedAction == addToPlacesAction)) {
const KUrl selectedUrl(m_fileInfo.url());
if (selectedUrl.isValid()) {
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
selectedUrl);
if (activatedAction != 0) {
if (activatedAction == addToPlacesAction) {
const KUrl selectedUrl(m_fileInfo.url());
if (selectedUrl.isValid()) {
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
selectedUrl);
}
} else if (activatedAction == openParentInNewWindowAction) {
m_command = OpenParentFolderInNewWindow;
} else if (activatedAction == openParentInNewTabAction) {
m_command = OpenParentFolderInNewTab;
}
}
}

View file

@ -56,6 +56,13 @@ class DolphinContextMenu : public QObject
Q_OBJECT
public:
enum Command
{
None,
OpenParentFolderInNewWindow,
OpenParentFolderInNewTab
};
/**
* @parent Pointer to the main window the context menu
* belongs to.
@ -73,8 +80,15 @@ public:
void setCustomActions(const QList<QAction*>& actions);
/** Opens the context menu model. */
void open();
/**
* Opens the context menu model and returns the requested
* command, that should be triggered by the caller. If
* Command::None has been returned, either the context-menu
* had been closed without executing an action or an
* already available action from the main-window has been
* executed.
*/
Command open();
/**
* TODO: This method is a workaround for a X11-issue in combination
@ -164,6 +178,8 @@ private:
QList<QAction*> m_customActions;
QScopedPointer<KMenu> m_popup;
Command m_command;
bool m_shiftPressed;
QAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
};

View file

@ -1184,7 +1184,24 @@ void DolphinMainWindow::openContextMenu(const KFileItem& item,
{
DolphinContextMenu contextMenu(this, item, url);
contextMenu.setCustomActions(customActions);
contextMenu.open();
const DolphinContextMenu::Command command = contextMenu.open();
switch (command) {
case DolphinContextMenu::OpenParentFolderInNewWindow: {
DolphinMainWindow* window = DolphinApplication::app()->createMainWindow();
window->changeUrl(item.url().upUrl());
window->show();
break;
}
case DolphinContextMenu::OpenParentFolderInNewTab:
openNewTab(item.url().upUrl());
break;
case DolphinContextMenu::None:
default:
break;
}
}
void DolphinMainWindow::init()