IDE: Execute a shortcut command only when it is enabled.

This commit is contained in:
Juha 2021-10-06 00:30:56 +03:00
parent 8c248da41d
commit b6a4282835
2 changed files with 12 additions and 4 deletions

View File

@ -570,6 +570,7 @@ type
FOnUpdateProc: TNotifyProcedure;
FUsers: TIDESpecialCommands;
function GetEnabled: Boolean;
function GetUser(Index: Integer): TIDESpecialCommand;
function GetUserCount: Integer;
procedure SetOnExecute(const aOnExecute: TNotifyEvent);
@ -609,7 +610,7 @@ type
procedure DoOnUpdate; overload;
procedure DoOnUpdate(Sender: TObject); overload;
public
property Enabled: Boolean write SetEnabled; // set Enabled of all "Users" TIDESpecialCommand, use Users to read
property Enabled: Boolean read GetEnabled write SetEnabled;
property Caption: string write SetCaption; // set Caption of all "Users" TIDESpecialCommand, use Users to read
property Hint: string write SetHint; // set Hint of all "Users" TIDESpecialCommand, use Users to read
// don't add Visible property here - it is not generic. Tool buttons should never be hidden programmatically
@ -1298,6 +1299,14 @@ begin
Result := FUsers[Index];
end;
function TIDECommand.GetEnabled: Boolean;
begin
if FUsers.Count > 0 then
Result := FUsers[0].Enabled
else
Result := True; // A command without SpecialCommands is enabled.
end;
function TIDECommand.GetUserCount: Integer;
begin
Result := FUsers.Count;

View File

@ -3506,7 +3506,7 @@ var
IDECmd: TIDECommand;
s: String;
begin
//debugln('TMainIDE.OnProcessIDECommand ',dbgs(Command));
//DebugLn('TMainIDE.OnProcessIDECommand START ',dbgs(Command));
Handled:=true;
case Command of
@ -3548,7 +3548,6 @@ begin
if ToolStatus = itNone then begin
if DebugBoss.InitDebugger([difInitForAttach]) then begin
s := GetPidForAttach;
if s <> '' then begin
ToolStatus := itDebugger;
DebugBoss.Attach(s);
@ -3635,7 +3634,7 @@ begin
// custom commands
IDECmd:=IDECommandList.FindIDECommand(Command);
//DebugLn('TMainIDE.OnProcessIDECommand Command=',dbgs(Command),' ',dbgs(IDECmd));
if IDECmd<>nil then
if Assigned(IDECmd) and IDECmd.Enabled then
Handled:=IDECmd.Execute(IDECmd);
end;
//DebugLn('TMainIDE.OnProcessIDECommand Handled=',dbgs(Handled),' Command=',dbgs(Command));