diff options
| author | Peter Penz <[email protected]> | 2009-02-24 08:09:35 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2009-02-24 08:09:35 +0000 |
| commit | 7b6ace6466cf349a4ce7a080d5e978aa0a7043e2 (patch) | |
| tree | 42f92ce2db3868834c7f06a63e256011989d93a7 /src/dolphinview.cpp | |
| parent | 7e7c14ba65bfc524d03bfce00d158010194e9534 (diff) | |
After renaming an item the view should be scrolled in a way to still have a fully visible renamed item. The implementation required a lot of more code changes as such a fix should require: QAbstractItemView::scrollTo() cannot be used directly (inconsistent default behavior in QListView and QTreeView, a special case for the column view), so the communication has to be done with the DolphinController...
BUG: 185191
svn path=/trunk/KDE/kdebase/apps/; revision=930754
Diffstat (limited to 'src/dolphinview.cpp')
| -rw-r--r-- | src/dolphinview.cpp | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index f40accdde..638e6e7cb 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -88,6 +88,7 @@ DolphinView::DolphinView(QWidget* parent, m_tabsForFiles(false), m_isContextMenuOpen(false), m_ignoreViewProperties(false), + m_assureVisibleCurrentIndex(false), m_mode(DolphinView::IconsView), m_topLayout(0), m_controller(0), @@ -142,6 +143,8 @@ DolphinView::DolphinView(QWidget* parent, 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())); applyViewProperties(url); m_topLayout->addWidget(itemView()); @@ -629,30 +632,31 @@ void DolphinView::renameSelectedItems() 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('#')); + return; + } - // currently the items are sorted by the selection order, resort - // them by the file name - qSort(items.begin(), items.end(), lessThan); + // 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('#')); - // 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++); + // currently the items are sorted by the selection order, resort + // them by the file name + qSort(items.begin(), items.end(), lessThan); - QString name = newName; - name.replace('#', number); + // 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++); - if (oldUrl.fileName() != name) { - KUrl newUrl = oldUrl; - newUrl.setFileName(name); - KonqOperations::rename(this, oldUrl, newUrl); - } + 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()) { @@ -676,13 +680,18 @@ void DolphinView::renameSelectedItems() 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() @@ -1147,6 +1156,17 @@ void DolphinView::restoreCurrentItem() } } +void DolphinView::slotRefreshItems() +{ + if (m_assureVisibleCurrentIndex) { + m_assureVisibleCurrentIndex = false; + // Invoking itemView()->scrollTo(itemView()->currentIndex()) is + // not sufficient, as QListView and QTreeView have an inconsistent + // default behavior. + m_controller->triggerScrollToCurrentItem(); + } +} + void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { |
