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
This commit is contained in:
David Faure 2008-02-11 12:34:48 +00:00
parent 99a10f551d
commit 45a1074b0a
9 changed files with 488 additions and 518 deletions

View file

@ -25,6 +25,7 @@ set(dolphinprivate_LIB_SRCS
dolphinsortfilterproxymodel.cpp
renamedialog.cpp
dolphinview.cpp
dolphinviewactionhandler.cpp
ratingpainter.cpp
dolphindropcontroller.cpp
)

View file

@ -20,6 +20,7 @@
***************************************************************************/
#include "dolphinmainwindow.h"
#include "dolphinviewactionhandler.h"
#include "dolphindropcontroller.h"
#include <config-nepomuk.h>
@ -60,7 +61,6 @@
#include <kmenubar.h>
#include <kmessagebox.h>
#include <konqmimedata.h>
#include <konq_operations.h>
#include <kpropertiesdialog.h>
#include <kprotocolinfo.h>
#include <ktoggleaction.h>
@ -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<KToggleAction>("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()
{
m_actionHandler->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());
}
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)

View file

@ -34,6 +34,7 @@
#include <QtCore/QList>
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<KonqFileUndoManager::CommandType> m_undoCommandTypes;
};

View file

@ -18,14 +18,15 @@
*/
#include "dolphinpart.h"
#include <kpropertiesdialog.h>
#include <kglobalsettings.h>
#include "dolphinviewactionhandler.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "dolphinmodel.h"
#include <konq_operations.h>
#include <kpropertiesdialog.h>
#include <kglobalsettings.h>
#include <kactioncollection.h>
#include <kdirlister.h>
#include <kiconloader.h>
@ -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<KToggleAction*>(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<KToggleAction*>(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"

View file

@ -22,6 +22,7 @@
#include <kparts/part.h>
#include <kparts/browserextension.h>
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;

View file

@ -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<bool, QString> 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<KToggleAction>("descending");
sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
return sortDescending;
}
KAction* DolphinView::createShowPreviewAction(KActionCollection* collection)
{
KToggleAction* showPreview = collection->add<KToggleAction>("show_preview");
showPreview->setText(i18nc("@action:intoolbar", "Preview"));
showPreview->setIcon(KIcon("view-preview"));
return showPreview;
}
KAction* DolphinView::createShowInGroupsAction(KActionCollection* collection)
{
KToggleAction* showInGroups = collection->add<KToggleAction>("show_in_groups");
showInGroups->setText(i18nc("@action:inmenu View", "Show in Groups"));
return showInGroups;
}
KAction* DolphinView::createShowHiddenFilesAction(KActionCollection* collection)
{
KToggleAction* showHiddenFiles = collection->add<KToggleAction>("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<KToggleAction>("show_size_info");
showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size"));
showSizeInfo->setData(KFileItemDelegate::Size);
showSizeInfo->setActionGroup(showInformationGroup);
KToggleAction* showDateInfo = collection->add<KToggleAction>("show_date_info");
showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date"));
showDateInfo->setData(KFileItemDelegate::ModificationTime);
showDateInfo->setActionGroup(showInformationGroup);
KToggleAction* showPermissionsInfo = collection->add<KToggleAction>("show_permissions_info");
showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions"));
showPermissionsInfo->setData(KFileItemDelegate::Permissions);
showPermissionsInfo->setActionGroup(showInformationGroup);
KToggleAction* showOwnerInfo = collection->add<KToggleAction>("show_owner_info");
showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner"));
showOwnerInfo->setData(KFileItemDelegate::Owner);
showOwnerInfo->setActionGroup(showInformationGroup);
KToggleAction* showGroupInfo = collection->add<KToggleAction>("show_group_info");
showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group"));
showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup);
showGroupInfo->setActionGroup(showInformationGroup);
KToggleAction* showMimeInfo = collection->add<KToggleAction>("show_mime_info");
showMimeInfo->setText(i18nc("@action:inmenu Additional information", "Type"));
showMimeInfo->setData(KFileItemDelegate::FriendlyMimeType);
showMimeInfo->setActionGroup(showInformationGroup);
return showInformationGroup;
}
#include "dolphinview.moc"

View file

@ -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.
*/

View file

@ -0,0 +1,286 @@
/***************************************************************************
* Copyright (C) 2008 by David Faure <faure@kde.org> *
* *
* 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 <konq_operations.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <klocale.h>
#include <ktoggleaction.h>
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<KToggleAction>("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<KToggleAction>("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<KToggleAction>("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<KToggleAction>("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<KToggleAction>("show_size_info");
showSizeInfo->setText(i18nc("@action:inmenu Additional information", "Size"));
showSizeInfo->setData(KFileItemDelegate::Size);
showSizeInfo->setActionGroup(showInformationGroup);
KToggleAction* showDateInfo = m_actionCollection->add<KToggleAction>("show_date_info");
showDateInfo->setText(i18nc("@action:inmenu Additional information", "Date"));
showDateInfo->setData(KFileItemDelegate::ModificationTime);
showDateInfo->setActionGroup(showInformationGroup);
KToggleAction* showPermissionsInfo = m_actionCollection->add<KToggleAction>("show_permissions_info");
showPermissionsInfo->setText(i18nc("@action:inmenu Additional information", "Permissions"));
showPermissionsInfo->setData(KFileItemDelegate::Permissions);
showPermissionsInfo->setActionGroup(showInformationGroup);
KToggleAction* showOwnerInfo = m_actionCollection->add<KToggleAction>("show_owner_info");
showOwnerInfo->setText(i18nc("@action:inmenu Additional information", "Owner"));
showOwnerInfo->setData(KFileItemDelegate::Owner);
showOwnerInfo->setActionGroup(showInformationGroup);
KToggleAction* showGroupInfo = m_actionCollection->add<KToggleAction>("show_group_info");
showGroupInfo->setText(i18nc("@action:inmenu Additional information", "Group"));
showGroupInfo->setData(KFileItemDelegate::OwnerAndGroup);
showGroupInfo->setActionGroup(showInformationGroup);
KToggleAction* showMimeInfo = m_actionCollection->add<KToggleAction>("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());
}

View file

@ -0,0 +1,165 @@
/***************************************************************************
* Copyright (C) 2008 by David Faure <faure@kde.org> *
* *
* 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 <QtCore/QObject>
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 */