mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 08:21:22 +00:00
Inline renaming fixes
- Don't use an outdated KFileItem when renaming an item more than once - Use the same font as the view - Don't lose the focus when an editor-popup is shown BUG: 299327 BUG: 298883 BUG: 301253 FIXED-IN: 4.9.0
This commit is contained in:
parent
0c206bda8e
commit
98a4aa10ef
|
@ -167,6 +167,12 @@ bool KFileItemModel::setData(int index, const QHash<QByteArray, QVariant>& value
|
|||
}
|
||||
|
||||
m_itemData[index]->values = currentValues;
|
||||
if (changedRoles.contains("text")) {
|
||||
KUrl url = m_itemData[index]->item.url();
|
||||
url.setFileName(currentValues["text"].toString());
|
||||
m_itemData[index]->item.setUrl(url);
|
||||
}
|
||||
|
||||
emit itemsChanged(KItemRangeList() << KItemRange(index, 1), changedRoles);
|
||||
|
||||
if (changedRoles.contains(sortRole())) {
|
||||
|
|
|
@ -597,6 +597,7 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
|
|||
m_roleEditor = new KItemListRoleEditor(parent);
|
||||
m_roleEditor->setIndex(index());
|
||||
m_roleEditor->setRole(current);
|
||||
m_roleEditor->setFont(styleOption().font);
|
||||
|
||||
const QString text = data().value(current).toString();
|
||||
m_roleEditor->setPlainText(text);
|
||||
|
|
|
@ -29,11 +29,14 @@ KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) :
|
|||
{
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setAcceptRichText(false);
|
||||
document()->setDocumentMargin(0);
|
||||
|
||||
if (parent) {
|
||||
parent->installEventFilter(this);
|
||||
}
|
||||
|
||||
connect(this, SIGNAL(textChanged()), this, SLOT(autoAdjustSize()));
|
||||
}
|
||||
|
||||
KItemListRoleEditor::~KItemListRoleEditor()
|
||||
|
@ -60,7 +63,7 @@ QByteArray KItemListRoleEditor::role() const
|
|||
return m_role;
|
||||
}
|
||||
|
||||
bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
|
||||
bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
if (watched == parentWidget() && event->type() == QEvent::Resize) {
|
||||
emit roleEditingFinished(m_index, m_role, toPlainText());
|
||||
|
@ -72,7 +75,10 @@ bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
|
|||
bool KItemListRoleEditor::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::FocusOut) {
|
||||
emit roleEditingFinished(m_index, m_role, toPlainText());
|
||||
QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event);
|
||||
if (focusEvent->reason() != Qt::PopupFocusReason) {
|
||||
emit roleEditingFinished(m_index, m_role, toPlainText());
|
||||
}
|
||||
}
|
||||
return KTextEdit::event(event);
|
||||
}
|
||||
|
@ -94,7 +100,6 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event)
|
|||
}
|
||||
|
||||
KTextEdit::keyPressEvent(event);
|
||||
autoAdjustSize();
|
||||
}
|
||||
|
||||
void KItemListRoleEditor::autoAdjustSize()
|
||||
|
|
|
@ -168,6 +168,8 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
|
|||
this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
|
||||
connect(m_view, SIGNAL(visibleRolesChanged(QList<QByteArray>,QList<QByteArray>)),
|
||||
this, SLOT(slotVisibleRolesChangedByHeader(QList<QByteArray>,QList<QByteArray>)));
|
||||
connect(m_view, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
|
||||
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
|
||||
connect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
|
||||
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
|
||||
connect(m_view->header(), SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
|
||||
|
@ -625,7 +627,7 @@ void DolphinView::renameSelectedItems()
|
|||
|
||||
if (items.count() == 1) {
|
||||
const int index = m_model->index(items.first());
|
||||
m_container->controller()->view()->editRole(index, "text");
|
||||
m_view->editRole(index, "text");
|
||||
} else {
|
||||
RenameDialog* dialog = new RenameDialog(this, items);
|
||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -1318,15 +1320,30 @@ void DolphinView::slotVisibleRolesChangedByHeader(const QList<QByteArray>& curre
|
|||
emit visibleRolesChanged(m_visibleRoles, previousVisibleRoles);
|
||||
}
|
||||
|
||||
void DolphinView::slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
Q_UNUSED(role);
|
||||
Q_UNUSED(value);
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
|
||||
{
|
||||
if (role == "text") {
|
||||
const KFileItem item = m_model->fileItem(index);
|
||||
const KFileItem oldItem = m_model->fileItem(index);
|
||||
const QString newName = value.toString();
|
||||
if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
|
||||
KonqOperations::rename(this, item.url(), newName);
|
||||
if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
|
||||
const KUrl oldUrl = oldItem.url();
|
||||
|
||||
QHash<QByteArray, QVariant> data;
|
||||
data.insert(role, value);
|
||||
m_model->setData(index, data);
|
||||
|
||||
KonqOperations::rename(this, oldUrl, newName);
|
||||
}
|
||||
}
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void DolphinView::loadDirectory(const KUrl& url, bool reload)
|
||||
|
|
|
@ -628,6 +628,7 @@ private slots:
|
|||
void slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
|
||||
const QList<QByteArray>& previous);
|
||||
|
||||
void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
|
||||
void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue