#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_tabsForFiles(false),
m_isContextMenuOpen(false),
m_ignoreViewProperties(false),
+ m_assureVisibleCurrentIndex(false),
m_mode(DolphinView::IconsView),
m_topLayout(0),
m_controller(0),
m_toolTipManager(0),
m_rootUrl(),
m_currentItemUrl(),
+ m_createdItemUrl(),
+ m_selectedItems(),
m_expandedDragSource(0)
{
m_topLayout = new QVBoxLayout(this);
this, SIGNAL(redirection(KUrl, KUrl)));
connect(m_dirLister, SIGNAL(completed()),
this, SLOT(restoreCurrentItem()));
+ 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);
}
}
}
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);
}
const QString newName = dialog.newName();
if (newName.isEmpty()) {
emit errorMessage(dialog.errorString());
- } else {
- // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
- // as one operation instead of n rename operations like it is done now...
- Q_ASSERT(newName.contains('#'));
-
- // currently the items are sorted by the selection order, resort
- // them by the file name
- qSort(items.begin(), items.end(), lessThan);
-
- // iterate through all selected items and rename them...
- int index = 1;
- foreach (const KFileItem& item, items) {
- const KUrl& oldUrl = item.url();
- QString number;
- number.setNum(index++);
-
- QString name = newName;
- name.replace('#', number);
-
- if (oldUrl.fileName() != name) {
- KUrl newUrl = oldUrl;
- newUrl.setFileName(name);
- KonqOperations::rename(this, oldUrl, newUrl);
- }
+ return;
+ }
+
+ // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
+ // as one operation instead of n rename operations like it is done now...
+ Q_ASSERT(newName.contains('#'));
+
+ // currently the items are sorted by the selection order, resort
+ // them by the file name
+ qSort(items.begin(), items.end(), lessThan);
+
+ // iterate through all selected items and rename them...
+ int index = 1;
+ foreach (const KFileItem& item, items) {
+ const KUrl& oldUrl = item.url();
+ QString number;
+ number.setNum(index++);
+
+ QString name = newName;
+ name.replace('#', number);
+
+ if (oldUrl.fileName() != name) {
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(name);
+ KonqOperations::rename(this, oldUrl, newUrl);
}
}
} else if (DolphinSettings::instance().generalSettings()->renameInline()) {
const QString& newName = dialog.newName();
if (newName.isEmpty()) {
emit errorMessage(dialog.errorString());
- } else {
- const KUrl& oldUrl = items.first().url();
- KUrl newUrl = oldUrl;
- newUrl.setFileName(newName);
- KonqOperations::rename(this, oldUrl, newUrl);
+ return;
}
+
+ const KUrl& oldUrl = items.first().url();
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(newName);
+ KonqOperations::rename(this, oldUrl, newUrl);
}
+
+ // assure that the current index remains visible when KDirLister
+ // will notify the view about changed items
+ m_assureVisibleCurrentIndex = true;
}
void DolphinView::trashSelectedItems()
QPair<bool, QString> DolphinView::pasteInfo() const
{
- QPair<bool, QString> ret;
- QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
-
- KUrl::List urls = KUrl::List::fromMimeData(mimeData);
- if (!urls.isEmpty()) {
- // disable the paste action if no writing is supported
- KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url());
- ret.first = KonqFileItemCapabilities(KFileItemList() << item).supportsWriting();
-
- if (urls.count() == 1) {
- const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first(), true);
- ret.second = item.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
- i18nc("@action:inmenu", "Paste One File");
-
- } else {
- ret.second = i18ncp("@action:inmenu", "Paste One Item", "Paste %1 Items", urls.count());
- }
- } else {
- ret.first = false;
- ret.second = i18nc("@action:inmenu", "Paste");
- }
-
- return ret;
+ return KonqOperations::pasteInfo(url());
}
void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
}
}
+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::slotRefreshItems()
+{
+ if (m_assureVisibleCurrentIndex) {
+ m_assureVisibleCurrentIndex = false;
+ itemView()->scrollTo(itemView()->currentIndex());
+ }
+}
+
void DolphinView::loadDirectory(const KUrl& url, bool reload)
{
if (!url.isValid()) {
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);
void DolphinView::pasteToUrl(const KUrl& url)
{
- QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
-
- const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
- if (KonqMimeData::decodeIsCutSelection(mimeData)) {
- KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url);
- clipboard->clear();
- } else {
- KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url);
- }
+ KonqOperations::doPaste(this, url);
}
void DolphinView::updateZoomLevel(int oldZoomLevel)
return m_dolphinModel->mimeData(selection.indexes());
}
+
#include "dolphinview.moc"