📄 mrumgr.pas
字号:
unit MRUMgr;
interface
uses
Windows, Messages, SysUtils, Classes, Forms, IniFiles;
type
TMRUMgr = class
private
FIniFileName: string;
FItems: TStrings;
public
constructor Create(IniFileName: string);
destructor Destroy; override;
property Items: TStrings read FItems;
procedure AddMRU(Item: string);
procedure ReadMRU(var Items: TStrings);
procedure WriteMRU(Items: TStrings);
function GetLimitLenStr(S: string; MaxLen: Integer): string;
end;
var
MRUManager: TMRUMgr;
implementation
uses Misc;
constructor TMRUMgr.Create(IniFileName: string);
begin
FIniFileName := IniFileName;
FItems := TStringList.Create;
ReadMRU(FItems);
end;
destructor TMRUMgr.Destroy;
begin
FItems.Free;
end;
procedure TMRUMgr.AddMRU(Item: string);
var
i: Integer;
begin
for i := 0 to FItems.Count - 1 do
begin
if UpperCase(FItems[i]) = UpperCase(Item) then
begin
FItems[i] := FItems[0];
FItems[0] := Item;
WriteMRU(FItems);
Exit;
end;
end;
if FItems.Count < 4 then FItems.Add('');
for i := FItems.Count - 1 downto 1 do
FItems[i] := FItems[i - 1];
FItems[0] := Item;
WriteMRU(FItems);
end;
procedure TMRUMgr.ReadMRU(var Items: TStrings);
var
Ini: TIniFile;
i: Integer;
S: string;
begin
Ini := TIniFile.Create(FIniFileName);
Items.Clear;
for i := 1 to 4 do
begin
S := Ini.ReadString('MRU', 'File' + IntToStr(i), '');
if S <> '' then Items.Add(S);
end;
Ini.Free;
end;
procedure TMRUMgr.WriteMRU(Items: TStrings);
var
Ini: TIniFile;
i: Integer;
begin
Ini := TIniFile.Create(FIniFileName);
Ini.EraseSection('MRU');
for i := 0 to Items.Count - 1 do
Ini.WriteString('MRU', 'File' + IntToStr(i+1), Items[i]);
Ini.Free;
end;
function TMRUMgr.GetLimitLenStr(S: string; MaxLen: Integer): string;
var
Temp: string;
i: Integer;
begin
if Length(S) <= MaxLen then
Result := S
else
begin
for i := 1 to Length(S) do
begin
if S[i] = '\' then
begin
Temp := '...' + Copy(S, i, Length(S) - i + 1);
if Length(Temp) <= MaxLen then
begin
Result := Temp;
Exit;
end;
end;
end;
Result := Copy(S, Length(S) - MaxLen, MaxLen);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -