X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/4bf7e5527c29e749d94b7b93b112fc2bb80138db..b8c2f5377772c618b2b032bcd67cd32045c97fc9:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 8b914de40..696caa04e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -52,17 +52,18 @@ #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 "tooltips/tooltipmanager.h" +#include "settings/dolphinsettings.h" #include "viewproperties.h" #include "zoomlevelinfo.h" @@ -104,6 +105,7 @@ DolphinView::DolphinView(QWidget* parent, m_toolTipManager(0), m_rootUrl(), m_currentItemUrl(), + m_createdItemUrl(), m_expandedDragSource(0) { m_topLayout = new QVBoxLayout(this); @@ -146,6 +148,12 @@ DolphinView::DolphinView(QWidget* parent, connect(m_dirLister, SIGNAL(refreshItems(const QList>&)), 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()); } @@ -600,15 +608,15 @@ void DolphinView::changeSelection(const KFileItemList& selection) } 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); } @@ -1081,6 +1089,26 @@ void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view) } } +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::emitContentsMoved() { // only emit the contents moved signal if: