allow to show hidden files in the Folders panel (treeview)

svn path=/trunk/KDE/kdebase/apps/; revision=789206
This commit is contained in:
Peter Penz 2008-03-23 15:51:30 +00:00
parent acb61c69a6
commit 99419d3d74
4 changed files with 98 additions and 53 deletions

View file

@ -20,6 +20,8 @@
#include "treeviewcontextmenu.h"
#include "dolphin_folderspanelsettings.h"
#include <kfileitem.h>
#include <kiconloader.h>
#include <kio/deletejob.h>
@ -30,12 +32,14 @@
#include <kpropertiesdialog.h>
#include "renamedialog.h"
#include "treeviewsidebarpage.h"
#include <QtGui/QApplication>
#include <QtGui/QClipboard>
TreeViewContextMenu::TreeViewContextMenu(QWidget* parent,
TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage* parent,
const KFileItem& fileInfo) :
QObject(parent),
m_parent(parent),
m_fileInfo(fileInfo)
{
@ -47,58 +51,67 @@ TreeViewContextMenu::~TreeViewContextMenu()
void TreeViewContextMenu::open()
{
Q_ASSERT(!m_fileInfo.isNull());
KMenu* popup = new KMenu(m_parent);
// insert 'Cut', 'Copy' and 'Paste'
QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
if (!m_fileInfo.isNull()) {
// insert 'Cut', 'Copy' and 'Paste'
QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this);
connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
pasteAction->setEnabled(!pasteData.isEmpty());
connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
pasteAction->setEnabled(!pasteData.isEmpty());
connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
popup->addAction(cutAction);
popup->addAction(copyAction);
popup->addAction(pasteAction);
popup->addSeparator();
popup->addAction(cutAction);
popup->addAction(copyAction);
popup->addAction(pasteAction);
popup->addSeparator();
// insert 'Rename'
QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this);
connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
popup->addAction(renameAction);
// insert 'Rename'
QAction* renameAction = new QAction(i18nc("@action:inmenu", "Rename..."), this);
connect(renameAction, SIGNAL(triggered()), this, SLOT(rename()));
popup->addAction(renameAction);
// insert 'Move to Trash' and (optionally) 'Delete'
KConfigGroup kdeConfig(KGlobal::config(), "KDE");
bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
const KUrl& url = m_fileInfo.url();
if (url.isLocalFile()) {
QAction* moveToTrashAction = new QAction(KIcon("user-trash"),
i18nc("@action:inmenu", "Move To Trash"), this);
connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
popup->addAction(moveToTrashAction);
} else {
showDeleteCommand = true;
// insert 'Move to Trash' and (optionally) 'Delete'
KConfigGroup kdeConfig(KGlobal::config(), "KDE");
bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
const KUrl& url = m_fileInfo.url();
if (url.isLocalFile()) {
QAction* moveToTrashAction = new QAction(KIcon("user-trash"),
i18nc("@action:inmenu", "Move To Trash"), this);
connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
popup->addAction(moveToTrashAction);
} else {
showDeleteCommand = true;
}
if (showDeleteCommand) {
QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
popup->addAction(deleteAction);
}
popup->addSeparator();
// insert 'Properties' entry
QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this);
connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties()));
popup->addAction(propertiesAction);
popup->addSeparator();
}
if (showDeleteCommand) {
QAction* deleteAction = new QAction(KIcon("edit-delete"), i18nc("@action:inmenu", "Delete"), this);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
popup->addAction(deleteAction);
}
QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
showHiddenFilesAction->setCheckable(true);
showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles());
popup->addAction(showHiddenFilesAction);
popup->addSeparator();
// insert 'Properties' entry
QAction* propertiesAction = new QAction(i18nc("@action:inmenu", "Properties"), this);
connect(propertiesAction, SIGNAL(triggered()), this, SLOT(showProperties()));
popup->addAction(propertiesAction);
connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
popup->exec(QCursor::pos());
popup->deleteLater();
@ -168,4 +181,9 @@ void TreeViewContextMenu::showProperties()
dialog.exec();
}
void TreeViewContextMenu::setShowHiddenFiles(bool show)
{
m_parent->setShowHiddenFiles(show);
}
#include "treeviewcontextmenu.moc"

View file

@ -23,6 +23,8 @@
#include <QtCore/QObject>
#include <KFileItem>
class TreeViewSidebarPage;
/**
* @brief Represents the context menu which appears when doing a right
* click on an item of the treeview.
@ -33,13 +35,13 @@ class TreeViewContextMenu : public QObject
public:
/**
* @parent Pointer to the parent widget the context menu
* @parent Pointer to the treeview sidebar page the context menu
* belongs to.
* @fileInfo Pointer to the file item the context menu
* is applied. If 0 is passed, the context menu
* is above the viewport.
*/
TreeViewContextMenu(QWidget* parent,
TreeViewContextMenu(TreeViewSidebarPage* parent,
const KFileItem& fileInfo);
virtual ~TreeViewContextMenu();
@ -69,8 +71,14 @@ private slots:
/** Shows the properties of the item m_fileInfo. */
void showProperties();
/**
* Sets the 'Show Hidden Files' setting for the
* folders panel to \a show.
*/
void setShowHiddenFiles(bool show);
private:
QWidget* m_parent;
TreeViewSidebarPage* m_parent;
KFileItem m_fileInfo;
};

View file

@ -23,6 +23,7 @@
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "dolphinsettings.h"
#include "dolphin_folderspanelsettings.h"
#include "sidebartreeview.h"
#include "treeviewcontextmenu.h"
@ -51,6 +52,8 @@ TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) :
TreeViewSidebarPage::~TreeViewSidebarPage()
{
FoldersPanelSettings::self()->writeConfig();
delete m_proxyModel;
m_proxyModel = 0;
delete m_dolphinModel;
@ -63,6 +66,20 @@ QSize TreeViewSidebarPage::sizeHint() const
return QSize(200, 400);
}
void TreeViewSidebarPage::setShowHiddenFiles(bool show)
{
FoldersPanelSettings::setShowHiddenFiles(show);
if (m_dirLister != 0) {
m_dirLister->setShowingDotFiles(show);
m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload);
}
}
bool TreeViewSidebarPage::showHiddenFiles() const
{
return FoldersPanelSettings::showHiddenFiles();
}
void TreeViewSidebarPage::setUrl(const KUrl& url)
{
if (!url.isValid() || (url == SidebarPage::url())) {
@ -93,6 +110,7 @@ void TreeViewSidebarPage::showEvent(QShowEvent* event)
m_dirLister->setMainWindow(window());
m_dirLister->setDelayedMimeTypes(true);
m_dirLister->setAutoErrorHandlingEnabled(false, this);
m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles());
connect(m_dirLister, SIGNAL(completed()),
this, SLOT(triggerLoadSubTree()));
@ -132,16 +150,14 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
{
SidebarPage::contextMenuEvent(event);
KFileItem item;
const QModelIndex index = m_treeView->indexAt(event->pos());
if (!index.isValid()) {
// only open a context menu above a directory item
return;
if (index.isValid()) {
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
emit changeSelection(KFileItemList());
}
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
KFileItem item = m_dolphinModel->itemForIndex(dolphinModelIndex);
emit changeSelection(KFileItemList());
TreeViewContextMenu contextMenu(this, item);
contextMenu.open();
}

View file

@ -48,6 +48,9 @@ public:
/** @see QWidget::sizeHint() */
virtual QSize sizeHint() const;
void setShowHiddenFiles(bool show);
bool showHiddenFiles() const;
public slots:
/**
* Changes the current selection inside the tree to \a url.