Fix subtle path handling bugs caused by recent changes to the title

Resolve issues with corner-cases introduced by [0].

- Comparing the filename & filepath was no longer a valid way to check
  for a directory component since the extension was stripped.
- Use BLI_path_extension_or_end which doesn't confuse extensions with
  the dot from hidden files.

The variable name include_directory was also misleading.

[0]: 1a648f5b22
This commit is contained in:
Campbell Barton
2023-10-13 10:21:08 +11:00
parent fb58aa5900
commit df108825c0

View File

@@ -487,26 +487,29 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win)
else if (win->ghostwin) {
GHOST_WindowHandle handle = static_cast<GHOST_WindowHandle>(win->ghostwin);
std::string filepath = BKE_main_blendfile_path_from_global();
std::string filename = BLI_path_basename(filepath.c_str());
size_t lastdot = filename.find_last_of(".");
if (lastdot != std::string::npos) {
filename = filename.substr(0, lastdot);
}
const char *filepath = BKE_main_blendfile_path_from_global();
const char *filename = BLI_path_basename(filepath);
bool has_filepath = !filepath.empty();
bool include_directory = has_filepath && (filepath != filename) &&
GHOST_SetPath(handle, filepath.c_str()) == GHOST_kFailure;
const bool has_filepath = filepath[0] != '\0';
const bool include_filepath = has_filepath && (filepath != filename) &&
(GHOST_SetPath(handle, filepath) == GHOST_kFailure);
std::string str;
str += wm->file_saved ? " " : "* ";
str += has_filepath ? filename : IFACE_("(Unsaved)");
if (has_filepath) {
const size_t filename_no_ext_len = BLI_path_extension_or_end(filename) - filename;
str.append(filename, filename_no_ext_len);
}
else {
str += IFACE_("(Unsaved)");
}
if (G_MAIN->recovered) {
str += IFACE_(" (Recovered)");
}
if (include_directory) {
str += " [" + filepath + "]";
if (include_filepath) {
str += " [" + std::string(filepath) + "]";
}
str += " - Blender ";