mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 01:19:16 +02:00
New file for Use Project Unit feature
git-svn-id: trunk@28796 -
This commit is contained in:
parent
b75a2a4bb5
commit
ae6986f2bd
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -3895,6 +3895,8 @@ ide/unitinfodlg.lfm svneol=native#text/plain
|
|||||||
ide/unitinfodlg.pp svneol=native#text/pascal
|
ide/unitinfodlg.pp svneol=native#text/pascal
|
||||||
ide/unusedunitsdlg.lfm svneol=native#text/plain
|
ide/unusedunitsdlg.lfm svneol=native#text/plain
|
||||||
ide/unusedunitsdlg.pas svneol=native#text/plain
|
ide/unusedunitsdlg.pas svneol=native#text/plain
|
||||||
|
ide/useprojunitdlg.lfm svneol=native#text/plain
|
||||||
|
ide/useprojunitdlg.pas svneol=native#text/pascal
|
||||||
ide/version.inc svneol=native#text/plain
|
ide/version.inc svneol=native#text/plain
|
||||||
ide/viewunit_dlg.lfm svneol=native#text/plain
|
ide/viewunit_dlg.lfm svneol=native#text/plain
|
||||||
ide/viewunit_dlg.pp svneol=native#text/pascal
|
ide/viewunit_dlg.pp svneol=native#text/pascal
|
||||||
|
71
ide/useprojunitdlg.lfm
Normal file
71
ide/useprojunitdlg.lfm
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
object UseProjUnitDialog: TUseProjUnitDialog
|
||||||
|
Left = 287
|
||||||
|
Height = 348
|
||||||
|
Top = 177
|
||||||
|
Width = 318
|
||||||
|
Caption = 'Use a Unit from this Project'
|
||||||
|
ClientHeight = 348
|
||||||
|
ClientWidth = 318
|
||||||
|
Position = poScreenCenter
|
||||||
|
LCLVersion = '0.9.29'
|
||||||
|
object ButtonPanel1: TButtonPanel
|
||||||
|
Left = 6
|
||||||
|
Height = 39
|
||||||
|
Top = 303
|
||||||
|
Width = 306
|
||||||
|
OKButton.Name = 'OKButton'
|
||||||
|
OKButton.Caption = '&OK'
|
||||||
|
HelpButton.Name = 'HelpButton'
|
||||||
|
HelpButton.Caption = '&Help'
|
||||||
|
HelpButton.Enabled = False
|
||||||
|
CloseButton.Name = 'CloseButton'
|
||||||
|
CloseButton.Caption = '&Close'
|
||||||
|
CloseButton.Enabled = False
|
||||||
|
CancelButton.Name = 'CancelButton'
|
||||||
|
CancelButton.Caption = 'Cancel'
|
||||||
|
TabOrder = 2
|
||||||
|
ShowButtons = [pbOK, pbCancel]
|
||||||
|
end
|
||||||
|
object SectionRadioGroup: TRadioGroup
|
||||||
|
AnchorSideLeft.Control = UnitsListBox
|
||||||
|
AnchorSideTop.Control = UnitsListBox
|
||||||
|
AnchorSideTop.Side = asrBottom
|
||||||
|
AnchorSideRight.Control = UnitsListBox
|
||||||
|
AnchorSideRight.Side = asrBottom
|
||||||
|
Left = 6
|
||||||
|
Height = 49
|
||||||
|
Top = 244
|
||||||
|
Width = 306
|
||||||
|
Anchors = [akTop, akLeft, akRight]
|
||||||
|
AutoFill = True
|
||||||
|
BorderSpacing.Top = 3
|
||||||
|
Caption = 'Insert into Uses Section'
|
||||||
|
ChildSizing.LeftRightSpacing = 6
|
||||||
|
ChildSizing.TopBottomSpacing = 6
|
||||||
|
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||||
|
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||||
|
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||||
|
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||||
|
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||||
|
ChildSizing.ControlsPerLine = 2
|
||||||
|
ClientHeight = 29
|
||||||
|
ClientWidth = 300
|
||||||
|
Columns = 2
|
||||||
|
ItemIndex = 1
|
||||||
|
Items.Strings = (
|
||||||
|
'Interface'
|
||||||
|
'Implementation'
|
||||||
|
)
|
||||||
|
TabOrder = 1
|
||||||
|
end
|
||||||
|
object UnitsListBox: TListBox
|
||||||
|
AnchorSideRight.Side = asrBottom
|
||||||
|
Left = 6
|
||||||
|
Height = 233
|
||||||
|
Top = 8
|
||||||
|
Width = 306
|
||||||
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
|
ItemHeight = 0
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
end
|
131
ide/useprojunitdlg.pas
Normal file
131
ide/useprojunitdlg.pas
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
unit UseProjUnitDlg;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, LCLProc, Forms, Controls, ComCtrls, StdCtrls, ExtCtrls, Buttons,
|
||||||
|
ButtonPanel, Dialogs,
|
||||||
|
SrcEditorIntf, LazIDEIntf, IDEImagesIntf, LazarusIDEStrConsts,
|
||||||
|
ProjectIntf, Project, CodeCache, CodeToolManager;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TUseProjUnitDialog }
|
||||||
|
|
||||||
|
TUseProjUnitDialog = class(TForm)
|
||||||
|
ButtonPanel1: TButtonPanel;
|
||||||
|
UnitsListBox: TListBox;
|
||||||
|
SectionRadioGroup: TRadioGroup;
|
||||||
|
private
|
||||||
|
procedure AddItems(AItems: TStrings);
|
||||||
|
function SelectFirst: string;
|
||||||
|
function SelectedUnit: string;
|
||||||
|
function InterfaceSelected: Boolean;
|
||||||
|
public
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ShowUseProjUnitDialog: TModalResult;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
function ShowUseProjUnitDialog: TModalResult;
|
||||||
|
var
|
||||||
|
UseProjUnitDlg: TUseProjUnitDialog;
|
||||||
|
SrcEdit: TSourceEditorInterface;
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
CurFile: TUnitInfo;
|
||||||
|
MainUsedUnits, ImplUsedUnits: TStrings;
|
||||||
|
AvailUnits: TStringList;
|
||||||
|
s: String;
|
||||||
|
IsIntf, CTRes: Boolean;
|
||||||
|
begin
|
||||||
|
Result:=mrOk;
|
||||||
|
if not LazarusIDE.BeginCodeTools then exit;
|
||||||
|
// get cursor position
|
||||||
|
SrcEdit:=SourceEditorManagerIntf.ActiveEditor;
|
||||||
|
if SrcEdit=nil then exit;
|
||||||
|
Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
|
||||||
|
if Code=nil then exit;
|
||||||
|
UseProjUnitDlg:=nil;
|
||||||
|
MainUsedUnits:=nil;
|
||||||
|
ImplUsedUnits:=nil;
|
||||||
|
AvailUnits:=TStringList.Create;
|
||||||
|
try
|
||||||
|
if not CodeToolBoss.FindUsedUnitNames(Code,MainUsedUnits,ImplUsedUnits) then begin
|
||||||
|
DebugLn(['ShowUseProjUnitDialog CodeToolBoss.FindUsedUnitNames failed']);
|
||||||
|
LazarusIDE.DoJumpToCodeToolBossError;
|
||||||
|
exit(mrCancel);
|
||||||
|
end;
|
||||||
|
TStringList(MainUsedUnits).CaseSensitive:=False;
|
||||||
|
TStringList(ImplUsedUnits).CaseSensitive:=False;
|
||||||
|
// Create dialog and add available unit names there.
|
||||||
|
UseProjUnitDlg:=TUseProjUnitDialog.Create(nil);
|
||||||
|
CurFile:=Project1.FirstPartOfProject;
|
||||||
|
while CurFile<>nil do begin
|
||||||
|
s:=CurFile.Unit_Name;
|
||||||
|
if (MainUsedUnits.IndexOf(s)<0) and (ImplUsedUnits.IndexOf(s)<0) then
|
||||||
|
AvailUnits.Add(s);
|
||||||
|
CurFile:=CurFile.NextPartOfProject;
|
||||||
|
end;
|
||||||
|
// Show the dialog.
|
||||||
|
if AvailUnits.Count>0 then begin
|
||||||
|
AvailUnits.Sorted:=True;
|
||||||
|
UseProjUnitDlg.AddItems(AvailUnits);
|
||||||
|
UseProjUnitDlg.SelectFirst;
|
||||||
|
if UseProjUnitDlg.ShowModal=mrOk then begin
|
||||||
|
s:=UseProjUnitDlg.SelectedUnit;
|
||||||
|
IsIntf:=UseProjUnitDlg.InterfaceSelected;
|
||||||
|
if s<>'' then begin
|
||||||
|
CTRes:=True;
|
||||||
|
if IsIntf then
|
||||||
|
CTRes:=CodeToolBoss.AddUnitToMainUsesSection(Code, s, '')
|
||||||
|
else
|
||||||
|
CTRes:=CodeToolBoss.AddUnitToImplementationUsesSection(Code, s, '');
|
||||||
|
if not CTRes then begin
|
||||||
|
LazarusIDE.DoJumpToCodeToolBossError;
|
||||||
|
exit(mrCancel);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ShowMessage('No unused items are available in this project.');
|
||||||
|
finally
|
||||||
|
CodeToolBoss.SourceCache.ClearAllSourceLogEntries;
|
||||||
|
UseProjUnitDlg.Free;
|
||||||
|
ImplUsedUnits.Free;
|
||||||
|
MainUsedUnits.Free;
|
||||||
|
AvailUnits.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TUseProjUnitDialog }
|
||||||
|
|
||||||
|
procedure TUseProjUnitDialog.AddItems(AItems: TStrings);
|
||||||
|
begin
|
||||||
|
UnitsListBox.Items.Assign(AItems);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUseProjUnitDialog.SelectFirst: string;
|
||||||
|
begin
|
||||||
|
UnitsListBox.Selected[0]:=True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUseProjUnitDialog.SelectedUnit: string;
|
||||||
|
begin
|
||||||
|
Result:=UnitsListBox.Items[UnitsListBox.ItemIndex];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUseProjUnitDialog.InterfaceSelected: Boolean;
|
||||||
|
begin
|
||||||
|
Result:=SectionRadioGroup.ItemIndex=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user