Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion gitfourchette/filelists/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,43 @@ def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIn
painter.setFont(font)
fullText = index.data(Qt.ItemDataRole.DisplayRole)
text = painter.fontMetrics().elidedText(fullText, option.textElideMode, textRect.width())
painter.drawText(textRect, option.displayAlignment, text)

# Split path into directory and filename for better readability
dirPortion = None
filePortion = None

if '/' in fullText:
slashesInFull = fullText.count('/')
slashesInElided = text.count('/')

if slashesInFull > slashesInElided:
# A slash was elided - gray everything up to the ellipsis
ellipsisPos = text.find('\u2026')
dirPortion = text[:ellipsisPos + 1]
filePortion = text[ellipsisPos + 1:]
elif slashesInElided > 0:
# No slash elided - gray up to the last slash
lastSlash = text.rfind('/')
dirPortion = text[:lastSlash + 1]
filePortion = text[lastSlash + 1:]

if dirPortion is not None:
textColor = QPalette.ColorRole.WindowText if not isSelected else QPalette.ColorRole.HighlightedText

# Draw directory with muted color
mutedColor = option.palette.color(colorGroup, textColor)
mutedColor.setAlphaF(0.4)
painter.setPen(mutedColor)
painter.drawText(textRect, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, dirPortion)

# Draw filename with normal color
painter.setPen(option.palette.color(colorGroup, textColor))
dirWidth = painter.fontMetrics().horizontalAdvance(dirPortion)
fileRect = QRect(textRect)
fileRect.setLeft(textRect.left() + dirWidth)
painter.drawText(fileRect, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, filePortion)
else:
painter.drawText(textRect, option.displayAlignment, text)

# Highlight search term
if searchTerm and searchTerm in fullText.lower():
Expand Down