diff options
| author | David Faure <[email protected]> | 2012-07-20 12:09:04 +0200 |
|---|---|---|
| committer | Emmanuel Pescosta <[email protected]> | 2012-08-13 22:25:49 +0200 |
| commit | eb14263c480ea37c306a9ae6a7fda64875cfe418 (patch) | |
| tree | 33f99e846e49379919d1829e84c156d301cbe58f /src/kitemviews | |
| parent | 5fbe52c1518037ad3dbb89ba18f2a318aee114f4 (diff) | |
Fix bug 303375 - Dots in directory names treated as file extension.
Patch by Emmanuel Pescosta <[email protected]>
BUG: 303375
REVIEW: 105575
FIXED-IN: 4.9.0
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.cpp | 31 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.h | 5 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.cpp | 24 | ||||
| -rw-r--r-- | src/kitemviews/kstandarditemlistwidget.h | 13 |
4 files changed, 57 insertions, 16 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index c99da383f..3a7724134 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -19,6 +19,7 @@ #include "kfileitemlistwidget.h" +#include <kmimetype.h> #include <KDebug> #include <KGlobal> #include <KLocale> @@ -101,4 +102,34 @@ QFont KFileItemListWidget::customizedFont(const QFont& baseFont) const return font; } +int KFileItemListWidget::selectionLength(const QString& text) const +{ + // Select the text without MIME-type extension + int selectionLength = text.length(); + + // If item is a directory, use the whole text length for + // selection (ignore all points) + if(data().value("isDir").toBool()) { + return selectionLength; + } + + const QString extension = KMimeType::extractKnownExtension(text); + if (extension.isEmpty()) { + // For an unknown extension just exclude the extension after + // the last point. This does not work for multiple extensions like + // *.tar.gz but usually this is anyhow a known extension. + selectionLength = text.lastIndexOf(QLatin1Char('.')); + + // If no point could be found, use whole text length for selection. + if (selectionLength < 1) { + selectionLength = text.length(); + } + + } else { + selectionLength -= extension.length() + 1; + } + + return selectionLength; +} + #include "kfileitemlistwidget.moc" diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h index b0d8e1cd7..24c677828 100644 --- a/src/kitemviews/kfileitemlistwidget.h +++ b/src/kitemviews/kfileitemlistwidget.h @@ -48,6 +48,11 @@ protected: virtual bool isRoleRightAligned(const QByteArray& role) const; virtual bool isHidden() const; virtual QFont customizedFont(const QFont& baseFont) const; + + /** + * @return Selection length without MIME-type extension + */ + virtual int selectionLength(const QString& text) const; }; #endif diff --git a/src/kitemviews/kstandarditemlistwidget.cpp b/src/kitemviews/kstandarditemlistwidget.cpp index d41b9161b..69c5602c7 100644 --- a/src/kitemviews/kstandarditemlistwidget.cpp +++ b/src/kitemviews/kstandarditemlistwidget.cpp @@ -581,6 +581,11 @@ void KStandardItemListWidget::siblingsInformationChanged(const QBitArray& curren m_dirtyLayout = true; } +int KStandardItemListWidget::selectionLength(const QString& text) const +{ + return text.length(); +} + void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous) { Q_UNUSED(previous); @@ -610,25 +615,12 @@ void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QTextOption textOption = textInfo->staticText.textOption(); m_roleEditor->document()->setDefaultTextOption(textOption); - // Select the text without MIME-type extension - // TODO: This is file-item-specific and should be moved - // into KFileItemListWidget. - int selectionLength = text.length(); - - const QString extension = KMimeType::extractKnownExtension(text); - if (extension.isEmpty()) { - // For an unknown extension just exclude the extension after - // the last point. This does not work for multiple extensions like - // *.tar.gz but usually this is anyhow a known extension. - selectionLength = text.lastIndexOf(QLatin1Char('.')); - } else { - selectionLength -= extension.length() + 1; - } + const int textSelectionLength = selectionLength(text); - if (selectionLength > 0) { + if (textSelectionLength > 0) { QTextCursor cursor = m_roleEditor->textCursor(); cursor.movePosition(QTextCursor::StartOfBlock); - cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, selectionLength); + cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, textSelectionLength); m_roleEditor->setTextCursor(cursor); } diff --git a/src/kitemviews/kstandarditemlistwidget.h b/src/kitemviews/kstandarditemlistwidget.h index f559f3d22..462d83d0f 100644 --- a/src/kitemviews/kstandarditemlistwidget.h +++ b/src/kitemviews/kstandarditemlistwidget.h @@ -133,6 +133,19 @@ protected: */ QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values) const; + /** + * Fixes: + * Select the text without MIME-type extension + * This is file-item-specific and should be moved + * into KFileItemListWidget. + * + * Inherited classes can define, if the MIME-type extension + * should be selected or not. + * + * @return Selection length (with or without MIME-type extension) + */ + virtual int selectionLength(const QString& text) const; + virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>()); virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous); virtual void columnWidthChanged(const QByteArray& role, qreal current, qreal previous); |
