Open Directory selects the file in the file manager
Showing a spritesheet, sound, library (or Explore XML Location's document) opens its folder with the file selected: explorer /select on Windows, the freedesktop FileManager1 ShowItems call on Linux (Nautilus, Dolphin, Nemo, Caja, Thunar...), falling back to opening the folder. Paths go to the shell single-quoted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6f9b425e8
commit
d77b2bae71
3 files changed
+48
-5
No files matched your search
@@ -129,7 +129,7 @@ namespace anm2ed::imgui
|
||||
if (ImGui::MenuItem(localize.get(LABEL_SAVE_AS), settings.shortcutSaveAs.c_str(), false, document))
|
||||
dialog.file_save(Dialog::ANM2_SAVE);
|
||||
if (ImGui::MenuItem(localize.get(LABEL_EXPLORE_XML_LOCATION), nullptr, false, document))
|
||||
dialog.file_explorer_open(document->directory_get());
|
||||
dialog.file_explorer_open(document->path);
|
||||
|
||||
// Which game this document is saved for: the editor's format alone, or Rebirth's (with the editor's copy).
|
||||
auto isExtendedFormat = document && document->model.isExtendedFormat;
|
||||
|
||||
@@ -342,13 +342,15 @@ namespace anm2ed::imgui
|
||||
return path::backslash_replace(path::make_relative(path::backslash_handle(path), document.directory_get()));
|
||||
}
|
||||
|
||||
// Shows a resource's file selected in the file manager (or the nearest folder there is, when it's missing).
|
||||
void directory_open(Dialog& dialog, Document& document, const std::filesystem::path& path)
|
||||
{
|
||||
if (path.empty()) return;
|
||||
std::error_code ec{};
|
||||
auto absolutePath = std::filesystem::weakly_canonical(document.directory_get() / path, ec);
|
||||
if (ec) absolutePath = document.directory_get() / path;
|
||||
auto target = std::filesystem::is_directory(absolutePath) ? absolutePath
|
||||
auto target = std::filesystem::is_regular_file(absolutePath, ec) || std::filesystem::is_directory(absolutePath, ec)
|
||||
? absolutePath
|
||||
: std::filesystem::is_directory(absolutePath.parent_path()) ? absolutePath.parent_path()
|
||||
: document.directory_get();
|
||||
dialog.file_explorer_open(target);
|
||||
|
||||
Reference in new issue
Block a user