***************************************************************************/
#include "dolphinviewactionhandler.h"
-#include <kdebug.h>
+#include "settings/viewpropertiesdialog.h"
#include "dolphinview.h"
-
+#include "zoomlevelinfo.h"
#include <konq_operations.h>
#include <kaction.h>
#include <kactioncollection.h>
#include <klocale.h>
+#include <knewmenu.h>
#include <ktoggleaction.h>
+#include <krun.h>
+#include <kpropertiesdialog.h>
+
DolphinViewActionHandler::DolphinViewActionHandler(KActionCollection* collection, QObject* parent)
: QObject(parent),
this, SLOT(slotShowPreviewChanged()));
connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(slotSortOrderChanged(Qt::SortOrder)));
+ connect(view, SIGNAL(sortFoldersFirstChanged(bool)),
+ this, SLOT(slotSortFoldersFirstChanged(bool)));
connect(view, SIGNAL(additionalInfoChanged()),
this, SLOT(slotAdditionalInfoChanged()));
connect(view, SIGNAL(categorizedSortingChanged()),
this, SLOT(slotShowHiddenFilesChanged()));
connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(slotSortingChanged(DolphinView::Sorting)));
+ connect(view, SIGNAL(zoomLevelChanged(int)),
+ this, SLOT(slotZoomLevelChanged(int)));
+}
+
+DolphinView* DolphinViewActionHandler::currentView()
+{
+ return m_currentView;
}
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->setText(i18nc("@action", "Create Folder..."));
newDirAction->setShortcut(Qt::Key_F10);
- connect(newDirAction, SIGNAL(triggered()), SLOT(slotCreateDir()));
+ newDirAction->setIcon(KIcon("folder-new"));
+ connect(newDirAction, SIGNAL(triggered()), this, SIGNAL(createDirectory()));
// Edit menu
KAction* rename = m_actionCollection->addAction("rename");
rename->setText(i18nc("@action:inmenu File", "Rename..."));
rename->setShortcut(Qt::Key_F2);
+ rename->setIcon(KIcon("edit-rename"));
connect(rename, SIGNAL(triggered()), this, SLOT(slotRename()));
KAction* moveToTrash = m_actionCollection->addAction("move_to_trash");
deleteAction->setShortcut(Qt::SHIFT | Qt::Key_Delete);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
+ // This action is useful for being enabled when "move_to_trash" should be
+ // disabled and "delete" is enabled (e.g. non-local files), so that Key_Del
+ // can be used for deleting the file (#76016). It needs to be a separate action
+ // so that the Edit menu isn't affected.
+ KAction* deleteWithTrashShortcut = m_actionCollection->addAction("delete_shortcut");
+ // The descriptive text is just for the shortcuts editor.
+ deleteWithTrashShortcut->setText(i18nc("@action:inmenu File", "Delete (using shortcut for Trash)"));
+ deleteWithTrashShortcut->setShortcut(QKeySequence::Delete);
+ deleteWithTrashShortcut->setEnabled(false);
+ connect(deleteWithTrashShortcut, SIGNAL(triggered()), this, SLOT(slotDeleteItems()));
+
+ KAction *propertiesAction = m_actionCollection->addAction( "properties" );
+ // Well, it's the File menu in dolphinmainwindow and the Edit menu in dolphinpart... :)
+ propertiesAction->setText( i18nc("@action:inmenu File", "Properties") );
+ propertiesAction->setIcon(KIcon("document-properties"));
+ propertiesAction->setShortcut(Qt::ALT | Qt::Key_Return);
+ connect(propertiesAction, SIGNAL(triggered()), SLOT(slotProperties()));
+
// View menu
QActionGroup* viewModeActions = new QActionGroup(this);
sortDescending->setText(i18nc("@action:inmenu Sort", "Descending"));
connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
+ KToggleAction* sortFoldersFirst = m_actionCollection->add<KToggleAction>("folders_first");
+ sortFoldersFirst->setText(i18nc("@action:inmenu Sort", "Folders First"));
+ connect(sortFoldersFirst, SIGNAL(triggered()), this, SLOT(toggleSortFoldersFirst()));
+
QActionGroup* sortByActionGroup = createSortByActionGroup();
connect(sortByActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSortTriggered(QAction*)));
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);
+ showHiddenFiles->setShortcuts(QList<QKeySequence>() << Qt::ALT + Qt::Key_Period << Qt::Key_F8);
connect(showHiddenFiles, SIGNAL(triggered(bool)), this, SLOT(toggleShowHiddenFiles(bool)));
+ KAction* adjustViewProps = m_actionCollection->addAction("view_properties");
+ adjustViewProps->setText(i18nc("@action:inmenu View", "Adjust View Properties..."));
+ connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(slotAdjustViewProperties()));
+
+ // Tools menu
+
+ KAction* findFile = m_actionCollection->addAction("find_file");
+ findFile->setText(i18nc("@action:inmenu Tools", "Find File..."));
+ findFile->setShortcut(Qt::CTRL | Qt::Key_F);
+ findFile->setIcon(KIcon("edit-find"));
+ connect(findFile, SIGNAL(triggered()), this, SLOT(slotFindFile()));
}
QActionGroup* DolphinViewActionHandler::createAdditionalInformationActionGroup()
return sortByActionGroup;
}
-void DolphinViewActionHandler::slotCreateDir()
-{
- Q_ASSERT(m_currentView);
- KonqOperations::newDir(m_currentView, m_currentView->url());
-}
-
void DolphinViewActionHandler::slotViewModeActionTriggered(QAction* action)
{
const DolphinView::Mode mode = action->data().value<DolphinView::Mode>();
return QString(); // can't happen
}
+KActionCollection* DolphinViewActionHandler::actionCollection()
+{
+ return m_actionCollection;
+}
+
void DolphinViewActionHandler::updateViewActions()
{
QAction* viewModeAction = m_actionCollection->action(currentViewModeActionName());
viewModeAction->setChecked(true);
}
- QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
- if (zoomInAction != 0) {
- zoomInAction->setEnabled(m_currentView->isZoomInPossible());
- }
-
- QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(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());
+ slotSortFoldersFirstChanged(m_currentView->sortFoldersFirst());
slotAdditionalInfoChanged();
slotCategorizedSortingChanged();
slotSortingChanged(m_currentView->sorting());
+ slotZoomLevelChanged(m_currentView->zoomLevel());
QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles());
void DolphinViewActionHandler::zoomIn()
{
- m_currentView->zoomIn();
+ const int level = m_currentView->zoomLevel();
+ m_currentView->setZoomLevel(level + 1);
updateViewActions();
}
void DolphinViewActionHandler::zoomOut()
{
- m_currentView->zoomOut();
+ const int level = m_currentView->zoomLevel();
+ m_currentView->setZoomLevel(level - 1);
updateViewActions();
}
m_currentView->toggleSortOrder();
}
+void DolphinViewActionHandler::toggleSortFoldersFirst()
+{
+ m_currentView->toggleSortFoldersFirst();
+}
+
void DolphinViewActionHandler::slotSortOrderChanged(Qt::SortOrder order)
{
QAction* descending = m_actionCollection->action("descending");
descending->setChecked(sortDescending);
}
+void DolphinViewActionHandler::slotSortFoldersFirstChanged(bool foldersFirst)
+{
+ m_actionCollection->action("folders_first")->setChecked(foldersFirst);
+}
+
void DolphinViewActionHandler::toggleAdditionalInfo(QAction* action)
{
emit actionBeingHandled();
}
}
+void DolphinViewActionHandler::slotZoomLevelChanged(int level)
+{
+ QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
+ if (zoomInAction != 0) {
+ zoomInAction->setEnabled(level < ZoomLevelInfo::maximumLevel());
+ }
+
+ QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut));
+ if (zoomOutAction != 0) {
+ zoomOutAction->setEnabled(level > ZoomLevelInfo::minimumLevel());
+ }
+}
+
void DolphinViewActionHandler::slotSortTriggered(QAction* action)
{
const DolphinView::Sorting sorting = action->data().value<DolphinView::Sorting>();
m_currentView->setSorting(sorting);
}
+
+void DolphinViewActionHandler::slotAdjustViewProperties()
+{
+ emit actionBeingHandled();
+ ViewPropertiesDialog dlg(m_currentView);
+ dlg.exec();
+}
+
+void DolphinViewActionHandler::slotFindFile()
+{
+ KRun::run("kfind %u", m_currentView->url(), m_currentView->window());
+}
+
+void DolphinViewActionHandler::slotProperties()
+{
+ KPropertiesDialog* dialog = 0;
+ const KFileItemList list = m_currentView->selectedItems();
+ if (list.isEmpty()) {
+ const KUrl url = m_currentView->url();
+ dialog = new KPropertiesDialog(url, m_currentView);
+ } else {
+ dialog = new KPropertiesDialog(list, m_currentView);
+ }
+
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->show();
+ dialog->raise();
+ dialog->activateWindow();
+}