]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Restore the "Edit->Selection" menu from Konqueror 3 for file
authorFrank Reininghaus <frank78ac@googlemail.com>
Wed, 25 Nov 2009 08:46:04 +0000 (08:46 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Wed, 25 Nov 2009 08:46:04 +0000 (08:46 +0000)
management. It includes the actions "Select All" and "Select Items
Matching a Pattern".

This feature will be in KDE 4.4.

FEATURE: 197536

svn path=/trunk/KDE/kdebase/apps/; revision=1053976

src/dolphinpart.cpp
src/dolphinpart.h
src/dolphinpart.rc
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewactionhandler.cpp

index a7e03deeb97166fed88fc1a5c2c9fdf1684c2b81..35cc81503b17110c577945071b6472a599392002 100644 (file)
@@ -44,6 +44,7 @@
 #include <kauthorized.h>
 #include <knewmenu.h>
 #include <kmenu.h>
+#include <kinputdialog.h>
 
 #include "settings/dolphinsettings.h"
 
@@ -164,6 +165,26 @@ void DolphinPart::createActions()
     editMimeTypeAction->setText( i18nc("@action:inmenu Edit", "&Edit File Type..." ) );
     connect(editMimeTypeAction, SIGNAL(triggered()), SLOT(slotEditMimeType()));
 
+    KAction* selectItemsMatching = actionCollection()->addAction("select_items_matching");
+    selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching..."));
+    selectItemsMatching->setShortcut(Qt::CTRL | Qt::Key_S);
+    connect(selectItemsMatching, SIGNAL(triggered()), this, SLOT(slotSelectItemsMatchingPattern()));
+
+    KAction* unselectItemsMatching = actionCollection()->addAction("unselect_items_matching");
+    unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching..."));
+    connect(unselectItemsMatching, SIGNAL(triggered()), this, SLOT(slotUnselectItemsMatchingPattern()));
+
+    actionCollection()->addAction(KStandardAction::SelectAll, "select_all", m_view, SLOT(selectAll()));
+
+    KAction* unselectAll = actionCollection()->addAction("unselect_all");
+    unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
+    connect(unselectAll, SIGNAL(triggered()), m_view, SLOT(clearSelection()));
+
+    KAction* invertSelection = actionCollection()->addAction("invert_selection");
+    invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
+    invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
+    connect(invertSelection, SIGNAL(triggered()), m_view, SLOT(invertSelection()));
+
     // View menu: all done by DolphinViewActionHandler
 
     // Go menu
@@ -493,6 +514,53 @@ void DolphinPart::slotEditMimeType()
     }
 }
 
+void DolphinPart::slotSelectItemsMatchingPattern()
+{
+    openSelectionDialog(i18nc("@title:window", "Select"),
+                        i18n("Select all items matching this pattern:"),
+                        QItemSelectionModel::Select);
+}
+
+void DolphinPart::slotUnselectItemsMatchingPattern()
+{
+    openSelectionDialog(i18nc("@title:window", "Unselect"),
+                        i18n("Unselect all items matching this pattern:"),
+                        QItemSelectionModel::Deselect);
+}
+
+void DolphinPart::openSelectionDialog(const QString& title, const QString& text, QItemSelectionModel::SelectionFlags command)
+{
+    bool okClicked;
+    QString pattern = KInputDialog::getText(title, text, "*", &okClicked, m_view);
+
+    if (okClicked && !pattern.isEmpty()) {
+        QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
+        QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), patternRegExp);
+        m_view->selectionModel()->select(matchingIndexes, command);
+    }
+}
+
+QItemSelection DolphinPart::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& patternRegExp)
+{
+    QItemSelection matchingIndexes;
+    int numRows = m_proxyModel->rowCount(parent);
+
+    for (int row = 0; row < numRows; row++) {
+        QModelIndex index = m_proxyModel->index(row, 0, parent);
+        QModelIndex sourceIndex = m_proxyModel->mapToSource(index);
+
+        if (sourceIndex.isValid() && patternRegExp.exactMatch(m_dolphinModel->data(sourceIndex).toString())) {
+            matchingIndexes += QItemSelectionRange(index);
+        }
+
+        if (m_proxyModel->hasChildren(index)) {
+            matchingIndexes += childrenMatchingPattern(index, patternRegExp);
+        }
+    }
+
+    return matchingIndexes;
+}
+
 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
 {
     QAction* action = actionCollection()->action(viewModeName);
index ee6e38417a55b65c9deb2e2e26360a4890c68dce..afbf387cc0933568620516268325b32d08254d3f 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <kparts/part.h>
 #include <kparts/browserextension.h>
+
+#include <QItemSelectionModel>
+
 class KNewMenu;
 class DolphinViewActionHandler;
 class QActionGroup;
@@ -175,6 +178,18 @@ private Q_SLOTS:
      */
     void slotEditMimeType();
 
+    /**
+     * Connected to the "select_items_matching" action.
+     * Opens a dialog which permits to select all items matching a pattern like "*.jpg".
+     */
+    void slotSelectItemsMatchingPattern();
+
+    /**
+     * Connected to the "unselect_items_matching" action.
+     * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg".
+     */
+    void slotUnselectItemsMatchingPattern();
+
     /**
      * Open a terminal window, starting with the current directory.
      */
@@ -205,6 +220,11 @@ private:
                         const QString& text, const QString& url,
                         QActionGroup* actionGroup);
 
