┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2010-09-22 20:24:49 +0000
committerPeter Penz <[email protected]>2010-09-22 20:24:49 +0000
commit7f7bea872b58b78813d99e5ef170c376ab1cc2c7 (patch)
treef86f740fd99600d90012f829f17c716e3a88f9e1 /src
parent5bb2a0f3c9f2d07dcb0739b88e37b203b451ecf3 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/dolphincontextmenu.cpp87
-rw-r--r--src/dolphincontextmenu.h20
-rw-r--r--src/dolphinmainwindow.cpp19
3 files changed, 93 insertions, 33 deletions
diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp
index a36d1aeb0..f868282b4 100644
--- a/src/dolphincontextmenu.cpp
+++ b/src/dolphincontextmenu.cpp
@@ -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();
+ 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();
+ }
}
+
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;
}
}
}
diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h
index 2913114ac..d6b991053 100644
--- a/src/dolphincontextmenu.h
+++ b/src/dolphincontextmenu.h
@@ -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'
};
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index 9a5e5e3a8..1c1343976 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -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()