ADD: Display drive context menu in drives list.

This commit is contained in:
cobines 2010-12-01 15:25:07 +00:00
commit 3c57f45b95
5 changed files with 63 additions and 11 deletions

View file

@ -1305,7 +1305,7 @@ begin
pt.X := X;
pt.Y := Y;
pt := ClientToScreen(pt);
ShowDriveContextMenu(Parent, DrivesList[Tag], pt.X, pt.Y);
ShowDriveContextMenu(Parent, DrivesList[Tag], pt.X, pt.Y, nil);
end;
end;
end;

View file

@ -51,16 +51,20 @@ procedure ShowFilePropertiesDialog(aFileSource: IFileSource; const Files: TFiles
@param(Files List of files to show context menu for. It is freed by this function.)
@param(X Screen X coordinate)
@param(Y Screen Y coordinate)
@param(CloseEvent Method called when popup menu is closed (optional))
}
procedure ShowContextMenu(Owner: TWinControl; var Files : TFiles; X, Y : Integer; Background: Boolean);
procedure ShowContextMenu(Owner: TWinControl; var Files : TFiles; X, Y : Integer;
Background: Boolean; CloseEvent: TNotifyEvent);
{en
Show drive context menu
@param(Owner Parent window)
@param(sPath Path to drive)
@param(X Screen X coordinate)
@param(Y Screen Y coordinate)
@param(CloseEvent Method called when popup menu is closed (optional))
}
procedure ShowDriveContextMenu(Owner: TWinControl; ADrive: PDrive; X, Y : Integer);
procedure ShowDriveContextMenu(Owner: TWinControl; ADrive: PDrive; X, Y : Integer;
CloseEvent: TNotifyEvent);
{en
Show open icon dialog
@param(Owner Owner)
@ -121,7 +125,8 @@ begin
end;
{$ENDIF}
procedure ShowContextMenu(Owner: TWinControl; var Files : TFiles; X, Y : Integer; Background: Boolean);
procedure ShowContextMenu(Owner: TWinControl; var Files : TFiles; X, Y : Integer;
Background: Boolean; CloseEvent: TNotifyEvent);
{$IFDEF MSWINDOWS}
begin
if Files.Count = 0 then
@ -133,6 +138,7 @@ begin
try
// Create new context menu
ShellContextMenu:= TShellContextMenu.Create(Owner, Files, Background);
ShellContextMenu.OnClose := CloseEvent;
// Show context menu
ShellContextMenu.PopUp(X, Y);
finally
@ -152,12 +158,14 @@ begin
FreeThenNil(ShellContextMenu);
// Create new context menu
ShellContextMenu:= TShellContextMenu.Create(Owner, Files, Background);
ShellContextMenu.OnClose := CloseEvent;
// Show context menu
ShellContextMenu.PopUp(X, Y);
end;
{$ENDIF}
procedure ShowDriveContextMenu(Owner: TWinControl; ADrive: PDrive; X, Y : Integer);
procedure ShowDriveContextMenu(Owner: TWinControl; ADrive: PDrive; X, Y : Integer;
CloseEvent: TNotifyEvent);
{$IFDEF MSWINDOWS}
var
aFile: TFile;
@ -170,7 +178,7 @@ begin
Files:= TFiles.Create(EmptyStr); // free in ShowContextMenu
Files.Add(aFile);
OldErrorMode:= SetErrorMode(SEM_FAILCRITICALERRORS or SEM_NOOPENFILEERRORBOX);
ShowContextMenu(Owner, Files, X, Y, False);
ShowContextMenu(Owner, Files, X, Y, False, CloseEvent);
SetErrorMode(OldErrorMode);
end;
{$ELSE}
@ -179,6 +187,7 @@ begin
FreeThenNil(ShellContextMenu);
// Create new context menu
ShellContextMenu:= TShellContextMenu.Create(Owner, ADrive);
ShellContextMenu.OnClose := CloseEvent;
// show context menu
ShellContextMenu.PopUp(X, Y);
end;
@ -276,4 +285,4 @@ begin
end;
end.

View file

@ -51,6 +51,7 @@ type
TShellContextMenu = class
private
FOnClose: TNotifyEvent;
FOwner: TWinControl;
FFiles: TFiles;
FBackground: Boolean;
@ -61,6 +62,7 @@ type
constructor Create(Owner: TWinControl; var Files : TFiles; Background: Boolean); reintroduce;
destructor Destroy; override;
procedure PopUp(X, Y: Integer);
property OnClose: TNotifyEvent read FOnClose write FOnClose;
property Menu: IContextMenu2 read FShellMenu2 write FShellMenu2;
end;
@ -463,6 +465,9 @@ begin
on e: EOleError do
raise EContextMenuException.Create(e.Message);
end;
if Assigned(FOnClose) then
FOnClose(Self);
end;
end.

View file

@ -683,7 +683,7 @@ begin
try
if aFiles.Count > 0 then
try
ShowContextMenu(frmMain, aFiles, X, Y, Background);
ShowContextMenu(frmMain, aFiles, X, Y, Background, nil);
except
on e: EContextMenuException do
ShowException(e);

View file

@ -64,6 +64,8 @@ type
procedure SelectDrive(ADriveIndex: Integer);
procedure DoDriveSelected(ADriveIndex: Integer);
procedure ShowContextMenu(ADriveIndex: Integer; X, Y: Integer);
procedure ContextMenuClosed(Sender: TObject);
{en
Checks if the given shortcut is assigned to a drive.
@ -119,7 +121,7 @@ implementation
uses
StdCtrls, Graphics, LCLProc,
uPixMapManager, uOSUtils, uDCUtils;
uPixMapManager, uOSUtils, uDCUtils, uOSForms;
const
DriveIconSize = 16;
@ -323,7 +325,14 @@ begin
if (ACol < 0) or (ARow < 0) then
Close
else
SelectDrive(GetDriveIndexByRow(ARow));
begin
case Button of
mbLeft:
SelectDrive(GetDriveIndexByRow(ARow));
mbRight:
ShowContextMenu(GetDriveIndexByRow(ARow), X, Y);
end;
end;
end;
end;
@ -397,6 +406,8 @@ end;
procedure TDrivesListPopup.KeyDownEvent(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Rect: TRect;
begin
case Key of
VK_HOME:
@ -437,6 +448,12 @@ begin
Close;
Key := 0;
end;
VK_APPS:
begin
Rect := CellRect(2, Row);
ShowContextMenu(GetDriveIndexByRow(Row), Rect.Left, Rect.Top);
Key := 0;
end;
end;
end;
@ -468,6 +485,27 @@ begin
FOnDriveSelected(Self, ADriveIndex, FPanel);
end;
procedure TDrivesListPopup.ShowContextMenu(ADriveIndex: Integer; X, Y: Integer);
var
pt: TPoint;
begin
if (ADriveIndex >= 0) and (ADriveIndex < FDrivesList.Count) then
begin
pt.X := X;
pt.Y := Y;
pt := ClientToScreen(pt);
// Context menu usually captures mouse so we have to disable ours.
MouseCapture := False;
ShowDriveContextMenu(Self, FDrivesList[ADriveIndex], pt.X, pt.Y, @ContextMenuClosed);
end;
end;
procedure TDrivesListPopup.ContextMenuClosed(Sender: TObject);
begin
MouseCapture := True;
end;
function TDrivesListPopup.CheckShortcut(AShortcut: TUTF8Char): Boolean;
var
i: Integer;
@ -558,4 +596,4 @@ begin
end;
end.