{
Component : TFavoritesMenu
Description: VCL component show a Menu with all your favorites internet
link present in your favorite Directory. (Internet Explorer only).
Version: 1.00 (Delphi 5)
Date: 06/28/2001
Company: Lighteam - ERKA S.L.
Copyrights...
FREEWARE
you can freely use or distribute files included to this archive.
The authors grant you the right to modify/change the source code as long as the
original authors are mentionned. Please let us know if you make any improvements,
so that we can keep an up to date version. We also welcome all comments,
preferably by email.
These components are supplied with no guarantees of any kind and must be used at
your own risk.
Help:
}
unit FavoritesMenu;
procedure TFavoritesMenu.DoClickUrl(Sender: TObject);
begin
if Assigned(FOnUrlClick) then FOnUrlClick(Sender, TMenuItem(Sender).Hint);
end;
function TFavoritesMenu.ReadUrl(AFileName: string): string;
var
Reg: TIniFile;
begin
Reg := TIniFile.Create(AFileName);
result := Reg.ReadString('InternetShortcut', 'URL', 'non url');
Reg.Free;
end;
function TFavoritesMenu.CreateMenuOption(AFileName: string; AMenuItem:
TMenuItem): TMenuItem;
var
Item: TMenuItem;
Cap: string;
Url: string;
begin
Item := TMenuItem.Create(AMenuItem);
Cap := Copy(ExtractFileName(AFileName), 1,
Length(ExtractFileName(AFileName)) - 4);
if Length(Cap) > FMaxLength then
Cap := Copy(Cap, 1, FMaxLength) + '..';
Item.ImageIndex := FImageUrl;
Item.Caption := Cap;
Item.Hint := ReadUrl(AFileName);
Item.OnClick := DoClickUrl;
AMenuItem.Add(Item);
result := Item;
end;
function PosRight(sub: char; s: string): integer;
var
i: integer;
begin
result := -1;
for i := Length(s) downto 1 do
if s = sub then
begin
result := i;
break;
end;
end;
function TFavoritesMenu.CreateMenuOptionDir(AFileName: string; AMenuItem:
TMenuItem): TMenuItem;
var
Item: TMenuItem;
p: integer;
begin
Item := TMenuItem.Create(AMenuItem);
p := PosRight('/', AFileName);
Item.Caption := Copy(AFileName, p + 1, Length(AfileName));
Item.ImageIndex := FImageFolder;
AMenuItem.Add(Item);
result := Item;
end;
procedure TFavoritesMenu.FillFavorites(Directory: string;
AMenuItem: TMenuItem);
var
search: TSearchRec;
Item: TMenuItem;
begin
if Directory[length(Directory)] <> '/' then Directory := Directory + '/';
if FindFirst(Directory + '*.*', faArchive + fadirectory, search) = 0 then
begin
repeat
if ((search.Attr and fadirectory) = fadirectory) and (search.name[1] <>
'.') then
begin
Item := CreateMenuOptionDir(Directory + search.Name, AMenuItem);
FillFavorites(Directory + search.Name, Item);
end
else if ((search.Attr and faArchive) = faArchive) then
CreateMenuOption(Directory + search.Name, AMenuItem);
until FindNext(search) <> 0;
FindClose(search);
end;
end;
procedure TFavoritesMenu.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent = FMenuItem) then FMenuItem := nil;
end;