diff options
| author | David Faure <[email protected]> | 2012-07-20 12:09:04 +0200 |
|---|---|---|
| committer | David Faure <[email protected]> | 2012-07-20 12:09:04 +0200 |
| commit | 149975a0044f0a964c44b98e3228f4aeb6588d00 (patch) | |
| tree | 7a192910d95ae42cd06fd12446ccea6c3dd483e2 /src/kitemviews/kfileitemlistwidget.cpp | |
| parent | 4a0454ff88a0900706826e7ed61aef405c73ba90 (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/kfileitemlistwidget.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.cpp | 31 |
1 files changed, 31 insertions, 0 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" |
