┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-03-23 15:51:30 +0000
committerPeter Penz <[email protected]>2008-03-23 15:51:30 +0000
commit99419d3d74b1aa6667dfb5132d0122779ebdb5aa (patch)
treefd12495647face1bbe41e778b39e6ab069e919dd
parentacb61c69a6191bee82bb87f04153300ab0c86859 (diff)
allow to show hidden files in the Folders panel (treeview)
svn path=/trunk/KDE/kdebase/apps/; revision=789206
-rw-r--r--src/treeviewcontextmenu.cpp102
-rw-r--r--src/treeviewcontextmenu.h14
-rw-r--r--src/treeviewsidebarpage.cpp30
-rw-r--r--src/treeviewsidebarpage.h3
4 files changed, 97 insertions, 52 deletions
diff --git a/src/treeviewcontextmenu.cpp b/src/treeviewcontextmenu.cpp
index 40c5e9cd8..f15ac0c6e 100644
--- a/src/treeviewcontextmenu.cpp
+++ b/src/treeviewcontextmenu.cpp
@@ -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);
- 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();
}
- popup->addSeparator();
+ QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
+ showHiddenFilesAction->setCheckable(true);
+ showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles());
+ popup->addAction(showHiddenFilesAction);
- // 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"
diff --git a/src/treeviewcontextmenu.h b/src/treeviewcontextmenu.h
index a8dfac126..ec6170bf2 100644
--- a/src/treeviewcontextmenu.h
+++ b/src/treeviewcontextmenu.h
@@ -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;
};
diff --git a/src/treeviewsidebarpage.cpp b/src/treeviewsidebarpage.cpp
index d84b72ae2..c4a793cbd 100644
--- a/src/treeviewsidebarpage.cpp
+++ b/src/treeviewsidebarpage.cpp
@@ -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();
}
diff --git a/src/treeviewsidebarpage.h b/src/treeviewsidebarpage.h
index a389077a9..624b6dc53 100644
--- a/src/treeviewsidebarpage.h
+++ b/src/treeviewsidebarpage.h
@@ -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.