Skip to content

Commit d910ce8

Browse files
committed
Simplify "Filename first" implementation
1 parent b5cf50c commit d910ce8

2 files changed

Lines changed: 8 additions & 19 deletions

File tree

gitfourchette/filelists/filelist.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIn
7272
if font:
7373
painter.setFont(font)
7474
fullText = index.data(Qt.ItemDataRole.DisplayRole)
75-
elideMode = Qt.TextElideMode.ElideRight if settings.prefs.pathDisplayStyle == PathDisplayStyle.FileNameFirst else option.textElideMode
76-
text = painter.fontMetrics().elidedText(fullText, elideMode, textRect.width())
75+
text = painter.fontMetrics().elidedText(fullText, option.textElideMode, textRect.width())
7776

7877
# Split path into directory and filename for better readability
7978
firstPortion = None
@@ -85,22 +84,10 @@ def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIn
8584
isFileNameFirst = settings.prefs.pathDisplayStyle == PathDisplayStyle.FileNameFirst
8685

8786
if isFileNameFirst:
88-
# Rely on the raw path to identify the filename, as filenames can contain spaces
89-
fullPath = index.data(FileListModel.Role.FilePath)
90-
fName = os.path.basename(fullPath)
91-
92-
prefix = fName + " "
93-
if not text.startswith(prefix) and '\u2026' in text:
94-
ellipsisPos = text.find('\u2026')
95-
if fName.startswith(text[:ellipsisPos]):
96-
prefix = text[:ellipsisPos + 1]
97-
98-
if text.startswith(prefix):
99-
firstPortion = prefix
100-
secondPortion = text[len(prefix):]
101-
else:
102-
firstPortion = text
103-
secondPortion = ""
87+
try:
88+
firstPortion, secondPortion = text.split('\0')
89+
except ValueError:
90+
firstPortion, secondPortion = text, ""
10491

10592
firstColor = QPalette.ColorRole.WindowText
10693
secondColor = QPalette.ColorRole.PlaceholderText
@@ -236,6 +223,8 @@ def __init__(self, repoModel: RepoModel, parent: QWidget, navContext: NavContext
236223

237224
def refreshPrefs(self):
238225
self.setVerticalScrollMode(settings.prefs.listViewScrollMode)
226+
nameFirst = settings.prefs.pathDisplayStyle == PathDisplayStyle.FileNameFirst
227+
self.setTextElideMode(Qt.TextElideMode.ElideRight if nameFirst else Qt.TextElideMode.ElideMiddle)
239228

240229
@property
241230
def repo(self) -> Repo:

gitfourchette/toolbox/pathutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def abbreviatePath(path: str, style: PathDisplayStyle = PathDisplayStyle.FullPat
3838
split = path.rsplit('/', 1)
3939
if len(split) == 1:
4040
return path
41-
return split[-1] + ' ' + split[0]
41+
return split[-1] + ' \0' + split[0]
4242
elif style == PathDisplayStyle.FileNameOnly:
4343
return path.rsplit('/', 1)[-1]
4444
else:

0 commit comments

Comments
 (0)