Commit 1a284bb7 authored by Aaron J. Seigo's avatar Aaron J. Seigo
Browse files

only try to change the name once

BUG:270414
parent 89c66b90
......@@ -1380,8 +1380,9 @@ void IconView::updateEditorGeometry()
void IconView::renameSelectedIcon()
{
QModelIndex index = m_selectionModel->currentIndex();
if (!index.isValid())
if (!index.isValid()) {
return;
}
// Don't allow renaming of files the aren't visible in the view
const QRect rect = visualRect(index);
......@@ -1476,7 +1477,6 @@ void IconView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint h
editor->hide();
editor->deleteLater();
m_editorIndex = QModelIndex();
markAreaDirty(visibleArea());
}
......@@ -1494,7 +1494,6 @@ void IconView::closeEditor(QGraphicsWidget *editor, QAbstractItemDelegate::EndEd
}
m_editorIndex = QModelIndex();
markAreaDirty(visibleArea());
}
......
......@@ -29,7 +29,8 @@
ItemEditor::ItemEditor(QGraphicsWidget *parent, const QStyleOptionViewItemV4 &option,
const QModelIndex &index)
: QGraphicsProxyWidget(parent),
m_index(index)
m_index(index),
m_uncommitted(true)
{
// Create the editor
m_editor = new KTextEdit();
......@@ -66,14 +67,18 @@ ItemEditor::~ItemEditor()
void ItemEditor::commitData()
{
const_cast<QAbstractItemModel*>(m_index.model())->setData(m_index, m_editor->toPlainText(), Qt::EditRole);
if (m_uncommitted) {
const_cast<QAbstractItemModel*>(m_index.model())->setData(m_index, m_editor->toPlainText(), Qt::EditRole);
m_uncommitted = false;
}
}
bool ItemEditor::eventFilter(QObject *watched, QEvent *event)
{
KTextEdit *editor = qobject_cast<KTextEdit*>(watched);
if (!editor)
if (!editor) {
return false;
}
switch (event->type())
{
......@@ -107,8 +112,10 @@ bool ItemEditor::eventFilter(QObject *watched, QEvent *event)
case QEvent::FocusOut:
{
commitData();
emit closeEditor(this, QAbstractItemDelegate::NoHint);
if (m_uncommitted) {
commitData();
emit closeEditor(this, QAbstractItemDelegate::NoHint);
}
return true;
}
......
......@@ -49,6 +49,7 @@ protected:
private:
KTextEdit *m_editor;
QModelIndex m_index;
bool m_uncommitted;
};
#endif
......
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