]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Elide file names in the middle again
authorNate Graham <nate@kde.org>
Fri, 3 Jan 2025 19:45:27 +0000 (12:45 -0700)
committerFelix Ernst <felixernst@kde.org>
Tue, 7 Jan 2025 01:46:12 +0000 (01:46 +0000)
In ye olden days, filenames were elided on the right. This prevented
seeing the filename extension and any suffix style text the user
included in the filename (e.g. "myfile 1", "myfile 2" and so on).

In 97f49347482519b9ad53b7596d7462e68b7c2e14, this was changed to elide
in the middle, fixing both problems and bringing Dolphin into Jakobs'
Law style consistency with MacOS Finder and Windows Explorer, and
possibly other file managers too.

However it worsened the situation for users who name their files such
that most of the information was on the left. After some complaints, it
was changed in 99cf24c03def1c0722ba8dbd86a27b9dbc521f43 to right-elide
again, but excluding the filename extension.

Unfortunately user complaints have continued. At this point it's clear
that nothing will satisfy everyone due to diversity of file naming
styles. In such a situation, Jakobs' Law consistency with the rest of
the industry is the best solution short of making it configurable,
which has its own drawbacks.

Accordingly, return to middle-elision.

BUG: 497664
CCBUG: 404955
FIXED-IN: 25.04.0

src/kitemviews/kstandarditemlistwidget.cpp
src/kitemviews/kstandarditemlistwidget.h

index 05628d3913030895f7f2592d99e20e17329338fc..a30a1bcd2ade909b7fef26d5dc56d734165ea2d2 100644 (file)
@@ -1285,23 +1285,6 @@ void KStandardItemListWidget::updateTextsCache()
     }
 }
 
     }
 }
 
-QString KStandardItemListWidget::elideRightKeepExtension(const QString &text, int elidingWidth) const
-{
-    const auto extensionIndex = text.lastIndexOf('.');
-    if (extensionIndex != -1) {
-        // has file extension
-        const auto extensionLength = text.length() - extensionIndex;
-        const auto extensionWidth = m_customizedFontMetrics.horizontalAdvance(text.right(extensionLength));
-        if (elidingWidth > extensionWidth && extensionLength < 6 && (float(extensionWidth) / float(elidingWidth)) < 0.3) {
-            // if we have room to display the file extension and the extension is not too long
-            QString ret = m_customizedFontMetrics.elidedText(text.chopped(extensionLength), Qt::ElideRight, elidingWidth - extensionWidth);
-            ret.append(QStringView(text).right(extensionLength));
-            return ret;
-        }
-    }
-    return m_customizedFontMetrics.elidedText(text, Qt::ElideRight, elidingWidth);
-}
-
 QString KStandardItemListWidget::escapeString(const QString &text) const
 {
     QString escaped(text);
 QString KStandardItemListWidget::escapeString(const QString &text) const
 {
     QString escaped(text);
@@ -1362,7 +1345,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
                 qreal lastLineWidth;
                 do {
                     QString lastTextLine = nameText.mid(line.textStart());
                 qreal lastLineWidth;
                 do {
                     QString lastTextLine = nameText.mid(line.textStart());
-                    lastTextLine = elideRightKeepExtension(lastTextLine, elidingWidth);
+                    lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine, Qt::ElideMiddle, elidingWidth);
                     const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
                     nameTextInfo->staticText.setText(elidedText);
 
                     const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
                     nameTextInfo->staticText.setText(elidedText);
 
@@ -1410,7 +1393,7 @@ void KStandardItemListWidget::updateIconsLayoutTextCache()
             textLine.setLineWidth(maxWidth);
             requiredWidth = textLine.naturalTextWidth();
             if (requiredWidth > maxWidth) {
             textLine.setLineWidth(maxWidth);
             requiredWidth = textLine.naturalTextWidth();
             if (requiredWidth > maxWidth) {
-                const QString elidedText = elideRightKeepExtension(text, maxWidth);
+                const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth);
                 textInfo->staticText.setText(elidedText);
                 requiredWidth = m_customizedFontMetrics.horizontalAdvance(elidedText);
             } else if (role == "rating") {
                 textInfo->staticText.setText(elidedText);
                 requiredWidth = m_customizedFontMetrics.horizontalAdvance(elidedText);
             } else if (role == "rating") {
@@ -1462,7 +1445,7 @@ void KStandardItemListWidget::updateCompactLayoutTextCache()
         qreal requiredWidth = m_customizedFontMetrics.horizontalAdvance(text);
         if (requiredWidth > maxWidth) {
             requiredWidth = maxWidth;
         qreal requiredWidth = m_customizedFontMetrics.horizontalAdvance(text);
         if (requiredWidth > maxWidth) {
             requiredWidth = maxWidth;
-            const QString elidedText = elideRightKeepExtension(text, maxWidth);
+            const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, maxWidth);
             textInfo->staticText.setText(elidedText);
         }
 
             textInfo->staticText.setText(elidedText);
         }
 
@@ -1522,7 +1505,7 @@ void KStandardItemListWidget::updateDetailsLayoutTextCache()
         }
 
         if (requiredWidth > availableTextWidth) {
         }
 
         if (requiredWidth > availableTextWidth) {
-            text = elideRightKeepExtension(text, availableTextWidth);
+            text = m_customizedFontMetrics.elidedText(text, Qt::ElideMiddle, availableTextWidth);
             requiredWidth = m_customizedFontMetrics.horizontalAdvance(text);
         }
 
             requiredWidth = m_customizedFontMetrics.horizontalAdvance(text);
         }
 
index 7ff97a126c6332e3df9fe87025ab4f9aa12ef472..d4a4f12314000f963f0c656fac446184446d0f51 100644 (file)
@@ -218,8 +218,6 @@ private:
 
     QRectF roleEditingRect(const QByteArray &role) const;
 
 
     QRectF roleEditingRect(const QByteArray &role) const;
 
-    QString elideRightKeepExtension(const QString &text, int elidingWidth) const;
-
     /**
      * Escapes text for display purposes.
      *
     /**
      * Escapes text for display purposes.
      *