diff --git a/kramv/KramViewerMain.mm b/kramv/KramViewerMain.mm index 269eccbe..c2bf6e2a 100644 --- a/kramv/KramViewerMain.mm +++ b/kramv/KramViewerMain.mm @@ -626,7 +626,7 @@ @implementation MyMTKView { ShowSettings* _showSettings; BOOL _noImageLoaded; - string _containerName; // folder, archive, or blank + string _archiveName; // archive or blank // folders and archives and multi-drop files are filled into this vector _files; @@ -2216,7 +2216,30 @@ - (void)updateHudVisibility _hudLabel2.hidden = _hudHidden || !_showSettings->isHudShown; } +- (void)setLoadedText:(string&)text +{ + text = "Loaded "; + + string filename = _showSettings->lastFilename; + text += toFilenameShort(filename.c_str()); + + // archives and file systems have folders, split that off + string folderName; + const char* slashPos = strrchr(filename.c_str(), '/'); + if (slashPos != nullptr) { + folderName = filename.substr(0, slashPos - filename.c_str()); + } + if (!folderName.empty()) { + text += " in folder "; + text += folderName; + } + + if (!_archiveName.empty()) { + text += " from archive "; + text += _archiveName; + } +} - (bool)handleEventAction:(const Action*)action isShiftKeyDown:(bool)isShiftKeyDown { @@ -2606,12 +2629,8 @@ - (bool)handleEventAction:(const Action*)action isShiftKeyDown:(bool)isShiftKeyD [self setEyedropperText:""]; isChanged = true; - text = "Loaded "; - text += toFilenameShort(_showSettings->lastFilename.c_str()); - if (!_containerName.empty()) { - text += " in "; - text += _containerName; - } + + [self setLoadedText:text]; } } } @@ -2630,12 +2649,7 @@ - (bool)handleEventAction:(const Action*)action isShiftKeyDown:(bool)isShiftKeyD isChanged = true; - text = "Loaded "; - text += toFilenameShort(_showSettings->lastFilename.c_str()); - if (!_containerName.empty()) { - text += " in "; - text += _containerName; - } + [self setLoadedText:text]; } } } @@ -3012,15 +3026,10 @@ - (BOOL)loadFile return NO; } - // TODO: better to extract from filename instead of root of folder dropped + // Note: better to extract from filename instead of root of folder dropped // or just keep displaying full path of filename. - _containerName.clear(); - NSURL* url = _urls[file.urlIndex]; - if (url.hasDirectoryPath) { - _containerName = "folder "; - _containerName += toFilenameShort(url.fileSystemRepresentation); - } + _archiveName.clear(); vector normalFilenames; string normalFilename; @@ -3249,8 +3258,7 @@ - (BOOL)loadFileFromArchive title += filenameShort; NSURL* archiveURL = _urls[file.urlIndex]; - _containerName = "archive "; - _containerName += toFilenameShort(archiveURL.fileSystemRepresentation); + _archiveName = toFilenameShort(archiveURL.fileSystemRepresentation); self.window.title = [NSString stringWithUTF8String:title.c_str()];