Skip to content

Commit 19aed92

Browse files
author
Joachim Marder
committed
* TUIRibbon.DoCommandCreated now assigns fRecentItems in case TUICommandType.ctRecentItems is created. Fixes issue #30
* Added new method TUIRibbon.AddToRecentItems() that simplifies adding a single path to the recently used list.
1 parent 631e9ff commit 19aed92

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Lib/UIRibbon.pas

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,13 @@ TUIRibbon = class(TWinControl, IUIApplication)
366366
/// Sets the "Recent items" list in the application menu.
367367
/// </summary>
368368
/// <param name="pAction">The related action for the recent items.</param>
369-
/// <param name="pPaths">The list of paths that shall be added to the list.</param>
369+
/// <param name="pPaths">The list of paths that shall be added to the recent list.</param>
370370
procedure SetRecentItems(pAction: TAction; pPaths: TStrings); overload;
371371

372+
/// Adds an item to the list of recent path.
373+
/// <param name="pPath">The path that shall be added to the recent list.</param>
374+
procedure AddToRecentItems(const pPath: string);
375+
372376
/// <summary>
373377
/// Get the currently selected "recent item".
374378
/// </summary>
@@ -653,6 +657,8 @@ procedure TUIRibbon.DoCommandCreated(const pCommand: TUICommand);
653657
pCommand.Assign(lAction)
654658
{$ifdef DEBUG}else
655659
OutputDebugString(PChar(Format(sNoMappingFound, [lMarkupItem.Name, pCommand.CommandId]))){$endif};
660+
if pCommand.CommandType = TUICommandType.ctRecentItems then
661+
fRecentItems := (pCommand as TUICommandRecentItems);
656662
end;
657663
// Try mapping ctAnchor (Tabs) to an action. If found, assign properties.
658664
// If not found, at least try to localize it.
@@ -1299,25 +1305,29 @@ procedure TUIRibbon.SetQuickAccessToolbarPosition(
12991305
end;
13001306
end;
13011307

1302-
procedure TUIRibbon.SetRecentItems(pAction: TAction; pPaths: TStrings);
1308+
procedure TUIRibbon.AddToRecentItems(const pPath: string);
13031309
var
13041310
lItem: TUIRecentItem;
1305-
lPath: string;
13061311
begin
1307-
if (not Self.Visible) then
1308-
exit;
1312+
lItem := TUIRecentItem.Create;
1313+
lItem.LabelText := pPath;
1314+
fRecentItems.Items.Add(lItem);
1315+
end;
13091316

1317+
procedure TUIRibbon.SetRecentItems(pAction: TAction; pPaths: TStrings);
1318+
var
1319+
lPath: string;
1320+
begin
13101321
if not Assigned(fRecentItems) then begin
13111322
fRecentItems := Self.GetCommand(pAction) as TUICommandRecentItems;
13121323
end;
1324+
if not Assigned(fRecentItems) then
1325+
exit;// Happens if this method is called too early, before the ribbon and its commands have been created
13131326

13141327
fRecentItems.Items.Clear();
13151328

1316-
for lPath in pPaths do begin
1317-
lItem := TUIRecentItem.Create;
1318-
lItem.LabelText := lPath;
1319-
fRecentItems.Items.Add(lItem);
1320-
end;
1329+
for lPath in pPaths do
1330+
AddToRecentItems(lPath);
13211331
end;
13221332

13231333
procedure TUIRibbon.SetTextColor(const Value: TColor);

0 commit comments

Comments
 (0)