Skip to content

Commit

Permalink
kramv - fix container name for files/folders
Browse files Browse the repository at this point in the history
Note the archives can have folders too.  So may want to set that similarly.
  • Loading branch information
alecazam committed Oct 3, 2022
1 parent bc3b61a commit 45d8acf
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions kramv/KramViewerMain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> _files;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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];
}
}
}
Expand All @@ -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];
}
}
}
Expand Down Expand Up @@ -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<string> normalFilenames;
string normalFilename;
Expand Down Expand Up @@ -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()];

Expand Down

0 comments on commit 45d8acf

Please sign in to comment.