#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"
m_toolTipManager(0),
m_rootUrl(),
m_currentItemUrl(),
+ m_createdItemUrl(),
+ m_selectedItems(),
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(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());
}
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();
}
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);
}
setSortOrder(order);
}
+void DolphinView::toggleSortFoldersFirst()
+{
+ setSortFoldersFirst(!sortFoldersFirst());
+}
+
void DolphinView::toggleAdditionalInfo(QAction* action)
{
const KFileItemDelegate::Information info =
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());
}
}
+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:
void DolphinView::restoreCurrentItem()
{
- 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_currentItemUrl.isEmpty()) {
+ 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();
+ }
}
+ m_currentItemUrl.clear();
}
}
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);
return m_dolphinModel->mimeData(selection.indexes());
}
+
#include "dolphinview.moc"