mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
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
This commit is contained in:
parent
7e7c14ba65
commit
7b6ace6466
|
@ -59,6 +59,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
|
|||
this, SLOT(setZoomLevel(int)));
|
||||
connect(controller, SIGNAL(activationChanged(bool)),
|
||||
this, SLOT(updateColumnsBackground(bool)));
|
||||
connect(controller, SIGNAL(scrollToCurrentItem()),
|
||||
this, SLOT(scrollToCurrentItem()));
|
||||
|
||||
const DolphinView* view = controller->dolphinView();
|
||||
connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
|
||||
|
@ -465,6 +467,12 @@ void DolphinColumnView::slotShowPreviewChanged()
|
|||
}
|
||||
}
|
||||
|
||||
void DolphinColumnView::scrollToCurrentItem()
|
||||
{
|
||||
const QModelIndex activeIndex = activeColumn()->currentIndex();
|
||||
activeColumn()->scrollTo(activeIndex);
|
||||
}
|
||||
|
||||
void DolphinColumnView::setActiveColumnIndex(int index)
|
||||
{
|
||||
if (m_index == index) {
|
||||
|
|
|
@ -112,7 +112,7 @@ public:
|
|||
* Returns the selected items of the active column.
|
||||
*/
|
||||
KFileItemList selectedItems() const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the MIME data for the selected items
|
||||
* of the active column.
|
||||
|
@ -169,6 +169,7 @@ private slots:
|
|||
void slotSortOrderChanged(Qt::SortOrder order);
|
||||
void slotShowHiddenFilesChanged();
|
||||
void slotShowPreviewChanged();
|
||||
void scrollToCurrentItem();
|
||||
|
||||
private:
|
||||
DolphinColumnWidget* activeColumn() const;
|
||||
|
|
|
@ -124,6 +124,11 @@ void DolphinController::setZoomLevel(int level)
|
|||
}
|
||||
}
|
||||
|
||||
void DolphinController::triggerScrollToCurrentItem()
|
||||
{
|
||||
emit scrollToCurrentItem();
|
||||
}
|
||||
|
||||
void DolphinController::handleKeyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
Q_ASSERT(m_itemView != 0);
|
||||
|
|
|
@ -73,6 +73,7 @@ class QWidget;
|
|||
* - setShowPreview()
|
||||
* - indicateActivationChange()
|
||||
* - setZoomLevel()
|
||||
* - triggerScrollToCurrentItem()
|
||||
*/
|
||||
class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
|
||||
{
|
||||
|
@ -189,6 +190,12 @@ public:
|
|||
void setZoomLevel(int level);
|
||||
int zoomLevel() const;
|
||||
|
||||
/**
|
||||
* Triggers the view implementation to assure having a fully visible
|
||||
* current item. The signal scrollToCurrentItem() will be emitted.
|
||||
*/
|
||||
void triggerScrollToCurrentItem();
|
||||
|
||||
/**
|
||||
* Tells the view implementation to zoom out by emitting the signal zoomOut()
|
||||
* and is invoked by the abstract Dolphin view.
|
||||
|
@ -369,6 +376,12 @@ signals:
|
|||
*/
|
||||
void hideToolTip();
|
||||
|
||||
/**
|
||||
* Is emitted if the view implementation should scroll to the current item, so
|
||||
* that it is fully visible.
|
||||
*/
|
||||
void scrollToCurrentItem();
|
||||
|
||||
private slots:
|
||||
void updateMouseButtonState();
|
||||
|
||||
|
|
|
@ -128,6 +128,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
|
|||
this, SLOT(updateColumnVisibility()));
|
||||
connect(controller, SIGNAL(activationChanged(bool)),
|
||||
this, SLOT(slotActivationChanged(bool)));
|
||||
connect(controller, SIGNAL(scrollToCurrentItem()),
|
||||
this, SLOT(scrollToCurrentItem()));
|
||||
|
||||
if (settings->useSystemFont()) {
|
||||
m_font = KGlobalSettings::generalFont();
|
||||
|
@ -866,6 +868,11 @@ void DolphinDetailsView::setFoldersExpandable(bool expandable)
|
|||
setItemsExpandable(expandable);
|
||||
}
|
||||
|
||||
void DolphinDetailsView::scrollToCurrentItem()
|
||||
{
|
||||
scrollTo(currentIndex());
|
||||
}
|
||||
|
||||
void DolphinDetailsView::updateDecorationSize(bool showPreview)
|
||||
{
|
||||
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
|
||||
|
|
|
@ -159,6 +159,8 @@ private slots:
|
|||
*/
|
||||
void setFoldersExpandable(bool expandable);
|
||||
|
||||
void scrollToCurrentItem();
|
||||
|
||||
private:
|
||||
/**
|
||||
* Updates the size of the decoration dependent on the
|
||||
|
|
|
@ -88,6 +88,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
|
|||
controller, SLOT(emitViewportEntered()));
|
||||
connect(controller, SIGNAL(zoomLevelChanged(int)),
|
||||
this, SLOT(setZoomLevel(int)));
|
||||
connect(controller, SIGNAL(scrollToCurrentItem()),
|
||||
this, SLOT(scrollToCurrentItem()));
|
||||
|
||||
const DolphinView* view = controller->dolphinView();
|
||||
connect(view, SIGNAL(showPreviewChanged()),
|
||||
|
@ -390,6 +392,13 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category)
|
|||
}
|
||||
}
|
||||
|
||||
void DolphinIconsView::scrollToCurrentItem()
|
||||
{
|
||||
m_enableScrollTo = true;
|
||||
scrollTo(currentIndex());
|
||||
m_enableScrollTo = false;
|
||||
}
|
||||
|
||||
void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
|
||||
{
|
||||
const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
|
||||
|
|
|
@ -76,6 +76,7 @@ private slots:
|
|||
void setZoomLevel(int level);
|
||||
void requestActivation();
|
||||
void slotGlobalSettingsChanged(int category);
|
||||
void scrollToCurrentItem();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -630,6 +630,11 @@ private slots:
|
|||
*/
|
||||
void restoreCurrentItem();
|
||||
|
||||
/**
|
||||
* Is invoked when the KDirLister indicates refreshed items.
|
||||
*/
|
||||
void slotRefreshItems();
|
||||
|
||||
/**
|
||||
* If \a view can be positively identified as not being the source for the
|
||||
* current drag operation, deleteLater() it immediately. Else stores
|
||||
|
@ -716,6 +721,7 @@ private:
|
|||
bool m_tabsForFiles : 1;
|
||||
bool m_isContextMenuOpen : 1; // TODO: workaround for Qt-issue 207192
|
||||
bool m_ignoreViewProperties : 1;
|
||||
bool m_assureVisibleCurrentIndex : 1;
|
||||
|
||||
Mode m_mode;
|
||||
|
||||
|
@ -739,7 +745,7 @@ private:
|
|||
KUrl m_rootUrl;
|
||||
KUrl m_currentItemUrl;
|
||||
|
||||
QAbstractItemView* m_expandedDragSource;
|
||||
QAbstractItemView* m_expandedDragSource;
|
||||
};
|
||||
|
||||
inline bool DolphinView::isColumnViewActive() const
|
||||
|
|
Loading…
Reference in a new issue