Merge branch 'Cody/Dictionary/ContextPopup' into 'main'

Cody/Dictionary: Do not display popup menu if non-identifier is selected

See merge request freepascal.org/lazarus/lazarus!501
This commit is contained in:
Maxim Ganetsky 2025-06-24 22:41:36 +03:00
commit 855b1803db
3 changed files with 18 additions and 23 deletions

View File

@ -69,6 +69,7 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
BorderSpacing.Right = 6
BorderSpacing.Bottom = 1
ItemHeight = 0
OnContextPopup = ItemsListBoxContextPopup
OnDblClick = ItemsListBoxDblClick
OnSelectionChange = ItemsListBoxSelectionChange
PopupMenu = PopupMenu1
@ -163,7 +164,6 @@ object CodyIdentifiersDlg: TCodyIdentifiersDlg
TabOrder = 6
end
object PopupMenu1: TPopupMenu
OnPopup = PopupMenu1Popup
left = 177
top = 133
object JumpMenuItem: TMenuItem

View File

@ -175,7 +175,8 @@ type
procedure ItemsListBoxDblClick(Sender: TObject);
procedure ItemsListBoxSelectionChange(Sender: TObject; {%H-}User: boolean);
procedure OnIdle(Sender: TObject; var {%H-}Done: Boolean);
procedure PopupMenu1Popup(Sender: TObject);
procedure ItemsListBoxContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure StartsRadioButtonClick(Sender: TObject);
private
FDlgAction: TCodyIdentifierDlgAction;
@ -1044,29 +1045,19 @@ begin
IdleConnected:=false;
end;
procedure TCodyIdentifiersDlg.PopupMenu1Popup(Sender: TObject);
procedure TCodyIdentifiersDlg.ItemsListBoxContextPopup(Sender: TObject;
MousePos: TPoint; var Handled: Boolean);
var
Identifier: string;
UnitFilename: string;
GroupName: string;
GroupFilename: string;
Identifier, UnitFilename, GroupName, GroupFilename: string;
begin
if FindSelectedItem(Identifier, UnitFilename, GroupName, GroupFilename) then
begin
UseMenuItem.Caption:='Use '+Identifier;
UseMenuItem.Enabled:=true;
JumpMenuItem.Caption:='Jump to '+Identifier;
JumpMenuItem.Enabled:=true;
DeleteUnitMenuItem.Caption:='Delete unit '+ExtractFilename(UnitFilename);
DeleteUnitMenuItem.Enabled:=true;
DeletePackageMenuItem.Caption:='Delete package '+ExtractFilename(GroupFilename);
DeletePackageMenuItem.Enabled:=true;
end else begin
UseMenuItem.Enabled:=false;
JumpMenuItem.Enabled:=false;
DeleteUnitMenuItem.Enabled:=false;
DeletePackageMenuItem.Enabled:=false;
end;
// show popup menu only if valid identificator is selected
Handled := not FindSelectedItem(Identifier, UnitFilename, GroupName, GroupFilename);
if Handled then exit;
UseMenuItem .Caption := Format(crsContextUseIdentifier, [Identifier]);
JumpMenuItem .Caption := Format(crsContextJumpTo , [Identifier]);
DeleteUnitMenuItem .Caption := Format(crsContextDeleteUnit , [ExtractFilename(UnitFilename)]);
DeletePackageMenuItem.Caption := Format(crsContextDeletePackage, [ExtractFilename(GroupFilename)]);
end;
procedure TCodyIdentifiersDlg.StartsRadioButtonClick(Sender: TObject);

View File

@ -183,6 +183,10 @@ resourcestring
+'containing filter text';
crsUseIdentifier = '&Use identifier';
crsAndMoreIdentifiers = '... and %s more identifiers';
crsContextUseIdentifier = 'Use "%s"';
crsContextJumpTo = 'Jump to "%s"';
crsContextDeleteUnit = 'Delete unit "%s"';
crsContextDeletePackage = 'Delete package "%s"';
crsCodyIdentifierDictionary = 'Identifier Dictionary';
crsReallyDeleteTheUnitFromTheDatabaseNoteThisDoesNo = 'Really delete the '
+'unit from the database?%sNote: This does not change the source or any'