+    void openSelectionDialog(const QString& title, const QString& text,
+                             QItemSelectionModel::SelectionFlags command);
+
+    QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& patternRegExp);
+
 private:
     DolphinView* m_view;
     DolphinViewActionHandler* m_actionHandler;
index d0b2cc634b9da37e82acc2e95df800a2c7f57837..7340c4dc17779bd8bb78a2bc064cbbc91819e5ce 100644 (file)
@@ -1,5 +1,5 @@
 <!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphinpart" version="9" >
+<kpartgui name="dolphinpart" version="10" >
  <MenuBar>
   <Menu name="edit"><text>&amp;Edit</text>
    <Action name="new_menu"/>
@@ -9,9 +9,16 @@
    <Action name="delete"/>
    <Action name="editMimeType"/>
    <Action name="properties"/>
-   <Separator />
-   <Action name="select_all" />
-   <Action name="invert_selection" />
+   <Separator/>
+   <Menu name="selection">
+    <text context="@title:menu">Selection</text>
+    <Action name="select_items_matching" />
+    <Action name="unselect_items_matching" />
+    <Separator/>
+    <Action name="select_all" />
+    <Action name="unselect_all" />
+    <Action name="invert_selection" />
+   </Menu>
   </Menu>
   <Menu name="view"><text>&amp;View</text>
    <Menu name="sort">
index b805543fded0dde982d1f0bcbfd8044a5d0c385c..e057c950acd6d83ce4ccd2347ceb38484e0d5b47 100644 (file)
@@ -285,45 +285,12 @@ bool DolphinView::supportsCategorizedSorting() const
     return m_viewAccessor.supportsCategorizedSorting();
 }
 
-void DolphinView::selectAll()
-{
-    QAbstractItemView* view = m_viewAccessor.itemView();
-    // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
-    // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
-    // selection instead of selecting all items. This is bypassed for KDE 4.0
-    // by invoking clearSelection() first.
-    view->clearSelection();
-    view->selectAll();
-}
-
-void DolphinView::invertSelection()
-{
-    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
-    const QAbstractItemModel* itemModel = selectionModel->model();
-
-    const QModelIndex topLeft = itemModel->index(0, 0);
-    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                     itemModel->columnCount() - 1);
-
-    const QItemSelection selection(topLeft, bottomRight);
-    selectionModel->select(selection, QItemSelectionModel::Toggle);
-}
-
 bool DolphinView::hasSelection() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
     return view && view->selectionModel()->hasSelection();
 }
 
-void DolphinView::clearSelection()
-{
-    QItemSelectionModel* selModel = m_viewAccessor.itemView()->selectionModel();
-    const QModelIndex currentIndex = selModel->currentIndex();
-    selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
-                                            QItemSelectionModel::Clear);
-    m_selectedItems.clear();
-}
-
 KFileItemList DolphinView::selectedItems() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
