#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
+#include "dolphindetailsview.h"
#include "dolphinfileitemdelegate.h"
+#include "dolphinnewmenuobserver.h"
#include "dolphinsortfilterproxymodel.h"
-#include "dolphindetailsview.h"
#include "dolphin_detailsmodesettings.h"
#include "dolphiniconsview.h"
-#include "settings/dolphinsettings.h"
#include "dolphin_generalsettings.h"
#include "draganddrophelper.h"
#include "folderexpander.h"
#include "renamedialog.h"
+#include "revisioncontrolobserver.h"
#include "tooltips/tooltipmanager.h"
+#include "settings/dolphinsettings.h"
#include "viewproperties.h"
#include "zoomlevelinfo.h"
m_columnView(0),
m_fileItemDelegate(0),
m_selectionModel(0),
+ m_selectionChangedTimer(0),
m_dolphinModel(dolphinModel),
m_dirLister(dirLister),
m_proxyModel(proxyModel),
m_previewGenerator(0),
m_toolTipManager(0),
+ m_revisionControlObserver(0),
m_rootUrl(),
- m_currentItemUrl(),
+ m_activeItemUrl(),
+ m_createdItemUrl(),
+ m_selectedItems(),
+ m_newFileNames(),
m_expandedDragSource(0)
{
m_topLayout = new QVBoxLayout(this);
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(updateSortOrder(Qt::SortOrder)));
+ connect(m_controller, SIGNAL(sortFoldersFirstChanged(bool)),
+ this, SLOT(updateSortFoldersFirst(bool)));
connect(m_controller, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
this, SIGNAL(redirection(KUrl, KUrl)));
connect(m_dirLister, SIGNAL(completed()),
- this, SLOT(restoreCurrentItem()));
+ this, SLOT(slotDirListerCompleted()));
connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
this, SLOT(slotRefreshItems()));
+ // When a new item has been created by the "Create New..." menu, the item should
+ // get selected and it must be assured that the item will get visible. As the
+ // creation is done asynchronously, several signals must be checked:
+ connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
+ this, SLOT(observeCreatedItem(const KUrl&)));
+
applyViewProperties(url);
m_topLayout->addWidget(itemView());
}
QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
if (active) {
- // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
- // bypasses the problem when having a split view and changing the active view to
- // update the some URL dependent states. A nicer approach should be no big deal...
- emit urlChanged(url());
- emit selectionChanged(selectedItems());
+ emitSelectionChangedSignal();
} else {
color.setAlpha(150);
}
const QModelIndex currentIndex = selModel->currentIndex();
selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
QItemSelectionModel::Clear);
+ m_selectedItems.clear();
}
KFileItemList DolphinView::selectedItems() const
return m_columnView->selectedItems().count();
}
- return itemView()->selectionModel()->selection().count();
+ return itemView()->selectionModel()->selectedIndexes().count();
}
void DolphinView::setContentsPosition(int x, int y)
if (level != zoomLevel()) {
m_controller->setZoomLevel(level);
- m_previewGenerator->updatePreviews();
+ m_previewGenerator->updateIcons();
emit zoomLevelChanged(level);
}
}
return m_proxyModel->sortOrder();
}
+void DolphinView::setSortFoldersFirst(bool foldersFirst)
+{
+ if (sortFoldersFirst() != foldersFirst) {
+ updateSortFoldersFirst(foldersFirst);
+ }
+}
+
+bool DolphinView::sortFoldersFirst() const
+{
+ return m_proxyModel->sortFoldersFirst();
+}
+
void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
{
const KUrl viewPropsUrl = viewPropertiesUrl();
loadDirectory(url);
}
+ // When changing the URL there is no need to keep the revision
+ // data of the previous URL.
+ m_dolphinModel->clearRevisionData();
+
emit startedPathLoading(url);
}
return text;
}
+QList<QAction*> DolphinView::revisionControlActions(const KFileItemList& items) const
+{
+ return items.isEmpty()
+ ? m_revisionControlObserver->contextMenuActions(url().path(KUrl::AddTrailingSlash))
+ : m_revisionControlObserver->contextMenuActions(items);
+}
+
void DolphinView::setUrl(const KUrl& url)
{
- // remember current item candidate (see restoreCurrentItem())
- m_currentItemUrl = url;
+ m_newFileNames.clear();
updateView(url, KUrl());
}
}
const KUrl& baseUrl = url();
KUrl url;
- QItemSelection new_selection;
+ QItemSelection newSelection;
foreach(const KFileItem& item, selection) {
url = item.url().upUrl();
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
QModelIndex index = m_proxyModel->mapFromSource(m_dolphinModel->indexForItem(item));
- new_selection.select(index, index);
+ newSelection.select(index, index);
}
}
- itemView()->selectionModel()->select(new_selection,
+ itemView()->selectionModel()->select(newSelection,
QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Current);
}
if (itemCount > 1) {
// More than one item has been selected for renaming. Open
// a rename dialog and rename all items afterwards.
- RenameDialog dialog(this, items);
- if (dialog.exec() == QDialog::Rejected) {
+ QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+ if (dialog->exec() == QDialog::Rejected) {
+ delete dialog;
return;
}
- const QString newName = dialog.newName();
+ const QString newName = dialog->newName();
if (newName.isEmpty()) {
- emit errorMessage(dialog.errorString());
+ emit errorMessage(dialog->errorString());
+ delete dialog;
return;
}
+ delete dialog;
+
+ // the selection would be invalid after renaming the items, so just clear
+ // it before
+ clearSelection();
// TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
// as one operation instead of n rename operations like it is done now...
} else {
Q_ASSERT(itemCount == 1);
- RenameDialog dialog(this, items);
- if (dialog.exec() == QDialog::Rejected) {
+ QPointer<RenameDialog> dialog = new RenameDialog(this, items);
+ if (dialog->exec() == QDialog::Rejected) {
+ delete dialog;
return;
}
- const QString& newName = dialog.newName();
+ const QString newName = dialog->newName();
if (newName.isEmpty()) {
- emit errorMessage(dialog.errorString());
+ emit errorMessage(dialog->errorString());
+ delete dialog;
return;
}
+ delete dialog;
const KUrl& oldUrl = items.first().url();
KUrl newUrl = oldUrl;
setSortOrder(order);
}
+void DolphinView::toggleSortFoldersFirst()
+{
+ setSortFoldersFirst(!sortFoldersFirst());
+}
+
void DolphinView::toggleAdditionalInfo(QAction* action)
{
const KFileItemDelegate::Information info =
emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
}
+void DolphinView::emitDelayedSelectionChangedSignal()
+{
+ // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
+ // that fast selection changes don't result in expensive operations to
+ // collect all file items for the signal (see DolphinView::selectedItems()).
+ m_selectionChangedTimer->start();
+}
+
void DolphinView::emitSelectionChangedSignal()
{
emit selectionChanged(DolphinView::selectedItems());
const KUrl& destPath,
QDropEvent* event)
{
+ addNewFileNames(event->mimeData());
DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
emit sortOrderChanged(order);
}
+void DolphinView::updateSortFoldersFirst(bool foldersFirst)
+{
+ ViewProperties props(viewPropertiesUrl());
+ props.setSortFoldersFirst(foldersFirst);
+
+ m_proxyModel->setSortFoldersFirst(foldersFirst);
+
+ emit sortFoldersFirstChanged(foldersFirst);
+}
+
void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList& info)
{
ViewProperties props(viewPropertiesUrl());
return m_tabsForFiles;
}
+void DolphinView::activateItem(const KUrl& url)
+{
+ m_activeItemUrl = url;
+}
+
bool DolphinView::itemsExpandable() const
{
return (m_detailsView != 0) && m_detailsView->itemsExpandable();
}
}
+void DolphinView::observeCreatedItem(const KUrl& url)
+{
+ m_createdItemUrl = url;
+ connect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+ this, SLOT(selectAndScrollToCreatedItem()));
+}
+
+void DolphinView::selectAndScrollToCreatedItem()
+{
+ const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_createdItemUrl);
+ if (dirIndex.isValid()) {
+ const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ itemView()->setCurrentIndex(proxyIndex);
+ }
+
+ disconnect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+ this, SLOT(selectAndScrollToCreatedItem()));
+ m_createdItemUrl = KUrl();
+}
+
+void DolphinView::restoreSelection()
+{
+ disconnect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
+ changeSelection(m_selectedItems);
+}
+
void DolphinView::emitContentsMoved()
{
// only emit the contents moved signal if:
m_controller->setUrl(url);
}
-void DolphinView::restoreCurrentItem()
+void DolphinView::slotDirListerCompleted()
{
- const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
- if (dirIndex.isValid()) {
- const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
- QAbstractItemView* view = itemView();
- const bool clearSelection = !hasSelection();
- view->setCurrentIndex(proxyIndex);
- if (clearSelection) {
- view->clearSelection();
+ if (!m_activeItemUrl.isEmpty()) {
+ // assure that the current item remains visible
+ const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_activeItemUrl);
+ if (dirIndex.isValid()) {
+ const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ QAbstractItemView* view = itemView();
+ const bool clearSelection = !hasSelection();
+ view->setCurrentIndex(proxyIndex);
+ if (clearSelection) {
+ view->clearSelection();
+ }
+ m_activeItemUrl.clear();
}
}
+
+ if (!m_newFileNames.isEmpty()) {
+ // select all newly added items created by a paste operation or
+ // a drag & drop operation
+ const int rowCount = m_proxyModel->rowCount();
+ QItemSelection selection;
+ for (int row = 0; row < rowCount; ++row) {
+ const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
+ const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+ const KUrl url = m_dolphinModel->itemForIndex(dirIndex).url();
+ if (m_newFileNames.contains(url.fileName())) {
+ selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select);
+ }
+ }
+ itemView()->selectionModel()->select(selection, QItemSelectionModel::Select);
+
+ m_newFileNames.clear();
+ }
}
void DolphinView::slotRefreshItems()
m_loadingDirectory = true;
+ if (reload) {
+ m_selectedItems = selectedItems();
+ connect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreSelection()));
+ }
+
m_dirLister->stop();
m_dirLister->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
emit sortOrderChanged(sortOrder);
}
+ const bool sortFoldersFirst = props.sortFoldersFirst();
+ if (sortFoldersFirst != m_proxyModel->sortFoldersFirst()) {
+ m_proxyModel->setSortFoldersFirst(sortFoldersFirst);
+ emit sortFoldersFirstChanged(sortFoldersFirst);
+ }
+
KFileItemDelegate::InformationList info = props.additionalInfo();
if (info != m_fileItemDelegate->showInformation()) {
m_fileItemDelegate->setShowInformation(info);
m_selectionModel = view->selectionModel();
}
+ m_selectionChangedTimer = new QTimer(this);
+ m_selectionChangedTimer->setSingleShot(true);
+ m_selectionChangedTimer->setInterval(300);
+ connect(m_selectionChangedTimer, SIGNAL(timeout()),
+ this, SLOT(emitSelectionChangedSignal()));
+
// reparent the selection model, as it should not be deleted
// when deleting the model
m_selectionModel->setParent(this);
m_previewGenerator = new KFilePreviewGenerator(view);
m_previewGenerator->setPreviewShown(m_showPreview);
+ m_revisionControlObserver = new RevisionControlObserver(view);
+ connect(m_revisionControlObserver, SIGNAL(infoMessage(const QString&)),
+ this, SIGNAL(infoMessage(const QString&)));
+ connect(m_revisionControlObserver, SIGNAL(errorMessage(const QString&)),
+ this, SIGNAL(errorMessage(const QString&)));
+ connect(m_revisionControlObserver, SIGNAL(operationCompletedMessage(const QString&)),
+ this, SIGNAL(operationCompletedMessage(const QString&)));
+
if (DolphinSettings::instance().generalSettings()->showToolTips()) {
m_toolTipManager = new ToolTipManager(view, m_proxyModel);
connect(m_controller, SIGNAL(hideToolTip()),
m_topLayout->insertWidget(1, view);
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
- this, SLOT(emitSelectionChangedSignal()));
+ this, SLOT(emitDelayedSelectionChangedSignal()));
connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(emitContentsMoved()));
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
return m_iconsView;
}
-bool DolphinView::isCutItem(const KFileItem& item) const
-{
- const QMimeData* mimeData = QApplication::clipboard()->mimeData();
- const KUrl::List cutUrls = KUrl::List::fromMimeData(mimeData);
-
- const KUrl& itemUrl = item.url();
- KUrl::List::const_iterator it = cutUrls.begin();
- const KUrl::List::const_iterator end = cutUrls.end();
- while (it != end) {
- if (*it == itemUrl) {
- return true;
- }
- ++it;
- }
-
- return false;
-}
-
void DolphinView::pasteToUrl(const KUrl& url)
{
+ addNewFileNames(QApplication::clipboard()->mimeData());
KonqOperations::doPaste(this, url);
}
return m_dolphinModel->mimeData(selection.indexes());
}
+void DolphinView::addNewFileNames(const QMimeData* mimeData)
+{
+ const KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+ foreach (const KUrl& url, urls) {
+ m_newFileNames.insert(url.fileName());
+ }
+}
+
#include "dolphinview.moc"