]> cloud.milkyroute.net Git - dolphin.git/commitdiff
allow to show hidden files in the Folders panel (treeview)
authorPeter Penz <peter.penz19@gmail.com>
Sun, 23 Mar 2008 15:51:30 +0000 (15:51 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 23 Mar 2008 15:51:30 +0000 (15:51 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=789206

src/treeviewcontextmenu.cpp
src/treeviewcontextmenu.h
src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h

index 40c5e9cd8f4fd8844685e3de72898314751650c0..f15ac0c6e1d51da4192fe4f1d604fc059dd91056 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "treeviewcontextmenu.h"
 
+#include "dolphin_folderspanelsettings.h"
+
 #include <kfileitem.h>
 #include <kiconloader.h>
 #include <kio/deletejob.h>
 #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()));
-
-    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()));
-
-    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 '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 (!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* 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();
+
+        // 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;
+        }
+
+        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"
index a8dfac1265f9b9d043483744c44044e9117795d7..ec6170bf2e1b5787477dc4ae0ede11c90cadc4c4 100644 (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;
 };
 
index d84b72ae24a66ce3e69e126e041d0639199dec2f..c4a793cbd90c54e0d300020354a713d89d2f0b79 100644 (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();
 }
index a389077a94e7da64ca8aeaf40321abe72201f128..624b6dc5395a80248eac90c289af2e417462c71b 100644 (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.