UPD: the Backward/Forward buttons can be enabled or disabled based on history

(cherry picked from commit d0d51b6474)
This commit is contained in:
rich2014 2026-01-05 18:11:26 +08:00 committed by Alexander Koblov
commit 99ae5e5725
3 changed files with 69 additions and 14 deletions

View file

@ -518,7 +518,9 @@ type
var DropParams: TDropParams); virtual abstract;
procedure GoToHistoryIndex(aFileSourceIndex, aPathIndex: Integer);
function hasPrevHistory: Boolean;
procedure GoToPrevHistory;
function hasNextHistory: Boolean;
procedure GoToNextHistory;
procedure SetDragCursor(Shift: TShiftState); virtual; abstract;
@ -3589,6 +3591,15 @@ begin
end;
end;
function TFileView.hasPrevHistory: Boolean;
begin
Result:= False;
if FHistory.CurrentPathIndex > 0 then
Result:= True
else if FHistory.CurrentFileSourceIndex > 0 then
Result:= True;
end;
procedure TFileView.GoToPrevHistory;
var
aFileSourceIndex, aPathIndex: Integer;
@ -3609,6 +3620,17 @@ begin
GoToHistoryIndex(aFileSourceIndex, aPathIndex);
end;
function TFileView.hasNextHistory: Boolean;
begin
Result:= False;
if FHistory.CurrentFileSourceIndex >= 0 then begin
if FHistory.CurrentPathIndex < FHistory.PathsCount[FHistory.CurrentFileSourceIndex] - 1 then
Result:= True
else if FHistory.CurrentFileSourceIndex < FHistory.Count - 1 then
Result:= True;
end;
end;
procedure TFileView.GoToNextHistory;
var
aFileSourceIndex, aPathIndex: Integer;

View file

@ -4822,6 +4822,9 @@ begin
ANoteBook.Hint := FileView.CurrentPath;
end;
if Assigned(onFileViewUpdated) then
onFileViewUpdated(FileView);
{if (fspDirectAccess in FileView.FileSource.GetProperties) then
begin
if gTermWindow and Assigned(Cons) then

View file

@ -55,21 +55,49 @@ begin
end;
procedure onFileViewUpdated( const fileView: TFileView );
var
itemGroup: NSToolbarItemGroup;
itemGroupWrapper: TCocoaToolBarItemGroupWrapper;
begin
itemGroup:= NSToolbarItemGroup( TCocoaToolBarUtils.findItemByIdentifier( frmMain, 'MainForm.ShowMode' ) );
if NOT Assigned(itemGroup) then
Exit;
itemGroupWrapper:= TCocoaToolBarItemGroupWrapper( itemGroup.target );
if fileView is TColumnsFileView then
itemGroupWrapper.lclSetSelectedIndex( 1 )
else if fileView is TBriefFileView then
itemGroupWrapper.lclSetSelectedIndex( 0 )
else if fileView is TThumbFileView then
itemGroupWrapper.lclSetSelectedIndex( 2 );
procedure updateShowMode;
var
itemGroup: NSToolbarItemGroup;
itemGroupWrapper: TCocoaToolBarItemGroupWrapper;
begin
itemGroup:= NSToolbarItemGroup( TCocoaToolBarUtils.findItemByIdentifier( frmMain, 'MainForm.ShowMode' ) );
if NOT Assigned(itemGroup) then
Exit;
itemGroupWrapper:= TCocoaToolBarItemGroupWrapper( itemGroup.target );
if fileView is TColumnsFileView then
itemGroupWrapper.lclSetSelectedIndex( 1 )
else if fileView is TBriefFileView then
itemGroupWrapper.lclSetSelectedIndex( 0 )
else if fileView is TThumbFileView then
itemGroupWrapper.lclSetSelectedIndex( 2 );
end;
procedure updateBackward;
var
item: NSToolbarItem;
begin
item:= TCocoaToolBarUtils.findItemByIdentifier( frmMain, 'MainForm.GoBackward' );
if NOT Assigned(item) then
Exit;
item.setEnabled( fileView.hasPrevHistory );
end;
procedure updateForward;
var
item: NSToolbarItem;
begin
item:= TCocoaToolBarUtils.findItemByIdentifier( frmMain, 'MainForm.GoForward' );
if NOT Assigned(item) then
Exit;
item.setEnabled( fileView.hasNextHistory );
end;
begin
updateShowMode;
updateBackward;
updateForward;
end;
function onGetSharingItems( item: NSToolBarItem ): TStringArray;
@ -452,6 +480,7 @@ const
identifier: 'MainForm.GoBackward';
priority: NSToolbarItemVisibilityPriorityStandard;
navigational: False;
appValidates: True;
iconName: 'chevron.backward';
title: rsMFSTBIGoBackwardTitle;
tips: rsMFSTBIGoBackwardTips;
@ -463,6 +492,7 @@ const
identifier: 'MainForm.GoForward';
priority: NSToolbarItemVisibilityPriorityStandard;
navigational: False;
appValidates: True;
iconName: 'chevron.forward';
title: rsMFSTBIGoForwardTitle;
tips: rsMFSTBIGoForwardTips;