Commit 4de9a233 authored by Frank Reininghaus's avatar Frank Reininghaus
Browse files

Do not rename files unexpectedly when changing the URL

If the role editor loses focus, it considers the current renaming
operation finished, and tells DolphinView to rename the file. This is a
problem when changing the directory, because the URL change happens
before DolphinView receives the signal, which results in a file in the
new directory being renamed unexpectedly.

The solution is to establish the connection to the
slotRoleEditingFinished signal only when the "rename inline" editor is
opened, and disconnect it when renaming is finished or canceled or the
URL changes.

BUG: 319912
FIXED-IN: 4.10.5
REVIEW: 110908
parent cc492bd5
......@@ -642,10 +642,10 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
if (m_roleEditor) {
emit roleEditingCanceled(index(), current, data().value(current));
disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
m_oldRoleEditor = m_roleEditor;
m_roleEditor->hide();
m_roleEditor = 0;
......@@ -663,7 +663,6 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
const TextInfo* textInfo = m_textInfo.value("text");
m_roleEditor = new KItemListRoleEditor(parent);
m_roleEditor->setIndex(index());
m_roleEditor->setRole(current);
m_roleEditor->setFont(styleOption().font);
......@@ -682,10 +681,10 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const
m_roleEditor->setTextCursor(cursor);
}
connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
connect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
connect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
// Adjust the geometry of the editor
QRectF rect = roleEditingRect(current);
......@@ -746,21 +745,19 @@ void KStandardItemListWidget::slotCutItemsChanged()
}
}
void KStandardItemListWidget::slotRoleEditingCanceled(int index,
const QByteArray& role,
void KStandardItemListWidget::slotRoleEditingCanceled(const QByteArray& role,
const QVariant& value)
{
closeRoleEditor();
emit roleEditingCanceled(index, role, value);
emit roleEditingCanceled(index(), role, value);
setEditedRole(QByteArray());
}
void KStandardItemListWidget::slotRoleEditingFinished(int index,
const QByteArray& role,
void KStandardItemListWidget::slotRoleEditingFinished(const QByteArray& role,
const QVariant& value)
{
closeRoleEditor();
emit roleEditingFinished(index, role, value);
emit roleEditingFinished(index(), role, value);
setEditedRole(QByteArray());
}
......@@ -1307,10 +1304,10 @@ QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const
void KStandardItemListWidget::closeRoleEditor()
{
disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
if (m_roleEditor->hasFocus()) {
// If the editing was not ended by a FocusOut event, we have
......
......@@ -160,8 +160,8 @@ protected:
private slots:
void slotCutItemsChanged();
void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value);
void slotRoleEditingFinished(const QByteArray& role, const QVariant& value);
private:
void triggerCacheRefreshing();
......
......@@ -25,7 +25,6 @@
KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) :
KTextEdit(parent),
m_index(0),
m_role(),
m_blockFinishedSignal(false)
{
......@@ -46,16 +45,6 @@ KItemListRoleEditor::~KItemListRoleEditor()
{
}
void KItemListRoleEditor::setIndex(int index)
{
m_index = index;
}
int KItemListRoleEditor::index() const
{
return m_index;
}
void KItemListRoleEditor::setRole(const QByteArray& role)
{
m_role = role;
......@@ -95,7 +84,7 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event)
// a roleEditingFinished signal (see KItemListRoleEditor::event),
// which is not wanted in this case.
m_blockFinishedSignal = true;
emit roleEditingCanceled(m_index, m_role, KIO::encodeFileName(toPlainText()));
emit roleEditingCanceled(m_role, KIO::encodeFileName(toPlainText()));
m_blockFinishedSignal = false;
event->accept();
return;
......@@ -139,7 +128,7 @@ void KItemListRoleEditor::autoAdjustSize()
void KItemListRoleEditor::emitRoleEditingFinished()
{
if (!m_blockFinishedSignal) {
emit roleEditingFinished(m_index, m_role, KIO::encodeFileName(toPlainText()));
emit roleEditingFinished(m_role, KIO::encodeFileName(toPlainText()));
}
}
......
......@@ -41,17 +41,14 @@ public:
explicit KItemListRoleEditor(QWidget* parent);
virtual ~KItemListRoleEditor();
void setIndex(int index);
int index() const;
void setRole(const QByteArray& role);
QByteArray role() const;
virtual bool eventFilter(QObject* watched, QEvent* event);
signals:
void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
void roleEditingFinished(const QByteArray& role, const QVariant& value);
void roleEditingCanceled(const QByteArray& role, const QVariant& value);
protected:
virtual bool event(QEvent* event);
......@@ -72,7 +69,6 @@ private:
void emitRoleEditingFinished();
private:
int m_index;
QByteArray m_role;
bool m_blockFinishedSignal;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment