Skip to content

Commit

Permalink
Short $HOME in recent files list on Windows too
Browse files Browse the repository at this point in the history
Don't use ~ because it is unfamiliar on Wnidows, just omit the home dir
instead. Do the same in the recent files submenu.
  • Loading branch information
vslavik committed Dec 11, 2023
1 parent 59704da commit 053f80d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/recent_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "recent_files.h"

#include "colorscheme.h"
#include "edapp.h"
#include "hidpi.h"
#include "str_helpers.h"
#include "unicode_helpers.h"
Expand Down Expand Up @@ -194,6 +195,25 @@ typedef std::shared_ptr<file_icons> file_icons_ptr;

#endif // !__WXOSX__


wxString pretty_print_path(wxFileName f)
{
f.MakeAbsolute();
f.ReplaceHomeDir();

// shorten the path for visual use:
auto path = f.GetPath();

#ifdef __WXMSW__
// ReplaceHomeDir() puts tilde at the beginning to replace $HOME, but this is uncommon on Windows,
// so remove it and just use plain path:
if (path.StartsWith("~\\"))
path = path.substr(2);
#endif

return path;
}

} // anonymous namespace


Expand Down Expand Up @@ -417,7 +437,7 @@ class RecentFiles::impl
{
auto menuEntry = bidi::platform_mark_direction(
showFullPath
? wxString::Format(L"%s — %s", fn.GetFullName(), fn.GetPath())
? wxString::Format(L"%s — %s", fn.GetFullName(), pretty_print_path(fn))
: fn.GetFullName());

// we need to quote '&' characters which are used for mnemonics
Expand Down Expand Up @@ -550,17 +570,13 @@ void RecentFilesCtrl::RefreshContent()
m_data->files = RecentFiles::Get().GetRecentFiles();
for (auto f : m_data->files)
{
#ifndef __WXMSW__
f.ReplaceHomeDir();
#endif

#ifdef __WXOSX__
wxBitmap icon([[NSWorkspace sharedWorkspace] iconForFileType:str::to_NS(f.GetExt())]);
#else
wxBitmap icon(m_data->icons_cache->get_large(f.GetExt()));
#endif

AppendFormattedItem(icon, f.GetFullName(), f.GetPath());
AppendFormattedItem(icon, f.GetFullName(), pretty_print_path(f));
}
}

Expand Down

0 comments on commit 053f80d

Please sign in to comment.