* Fast unit open package

This commit is contained in:
Michaël Van Canneyt 2025-06-20 11:23:02 +02:00
parent 0103e0a803
commit 3d540e424d
4 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,12 @@
# Fast unit open
This package registers a shortcut key for a dialog in which you can type a
unit name. The IDE will then search for the given name in the search path,
and will open the unit.
It is similar to the 'Open file at cursor' functionality but it can be used
to open a file which is not in a uses clause (or in the sources) without
having to look for it.
The dialog is registered below the 'Search' menu, and the shortcut is set to
Ctrl-Shift-Enter. This can be changed in the keymap settings.

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<Name Value="lazfastopenunit"/>
<Type Value="DesignTime"/>
<Author Value="Michael Van Canneyt (michael@freepascal.org)"/>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
</SearchPaths>
</CompilerOptions>
<Description Value="Fast open of unit file:
This functionality mimics the open file at cursor."/>
<License Value="Lazarus version of LGPL"/>
<Version Minor="1"/>
<Files>
<Item>
<Filename Value="regfastopen.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="regfastopen"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="IDEIntf"/>
</Item>
<Item>
<PackageName Value="FCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,22 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit lazfastopenunit;
{$warn 5023 off : no warning about unused units}
interface
uses
regfastopen, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('regfastopen', @regfastopen.Register);
end;
initialization
RegisterPackage('lazfastopenunit', @Register);
end.

View File

@ -0,0 +1,54 @@
unit regfastopen;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Controls, Forms, Dialogs, lclintf, LCLType,
LazIDEIntf, MenuIntf, IDECommands, IDEWindowIntf, BaseIDEIntf;
procedure register;
implementation
Resourcestring
SUnitNotFound = 'Unit "%s" not found.';
SFastOpenCaption = 'Fast open unit';
SEnterUnitName = 'Enter the unit name to search and open';
procedure ShowFastOpenUnit(Sender: TObject);
var
lUnitName : string;
lFileName : string;
begin
lUnitName:='';
if not InputQuery(SFastOpenCaption,SEnterUnitName,lUnitName) then exit;
lFileName:=LazarusIDE.FindUnitFile(lUnitName);
if lFileName='' then
MessageDlg(SFastOpenCaption,Format(SUnitNotFound,[lUnitName]),mtInformation,[mbOK],0)
else
LazarusIDE.DoOpenEditorFile(lFileName,0,0,[ofAddToRecent,ofOnlyIfExists]);
end;
procedure Register;
var
ParentCat: TIDECommandCategory;
FastOpenCommand: TIDECommand;
begin
// search shortcut category
ParentCat:=IDECommandList.FindCategoryByName(CommandCategoryToolMenuName);
// register shortcut
FastOpenCommand:=RegisterIDECommand(ParentCat,
'ViewFastOpen',SFastOpenCaption,
IDEShortCut(VK_RETURN, [ssctrl,ssShift]),nil,@ShowFastOpenUnit);
RegisterIDEMenuCommand(mnuSearch,
FastOpenCommand.Name,
SFastOpenCaption, nil, nil, FastOpenCommand);
end;
end.