ADD: In viewer, show in the title collapsed filename (fixes #164)

This commit is contained in:
Alexander Koblov 2022-11-05 12:40:44 +03:00
commit 056efc6fa8
3 changed files with 24 additions and 3 deletions

View file

@ -585,7 +585,7 @@ begin
Exit;
FFileName := AValue;
Caption := FFileName;
Caption := ReplaceHome(FFileName);
end;
destructor TfrmEditor.Destroy;

View file

@ -683,7 +683,7 @@ var
dwFileAttributes: TFileAttrs;
begin
FLastSearchPos := -1;
Caption := aFileName;
Caption := ReplaceHome(aFileName);
ViewerControl.FileName := EmptyStr;
// Clear text on status bar.
@ -751,7 +751,7 @@ begin
begin
Status.Panels[sbpFileNr].Text:= Format('%d/%d', [Index + 1, FileList.Count]);
Status.Panels[sbpFileName].Text:= FileList[Index];
Caption:= FileList[Index];
Caption:= ReplaceHome(FileList[Index]);
iActiveFile := Index;
Exit;
end;

View file

@ -67,6 +67,10 @@ function SetCmdDirAsEnvVar(const sPath : String) : String;
Also replaces the internal "%COMMANDER_PATH%".
}
function ReplaceEnvVars(const sText: String): String;
{en
Replaces home directory at the beginning of the string with tilde ~.
}
function ReplaceHome(const Path: String): String;
{en
Replaces tilde ~ at the beginning of the string with home directory.
}
@ -317,6 +321,23 @@ begin
Result:= mbExpandEnvironmentStrings(Result);
end;
function ReplaceHome(const Path: String): String;
{$IFDEF UNIX}
var
Len: Integer;
AHome: String;
{$ENDIF}
begin
{$IFDEF UNIX}
AHome:= GetHomeDir;
Len:= Length(AHome);
if StrBegins(Path, AHome) and ((Length(Path) = Len) or (Path[Len + 1] = PathDelim)) then
Result := '~' + Copy(Path, Len + 1, MaxInt)
else
{$ENDIF}
Result := Path;
end;
function ReplaceTilde(const Path: String): String;
begin
{$IFDEF UNIX}