┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2009-11-25 08:46:04 +0000
committerFrank Reininghaus <[email protected]>2009-11-25 08:46:04 +0000
commitab39a5952001cdb3d1b9ca693da7f8e246558fb8 (patch)
treea19f20c2fc6f478de371c694e9fdd98c4e201cee
parenta6a253667e20c551fba128cc68891f52470da524 (diff)
Restore the "Edit->Selection" menu from Konqueror 3 for file
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
-rw-r--r--src/dolphinpart.cpp68
-rw-r--r--src/dolphinpart.h20
-rw-r--r--src/dolphinpart.rc15
-rw-r--r--src/dolphinview.cpp71
-rw-r--r--src/dolphinview.h38
-rw-r--r--src/dolphinviewactionhandler.cpp2
6 files changed, 158 insertions, 56 deletions
diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp
index a7e03deeb..35cc81503 100644
--- a/src/dolphinpart.cpp
+++ b/src/dolphinpart.cpp
@@ -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);
diff --git a/src/dolphinpart.h b/src/dolphinpart.h
index ee6e38417..afbf387cc 100644
--- a/src/dolphinpart.h
+++ b/src/dolphinpart.h
@@ -22,6 +22,9 @@
#include <kparts/part.h>
#include <kparts/browserextension.h>
+
+#include <QItemSelectionModel>
+
class KNewMenu;
class DolphinViewActionHandler;
class QActionGroup;
@@ -176,6 +179,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.
*/
void slotOpenTerminal();
@@ -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;
diff --git a/src/dolphinpart.rc b/src/dolphinpart.rc
index d0b2cc634..7340c4dc1 100644
--- a/src/dolphinpart.rc
+++ b/src/dolphinpart.rc
@@ -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">
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index b805543fd..e057c950a 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -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();
diff --git a/src/dolphinview.h b/src/dolphinview.h
index 0d3b15098..97054b754 100644
--- a/src/dolphinview.h
+++ b/src/dolphinview.h
@@ -182,24 +182,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.
* @see DolphinView::selectedUrls()
@@ -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
@@ -382,6 +366,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
* will actually get selected. The view will e.g. not select items which
diff --git a/src/dolphinviewactionhandler.cpp b/src/dolphinviewactionhandler.cpp
index 5844fff81..cc89725c2 100644
--- a/src/dolphinviewactionhandler.cpp
+++ b/src/dolphinviewactionhandler.cpp
@@ -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..."));