mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 23:59:24 +02:00
LCL: Restore function MinimizeName which was deleted in r62444 #d0ca74aa06. Needed at least for Delphi compatibility.
git-svn-id: trunk@62448 -
This commit is contained in:
parent
0ff93d16af
commit
bfee802bc9
@ -222,11 +222,73 @@ Type
|
|||||||
property OnUTF8KeyPress;
|
property OnUTF8KeyPress;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function MinimizeName(FileName: String; Canvas: TCanvas; MaxWidth: Integer): String;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
function MinimizeName(FileName: String; Canvas: TCanvas; MaxWidth: Integer): String;
|
||||||
|
{
|
||||||
|
This function will return a shortened version of FileName, so that it fits
|
||||||
|
on the given Canvas, with a given MaxWidth.
|
||||||
|
eg. C:\Documents and Settings\User\Application Data\Microsoft\Word\custom.dic
|
||||||
|
would become something like: C:\...\Word\custom.dic
|
||||||
|
}
|
||||||
|
procedure RemoveFirstDir(var Dir: String);
|
||||||
|
{
|
||||||
|
This procedure will remove the first directory from Dir
|
||||||
|
and will set ADelim to the Delimiter that separated the first Dir
|
||||||
|
eg. In: Dir: 'Dir1\Dir2\Dir3'
|
||||||
|
}
|
||||||
|
var p: Integer;
|
||||||
|
begin
|
||||||
|
p:= Pos(PathDelim,Dir);
|
||||||
|
if (p > 0) then
|
||||||
|
begin
|
||||||
|
Dir := Copy(Dir,p+1,Length(Dir)-p);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var Drive, Dir, Fn: String;
|
||||||
|
ComposedName: String;
|
||||||
|
TWidth: Integer;
|
||||||
|
begin
|
||||||
|
Result := FileName;
|
||||||
|
//if FileName does not contain any (sub)dir then return FileName
|
||||||
|
if Pos(PathDelim, FileName) = 0 then Exit;
|
||||||
|
//if FileName fits, no need to do anyhing
|
||||||
|
if Canvas.TextWidth(FileName) <= MaxWidth then Exit;
|
||||||
|
Drive := ExtractFileDrive(FileName);
|
||||||
|
Fn := ExtractFileName(FileName);
|
||||||
|
Dir := ExtractFilePath(FileName);
|
||||||
|
//Remove Drive from Dir
|
||||||
|
if (Length(Drive) > 0) then System.Delete(Dir, 1, Length(Drive));
|
||||||
|
//Transfer all PathDelimiters at the start of Dir to Drive
|
||||||
|
While (Length(Dir) > 0) and (Dir[1] in ['/','\']) do
|
||||||
|
begin
|
||||||
|
Drive := Drive + Dir[1];
|
||||||
|
System.Delete(Dir,1,1);
|
||||||
|
end;
|
||||||
|
//if Dir is empty then we cannot shorten it,
|
||||||
|
//and we know at this point that Drive+FileName is too long, so we return only filename
|
||||||
|
if (Length(Dir) = 0) then
|
||||||
|
begin
|
||||||
|
Result := Fn;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
repeat
|
||||||
|
//at this point we know that Dir ends with PathDelim (otherwise we exited before this point,
|
||||||
|
//so RemoveFirstDir will return a truncated Dir or an empty string
|
||||||
|
RemoveFirstDir(Dir);
|
||||||
|
ComposedName := Drive+'...'+PathDelim+Dir+Fn;
|
||||||
|
TWidth := Canvas.TextWidth(ComposedName);
|
||||||
|
until (Length(Dir) = 0) or (TWidth <= MaxWidth);
|
||||||
|
if (TWidth <= MaxWidth) then Result := ComposedName else Result := Fn;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TCustomFileListBox }
|
{ TCustomFileListBox }
|
||||||
|
|
||||||
procedure TCustomFileListBox.UpdateFileList;
|
procedure TCustomFileListBox.UpdateFileList;
|
||||||
|
Loading…
Reference in New Issue
Block a user