@@ -361,6 +328,11 @@ int DolphinView::selectedItemsCount() const
     return m_viewAccessor.itemView()->selectionModel()->selectedIndexes().count();
 }
 
+QItemSelectionModel* DolphinView::selectionModel() const
+{
+    return m_viewAccessor.itemView()->selectionModel();
+}
+
 void DolphinView::setContentsPosition(int x, int y)
 {
     QAbstractItemView* view = m_viewAccessor.itemView();
@@ -595,6 +567,39 @@ void DolphinView::setUrl(const KUrl& url)
     updateView(url, KUrl());
 }
 
+void DolphinView::selectAll()
+{
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
+    // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
+    // selection instead of selecting all items. This is bypassed for KDE 4.0
+    // by invoking clearSelection() first.
+    view->clearSelection();
+    view->selectAll();
+}
+
+void DolphinView::invertSelection()
+{
+    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
+    const QAbstractItemModel* itemModel = selectionModel->model();
+
+    const QModelIndex topLeft = itemModel->index(0, 0);
+    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                     itemModel->columnCount() - 1);
+
+    const QItemSelection selection(topLeft, bottomRight);
+    selectionModel->select(selection, QItemSelectionModel::Toggle);
+}
+
+void DolphinView::clearSelection()
+{
+    QItemSelectionModel* selModel = m_viewAccessor.itemView()->selectionModel();
+    const QModelIndex currentIndex = selModel->currentIndex();
+    selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
+                                            QItemSelectionModel::Clear);
+    m_selectedItems.clear();
+}
+
 void DolphinView::changeSelection(const KFileItemList& selection)
 {
     clearSelection();
index 0d3b1509818b1ffc0e96de2194b49c3d20c463ae..97054b7542c8f6fbde3965125d37d0dc078ec88b 100644 (file)
@@ -181,24 +181,6 @@ public:
      */
     bool supportsCategorizedSorting() const;
 
-    /**
-     * Selects all items.
-     * @see DolphinView::selectedItems()
-     */
-    void selectAll();
-
-    /**
-     * Inverts the current selection: selected items get unselected,
-     * unselected items get selected.
-     * @see DolphinView::selectedItems()
-     */
-    void invertSelection();
-
-    /** Returns true, if at least one item is selected. */
-    bool hasSelection() const;
-
-    void clearSelection();
-
     /**
      * Returns the selected items. The list is empty if no item has been
      * selected.
@@ -219,6 +201,8 @@ public:
      */
     int selectedItemsCount() const;
 
+    QItemSelectionModel* selectionModel() const;
+
     /**
      * Sets the upper left position of the view content
      * to (x,y). The content of the view might be larger than the visible area
@@ -381,6 +365,24 @@ public slots:
      */
     void setUrl(const KUrl& url);
 
+    /**
+     * Selects all items.
+     * @see DolphinView::selectedItems()
+     */
+    void selectAll();
+
+    /**
+     * Inverts the current selection: selected items get unselected,
+     * unselected items get selected.
+     * @see DolphinView::selectedItems()
+     */
+    void invertSelection();
+
+    /** Returns true, if at least one item is selected. */
+    bool hasSelection() const;
+
+    void clearSelection();
+
     /**
      * Request of a selection change. The view will do its best to accommodate
      * the request, but it is not guaranteed that all items in \a selection
index 5844fff8193912d4f91838b2495a0cab6c9af591..cc89725c257491f11a206989c2c082080b7c9a80 100644 (file)
@@ -87,7 +87,7 @@ void DolphinViewActionHandler::createActions()
     newDirAction->setIcon(KIcon("folder-new"));
     connect(newDirAction, SIGNAL(triggered()), this, SIGNAL(createDirectory()));
 
-    // Edit menu
+    // File menu
 
     KAction* rename = m_actionCollection->addAction("rename");
     rename->setText(i18nc("@action:inmenu File", "Rename..."));