]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix bug 303375 - Dots in directory names treated as file extension.
authorDavid Faure <faure@kde.org>
Fri, 20 Jul 2012 10:09:04 +0000 (12:09 +0200)
committerEmmanuel Pescosta <emmanuelpescosta099@gmail.com>
Mon, 13 Aug 2012 20:25:49 +0000 (22:25 +0200)
Patch by Emmanuel Pescosta <emmanuelpescosta099@gmail.com>

BUG: 303375
REVIEW: 105575
FIXED-IN: 4.9.0

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemlistwidget.h
src/kitemviews/kstandarditemlistwidget.cpp
src/kitemviews/kstandarditemlistwidget.h
src/views/renamedialog.cpp

index c99da383fcc13298e3240a6eb3dba6aab34343fa..3a7724134373a9e21c935d996515cd6b3aea8a33 100644 (file)
@@ -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"
index b0d8e1cd7e4f94bc674bd3de772357d4b8afe988..24c6778281773823122836a16830a1153bc2f7af 100644 (file)
@@ -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
index d41b9161bf4f5e7a9ce3fe38c3e3c3a82ed492df..69c5602c77378601cba2516f659f51122d33c1ca 100644 (file)
@@ -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);
     }
 
index f559f3d223527e6511b1a66a973a17185bca8cf9..462d83d0fad1b8b8785ffff9aa0f7971164582c7 100644 (file)
@@ -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);
index e232b9614a075c0a10c868aaf82919d77f2e4a19..a91f91b1b431246ad6e04cfc28c59d6f615bdf82 100644 (file)
@@ -87,7 +87,9 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) :
     if (m_renameOneItem) {
         const QString fileName = items.first().url().prettyUrl();
         const QString extension = KMimeType::extractKnownExtension(fileName.toLower());
-        if (extension.length() > 0) {
+
+        // If the current item is a directory, select the whole file name.
+        if ((extension.length() > 0) && !items.first().isDir()) {
             // Don't select the extension
             selectionLength -= extension.length() + 1;
         }