{
openSelectionDialog(i18nc("@title:window", "Select"),
i18n("Select all items matching this pattern:"),
- QItemSelectionModel::Select);
+ true);
}
void DolphinPart::slotUnselectItemsMatchingPattern()
{
openSelectionDialog(i18nc("@title:window", "Unselect"),
i18n("Unselect all items matching this pattern:"),
- QItemSelectionModel::Deselect);
+ false);
}
-void DolphinPart::openSelectionDialog(const QString& title, const QString& text, QItemSelectionModel::SelectionFlags command)
+void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
{
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);
+ m_view->setItemSelectionEnabled(patternRegExp, selectItems);
}
}
-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);
return part()->view()->selectedItems();
break;
case KParts::FileInfoExtension::AllItems:
- return part()->view()->allItems();
+ return part()->view()->items();
default:
break;
}
QActionGroup* actionGroup);
void openSelectionDialog(const QString& title, const QString& text,
- QItemSelectionModel::SelectionFlags command);
-
- QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& patternRegExp);
+ bool selectItems);
private:
DolphinView* m_view;
return m_viewAccessor.supportsCategorizedSorting();
}
-bool DolphinView::hasSelection() const
+KFileItemList DolphinView::items() const
{
- const QAbstractItemView* view = m_viewAccessor.itemView();
- return (view != 0) && view->selectionModel()->hasSelection();
-}
-
-void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
-{
- foreach (const KUrl& url, urls) {
- KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
- m_selectedItems.append(item);
- }
+ return m_viewAccessor.dirLister()->items();
}
KFileItemList DolphinView::selectedItems() const
return view->selectionModel()->selectedIndexes().count();
}
-QItemSelectionModel* DolphinView::selectionModel() const
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
+{
+ foreach (const KUrl& url, urls) {
+ KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+ m_selectedItems.append(item);
+ }
+}
+
+void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
{
- return m_viewAccessor.itemView()->selectionModel();
+ const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern);
+ const QItemSelectionModel::SelectionFlags command = enabled
+ ? QItemSelectionModel::Select
+ : QItemSelectionModel::Deselect;
+ m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);
}
void DolphinView::setZoomLevel(int level)
stream << m_viewAccessor.expandedUrls();
}
+bool DolphinView::hasSelection() const
+{
+ const QAbstractItemView* view = m_viewAccessor.itemView();
+ return (view != 0) && view->selectionModel()->hasSelection();
+}
+
void DolphinView::observeCreatedItem(const KUrl& url)
{
m_createdItemUrl = url;
}
}
+QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const
+{
+ QItemSelection matchingIndexes;
+ const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
+ const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
+
+ const int rowCount = proxyModel->rowCount(parent);
+
+ for (int row = 0; row < rowCount; ++row) {
+ QModelIndex index = proxyModel->index(row, 0, parent);
+ QModelIndex sourceIndex = proxyModel->mapToSource(index);
+
+ if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
+ matchingIndexes += QItemSelectionRange(index);
+ }
+
+ if (proxyModel->hasChildren(index)) {
+ matchingIndexes += childrenMatchingPattern(index, pattern);
+ }
+ }
+
+ return matchingIndexes;
+}
+
DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) :
m_iconsView(0),
m_detailsView(0),
}
}
-KFileItemList DolphinView::allItems() const
-{
- return m_viewAccessor.dirLister()->items();
-}
-
#include "dolphinview.moc"
class DolphinColumnViewContainer;
class DolphinDetailsView;
+class DolphinDetailsViewExpander;
class DolphinIconsView;
class DolphinModel;
class DolphinSortFilterProxyModel;
class KUrl;
class ViewModeController;
class ViewProperties;
-class DolphinDetailsViewExpander;
+class QRegExp;
/**
* @short Represents a view for the directory content.
bool supportsCategorizedSorting() const;
/**
- * Marks the items indicated by \p urls to get selected after the
- * directory DolphinView::url() has been loaded. Note that nothing
- * gets selected if no loading of a directory has been triggered
- * by DolphinView::setUrl() or DolphinView::reload().
+ * Returns the items of the view.
*/
- void markUrlsAsSelected(const QList<KUrl>& urls);
+ KFileItemList items() const;
/**
* Returns the selected items. The list is empty if no item has been
*/
int selectedItemsCount() const;
- QItemSelectionModel* selectionModel() const;
+ /**
+ * Marks the items indicated by \p urls to get selected after the
+ * directory DolphinView::url() has been loaded. Note that nothing
+ * gets selected if no loading of a directory has been triggered
+ * by DolphinView::setUrl() or DolphinView::reload().
+ */
+ void markUrlsAsSelected(const QList<KUrl>& urls);
+
+ /**
+ * All items that match to the pattern \a pattern will get selected
+ * if \a enabled is true and deselected if \a enabled is false.
+ */
+ void setItemSelectionEnabled(const QRegExp& pattern, bool enabled);
/**
* Sets the zoom level to \a level. It is assured that the used
*/
void saveState(QDataStream& stream);
- /**
- * Returns all the items in the current view.
- */
- KFileItemList allItems() const;
+ /** Returns true, if at least one item is selected. */
+ bool hasSelection() const;
public slots:
/**
*/
void invertSelection();
- /** Returns true, if at least one item is selected. */
- bool hasSelection() const;
-
void clearSelection();
/**
*/
void addNewFileNames(const QMimeData* mimeData);
+ /**
+ * Helper method for DolphinView::setItemSelectionEnabled(): Returns the selection for
+ * all items of \p parent that match with the regular expression defined by \p pattern.
+ */
+ QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const;
+
private:
/**
* Abstracts the access to the different view implementations