From 09e1cc4d7726b649710fe5ce49741ae736ce4d06 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 27 Aug 2010 05:26:27 +0000 Subject: Context-menu cleanups: - KNewMenu has been deprecated by KNewFileMenu. Reflect this in the names of related Dolphin classes. - Provide context-sensitive actions also when a context-menu is opened on the viewport BUG: 191938 FIXED-IN: 4.6.0 svn path=/trunk/KDE/kdebase/apps/; revision=1168586 --- src/CMakeLists.txt | 4 +- src/dolphincontextmenu.cpp | 114 +++++++++++++++---------------- src/dolphincontextmenu.h | 2 + src/dolphinmainwindow.cpp | 22 +++--- src/dolphinmainwindow.h | 8 +-- src/dolphinnewfilemenu.cpp | 54 +++++++++++++++ src/dolphinnewfilemenu.h | 53 ++++++++++++++ src/dolphinnewmenu.cpp | 54 --------------- src/dolphinnewmenu.h | 53 -------------- src/dolphinpart.cpp | 24 +++---- src/dolphinpart.h | 2 +- src/views/dolphinnewfilemenuobserver.cpp | 62 +++++++++++++++++ src/views/dolphinnewfilemenuobserver.h | 56 +++++++++++++++ src/views/dolphinnewmenuobserver.cpp | 62 ----------------- src/views/dolphinnewmenuobserver.h | 56 --------------- src/views/dolphinview.cpp | 4 +- 16 files changed, 314 insertions(+), 316 deletions(-) create mode 100644 src/dolphinnewfilemenu.cpp create mode 100644 src/dolphinnewfilemenu.h delete mode 100644 src/dolphinnewmenu.cpp delete mode 100644 src/dolphinnewmenu.h create mode 100644 src/views/dolphinnewfilemenuobserver.cpp create mode 100644 src/views/dolphinnewfilemenuobserver.h delete mode 100644 src/views/dolphinnewmenuobserver.cpp delete mode 100644 src/views/dolphinnewmenuobserver.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 09e58b720..b6b9410ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,7 +33,7 @@ set(dolphinprivate_LIB_SRCS views/dolphincolumnview.cpp views/dolphincolumnviewcontainer.cpp views/dolphinmodel.cpp - views/dolphinnewmenuobserver.cpp + views/dolphinnewfilemenuobserver.cpp views/dolphinremoteencoding.cpp views/dolphinsortfilterproxymodel.cpp views/dolphinviewactionhandler.cpp @@ -97,7 +97,7 @@ install(FILES views/versioncontrol/fileviewversioncontrolplugin.desktop DESTINAT set(dolphin_SRCS dolphinapplication.cpp dolphinmainwindow.cpp - dolphinnewmenu.cpp + dolphinnewfilemenu.cpp dolphinviewcontainer.cpp dolphincontextmenu.cpp filterbar/filterbar.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 57cef97df..d76cd8d23 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -21,7 +21,7 @@ #include "dolphincontextmenu.h" #include "dolphinmainwindow.h" -#include "dolphinnewmenu.h" +#include "dolphinnewfilemenu.h" #include "settings/dolphinsettings.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -189,17 +189,17 @@ void DolphinContextMenu::openItemContextMenu() KMenu* popup = new KMenu(m_mainWindow); if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) { // setup 'Create New' menu - DolphinNewMenu* newMenu = new DolphinNewMenu(popup, m_mainWindow); + DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(popup, m_mainWindow); const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - newMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); - newMenu->checkUpToDate(); - newMenu->setPopupFiles(m_fileInfo.url()); - newMenu->setEnabled(capabilities().supportsWriting()); + newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); + newFileMenu->checkUpToDate(); + newFileMenu->setPopupFiles(m_fileInfo.url()); + newFileMenu->setEnabled(capabilities().supportsWriting()); - KMenu* menu = newMenu->menu(); + KMenu* menu = newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); menu->setIcon(KIcon("document-new")); - popup->addMenu(newMenu->menu()); + popup->addMenu(menu); popup->addSeparator(); // insert 'Open in new window' and 'Open in new tab' entries @@ -212,30 +212,10 @@ void DolphinContextMenu::openItemContextMenu() popup->addSeparator(); - // insert 'Bookmark This Folder' entry if exactly one item is selected - QAction* addToPlacesAction = 0; - if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) { - addToPlacesAction = popup->addAction(KIcon("bookmark-new"), - i18nc("@action:inmenu Add selected folder to places", "Add to Places")); - // Don't show if url is already in places - if (placeExists(m_fileInfo.url())) { - addToPlacesAction->setVisible(false); - } - } + KFileItemActions fileItemActions; + fileItemActions.setItemListProperties(capabilities()); + addServiceActions(popup, fileItemActions); - KFileItemActions menuActions; - menuActions.setParentWidget(m_mainWindow); - menuActions.setItemListProperties(m_selectedItems); - - // insert 'Open With...' action or sub menu - menuActions.addOpenWithActionsTo(popup, "DesktopEntryName != 'dolphin'"); - - // insert 'Actions' sub menu - if (menuActions.addServiceActionsTo(popup)) { - popup->addSeparator(); - } - - // insert version control actions addVersionControlActions(popup); // insert 'Copy To' and 'Move To' sub menus @@ -246,6 +226,13 @@ void DolphinContextMenu::openItemContextMenu() 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 = popup->addAction(KIcon("bookmark-new"), + i18nc("@action:inmenu Add selected folder to places", "Add to Places")); + } + // insert 'Properties...' entry QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties"); popup->addAction(propertiesAction); @@ -270,41 +257,37 @@ void DolphinContextMenu::openViewportContextMenu() addShowMenubarAction(popup); // setup 'Create New' menu - KNewFileMenu* newMenu = m_mainWindow->newMenu(); + KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - newMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); - newMenu->checkUpToDate(); - newMenu->setPopupFiles(m_baseUrl); - popup->addMenu(newMenu->menu()); + newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles()); + newFileMenu->checkUpToDate(); + newFileMenu->setPopupFiles(m_baseUrl); + popup->addMenu(newFileMenu->menu()); + popup->addSeparator(); + + // insert 'Open in new window' and 'Open in new tab' entries + popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window")); + popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab")); popup->addSeparator(); QAction* pasteAction = createPasteAction(); popup->addAction(pasteAction); - - // setup 'View Mode' menu - KMenu* viewModeMenu = new KMenu(i18nc("@title:menu", "View Mode"), popup); - - QAction* iconsMode = m_mainWindow->actionCollection()->action("icons"); - viewModeMenu->addAction(iconsMode); - - QAction* detailsMode = m_mainWindow->actionCollection()->action("details"); - viewModeMenu->addAction(detailsMode); - - QAction* columnsMode = m_mainWindow->actionCollection()->action("columns"); - viewModeMenu->addAction(columnsMode); - - popup->addMenu(viewModeMenu); - popup->addSeparator(); - addVersionControlActions(popup); + // insert service actions + const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_baseUrl); + const KFileItemListProperties baseUrlProperties(KFileItemList() << item); + KFileItemActions fileItemActions; + fileItemActions.setItemListProperties(baseUrlProperties); + addServiceActions(popup, fileItemActions); - QAction* addToPlacesAction = popup->addAction(KIcon("bookmark-new"), - i18nc("@action:inmenu Add current folder to places", "Add to Places")); + addVersionControlActions(popup); - // Don't show if url is already in places - if (placeExists(m_mainWindow->activeViewContainer()->url())) { - addToPlacesAction->setVisible(false); + // insert 'Add to Places' entry if exactly one item is selected + QAction* addToPlacesAction = 0; + if (!placeExists(m_mainWindow->activeViewContainer()->url())) { + addToPlacesAction = popup->addAction(KIcon("bookmark-new"), + i18nc("@action:inmenu Add current folder to places", "Add to Places")); } addCustomActions(popup); @@ -318,7 +301,7 @@ void DolphinContextMenu::openViewportContextMenu() KPropertiesDialog* dialog = new KPropertiesDialog(url, m_mainWindow); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); - } else if (action == addToPlacesAction) { + } else if ((addToPlacesAction != 0) && (action == addToPlacesAction)) { const KUrl& url = m_mainWindow->activeViewContainer()->url(); if (url.isValid()) { DolphinSettings::instance().placesModel()->addPlace(placesName(url), url); @@ -424,6 +407,19 @@ KFileItemListProperties& DolphinContextMenu::capabilities() return *m_capabilities; } +void DolphinContextMenu::addServiceActions(KMenu* menu, KFileItemActions& fileItemActions) +{ + fileItemActions.setParentWidget(m_mainWindow); + + // insert 'Open With...' action or sub menu + fileItemActions.addOpenWithActionsTo(menu, "DesktopEntryName != 'dolphin'"); + + // insert 'Actions' sub menu + if (fileItemActions.addServiceActionsTo(menu)) { + menu->addSeparator(); + } +} + void DolphinContextMenu::addVersionControlActions(KMenu* menu) { const DolphinView* view = m_mainWindow->activeViewContainer()->view(); diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h index e286e61d2..ae0d1c336 100644 --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -34,6 +34,7 @@ class KMenu; class KFileItem; class QAction; class DolphinMainWindow; +class KFileItemActions; class KFileItemListProperties; /** @@ -98,6 +99,7 @@ private: private: KFileItemListProperties& capabilities(); + void addServiceActions(KMenu* menu, KFileItemActions& fileItemActions); void addVersionControlActions(KMenu* menu); void addCustomActions(KMenu* menu); diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index bc0f9d651..e58b81740 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,7 +25,7 @@ #include "dolphinapplication.h" #include "dolphincontextmenu.h" -#include "dolphinnewmenu.h" +#include "dolphinnewfilemenu.h" #include "dolphinviewcontainer.h" #include "mainwindowadaptor.h" #include "panels/folders/folderspanel.h" @@ -103,7 +103,7 @@ Q_DECLARE_METATYPE(ClosedTab) DolphinMainWindow::DolphinMainWindow(int id) : KXmlGuiWindow(0), - m_newMenu(0), + m_newFileMenu(0), m_showMenuBar(0), m_tabBar(0), m_activeViewContainer(0), @@ -630,16 +630,16 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group) void DolphinMainWindow::updateNewMenu() { - m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles()); - m_newMenu->checkUpToDate(); - m_newMenu->setPopupFiles(activeViewContainer()->url()); + m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles()); + m_newFileMenu->checkUpToDate(); + m_newFileMenu->setPopupFiles(activeViewContainer()->url()); } void DolphinMainWindow::createDirectory() { - m_newMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles()); - m_newMenu->setPopupFiles(activeViewContainer()->url()); - m_newMenu->createDirectory(); + m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->showHiddenFiles()); + m_newFileMenu->setPopupFiles(activeViewContainer()->url()); + m_newFileMenu->createDirectory(); } void DolphinMainWindow::quit() @@ -1177,7 +1177,7 @@ void DolphinMainWindow::slotCaptionStatFinished(KJob* job) void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) { - newMenu()->setEnabled(isFolderWritable); + newFileMenu()->setEnabled(isFolderWritable); } void DolphinMainWindow::openContextMenu(const KFileItem& item, @@ -1327,8 +1327,8 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContain void DolphinMainWindow::setupActions() { // setup 'File' menu - m_newMenu = new DolphinNewMenu(this, this); - KMenu* menu = m_newMenu->menu(); + m_newFileMenu = new DolphinNewFileMenu(this, this); + KMenu* menu = m_newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); menu->setIcon(KIcon("document-new")); connect(menu, SIGNAL(aboutToShow()), diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 4d993865f..b9dbe9f9d 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -114,7 +114,7 @@ public: * Returns the 'Create New...' sub menu which also can be shared * with other menus (e. g. a context menu). */ - KNewFileMenu* newMenu() const; + KNewFileMenu* newFileMenu() const; /** * Returns the 'Show Menubar' action which can be shared with @@ -524,7 +524,7 @@ private: virtual void jobError(KIO::Job* job); }; - KNewFileMenu* m_newMenu; + KNewFileMenu* m_newFileMenu; KActionMenu* m_recentTabsMenu; KAction* m_showMenuBar; KTabBar* m_tabBar; @@ -562,9 +562,9 @@ inline bool DolphinMainWindow::isSplit() const return m_viewTab[m_tabIndex].secondaryView != 0; } -inline KNewFileMenu* DolphinMainWindow::newMenu() const +inline KNewFileMenu* DolphinMainWindow::newFileMenu() const { - return m_newMenu; + return m_newFileMenu; } inline KAction* DolphinMainWindow::showMenuBarAction() const diff --git a/src/dolphinnewfilemenu.cpp b/src/dolphinnewfilemenu.cpp new file mode 100644 index 000000000..c7ffb788e --- /dev/null +++ b/src/dolphinnewfilemenu.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinnewfilemenu.h" + +#include "dolphinmainwindow.h" +#include "dolphinviewcontainer.h" +#include "statusbar/dolphinstatusbar.h" +#include "views/dolphinnewfilemenuobserver.h" +#include "views/dolphinview.h" + +#include +#include + +DolphinNewFileMenu::DolphinNewFileMenu(QWidget* parent, DolphinMainWindow* mainWin) : + KNewFileMenu(mainWin->actionCollection(), "create_new", parent), + m_mainWin(mainWin) +{ + DolphinNewFileMenuObserver::instance().attach(this); +} + +DolphinNewFileMenu::~DolphinNewFileMenu() +{ + DolphinNewFileMenuObserver::instance().detach(this); +} + +void DolphinNewFileMenu::slotResult(KJob* job) +{ + if (job->error()) { + DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar(); + statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); + } else { + KNewFileMenu::slotResult(job); + } +} + +#include "dolphinnewfilemenu.moc" diff --git a/src/dolphinnewfilemenu.h b/src/dolphinnewfilemenu.h new file mode 100644 index 000000000..dae97d667 --- /dev/null +++ b/src/dolphinnewfilemenu.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2006 by Peter Penz * + * peter.penz@gmx.at * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINNEWFILEMENU_H +#define DOLPHINNEWFILEMENU_H + +#include + +class DolphinMainWindow; +class KJob; + +/** + * @brief Represents the 'Create New...' sub menu for the File menu + * and the context menu. + * + * The only difference to KNewFileMenu is the custom error handling. + * All errors are shown in the status bar of Dolphin + * instead as modal error dialog with an OK button. + */ +class DolphinNewFileMenu : public KNewFileMenu +{ + Q_OBJECT + +public: + DolphinNewFileMenu(QWidget* parent, DolphinMainWindow* mainWin); + virtual ~DolphinNewFileMenu(); + +protected slots: + /** @see KNewFileMenu::slotResult() */ + virtual void slotResult(KJob* job); + +private: + DolphinMainWindow* m_mainWin; +}; + +#endif diff --git a/src/dolphinnewmenu.cpp b/src/dolphinnewmenu.cpp deleted file mode 100644 index a6dec150e..000000000 --- a/src/dolphinnewmenu.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinnewmenu.h" - -#include "dolphinmainwindow.h" -#include "dolphinviewcontainer.h" -#include "statusbar/dolphinstatusbar.h" -#include "views/dolphinnewmenuobserver.h" -#include "views/dolphinview.h" - -#include -#include - -DolphinNewMenu::DolphinNewMenu(QWidget* parent, DolphinMainWindow* mainWin) : - KNewFileMenu(mainWin->actionCollection(), "create_new", parent), - m_mainWin(mainWin) -{ - DolphinNewMenuObserver::instance().attach(this); -} - -DolphinNewMenu::~DolphinNewMenu() -{ - DolphinNewMenuObserver::instance().detach(this); -} - -void DolphinNewMenu::slotResult(KJob* job) -{ - if (job->error()) { - DolphinStatusBar* statusBar = m_mainWin->activeViewContainer()->statusBar(); - statusBar->setMessage(job->errorString(), DolphinStatusBar::Error); - } else { - KNewFileMenu::slotResult(job); - } -} - -#include "dolphinnewmenu.moc" diff --git a/src/dolphinnewmenu.h b/src/dolphinnewmenu.h deleted file mode 100644 index 176c84648..000000000 --- a/src/dolphinnewmenu.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINNEWMENU_H -#define DOLPHINNEWMENU_H - -#include - -class DolphinMainWindow; -class KJob; - -/** - * @brief Represents the 'Create New...' sub menu for the File menu - * and the context menu. - * - * The only difference to KNewFileMenu is the custom error handling. - * All errors are shown in the status bar of Dolphin - * instead as modal error dialog with an OK button. - */ -class DolphinNewMenu : public KNewFileMenu -{ - Q_OBJECT - -public: - DolphinNewMenu(QWidget* parent, DolphinMainWindow* mainWin); - virtual ~DolphinNewMenu(); - -protected slots: - /** @see KNewFileMenu::slotResult() */ - virtual void slotResult(KJob* job); - -private: - DolphinMainWindow* m_mainWin; -}; - -#endif diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index a8254552e..3309f4b38 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -45,7 +45,7 @@ #include "views/dolphinviewactionhandler.h" #include "views/dolphinsortfilterproxymodel.h" #include "views/dolphinmodel.h" -#include "views/dolphinnewmenuobserver.h" +#include "views/dolphinnewfilemenuobserver.h" #include "views/dolphinremoteencoding.h" #include @@ -146,7 +146,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL DolphinPart::~DolphinPart() { DolphinSettings::instance().save(); - DolphinNewMenuObserver::instance().detach(m_newMenu); + DolphinNewFileMenuObserver::instance().detach(m_newFileMenu); delete m_dirLister; } @@ -154,10 +154,10 @@ void DolphinPart::createActions() { // Edit menu - m_newMenu = new KNewFileMenu(actionCollection(), "new_menu", this); - m_newMenu->setParentWidget(widget()); - DolphinNewMenuObserver::instance().attach(m_newMenu); - connect(m_newMenu->menu(), SIGNAL(aboutToShow()), + m_newFileMenu = new KNewFileMenu(actionCollection(), "new_menu", this); + m_newFileMenu->setParentWidget(widget()); + DolphinNewFileMenuObserver::instance().attach(m_newFileMenu); + connect(m_newFileMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); KAction *editMimeTypeAction = actionCollection()->addAction( "editMimeType" ); @@ -600,10 +600,10 @@ void DolphinPart::slotOpenTerminal() void DolphinPart::updateNewMenu() { // As requested by KNewFileMenu : - m_newMenu->checkUpToDate(); - m_newMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles()); + m_newFileMenu->checkUpToDate(); + m_newFileMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles()); // And set the files that the menu apply on : - m_newMenu->setPopupFiles(url()); + m_newFileMenu->setPopupFiles(url()); } void DolphinPart::updateStatusBar() @@ -618,9 +618,9 @@ void DolphinPart::updateProgress(int percent) void DolphinPart::createDirectory() { - m_newMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles()); - m_newMenu->setPopupFiles(url()); - m_newMenu->createDirectory(); + m_newFileMenu->setViewShowsHiddenFiles(m_view->showHiddenFiles()); + m_newFileMenu->setPopupFiles(url()); + m_newFileMenu->createDirectory(); } void DolphinPart::setFilesToSelect(const KUrl::List& files) diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 5629b9c2d..dd5fe1e37 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -236,7 +236,7 @@ private: DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; DolphinPartBrowserExtension* m_extension; - KNewFileMenu* m_newMenu; + KNewFileMenu* m_newFileMenu; QString m_nameFilter; Q_DISABLE_COPY(DolphinPart) }; diff --git a/src/views/dolphinnewfilemenuobserver.cpp b/src/views/dolphinnewfilemenuobserver.cpp new file mode 100644 index 000000000..50a755b9a --- /dev/null +++ b/src/views/dolphinnewfilemenuobserver.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#include "dolphinnewfilemenuobserver.h" + +#include +#include + +class DolphinNewFileMenuObserverSingleton +{ +public: + DolphinNewFileMenuObserver instance; +}; +K_GLOBAL_STATIC(DolphinNewFileMenuObserverSingleton, s_DolphinNewFileMenuObserver) + +DolphinNewFileMenuObserver& DolphinNewFileMenuObserver::instance() +{ + return s_DolphinNewFileMenuObserver->instance; +} + +void DolphinNewFileMenuObserver::attach(const KNewFileMenu* menu) +{ + connect(menu, SIGNAL(fileCreated(const KUrl&)), + this, SIGNAL(itemCreated(const KUrl&))); + connect(menu, SIGNAL(directoryCreated(const KUrl&)), + this, SIGNAL(itemCreated(const KUrl&))); +} + +void DolphinNewFileMenuObserver::detach(const KNewFileMenu* menu) +{ + disconnect(menu, SIGNAL(fileCreated(const KUrl&)), + this, SIGNAL(itemCreated(const KUrl&))); + disconnect(menu, SIGNAL(directoryCreated(const KUrl&)), + this, SIGNAL(itemCreated(const KUrl&))); +} + +DolphinNewFileMenuObserver::DolphinNewFileMenuObserver() : + QObject(0) +{ +} + +DolphinNewFileMenuObserver::~DolphinNewFileMenuObserver() +{ +} + +#include "dolphinnewfilemenuobserver.moc" diff --git a/src/views/dolphinnewfilemenuobserver.h b/src/views/dolphinnewfilemenuobserver.h new file mode 100644 index 000000000..35fda11db --- /dev/null +++ b/src/views/dolphinnewfilemenuobserver.h @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2009 by Peter Penz * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef DOLPHINNEWFILEMENUOBSERVER_H +#define DOLPHINNEWFILEMENUOBSERVER_H + +#include + +#include "libdolphin_export.h" + +class KNewFileMenu; +class KUrl; + +/** + * @brief Allows to observe new file items that have been created + * by a DolphinNewFileMenu instance. + * + * As soon as a DolphinNewFileMenu instance created a new item, + * the observer will emit the signal itemCreated(). + */ +class LIBDOLPHINPRIVATE_EXPORT DolphinNewFileMenuObserver : public QObject +{ + Q_OBJECT + +public: + static DolphinNewFileMenuObserver& instance(); + void attach(const KNewFileMenu* menu); + void detach(const KNewFileMenu* menu); + +signals: + void itemCreated(const KUrl& url); + +private: + DolphinNewFileMenuObserver(); + virtual ~DolphinNewFileMenuObserver(); + + friend class DolphinNewFileMenuObserverSingleton; +}; + +#endif diff --git a/src/views/dolphinnewmenuobserver.cpp b/src/views/dolphinnewmenuobserver.cpp deleted file mode 100644 index def510c53..000000000 --- a/src/views/dolphinnewmenuobserver.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinnewmenuobserver.h" - -#include -#include - -class DolphinNewMenuObserverSingleton -{ -public: - DolphinNewMenuObserver instance; -}; -K_GLOBAL_STATIC(DolphinNewMenuObserverSingleton, s_dolphinNewMenuObserver) - -DolphinNewMenuObserver& DolphinNewMenuObserver::instance() -{ - return s_dolphinNewMenuObserver->instance; -} - -void DolphinNewMenuObserver::attach(const KNewFileMenu* menu) -{ - connect(menu, SIGNAL(fileCreated(const KUrl&)), - this, SIGNAL(itemCreated(const KUrl&))); - connect(menu, SIGNAL(directoryCreated(const KUrl&)), - this, SIGNAL(itemCreated(const KUrl&))); -} - -void DolphinNewMenuObserver::detach(const KNewFileMenu* menu) -{ - disconnect(menu, SIGNAL(fileCreated(const KUrl&)), - this, SIGNAL(itemCreated(const KUrl&))); - disconnect(menu, SIGNAL(directoryCreated(const KUrl&)), - this, SIGNAL(itemCreated(const KUrl&))); -} - -DolphinNewMenuObserver::DolphinNewMenuObserver() : - QObject(0) -{ -} - -DolphinNewMenuObserver::~DolphinNewMenuObserver() -{ -} - -#include "dolphinnewmenuobserver.moc" diff --git a/src/views/dolphinnewmenuobserver.h b/src/views/dolphinnewmenuobserver.h deleted file mode 100644 index dc9010a43..000000000 --- a/src/views/dolphinnewmenuobserver.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINNEWMENUOBSERVER_H -#define DOLPHINNEWMENUOBSERVER_H - -#include - -#include "libdolphin_export.h" - -class KNewFileMenu; -class KUrl; - -/** - * @brief Allows to observe new file items that have been created - * by a DolphinNewMenu instance. - * - * As soon as a DolphinNewMenu instance created a new item, - * the observer will emit the signal itemCreated(). - */ -class LIBDOLPHINPRIVATE_EXPORT DolphinNewMenuObserver : public QObject -{ - Q_OBJECT - -public: - static DolphinNewMenuObserver& instance(); - void attach(const KNewFileMenu* menu); - void detach(const KNewFileMenu* menu); - -signals: - void itemCreated(const KUrl& url); - -private: - DolphinNewMenuObserver(); - virtual ~DolphinNewMenuObserver(); - - friend class DolphinNewMenuObserverSingleton; -}; - -#endif diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 9d42aad0c..00751bf77 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -55,7 +55,7 @@ #include "dolphinviewcontroller.h" #include "dolphindetailsview.h" #include "dolphinfileitemdelegate.h" -#include "dolphinnewmenuobserver.h" +#include "dolphinnewfilemenuobserver.h" #include "dolphinsortfilterproxymodel.h" #include "dolphin_detailsmodesettings.h" #include "dolphiniconsview.h" @@ -149,7 +149,7 @@ DolphinView::DolphinView(QWidget* parent, // When a new item has been created by the "Create New..." menu, the item should // get selected and it must be assured that the item will get visible. As the // creation is done asynchronously, several signals must be checked: - connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)), + connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)), this, SLOT(observeCreatedItem(const KUrl&))); m_selectionChangedTimer = new QTimer(this); -- cgit v1.3