From f9aeb825c605ec4ca8b95aae0be1b441ca8ceb91 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 21 Jan 2008 16:12:25 +0000 Subject: merge -c764347 by Peter, needed for dolphinpart bugfixing svn path=/branches/KDE/4.0/kdebase/apps/; revision=764379 --- src/dolphinpart.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index d26f14061..235f176cd 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -70,7 +70,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi KUrl(), m_dirLister, m_dolphinModel, - m_proxyModel); + m_proxyModel, + actionCollection()); setWidget(m_view); setXMLFile("dolphinpart.rc"); @@ -144,14 +145,6 @@ void DolphinPart::createActions() propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return); connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties())); - // This action doesn't appear in the GUI, it's for the shortcut only. - // KNewMenu takes care of the GUI stuff. - KAction* newDirAction = actionCollection()->addAction( "create_dir" ); - newDirAction->setText( i18n("Create Folder..." ) ); - connect(newDirAction, SIGNAL(triggered()), SLOT(slotNewDir())); - newDirAction->setShortcut(Qt::Key_F10); - widget()->addAction(newDirAction); - // Go menu QActionGroup* goActionGroup = new QActionGroup(this); @@ -414,11 +407,6 @@ void DolphinPart::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers mod m_view->trashSelectedItems(); } -void DolphinPart::slotNewDir() -{ - KonqOperations::newDir(widget(), url()); -} - void DolphinPart::slotEditMimeType() { const KFileItemList items = m_view->selectedItems(); -- cgit v1.3 From c00478bbc1001d10dcfc04e9b0ea251620837e85 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 21 Jan 2008 19:08:52 +0000 Subject: Revert the moving of the action to the DolphinView instance, this doesn't work with splitted views. (Each view would need its own action collection, but then DolphinView would have to become a KXMLGUIClient, and the GUI would flicker when switching views). Instead, use the same solution as the other shared actions: static method in DolphinView (for now), slot in the mainwindow (and for the more complex actions than this one, shared code in DolphinView) svn path=/branches/KDE/4.0/kdebase/apps/; revision=764429 --- src/dolphinmainwindow.cpp | 10 ++++++++++ src/dolphinmainwindow.h | 6 ++++++ src/dolphinpart.cpp | 11 +++++++++-- src/dolphinpart.h | 6 ++++++ src/dolphinview.cpp | 32 +++++++++++++------------------- src/dolphinview.h | 16 +++++++--------- src/dolphinviewcontainer.cpp | 3 +-- 7 files changed, 52 insertions(+), 32 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 2048de1a5..1da9377c7 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -422,6 +423,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group) } } +void DolphinMainWindow::createDir() +{ + const KUrl& url = m_activeViewContainer->view()->url(); + KonqOperations::newDir(this, url); +} + void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); @@ -985,6 +992,9 @@ void DolphinMainWindow::setupActions() connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); + KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); + connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); + KAction* newWindow = actionCollection()->addAction("new_window"); newWindow->setIcon(KIcon("window-new")); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index f757520c3..e99add896 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -163,6 +163,12 @@ protected: virtual void readProperties(const KConfigGroup& group); private slots: + /** + * Opens the dialog for creating a directory. Is connected + * with the key shortcut for "new directory" (F10). + */ + void createDir(); + /** Updates the 'Create New...' sub menu. */ void updateNewMenu(); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 235f176cd..2c4c1eaa3 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -70,8 +70,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi KUrl(), m_dirLister, m_dolphinModel, - m_proxyModel, - actionCollection()); + m_proxyModel); setWidget(m_view); setXMLFile("dolphinpart.rc"); @@ -147,6 +146,9 @@ void DolphinPart::createActions() // Go menu + KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); + connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); + QActionGroup* goActionGroup = new QActionGroup(this); connect(goActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotGoTriggered(QAction*))); @@ -424,4 +426,9 @@ void DolphinPart::slotProperties() } } +void DolphinPart::createDir() +{ + KonqOperations::newDir(m_view, url()); +} + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 3e3c73f66..04161b6be 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -130,6 +130,12 @@ private Q_SLOTS: */ void slotProperties(); + /** + * Opens the dialog for creating a directory. Is connected + * with the key shortcut for "new directory" (F10). + */ + void createDir(); + private: void createActions(); void createGoAction(const char* name, const char* iconName, diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4a1fbb927..138971360 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -19,8 +19,6 @@ ***************************************************************************/ #include "dolphinview.h" -#include -#include #include #include @@ -30,6 +28,7 @@ #include #include +#include #include #include #include @@ -43,6 +42,7 @@ #include #include #include +#include #include #include "dolphindropcontroller.h" @@ -61,8 +61,7 @@ DolphinView::DolphinView(QWidget* parent, const KUrl& url, KDirLister* dirLister, DolphinModel* dolphinModel, - DolphinSortFilterProxyModel* proxyModel, - KActionCollection* actionCollection) : + DolphinSortFilterProxyModel* proxyModel) : QWidget(parent), m_active(true), m_showPreview(false), @@ -128,16 +127,6 @@ DolphinView::DolphinView(QWidget* parent, applyViewProperties(url); m_topLayout->addWidget(itemView()); - - Q_ASSERT(actionCollection != 0); - if (actionCollection->action("create_dir") == 0) { - // This action doesn't appear in the GUI, it's for the shortcut only. - // KNewMenu takes care of the GUI stuff. - KAction* newDirAction = actionCollection->addAction("create_dir"); - newDirAction->setText(i18n("Create Folder...")); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - newDirAction->setShortcut(Qt::Key_F10); - } } DolphinView::~DolphinView() @@ -1149,11 +1138,6 @@ void DolphinView::slotPreviewJobFinished(KJob* job) m_previewJob = 0; } -void DolphinView::createDir() -{ - KonqOperations::newDir(this, url()); -} - void DolphinView::cutSelectedItems() { QMimeData* mimeData = new QMimeData(); @@ -1263,4 +1247,14 @@ KAction* DolphinView::createDeleteAction(KActionCollection* collection) return deleteAction; } +KAction* DolphinView::createNewDirAction(KActionCollection* collection) +{ + // This action doesn't appear in the GUI, it's for the shortcut only. + // KNewMenu takes care of the GUI stuff. + KAction* newDirAction = collection->addAction("create_dir"); + newDirAction->setText(i18n("Create Folder...")); + newDirAction->setShortcut(Qt::Key_F10); + return newDirAction; +} + #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 485748751..8076a62f0 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -128,14 +128,12 @@ public: * @param proxyModel Used proxy model which specifies the sorting. The * model is not owned by the view and won't get * deleted. - * @param actionCollection Action collection which contains the menu actions. */ DolphinView(QWidget* parent, const KUrl& url, KDirLister* dirLister, DolphinModel* dolphinModel, - DolphinSortFilterProxyModel* proxyModel, - KActionCollection* actionCollection); + DolphinSortFilterProxyModel* proxyModel); virtual ~DolphinView(); @@ -364,6 +362,12 @@ public: */ static KAction* createDeleteAction(KActionCollection* collection); + /** + * Creates the "new directory" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createNewDirAction(KActionCollection* collection); + /** * Returns the action name corresponding to the current view mode */ @@ -618,12 +622,6 @@ private slots: */ void slotPreviewJobFinished(KJob* job); - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); - private: void loadDirectory(const KUrl& url, bool reload = false); diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index b9caa7b8e..a1846dc75 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -115,8 +115,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow, url, m_dirLister, m_dolphinModel, - m_proxyModel, - mainWindow->actionCollection()); + m_proxyModel); connect(m_view, SIGNAL(urlChanged(const KUrl&)), m_urlNavigator, SLOT(setUrl(const KUrl&))); connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)), -- cgit v1.3 From af333d9c7a8f344ed7f2a5cae02b383a5d0ee792 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 21 Jan 2008 19:42:16 +0000 Subject: Make sort/descending available in dolphinpart svn path=/branches/KDE/4.0/kdebase/apps/; revision=764444 --- src/dolphinmainwindow.cpp | 9 ++------- src/dolphinpart.cpp | 16 ++++++++++++++++ src/dolphinpart.h | 3 +++ src/dolphinview.cpp | 15 +++++++++++++++ src/dolphinview.h | 9 +++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 1da9377c7..407ec16b4 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -650,11 +650,7 @@ void DolphinMainWindow::sortByTags() void DolphinMainWindow::toggleSortOrder() { - DolphinView* view = m_activeViewContainer->view(); - const Qt::SortOrder order = (view->sortOrder() == Qt::AscendingOrder) ? - Qt::DescendingOrder : - Qt::AscendingOrder; - view->setSortOrder(order); + m_activeViewContainer->view()->toggleSortOrder(); } void DolphinMainWindow::toggleSortCategorization() @@ -1126,8 +1122,7 @@ void DolphinMainWindow::setupActions() //sortGroup->addAction(sortByRating); //sortGroup->addAction(sortByTags); - KToggleAction* sortDescending = actionCollection()->add("descending"); - sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); KToggleAction* showInGroups = actionCollection()->add("show_in_groups"); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 2c4c1eaa3..e7c919ad8 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -93,6 +93,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -144,6 +146,13 @@ void DolphinPart::createActions() propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return); connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties())); + // View menu + + // TODO sort_by_* + + KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); + connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder())); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -431,4 +440,11 @@ void DolphinPart::createDir() KonqOperations::newDir(m_view, url()); } +void DolphinPart::slotSortOrderChanged(Qt::SortOrder order) +{ + KToggleAction* descending = static_cast(actionCollection()->action("descending")); + const bool sortDescending = (order == Qt::DescendingOrder); + descending->setChecked(sortDescending); +} + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 04161b6be..883cf9456 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -136,6 +136,9 @@ private Q_SLOTS: */ void createDir(); + /** Updates the state of the 'Sort Ascending/Descending' action. */ + void slotSortOrderChanged(Qt::SortOrder); + private: void createActions(); void createGoAction(const char* name, const char* iconName, diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 138971360..cccbd36b9 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -794,6 +794,14 @@ void DolphinView::updateSortOrder(Qt::SortOrder order) emit sortOrderChanged(order); } +void DolphinView::toggleSortOrder() +{ + const Qt::SortOrder order = (sortOrder() == Qt::AscendingOrder) ? + Qt::DescendingOrder : + Qt::AscendingOrder; + setSortOrder(order); +} + void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info) { ViewProperties props(viewPropertiesUrl()); @@ -1257,4 +1265,11 @@ KAction* DolphinView::createNewDirAction(KActionCollection* collection) return newDirAction; } +KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) +{ + KToggleAction* sortDescending = collection->add("descending"); + sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + return sortDescending; +} + #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 8076a62f0..80430ca77 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -368,6 +368,12 @@ public: */ static KAction* createNewDirAction(KActionCollection* collection); + /** + * Creates the "sort descending" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createSortDescendingAction(KActionCollection* collection); + /** * Returns the action name corresponding to the current view mode */ @@ -423,6 +429,9 @@ public slots: /** Pastes the clipboard data to this view. */ void paste(); + /** Switches between an ascending and descending sorting order. */ + void toggleSortOrder(); + signals: /** * Is emitted if the view has been activated by e. g. a mouse click. -- cgit v1.3 From e6dcf5e8ffd8c4fe9a011aba92783d6ad1a7a63c Mon Sep 17 00:00:00 2001 From: David Faure Date: Tue, 22 Jan 2008 01:36:28 +0000 Subject: And finally: provide those "additional info" actions in the part too. svn path=/branches/KDE/4.0/kdebase/apps/; revision=764549 --- src/dolphinpart.cpp | 10 ++++++++++ src/dolphinpart.h | 3 +++ 2 files changed, 13 insertions(+) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index e7c919ad8..f144109cb 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -95,6 +95,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(updateViewActions())); connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(m_view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -153,6 +155,9 @@ void DolphinPart::createActions() KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder())); + QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); + connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -447,4 +452,9 @@ void DolphinPart::slotSortOrderChanged(Qt::SortOrder order) descending->setChecked(sortDescending); } +void DolphinPart::slotAdditionalInfoChanged() +{ + m_view->updateAdditionalInfoActions(actionCollection()); +} + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 883cf9456..3d9ec0306 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -139,6 +139,9 @@ private Q_SLOTS: /** Updates the state of the 'Sort Ascending/Descending' action. */ void slotSortOrderChanged(Qt::SortOrder); + /** Updates the state of the 'Additional Information' actions. */ + void slotAdditionalInfoChanged(); + private: void createActions(); void createGoAction(const char* name, const char* iconName, -- cgit v1.3 From cdc40d4398510878e5ff5926be3f87e6ac5108c9 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 28 Jan 2008 11:33:49 +0000 Subject: Centralize three more actions so that they are available in DolphinPart: 'Show preview' 'Show hidden files' 'Categorized sorting' Found a way of sharing the actions with even less code duplication, discussed it with Peter, but this will be for after 4.0.1 svn path=/branches/KDE/4.0/kdebase/apps/; revision=767566 --- src/dolphinmainwindow.cpp | 78 ++++++++++++++++------------------------------- src/dolphinmainwindow.h | 14 ++++----- src/dolphinpart.cpp | 38 ++++++++++++++++++++++- src/dolphinpart.h | 9 ++++++ src/dolphinview.cpp | 23 ++++++++++++++ src/dolphinview.h | 74 +++++++++++++++++++++++++++++--------------- 6 files changed, 150 insertions(+), 86 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 44a44efa2..2ed59279f 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -191,16 +191,14 @@ void DolphinMainWindow::slotShowPreviewChanged() void DolphinMainWindow::slotShowHiddenFilesChanged() { - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); const DolphinView* view = m_activeViewContainer->view(); showHiddenFilesAction->setChecked(view->showHiddenFiles()); } void DolphinMainWindow::slotCategorizedSortingChanged() { - KToggleAction* showInGroupsAction = - static_cast(actionCollection()->action("show_in_groups")); + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); const DolphinView* view = m_activeViewContainer->view(); showInGroupsAction->setChecked(view->categorizedSorting()); showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); @@ -244,14 +242,13 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) } if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } } void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) { - KToggleAction* descending = static_cast(actionCollection()->action("descending")); + QAction* descending = actionCollection()->action("descending"); const bool sortDescending = (order == Qt::DescendingOrder); descending->setChecked(sortDescending); } @@ -297,8 +294,7 @@ void DolphinMainWindow::slotHistoryChanged() void DolphinMainWindow::updateFilterBarAction(bool show) { - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(show); } @@ -605,11 +601,10 @@ void DolphinMainWindow::toggleSortOrder() m_activeViewContainer->view()->toggleSortOrder(); } -void DolphinMainWindow::toggleSortCategorization() +void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) { DolphinView* view = m_activeViewContainer->view(); - const bool categorizedSorting = view->categorizedSorting(); - view->setCategorizedSorting(!categorizedSorting); + view->setCategorizedSorting(categorizedSorting); } void DolphinMainWindow::toggleSplitView() @@ -657,31 +652,20 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::togglePreview() +void DolphinMainWindow::togglePreview(bool show) { clearStatusBar(); - - const KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); - const bool show = showPreviewAction->isChecked(); m_activeViewContainer->view()->setShowPreview(show); } -void DolphinMainWindow::toggleShowHiddenFiles() +void DolphinMainWindow::toggleShowHiddenFiles(bool show) { clearStatusBar(); - - const KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); - const bool show = showHiddenFilesAction->isChecked(); m_activeViewContainer->view()->setShowHiddenFiles(show); } -void DolphinMainWindow::toggleFilterBarVisibility() +void DolphinMainWindow::toggleFilterBarVisibility(bool show) { - const KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - const bool show = showFilterBarAction->isChecked(); m_activeViewContainer->showFilterBar(show); } @@ -701,11 +685,9 @@ void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); - KToggleAction* action = static_cast(actionCollection()->action("editable_location")); - - bool editOrBrowse = action->isChecked(); + QAction* action = actionCollection()->action("editable_location"); KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); - urlNavigator->setUrlEditable(editOrBrowse); + urlNavigator->setUrlEditable(action->isChecked()); } void DolphinMainWindow::editLocation() @@ -979,6 +961,8 @@ void DolphinMainWindow::setupActions() viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + // TODO use a QActionGroup + KToggleAction* sortByName = actionCollection()->add("sort_by_name"); sortByName->setText(i18nc("@action:inmenu Sort By", "Name")); connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); @@ -1047,22 +1031,17 @@ void DolphinMainWindow::setupActions() KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - KToggleAction* showInGroups = actionCollection()->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - connect(showInGroups, SIGNAL(triggered()), this, SLOT(toggleSortCategorization())); + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - KToggleAction* showPreview = actionCollection()->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview())); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - KToggleAction* showHiddenFiles = actionCollection()->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles())); + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); @@ -1117,7 +1096,7 @@ void DolphinMainWindow::setupActions() KToggleAction* showFilterBar = actionCollection()->add("show_filter_bar"); showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar")); showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(toggleFilterBarVisibility())); + connect(showFilterBar, SIGNAL(triggered(bool)), this, SLOT(toggleFilterBarVisibility(bool))); KAction* compareFiles = actionCollection()->addAction("compare_files"); compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files")); @@ -1278,8 +1257,7 @@ void DolphinMainWindow::updateViewActions() QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } slotSortingChanged(view->sorting()); @@ -1287,22 +1265,18 @@ void DolphinMainWindow::updateViewActions() slotCategorizedSortingChanged(); slotAdditionalInfoChanged(); - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); + QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - KToggleAction* showPreviewAction = - static_cast(actionCollection()->action("show_preview")); + QAction* showPreviewAction = actionCollection()->action("show_preview"); showPreviewAction->setChecked(view->showPreview()); - KToggleAction* showHiddenFilesAction = - static_cast(actionCollection()->action("show_hidden_files")); + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); showHiddenFilesAction->setChecked(view->showHiddenFiles()); updateSplitAction(); - KToggleAction* editableLocactionAction = - static_cast(actionCollection()->action("editable_location")); + QAction* editableLocactionAction = actionCollection()->action("editable_location"); const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); editableLocactionAction->setChecked(urlNavigator->isUrlEditable()); } diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 444a4a946..37cdcb43e 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -271,7 +271,7 @@ private slots: void toggleSortOrder(); /** Switches between sorting by categories or not. */ - void toggleSortCategorization(); + void toggleSortCategorization(bool); /** * Switches on or off the displaying of additional information @@ -293,19 +293,17 @@ private slots: void stopLoading(); /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(); + void togglePreview(bool); /** - * Switches between showing and hiding of hidden marked files dependent - * from the current state of the 'Show Hidden Files' menu toggle action. + * Switches between showing and hiding of hidden marked files */ - void toggleShowHiddenFiles(); + void toggleShowHiddenFiles(bool); /** - * Toggles between showing and hiding of the filter bar dependent - * from the current state of the 'Show Filter Bar' menu toggle action. + * Toggles between showing and hiding of the filter bar */ - void toggleFilterBarVisibility(); + void toggleFilterBarVisibility(bool show); /** Increases the size of the current set view mode. */ void zoomIn(); diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index f144109cb..4d2eebcc6 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -93,6 +93,13 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); + connect(m_view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(m_view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(m_view, SIGNAL(categorizedSortingChanged()), + this, SLOT(slotCategorizedSortingChanged())); + // TODO slotSortingChanged connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), this, SLOT(slotSortOrderChanged(Qt::SortOrder))); connect(m_view, SIGNAL(additionalInfoChanged()), @@ -110,7 +117,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi // [Q_PROPERTY introspection?] // TODO sort_by_* actions - // TODO show_*_info actions // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror // (sort of spacial navigation) @@ -158,6 +164,15 @@ void DolphinPart::createActions() QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); + KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); + connect(showPreview, SIGNAL(triggered(bool)), m_view, SLOT(setShowPreview(bool))); + + KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); + connect(showInGroups, SIGNAL(triggered(bool)), m_view, SLOT(setCategorizedSorting(bool))); + + KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); + connect(showHiddenFiles, SIGNAL(triggered(bool)), m_view, SLOT(setShowHiddenFiles(bool))); + // Go menu KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); @@ -457,4 +472,25 @@ void DolphinPart::slotAdditionalInfoChanged() m_view->updateAdditionalInfoActions(actionCollection()); } +void DolphinPart::slotShowPreviewChanged() +{ + updateViewActions(); // see DolphinMainWindow +} + +void DolphinPart::slotShowHiddenFilesChanged() +{ + QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_view->showHiddenFiles()); +} + +void DolphinPart::slotCategorizedSortingChanged() +{ + // Duplicated from DolphinMainWindow too. + QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); + showInGroupsAction->setChecked(m_view->categorizedSorting()); + showInGroupsAction->setEnabled(m_view->supportsCategorizedSorting()); +} + +// TODO a DolphinViewActionHandler for reducing the duplication in the action handling + #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 3d9ec0306..797c34d71 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -136,6 +136,15 @@ private Q_SLOTS: */ void createDir(); + /** Updates the state of the 'Show preview' menu action. */ + void slotShowPreviewChanged(); + + /** Updates the state of the 'Show hidden files' menu action. */ + void slotShowHiddenFilesChanged(); + + /** Updates the state of the 'Categorized sorting' menu action. */ + void slotCategorizedSortingChanged(); + /** Updates the state of the 'Sort Ascending/Descending' action. */ void slotSortOrderChanged(Qt::SortOrder); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4aeabb265..530508fb7 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -1344,6 +1344,29 @@ KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) return sortDescending; } +KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) +{ + KToggleAction* showPreview = collection->add("show_preview"); + showPreview->setText(i18nc("@action:intoolbar", "Preview")); + showPreview->setIcon(KIcon("view-preview")); + return showPreview; +} + +KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) +{ + KToggleAction* showInGroups = collection->add("show_in_groups"); + showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); + return showInGroups; +} + +KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) +{ + KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); + showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); + showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); + return showHiddenFiles; +} + QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) { QActionGroup* showInformationGroup = new QActionGroup(collection); diff --git a/src/dolphinview.h b/src/dolphinview.h index a85c184ef..0c0bbcd2e 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -166,39 +166,18 @@ public: * Changes the view mode for the current directory to \a mode. * If the view properties should be remembered for each directory * (GeneralSettings::globalViewProps() returns false), then the - * changed view mode will be be stored automatically. + * changed view mode will be stored automatically. */ void setMode(Mode mode); Mode mode() const; - /** - * Turns on the file preview for the all files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * preview setting will be be stored automatically. - */ - void setShowPreview(bool show); + /** See setShowPreview */ bool showPreview() const; - /** - * Shows all hidden files of the current directory, - * if \a show is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * show hidden file setting will be be stored automatically. - */ - void setShowHiddenFiles(bool show); + /** See setShowHiddenFiles */ bool showHiddenFiles() const; - /** - * Summarizes all sorted items by their category \a categorized - * is true. - * If the view properties should be remembered for each directory - * (GeneralSettings::globalViewProps() returns false), then the - * categorized sorting setting will be be stored automatically. - */ - void setCategorizedSorting(bool categorized); + /** See setCategorizedSorting */ bool categorizedSorting() const; /** @@ -381,6 +360,24 @@ public: */ static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); + /** + * Creates the "show preview" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowPreviewAction(KActionCollection* collection); + + /** + * Creates the "show in groups" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowInGroupsAction(KActionCollection* collection); + + /** + * Creates the "show hidden files" action. + * This code is here to share it between the mainwindow and the part + */ + static KAction* createShowHiddenFilesAction(KActionCollection* collection); + /** * Updates the state of the 'Additional Information' actions in \a collection. */ @@ -441,6 +438,33 @@ public slots: /** Pastes the clipboard data to this view. */ void paste(); + /** + * Turns on the file preview for the all files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * preview setting will be stored automatically. + */ + void setShowPreview(bool show); + + /** + * Shows all hidden files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * show hidden file setting will be stored automatically. + */ + void setShowHiddenFiles(bool show); + + /** + * Summarizes all sorted items by their category \a categorized + * is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * categorized sorting setting will be stored automatically. + */ + void setCategorizedSorting(bool categorized); + /** Switches between an ascending and descending sorting order. */ void toggleSortOrder(); -- cgit v1.3 From 45a1074b0a38f38cfebde8bb65d5a6520b2db3e8 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 11 Feb 2008 12:34:48 +0000 Subject: Factorize all the view-related action handling to DolphinViewActionHandler, to remove code duplication between mainwindow and part, and to remove my code-splitting with the static createFooAction methods in the view. svn path=/branches/KDE/4.0/kdebase/apps/; revision=773570 --- src/CMakeLists.txt | 1 + src/dolphinmainwindow.cpp | 200 +++------------------------ src/dolphinmainwindow.h | 63 +-------- src/dolphinpart.cpp | 103 ++------------ src/dolphinpart.h | 28 +--- src/dolphinview.cpp | 106 +-------------- src/dolphinview.h | 54 -------- src/dolphinviewactionhandler.cpp | 286 +++++++++++++++++++++++++++++++++++++++ src/dolphinviewactionhandler.h | 165 ++++++++++++++++++++++ 9 files changed, 488 insertions(+), 518 deletions(-) create mode 100644 src/dolphinviewactionhandler.cpp create mode 100644 src/dolphinviewactionhandler.h (limited to 'src/dolphinpart.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9902dc66..b2cdfd582 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ set(dolphinprivate_LIB_SRCS dolphinsortfilterproxymodel.cpp renamedialog.cpp dolphinview.cpp + dolphinviewactionhandler.cpp ratingpainter.cpp dolphindropcontroller.cpp ) diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 2ed59279f..c1d6cef39 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -20,6 +20,7 @@ ***************************************************************************/ #include "dolphinmainwindow.h" +#include "dolphinviewactionhandler.h" #include "dolphindropcontroller.h" #include @@ -60,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -182,28 +182,6 @@ void DolphinMainWindow::slotViewModeChanged() updateViewActions(); } -void DolphinMainWindow::slotShowPreviewChanged() -{ - // It is not enough to update the 'Show Preview' action, also - // the 'Zoom In' and 'Zoom Out' actions must be adapted. - updateViewActions(); -} - -void DolphinMainWindow::slotShowHiddenFilesChanged() -{ - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - const DolphinView* view = m_activeViewContainer->view(); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); -} - -void DolphinMainWindow::slotCategorizedSortingChanged() -{ - QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); - const DolphinView* view = m_activeViewContainer->view(); - showInGroupsAction->setChecked(view->categorizedSorting()); - showInGroupsAction->setEnabled(view->supportsCategorizedSorting()); -} - void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) { QAction* action = 0; @@ -246,19 +224,6 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) } } -void DolphinMainWindow::slotSortOrderChanged(Qt::SortOrder order) -{ - QAction* descending = actionCollection()->action("descending"); - const bool sortDescending = (order == Qt::DescendingOrder); - descending->setChecked(sortDescending); -} - -void DolphinMainWindow::slotAdditionalInfoChanged() -{ - DolphinView* view = m_activeViewContainer->view(); - view->updateAdditionalInfoActions(actionCollection()); -} - void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { updateEditActions(); @@ -371,43 +336,12 @@ void DolphinMainWindow::readProperties(const KConfigGroup& group) } } -void DolphinMainWindow::createDir() -{ - const KUrl& url = m_activeViewContainer->view()->url(); - KonqOperations::newDir(this, url); -} - void DolphinMainWindow::updateNewMenu() { m_newMenu->slotCheckUpToDate(); m_newMenu->setPopupFiles(activeViewContainer()->url()); } -void DolphinMainWindow::rename() -{ - clearStatusBar(); - m_activeViewContainer->view()->renameSelectedItems(); -} - -void DolphinMainWindow::moveToTrash() -{ - clearStatusBar(); - - DolphinView* view = m_activeViewContainer->view(); - - if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { - view->deleteSelectedItems(); - } else { - view->trashSelectedItems(); - } -} - -void DolphinMainWindow::deleteItems() -{ - clearStatusBar(); - m_activeViewContainer->view()->deleteSelectedItems(); -} - void DolphinMainWindow::properties() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); @@ -596,17 +530,6 @@ void DolphinMainWindow::sortByTags() #endif } -void DolphinMainWindow::toggleSortOrder() -{ - m_activeViewContainer->view()->toggleSortOrder(); -} - -void DolphinMainWindow::toggleSortCategorization(bool categorizedSorting) -{ - DolphinView* view = m_activeViewContainer->view(); - view->setCategorizedSorting(categorizedSorting); -} - void DolphinMainWindow::toggleSplitView() { if (m_viewContainer[SecondaryView] == 0) { @@ -639,7 +562,7 @@ void DolphinMainWindow::toggleSplitView() setActiveViewContainer(m_viewContainer[PrimaryView]); updateViewActions(); - emit activeViewChanged(); + emit activeViewChanged(); // TODO unused; remove? } void DolphinMainWindow::reloadView() @@ -652,35 +575,11 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::togglePreview(bool show) -{ - clearStatusBar(); - m_activeViewContainer->view()->setShowPreview(show); -} - -void DolphinMainWindow::toggleShowHiddenFiles(bool show) -{ - clearStatusBar(); - m_activeViewContainer->view()->setShowHiddenFiles(show); -} - void DolphinMainWindow::toggleFilterBarVisibility(bool show) { m_activeViewContainer->showFilterBar(show); } -void DolphinMainWindow::zoomIn() -{ - m_activeViewContainer->view()->zoomIn(); - updateViewActions(); -} - -void DolphinMainWindow::zoomOut() -{ - m_activeViewContainer->view()->zoomOut(); - updateViewActions(); -} - void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); @@ -820,6 +719,8 @@ void DolphinMainWindow::init() const KUrl& homeUrl = settings.generalSettings()->homeUrl(); setCaption(homeUrl.fileName()); + m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); + connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar())); ViewProperties props(homeUrl); m_viewContainer[PrimaryView] = new DolphinViewContainer(this, m_splitter, @@ -827,8 +728,10 @@ void DolphinMainWindow::init() m_activeViewContainer = m_viewContainer[PrimaryView]; connectViewSignals(PrimaryView); - m_viewContainer[PrimaryView]->view()->reload(); + DolphinView* view = m_viewContainer[PrimaryView]->view(); + view->reload(); m_viewContainer[PrimaryView]->show(); + m_actionHandler->setCurrentView(view); setCentralWidget(m_splitter); setupDockWidgets(); @@ -858,16 +761,16 @@ void DolphinMainWindow::init() emit urlChanged(homeUrl); } -void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* view) +void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) { - Q_ASSERT(view != 0); - Q_ASSERT((view == m_viewContainer[PrimaryView]) || (view == m_viewContainer[SecondaryView])); - if (m_activeViewContainer == view) { + Q_ASSERT(viewContainer != 0); + Q_ASSERT((viewContainer == m_viewContainer[PrimaryView]) || (viewContainer == m_viewContainer[SecondaryView])); + if (m_activeViewContainer == viewContainer) { return; } m_activeViewContainer->setActive(false); - m_activeViewContainer = view; + m_activeViewContainer = viewContainer; m_activeViewContainer->setActive(true); updateHistory(); @@ -878,7 +781,9 @@ void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* view) const KUrl& url = m_activeViewContainer->url(); setCaption(url.fileName()); - emit activeViewChanged(); + m_actionHandler->setCurrentView(viewContainer->view()); + + emit activeViewChanged(); // TODO unused; remove? emit urlChanged(url); } @@ -892,24 +797,12 @@ void DolphinMainWindow::setupActions() connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateNewMenu())); - KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - KAction* newWindow = actionCollection()->addAction("new_window"); newWindow->setIcon(KIcon("window-new")); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); newWindow->setShortcut(Qt::CTRL | Qt::Key_N); connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); - KAction* rename = DolphinView::createRenameAction(actionCollection()); - connect(rename, SIGNAL(triggered()), this, SLOT(rename())); - - KAction* moveToTrash = DolphinView::createMoveToTrashAction(actionCollection()); - connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); - - KAction* deleteAction = DolphinView::createDeleteAction(actionCollection()); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); - KAction* properties = actionCollection()->addAction("properties"); properties->setText(i18nc("@action:inmenu File", "Properties")); properties->setShortcut(Qt::ALT | Qt::Key_Return); @@ -942,14 +835,6 @@ void DolphinMainWindow::setupActions() connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); // setup 'View' menu - KStandardAction::zoomIn(this, - SLOT(zoomIn()), - actionCollection()); - - KStandardAction::zoomOut(this, - SLOT(zoomOut()), - actionCollection()); - KToggleAction* iconsView = DolphinView::iconsModeAction(actionCollection()); KToggleAction* detailsView = DolphinView::detailsModeAction(actionCollection()); @@ -961,6 +846,9 @@ void DolphinMainWindow::setupActions() viewModeGroup->addAction(columnView); connect(viewModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(setViewMode(QAction*))); + //QActionGroup* sortActionGroup = DolphinView::createSortActionGroup(actionCollection()); + //connect(sortActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(sortActionGroupTriggered(QAction*))); + // TODO use a QActionGroup KToggleAction* sortByName = actionCollection()->add("sort_by_name"); @@ -1028,21 +916,6 @@ void DolphinMainWindow::setupActions() //sortGroup->addAction(sortByRating); //sortGroup->addAction(sortByTags); - KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); - connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - - KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); - connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); - - QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); - connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); - - KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); - connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); - - KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); - connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); - KAction* split = actionCollection()->addAction("split_view"); split->setShortcut(Qt::Key_F3); updateSplitAction(); @@ -1244,36 +1117,19 @@ void DolphinMainWindow::updateEditActions() void DolphinMainWindow::updateViewActions() { - const DolphinView* view = m_activeViewContainer->view(); - QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn)); - if (zoomInAction != 0) { - zoomInAction->setEnabled(view->isZoomInPossible()); - } - - QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut)); - if (zoomOutAction != 0) { - zoomOutAction->setEnabled(view->isZoomOutPossible()); - } + m_actionHandler->updateViewActions(); + const DolphinView* view = m_activeViewContainer->view(); QAction* action = actionCollection()->action(view->currentViewModeActionName()); if (action != 0) { action->setChecked(true); } slotSortingChanged(view->sorting()); - slotSortOrderChanged(view->sortOrder()); - slotCategorizedSortingChanged(); - slotAdditionalInfoChanged(); QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); - QAction* showPreviewAction = actionCollection()->action("show_preview"); - showPreviewAction->setChecked(view->showPreview()); - - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - showHiddenFilesAction->setChecked(view->showHiddenFiles()); - updateSplitAction(); QAction* editableLocactionAction = actionCollection()->action("editable_location"); @@ -1302,18 +1158,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) DolphinView* view = container->view(); connect(view, SIGNAL(modeChanged()), this, SLOT(slotViewModeChanged())); - connect(view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), this, SLOT(slotSortingChanged(DolphinView::Sorting))); - connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); connect(view, SIGNAL(selectionChanged(KFileItemList)), this, SLOT(slotSelectionChanged(KFileItemList))); connect(view, SIGNAL(requestItemInfo(KFileItem)), @@ -1347,12 +1193,6 @@ void DolphinMainWindow::updateSplitAction() } } -void DolphinMainWindow::toggleAdditionalInfo(QAction* action) -{ - clearStatusBar(); - m_activeViewContainer->view()->toggleAdditionalInfo(action); -} - DolphinMainWindow::UndoUiInterface::UndoUiInterface(DolphinMainWindow* mainWin) : KonqFileUndoManager::UiInterface(mainWin), m_mainWin(mainWin) diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 37cdcb43e..b1694c323 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -34,6 +34,7 @@ #include +class DolphinViewActionHandler; class DolphinApplication; class DolphinViewContainer; class KNewMenu; @@ -163,27 +164,11 @@ protected: virtual void readProperties(const KConfigGroup& group); private slots: - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); + void clearStatusBar(); /** Updates the 'Create New...' sub menu. */ void updateNewMenu(); - /** - * Let the user input a name for the selected item(s) and trigger - * a renaming afterwards. - */ - void rename(); - - /** Moves the selected items of the active view to the trash. */ - void moveToTrash(); - - /** Deletes the selected items of the active view. */ - void deleteItems(); - /** * Opens the properties window for the selected items of the * active view. The properties windows shows information @@ -267,18 +252,6 @@ private slots: /** The sorting of the current view should be done by tags. */ void sortByTags(); - /** Switches between an ascending and descending sorting order. */ - void toggleSortOrder(); - - /** Switches between sorting by categories or not. */ - void toggleSortCategorization(bool); - - /** - * Switches on or off the displaying of additional information - * as specified by \a action. - */ - void toggleAdditionalInfo(QAction* action); - /** * Switches between one and two views: * If one view is visible, it will get split into two views. @@ -292,25 +265,11 @@ private slots: /** Stops the loading process for the current active view. */ void stopLoading(); - /** Switches between showing a preview of the file content and showing the icon. */ - void togglePreview(bool); - - /** - * Switches between showing and hiding of hidden marked files - */ - void toggleShowHiddenFiles(bool); - /** * Toggles between showing and hiding of the filter bar */ void toggleFilterBarVisibility(bool show); - /** Increases the size of the current set view mode. */ - void zoomIn(); - - /** Decreases the size of the current set view mode. */ - void zoomOut(); - /** * Toggles between edit and brose mode of the navigation bar. */ @@ -358,24 +317,9 @@ private slots: /** Updates the state of all 'View' menu actions. */ void slotViewModeChanged(); - /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); - /** Updates the state of the 'Sort by' actions. */ void slotSortingChanged(DolphinView::Sorting sorting); - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder order); - - /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); - /** * Updates the state of the 'Edit' menu actions and emits * the signal selectionChanged(). @@ -421,7 +365,6 @@ private: void updateEditActions(); void updateViewActions(); void updateGoActions(); - void clearStatusBar(); /** * Connects the signals from the created DolphinView with @@ -473,6 +416,8 @@ private: DolphinViewContainer* m_viewContainer[SecondaryView + 1]; + DolphinViewActionHandler* m_actionHandler; + /// remember pending undo operations until they are finished QList m_undoCommandTypes; }; diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 4d2eebcc6..b6f2698c3 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -18,14 +18,15 @@ */ #include "dolphinpart.h" -#include -#include +#include "dolphinviewactionhandler.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinmodel.h" #include +#include +#include #include #include #include @@ -93,17 +94,10 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi this, SLOT(slotUrlChanged(KUrl))); connect(m_view, SIGNAL(modeChanged()), this, SLOT(updateViewActions())); - connect(m_view, SIGNAL(showPreviewChanged()), - this, SLOT(slotShowPreviewChanged())); - connect(m_view, SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(m_view, SIGNAL(categorizedSortingChanged()), - this, SLOT(slotCategorizedSortingChanged())); // TODO slotSortingChanged - connect(m_view, SIGNAL(sortOrderChanged(Qt::SortOrder)), - this, SLOT(slotSortOrderChanged(Qt::SortOrder))); - connect(m_view, SIGNAL(additionalInfoChanged()), - this, SLOT(slotAdditionalInfoChanged())); + + m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); + m_actionHandler->setCurrentView(m_view); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -135,16 +129,6 @@ void DolphinPart::createActions() viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection())); connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); - KAction* renameAction = DolphinView::createRenameAction(actionCollection()); - connect(renameAction, SIGNAL(triggered()), m_view, SLOT(renameSelectedItems())); - - KAction* moveToTrashAction = DolphinView::createMoveToTrashAction(actionCollection()); - connect(moveToTrashAction, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), - this, SLOT(slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers))); - - KAction* deleteAction = DolphinView::createDeleteAction(actionCollection()); - connect(deleteAction, SIGNAL(triggered()), m_view, SLOT(deleteSelectedItems())); - KAction *editMimeTypeAction = actionCollection()->addAction( "editMimeType" ); editMimeTypeAction->setText( i18nc("@action:inmenu Edit", "&Edit File Type..." ) ); connect(editMimeTypeAction, SIGNAL(triggered()), SLOT(slotEditMimeType())); @@ -154,30 +138,10 @@ void DolphinPart::createActions() propertiesAction->setShortcut(Qt::ALT+Qt::Key_Return); connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties())); - // View menu - - // TODO sort_by_* - - KAction* sortDescending = DolphinView::createSortDescendingAction(actionCollection()); - connect(sortDescending, SIGNAL(triggered()), m_view, SLOT(toggleSortOrder())); - - QActionGroup* showInformationActionGroup = DolphinView::createAdditionalInformationActionGroup(actionCollection()); - connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), m_view, SLOT(toggleAdditionalInfo(QAction*))); - - KAction* showPreview = DolphinView::createShowPreviewAction(actionCollection()); - connect(showPreview, SIGNAL(triggered(bool)), m_view, SLOT(setShowPreview(bool))); - - KAction* showInGroups = DolphinView::createShowInGroupsAction(actionCollection()); - connect(showInGroups, SIGNAL(triggered(bool)), m_view, SLOT(setCategorizedSorting(bool))); - - KAction* showHiddenFiles = DolphinView::createShowHiddenFilesAction(actionCollection()); - connect(showHiddenFiles, SIGNAL(triggered(bool)), m_view, SLOT(setShowHiddenFiles(bool))); + // View menu: all done by DolphinViewActionHandler // Go menu - KAction* newDirAction = DolphinView::createNewDirAction(actionCollection()); - connect(newDirAction, SIGNAL(triggered()), SLOT(createDir())); - QActionGroup* goActionGroup = new QActionGroup(this); connect(goActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotGoTriggered(QAction*))); @@ -248,10 +212,10 @@ void DolphinPart::updatePasteAction() void DolphinPart::updateViewActions() { + m_actionHandler->updateViewActions(); QAction* action = actionCollection()->action(m_view->currentViewModeActionName()); if (action != 0) { - KToggleAction* toggleAction = static_cast(action); - toggleAction->setChecked(true); + action->setChecked(true); } } @@ -427,17 +391,6 @@ void DolphinPartBrowserExtension::paste() //// -void DolphinPart::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers) -{ - // Note: kde3's konq_mainwindow.cpp used to check - // reason == KAction::PopupMenuActivation && ... - // but this isn't supported anymore - if (modifiers & Qt::ShiftModifier) - m_view->deleteSelectedItems(); - else - m_view->trashSelectedItems(); -} - void DolphinPart::slotEditMimeType() { const KFileItemList items = m_view->selectedItems(); @@ -455,42 +408,4 @@ void DolphinPart::slotProperties() } } -void DolphinPart::createDir() -{ - KonqOperations::newDir(m_view, url()); -} - -void DolphinPart::slotSortOrderChanged(Qt::SortOrder order) -{ - KToggleAction* descending = static_cast(actionCollection()->action("descending")); - const bool sortDescending = (order == Qt::DescendingOrder); - descending->setChecked(sortDescending); -} - -void DolphinPart::slotAdditionalInfoChanged() -{ - m_view->updateAdditionalInfoActions(actionCollection()); -} - -void DolphinPart::slotShowPreviewChanged() -{ - updateViewActions(); // see DolphinMainWindow -} - -void DolphinPart::slotShowHiddenFilesChanged() -{ - QAction* showHiddenFilesAction = actionCollection()->action("show_hidden_files"); - showHiddenFilesAction->setChecked(m_view->showHiddenFiles()); -} - -void DolphinPart::slotCategorizedSortingChanged() -{ - // Duplicated from DolphinMainWindow too. - QAction* showInGroupsAction = actionCollection()->action("show_in_groups"); - showInGroupsAction->setChecked(m_view->categorizedSorting()); - showInGroupsAction->setEnabled(m_view->supportsCategorizedSorting()); -} - -// TODO a DolphinViewActionHandler for reducing the duplication in the action handling - #include "dolphinpart.moc" diff --git a/src/dolphinpart.h b/src/dolphinpart.h index 797c34d71..795a7b194 100644 --- a/src/dolphinpart.h +++ b/src/dolphinpart.h @@ -22,6 +22,7 @@ #include #include +class DolphinViewActionHandler; class QActionGroup; class KAction; class KFileItemList; @@ -110,11 +111,6 @@ private Q_SLOTS: */ void updatePasteAction(); - /** - * Connected to the "move_to_trash" action; adds "shift means del" handling. - */ - void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers); - /** * Connected to all "Go" menu actions provided by DolphinPart */ @@ -130,27 +126,6 @@ private Q_SLOTS: */ void slotProperties(); - /** - * Opens the dialog for creating a directory. Is connected - * with the key shortcut for "new directory" (F10). - */ - void createDir(); - - /** Updates the state of the 'Show preview' menu action. */ - void slotShowPreviewChanged(); - - /** Updates the state of the 'Show hidden files' menu action. */ - void slotShowHiddenFilesChanged(); - - /** Updates the state of the 'Categorized sorting' menu action. */ - void slotCategorizedSortingChanged(); - - /** Updates the state of the 'Sort Ascending/Descending' action. */ - void slotSortOrderChanged(Qt::SortOrder); - - /** Updates the state of the 'Additional Information' actions. */ - void slotAdditionalInfoChanged(); - private: void createActions(); void createGoAction(const char* name, const char* iconName, @@ -159,6 +134,7 @@ private: private: DolphinView* m_view; + DolphinViewActionHandler* m_actionHandler; KDirLister* m_dirLister; DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 530508fb7..7979b06c3 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -810,7 +810,7 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& m_fileItemDelegate->setShowInformation(info); - emit additionalInfoChanged(); // will call updateAdditionalInfoActions just below + emit additionalInfoChanged(); } void DolphinView::updateAdditionalInfoActions(KActionCollection* collection) @@ -1301,108 +1301,4 @@ QPair DolphinView::pasteInfo() const return ret; } -KAction* DolphinView::createRenameAction(KActionCollection* collection) -{ - KAction* rename = collection->addAction("rename"); - rename->setText(i18nc("@action:inmenu File", "Rename...")); - rename->setShortcut(Qt::Key_F2); - return rename; -} - -KAction* DolphinView::createMoveToTrashAction(KActionCollection* collection) -{ - KAction* moveToTrash = collection->addAction("move_to_trash"); - moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash")); - moveToTrash->setIcon(KIcon("user-trash")); - moveToTrash->setShortcut(QKeySequence::Delete); - return moveToTrash; -} - -KAction* DolphinView::createDeleteAction(KActionCollection* collection) -{ - KAction* deleteAction = collection->addAction("delete"); - deleteAction->setIcon(KIcon("edit-delete")); - deleteAction->setText(i18nc("@action:inmenu File", "Delete")); - deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete); - return deleteAction; -} - -KAction* DolphinView::createNewDirAction(KActionCollection* collection) -{ - // This action doesn't appear in the GUI, it's for the shortcut only. - // KNewMenu takes care of the GUI stuff. - KAction* newDirAction = collection->addAction("create_dir"); - newDirAction->setText(i18n("Create Folder...")); - newDirAction->setShortcut(Qt::Key_F10); - return newDirAction; -} - -KAction* DolphinView::createSortDescendingAction(KActionCollection* collection) -{ - KToggleAction* sortDescending = collection->add("descending"); - sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); - return sortDescending; -} - -KAction* DolphinView::createShowPreviewAction(KActionCollection* collection) -{ - KToggleAction* showPreview = collection->add("show_preview"); - showPreview->setText(i18nc("@action:intoolbar", "Preview")); - showPreview->setIcon(KIcon("view-preview")); - return showPreview; -} - -KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection) -{ - KToggleAction* showInGroups = collection->add("show_in_groups"); - showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); - return showInGroups; -} - -KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection) -{ - KToggleAction* showHiddenFiles = collection->add("show_hidden_files"); - showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); - showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); - return showHiddenFiles; -} - -QActionGroup* DolphinView::createAdditionalInformationActionGroup(KActionCollection* collection) -{ - QActionGroup* showInformationGroup = new QActionGroup(collection); - showInformationGroup->setExclusive(false); - - KToggleAction* showSizeInfo = collection->add("show_size_info"); - showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); - showSizeInfo->setData(KFileItemDelegate::Size); - showSizeInfo->setActionGroup(showInformationGroup); - - KToggleAction* showDateInfo = collection->add("show_date_info"); - showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); - showDateInfo->setData(KFileItemDelegate::ModificationTime); - showDateInfo->setActionGroup(showInformationGroup); - - KToggleAction* showPermissionsInfo = collection->add("show_permissions_info"); - showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); - showPermissionsInfo->setData(KFileItemDelegate::Permissions); - showPermissionsInfo->setActionGroup(showInformationGroup); - - KToggleAction* showOwnerInfo = collection->add("show_owner_info"); - showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); - showOwnerInfo->setData(KFileItemDelegate::Owner); - showOwnerInfo->setActionGroup(showInformationGroup); - - KToggleAction* showGroupInfo = collection->add("show_group_info"); - showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); - showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); - showGroupInfo->setActionGroup(showInformationGroup); - - KToggleAction* showMimeInfo = collection->add("show_mime_info"); - showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); - showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); - showMimeInfo->setActionGroup(showInformationGroup); - - return showInformationGroup; -} - #include "dolphinview.moc" diff --git a/src/dolphinview.h b/src/dolphinview.h index 0c0bbcd2e..6f0289f62 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -324,60 +324,6 @@ public: */ static KToggleAction* columnsModeAction(KActionCollection* collection); - /** - * Creates the rename action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createRenameAction(KActionCollection* collection); - - /** - * Creates the "move to trash" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createMoveToTrashAction(KActionCollection* collection); - - /** - * Creates the delete action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createDeleteAction(KActionCollection* collection); - - /** - * Creates the "new directory" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createNewDirAction(KActionCollection* collection); - - /** - * Creates the "sort descending" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createSortDescendingAction(KActionCollection* collection); - - /** - * Creates an action group with all the "show additional information" actions in it. - * This code is here to share it between the mainwindow and the part - */ - static QActionGroup* createAdditionalInformationActionGroup(KActionCollection* collection); - - /** - * Creates the "show preview" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowPreviewAction(KActionCollection* collection); - - /** - * Creates the "show in groups" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowInGroupsAction(KActionCollection* collection); - - /** - * Creates the "show hidden files" action. - * This code is here to share it between the mainwindow and the part - */ - static KAction* createShowHiddenFilesAction(KActionCollection* collection); - /** * Updates the state of the 'Additional Information' actions in \a collection. */ diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp new file mode 100644 index 000000000..6cd539d36 --- /dev/null +++ b/src/dolphinviewactionhandler.cpp @@ -0,0 +1,286 @@ +/*************************************************************************** + * Copyright (C) 2008 by David Faure * + * * + * 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 "dolphinviewactionhandler.h" + +#include "dolphinview.h" + +#include + +#include +#include +#include +#include + +DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent) + : QObject(parent), + m_actionCollection(collection), + m_currentView(0) +{ + Q_ASSERT(m_actionCollection); + createActions(); +} + +void DolphinViewActionHandler::setCurrentView(DolphinView* view) +{ + Q_ASSERT(view); + + if (m_currentView) + disconnect(m_currentView, 0, this, 0); + + m_currentView = view; + + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); + connect(view, SIGNAL(categorizedSortingChanged()), + this, SLOT(slotCategorizedSortingChanged())); + connect(view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); +} + +void DolphinViewActionHandler::createActions() +{ + // This action doesn't appear in the GUI, it's for the shortcut only. + // KNewMenu takes care of the GUI stuff. + KAction* newDirAction = m_actionCollection->addAction("create_dir"); + newDirAction->setText(i18n("Create Folder...")); + newDirAction->setShortcut(Qt::Key_F10); + connect(newDirAction, SIGNAL(triggered()), SLOT(slotCreateDir())); + + // Edit menu + + KAction* rename = m_actionCollection->addAction("rename"); + rename->setText(i18nc("@action:inmenu File", "Rename...")); + rename->setShortcut(Qt::Key_F2); + connect(rename, SIGNAL(triggered()), this, SLOT(slotRename())); + + KAction* moveToTrash = m_actionCollection->addAction("move_to_trash"); + moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash")); + moveToTrash->setIcon(KIcon("user-trash")); + moveToTrash->setShortcut(QKeySequence::Delete); + connect(moveToTrash, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)), + this, SLOT(slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers))); + + KAction* deleteAction = m_actionCollection->addAction("delete"); + deleteAction->setIcon(KIcon("edit-delete")); + deleteAction->setText(i18nc("@action:inmenu File", "Delete")); + deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete); + connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDeleteItems())); + + // View menu + + KStandardAction::zoomIn(this, + SLOT(zoomIn()), + m_actionCollection); + + KStandardAction::zoomOut(this, + SLOT(zoomOut()), + m_actionCollection); + + KToggleAction* showPreview = m_actionCollection->add("show_preview"); + showPreview->setText(i18nc("@action:intoolbar", "Preview")); + showPreview->setIcon(KIcon("view-preview")); + connect(showPreview, SIGNAL(triggered(bool)), this, SLOT(togglePreview(bool))); + + KToggleAction* sortDescending = m_actionCollection->add("descending"); + sortDescending->setText(i18nc("@action:inmenu Sort", "Descending")); + connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); + + QActionGroup* showInformationActionGroup = createAdditionalInformationActionGroup(); + connect(showInformationActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(toggleAdditionalInfo(QAction*))); + + KToggleAction* showInGroups = m_actionCollection->add("show_in_groups"); + showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups")); + connect(showInGroups, SIGNAL(triggered(bool)), this, SLOT(toggleSortCategorization(bool))); + + KToggleAction* showHiddenFiles = m_actionCollection->add("show_hidden_files"); + showHiddenFiles->setText(i18nc("@action:inmenu View", "Show Hidden Files")); + showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_Period); + connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool))); + +} + +QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup() +{ + QActionGroup* showInformationGroup = new QActionGroup(m_actionCollection); + showInformationGroup->setExclusive(false); + + KToggleAction* showSizeInfo = m_actionCollection->add("show_size_info"); + showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size")); + showSizeInfo->setData(KFileItemDelegate::Size); + showSizeInfo->setActionGroup(showInformationGroup); + + KToggleAction* showDateInfo = m_actionCollection->add("show_date_info"); + showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date")); + showDateInfo->setData(KFileItemDelegate::ModificationTime); + showDateInfo->setActionGroup(showInformationGroup); + + KToggleAction* showPermissionsInfo = m_actionCollection->add("show_permissions_info"); + showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions")); + showPermissionsInfo->setData(KFileItemDelegate::Permissions); + showPermissionsInfo->setActionGroup(showInformationGroup); + + KToggleAction* showOwnerInfo = m_actionCollection->add("show_owner_info"); + showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner")); + showOwnerInfo->setData(KFileItemDelegate::Owner); + showOwnerInfo->setActionGroup(showInformationGroup); + + KToggleAction* showGroupInfo = m_actionCollection->add("show_group_info"); + showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group")); + showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup); + showGroupInfo->setActionGroup(showInformationGroup); + + KToggleAction* showMimeInfo = m_actionCollection->add("show_mime_info"); + showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type")); + showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType); + showMimeInfo->setActionGroup(showInformationGroup); + + return showInformationGroup; +} + +void DolphinViewActionHandler::slotCreateDir() +{ + Q_ASSERT(m_currentView); + KonqOperations::newDir(m_currentView, m_currentView->url()); +} + +void DolphinViewActionHandler::slotRename() +{ + emit actionBeingHandled(); + m_currentView->renameSelectedItems(); +} + +void DolphinViewActionHandler::slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers modifiers) +{ + emit actionBeingHandled(); + // Note: kde3's konq_mainwindow.cpp used to check + // reason == KAction::PopupMenuActivation && ... + // but this isn't supported anymore + if (modifiers & Qt::ShiftModifier) + m_currentView->deleteSelectedItems(); + else + m_currentView->trashSelectedItems(); +} + +void DolphinViewActionHandler::slotDeleteItems() +{ + emit actionBeingHandled(); + m_currentView->deleteSelectedItems(); +} + +void DolphinViewActionHandler::togglePreview(bool show) +{ + emit actionBeingHandled(); + m_currentView->setShowPreview(show); +} + +void DolphinViewActionHandler::slotShowPreviewChanged() +{ + // It is not enough to update the 'Show Preview' action, also + // the 'Zoom In' and 'Zoom Out' actions must be adapted. + updateViewActions(); +} + +void DolphinViewActionHandler::updateViewActions() +{ + QAction* zoomInAction = m_actionCollection->action(KStandardAction::stdName(KStandardAction::ZoomIn)); + if (zoomInAction != 0) { + zoomInAction->setEnabled(m_currentView->isZoomInPossible()); + } + + QAction* zoomOutAction = m_actionCollection->action(KStandardAction::stdName(KStandardAction::ZoomOut)); + if (zoomOutAction != 0) { + zoomOutAction->setEnabled(m_currentView->isZoomOutPossible()); + } + + QAction* showPreviewAction = m_actionCollection->action("show_preview"); + showPreviewAction->setChecked(m_currentView->showPreview()); + + slotSortOrderChanged(m_currentView->sortOrder()); + slotAdditionalInfoChanged(); + slotCategorizedSortingChanged(); + + QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); + +} + +void DolphinViewActionHandler::zoomIn() +{ + m_currentView->zoomIn(); + updateViewActions(); +} + +void DolphinViewActionHandler::zoomOut() +{ + m_currentView->zoomOut(); + updateViewActions(); +} + +void DolphinViewActionHandler::toggleSortOrder() +{ + m_currentView->toggleSortOrder(); +} + +void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order) +{ + QAction* descending = m_actionCollection->action("descending"); + const bool sortDescending = (order == Qt::DescendingOrder); + descending->setChecked(sortDescending); +} + +void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action) +{ + emit actionBeingHandled(); + m_currentView->toggleAdditionalInfo(action); +} + +void DolphinViewActionHandler::slotAdditionalInfoChanged() +{ + m_currentView->updateAdditionalInfoActions(m_actionCollection); +} + +void DolphinViewActionHandler::toggleSortCategorization(bool categorizedSorting) +{ + m_currentView->setCategorizedSorting(categorizedSorting); +} + +void DolphinViewActionHandler::slotCategorizedSortingChanged() +{ + QAction* showInGroupsAction = m_actionCollection->action("show_in_groups"); + showInGroupsAction->setChecked(m_currentView->categorizedSorting()); + showInGroupsAction->setEnabled(m_currentView->supportsCategorizedSorting()); +} + +void DolphinViewActionHandler::toggleShowHiddenFiles(bool show) +{ + emit actionBeingHandled(); + m_currentView->setShowHiddenFiles(show); +} + +void DolphinViewActionHandler::slotShowHiddenFilesChanged() +{ + QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files"); + showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles()); +} + diff --git a/src/dolphinviewactionhandler.h b/src/dolphinviewactionhandler.h new file mode 100644 index 000000000..a11d19bb1 --- /dev/null +++ b/src/dolphinviewactionhandler.h @@ -0,0 +1,165 @@ +/*************************************************************************** + * Copyright (C) 2008 by David Faure * + * * + * 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 DOLPHINVIEWACTIONHANDLER_H +#define DOLPHINVIEWACTIONHANDLER_H + +#include "libdolphin_export.h" +#include +class QAction; +class QActionGroup; +class DolphinView; +class KActionCollection; + +/** + * @short Handles all actions for DolphinView + * + * The action handler owns all the actions and slots related to DolphinView, + * but can the view that is acts upon can be switched to another one + * (this is used in the case of split views). + * + * The purpose of this class is also to share this code between DolphinMainWindow + * and DolphinPart. + * + * @see DolphinView + * @see DolphinMainWindow + * @see DolphinPart + */ +class LIBDOLPHINPRIVATE_EXPORT DolphinViewActionHandler : public QObject +{ + Q_OBJECT + +public: + explicit DolphinViewActionHandler(KActionCollection* collection, QObject* parent); + + /** + * Sets the view that this action handler should work on. + */ + void setCurrentView(DolphinView* view); + + /** + * Update all actions in the 'View' menu, i.e. those that depend on the + * settings in the current view. + */ + void updateViewActions(); + +Q_SIGNALS: + /** + * Emitted by DolphinViewActionHandler when the user triggered an action. + * This is only used for clearining the statusbar in DolphinMainWindow. + */ + void actionBeingHandled(); + +private Q_SLOTS: + /** + * Opens the dialog for creating a directory. Is connected + * with the key shortcut for "new directory" (F10). + */ + void slotCreateDir(); + + /** + * Let the user input a name for the selected item(s) and trigger + * a renaming afterwards. + */ + void slotRename(); + + /** + * Moves the selected items of the active view to the trash. + * This methods adds "shift means del" handling. + */ + void slotTrashActivated(Qt::MouseButtons, Qt::KeyboardModifiers); + + /** + * Deletes the selected items of the active view. + */ + void slotDeleteItems(); + + /** + * Switches between showing a preview of the file content and showing the icon. + */ + void togglePreview(bool); + + /** Updates the state of the 'Show preview' menu action. */ + void slotShowPreviewChanged(); + + /** Increases the size of the current set view mode. */ + void zoomIn(); + + /** Decreases the size of the current set view mode. */ + void zoomOut(); + + /** Switches between an ascending and descending sorting order. */ + void toggleSortOrder(); + + /** + * Updates the state of the 'Sort Ascending/Descending' action. + */ + void slotSortOrderChanged(Qt::SortOrder order); + + /** + * Switches on or off the displaying of additional information + * as specified by \a action. + */ + void toggleAdditionalInfo(QAction* action); + + /** + * Updates the state of the 'Additional Information' actions. + */ + void slotAdditionalInfoChanged(); + + /** + * Switches between sorting by categories or not. + */ + void toggleSortCategorization(bool); + + /** + * Updates the state of the 'Categorized sorting' menu action. + */ + void slotCategorizedSortingChanged(); + + /** + * Switches between showing and hiding of hidden marked files + */ + void toggleShowHiddenFiles(bool); + + /** + * Updates the state of the 'Show hidden files' menu action. + */ + void slotShowHiddenFilesChanged(); + +private: + /** + * Create all the actions. + * This is called only once (by the constructor) + */ + void createActions(); + /** + * Creates an action group with all the "show additional information" actions in it. + * Helper method for createActions(); + */ + QActionGroup* createAdditionalInformationActionGroup(); + + KActionCollection* m_actionCollection; + DolphinView* m_currentView; +}; + + +#endif /* DOLPHINVIEWACTIONHANDLER_H */ + -- cgit v1.3