#include <kauthorized.h>
#include <knewmenu.h>
#include <kmenu.h>
+#include <kinputdialog.h>
#include "settings/dolphinsettings.h"
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
}
}
+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);
#include <kparts/part.h>
#include <kparts/browserextension.h>
+
+#include <QItemSelectionModel>
+
class KNewMenu;
class DolphinViewActionHandler;
class QActionGroup;
*/
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.
*/
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;
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="dolphinpart" version="9" >
+<kpartgui name="dolphinpart" version="10" >
<MenuBar>
<Menu name="edit"><text>&Edit</text>
<Action name="new_menu"/>
<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>&View</text>
<Menu name="sort">
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();
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();
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();
*/
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.
*/
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
*/
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
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..."));