const int oldZoomLevel = m_controller->zoomLevel();
m_mode = mode;
+ // remember the currently selected items, so that they will
+ // be restored after reloading the directory
+ m_selectedItems = selectedItems();
+
deleteView();
const KUrl viewPropsUrl = rootUrl();
emit modeChanged();
updateZoomLevel(oldZoomLevel);
- if (m_showPreview) {
- loadDirectory(viewPropsUrl);
- }
+ loadDirectory(viewPropsUrl);
}
DolphinView::Mode DolphinView::mode() const
return view && 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);
+ }
+}
+
KFileItemList DolphinView::selectedItems() const
{
const QAbstractItemView* view = m_viewAccessor.itemView();
void DolphinView::reload()
{
+ QByteArray viewState;
+ QDataStream saveStream(&viewState, QIODevice::WriteOnly);
+ saveState(saveStream);
+ m_selectedItems= selectedItems();
+
setUrl(url());
loadDirectory(url(), true);
+
+ QDataStream restoreStream(viewState);
+ restoreState(restoreStream);
}
void DolphinView::refresh()
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();
+ m_viewAccessor.itemView()->selectAll();
}
void DolphinView::invertSelection()
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();
- if (selection.isEmpty()) {
- return;
- }
- const KUrl& baseUrl = url();
- KUrl url;
- QItemSelection newSelection;
- foreach(const KFileItem& item, selection) {
- url = item.url().upUrl();
- if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
- QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
- newSelection.select(index, index);
- }
- }
- m_viewAccessor.itemView()->selectionModel()->select(newSelection,
- QItemSelectionModel::ClearAndSelect
- | QItemSelectionModel::Current);
+ m_viewAccessor.itemView()->clearSelection();
}
void DolphinView::renameSelectedItems()
m_createdItemUrl = KUrl();
}
-void DolphinView::restoreSelection()
-{
- disconnect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
- changeSelection(m_selectedItems);
-}
-
void DolphinView::emitContentsMoved()
{
// TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
}
}
+ if (!m_selectedItems.isEmpty()) {
+ const KUrl& baseUrl = url();
+ KUrl url;
+ QItemSelection newSelection;
+ foreach(const KFileItem& item, m_selectedItems) {
+ url = item.url().upUrl();
+ if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
+ QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+ newSelection.select(index, index);
+ }
+ }
+ m_viewAccessor.itemView()->selectionModel()->select(newSelection,
+ QItemSelectionModel::ClearAndSelect
+ | QItemSelectionModel::Current);
+ m_selectedItems.clear();
+ }
+
// Restore the contents position. This has to be done using a Qt::QueuedConnection
// because the view might not be in its final state yet.
QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection);
m_loadingDirectory = true;
m_expanderActive = false;
- if (reload) {
- m_selectedItems = selectedItems();
- connect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
- }
-
m_viewAccessor.dirLister()->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
}