mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-24 03:42:35 +02:00
IDE, IDEIntf: add icons to project files in recent drop-down menu
git-svn-id: trunk@51233 -
This commit is contained in:
parent
d593e000f8
commit
3a1c8fac99
@ -18,7 +18,7 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LazFileUtils, Controls, Forms, AvgLvlTree,
|
||||
NewItemIntf, ProjPackIntf, CompOptsIntf, ObjInspStrConsts, LazFileCache,
|
||||
LazMethodList;
|
||||
LazMethodList, ImgList, Graphics;
|
||||
|
||||
const
|
||||
FileDescGroupName = 'File';
|
||||
@ -585,6 +585,9 @@ const
|
||||
);
|
||||
|
||||
|
||||
function LoadProjectIconIntoImages(const ProjFile: string;
|
||||
const Images: TCustomImageList; const Index: TStrings): Integer;
|
||||
|
||||
function ProjectFlagsToStr(Flags: TProjectFlags): string;
|
||||
function StrToProjectSessionStorage(const s: string): TProjectSessionStorage;
|
||||
function CompilationExecutableTypeNameToType(const s: string
|
||||
@ -694,6 +697,44 @@ begin
|
||||
Result:=ProjectDescriptors.FindByName(ProjDescNameEmpty);
|
||||
end;
|
||||
|
||||
function LoadProjectIconIntoImages(const ProjFile: string;
|
||||
const Images: TCustomImageList; const Index: TStrings): Integer;
|
||||
var
|
||||
xIconFile: RawByteString;
|
||||
xIcon: TIcon;
|
||||
I: Integer;
|
||||
begin
|
||||
//ToDo: better index
|
||||
|
||||
I := Index.IndexOf(ProjFile);
|
||||
if I >= 0 then
|
||||
Exit(NativeInt(Index.Objects[I]));
|
||||
|
||||
Result := -1;
|
||||
xIconFile := ChangeFileExt(ProjFile, '.ico');
|
||||
if FileExists(xIconFile) then
|
||||
begin
|
||||
xIcon := TIcon.Create;
|
||||
try
|
||||
xIcon.LoadFromFile(xIconFile);
|
||||
for I := 0 to xIcon.Count-1 do
|
||||
begin
|
||||
xIcon.Current := I;
|
||||
if (xIcon.Width = Images.Width)
|
||||
and(xIcon.Height = Images.Height) then
|
||||
begin
|
||||
Result := Images.AddIcon(xIcon);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
xIcon.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
Index.AddObject(ProjFile, TObject(Result));
|
||||
end;
|
||||
|
||||
function ProjectFlagsToStr(Flags: TProjectFlags): string;
|
||||
var f: TProjectFlag;
|
||||
begin
|
||||
|
||||
@ -68,7 +68,7 @@ uses
|
||||
Debugger, IDEOptionDefs, Splash, Designer,
|
||||
SourceEditor, FindInFilesDlg,
|
||||
MainBar, MainIntf, SourceSynEditor, PseudoTerminalDlg,
|
||||
DesktopManager;
|
||||
DesktopManager, ImgList;
|
||||
|
||||
type
|
||||
TResetToolFlag = (
|
||||
@ -218,10 +218,15 @@ type
|
||||
|
||||
TOpenFileToolButton = class(TIDEToolButton)
|
||||
private
|
||||
FIndex: TStringList;
|
||||
|
||||
procedure RefreshMenu(Sender: TObject);
|
||||
procedure mnuOpenFile(Sender: TObject);
|
||||
procedure mnuProjectFile(Sender: TObject);
|
||||
public
|
||||
constructor Create(aOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure DoOnAdded; override;
|
||||
end;
|
||||
|
||||
@ -411,12 +416,32 @@ end;
|
||||
|
||||
{ TOpenFileToolButton }
|
||||
|
||||
constructor TOpenFileToolButton.Create(aOwner: TComponent);
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
|
||||
FIndex := TStringList.Create;
|
||||
FIndex.Sorted := True;
|
||||
FIndex.Duplicates := dupIgnore;
|
||||
FIndex.CaseSensitive := False;
|
||||
end;
|
||||
|
||||
destructor TOpenFileToolButton.Destroy;
|
||||
begin
|
||||
FIndex.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TOpenFileToolButton.DoOnAdded;
|
||||
begin
|
||||
inherited DoOnAdded;
|
||||
|
||||
DropdownMenu := TPopupMenu.Create(Self);
|
||||
DropdownMenu.OnPopup := @RefreshMenu;
|
||||
DropdownMenu.Images := TCustomImageList.Create(Self);
|
||||
DropdownMenu.Images.Width := 16;
|
||||
DropdownMenu.Images.Height := 16;
|
||||
Style := tbsDropDown;
|
||||
end;
|
||||
|
||||
@ -439,12 +464,16 @@ procedure TOpenFileToolButton.RefreshMenu(Sender: TObject);
|
||||
procedure AddFile(const AFileName: string; const AOnClick: TNotifyEvent);
|
||||
var
|
||||
AMenuItem: TOpenFileMenuItem;
|
||||
xExt: string;
|
||||
begin
|
||||
AMenuItem := TOpenFileMenuItem.Create(DropdownMenu);
|
||||
DropdownMenu.Items.Add(AMenuItem);
|
||||
AMenuItem.OnClick := AOnClick;
|
||||
AMenuItem.FileName := AFileName;
|
||||
DropdownMenu.Items.Add(AMenuItem);
|
||||
AMenuItem.Caption := AFilename;
|
||||
xExt := ExtractFileExt(AFileName);
|
||||
if SameFileName(xExt, '.lpi') or SameFileName(xExt, '.lpr') then
|
||||
AMenuItem.ImageIndex := LoadProjectIconIntoImages(AFileName, DropdownMenu.Images, FIndex);
|
||||
end;
|
||||
|
||||
procedure AddFiles(List: TStringList; MaxCount: integer; const AOnClick: TNotifyEvent);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user