ide: implement "Open unit" dialog

git-svn-id: trunk@52272 -
This commit is contained in:
ondrej 2016-05-03 13:36:39 +00:00
parent fd5482a304
commit b04af8ad35
11 changed files with 94 additions and 28 deletions

1
.gitattributes vendored
View File

@ -6119,6 +6119,7 @@ images/actions/laz_edit.png -text svneol=unset#image/png
images/actions/laz_export.png -text svneol=unset#image/png
images/actions/laz_highlighter.png -text svneol=unset#image/png
images/actions/laz_open.png -text svneol=unset#image/png
images/actions/laz_openunit.png -text
images/actions/laz_refresh.png -text svneol=unset#image/png
images/actions/laz_save.png -text svneol=unset#image/png
images/actions/laz_set_color_default.png -text svneol=unset#image/png

View File

@ -168,6 +168,7 @@ const
ecCleanDirectory = ecFirstLazarus + 212;
ecRestart = ecFirstLazarus + 213;
ecQuit = ecFirstLazarus + 214;
ecOpenUnit = ecFirstLazarus + 215;
// IDE navigation
ecToggleFormUnit = ecFirstLazarus + 301;

View File

@ -492,6 +492,7 @@ begin
ecNewUnit : Result:= lisMenuNewUnit;
ecNewForm : Result:= lisMenuNewForm;
ecOpen : Result:= lisMenuOpen;
ecOpenUnit : Result:= lisMenuOpenUnit;
ecRevert : Result:= lisMenuRevert;
ecSave : Result:= lisSave;
ecSaveAs : Result:= lisMenuSaveAs;
@ -1229,6 +1230,7 @@ begin
ecNewUnit: SetSingle(VK_UNKNOWN,[]);
ecNewForm: SetSingle(VK_UNKNOWN,[]);
ecOpen: SetSingle(VK_O,[XCtrl]);
ecOpenUnit: SetSingle(VK_F12,[ssAlt]);
ecRevert: SetSingle(VK_UNKNOWN,[]);
ecSave: SetSingle(VK_S,[XCtrl]);
ecSaveAs: SetSingle(VK_UNKNOWN,[]);
@ -1668,6 +1670,7 @@ begin
ecNewUnit: SetSingle(VK_UNKNOWN,[]);
ecNewForm: SetSingle(VK_UNKNOWN,[]);
ecOpen: SetSingle(VK_F3,[]);
ecOpenUnit: SetSingle(VK_F12,[ssAlt]);
ecRevert: SetSingle(VK_UNKNOWN,[]);
ecSave: SetSingle(VK_F2,[]);
ecSaveAs: SetSingle(VK_UNKNOWN,[]);
@ -2289,6 +2292,7 @@ begin
ecNewUnit: SetSingle(VK_UNKNOWN,[]);
ecNewForm: SetSingle(VK_UNKNOWN,[]);
ecOpen: SetSingle(VK_O,[ssMeta]);
ecOpenUnit: SetSingle(VK_F12,[ssAlt]);
ecRevert: SetSingle(VK_UNKNOWN,[]);
ecSave: SetSingle(VK_S,[ssMeta]);
ecSaveAs: SetSingle(VK_S,[ssMeta,ssShift]);
@ -2972,6 +2976,7 @@ begin
AddDefault(C, 'NewUnit', lisKMNewUnit, ecNewUnit);
AddDefault(C, 'NewForm', lisMenuNewForm, ecNewForm);
AddDefault(C, 'Open', lisOpen, ecOpen);
AddDefault(C, 'OpenUnit', lisOpenUnit, ecOpenUnit);
AddDefault(C, 'Revert', lisMenuRevert, ecRevert);
AddDefault(C, 'Save', lisSave, ecSave);
AddDefault(C, 'SaveAs', lisKMSaveAs, ecSaveAs);

View File

@ -67,6 +67,7 @@ resourcestring
lisDlgEdit = 'Edit ...';
lisClear = 'Clear';
lisOpen = 'Open';
lisOpenUnit = 'Open Unit';
lisSave = 'Save';
lisDlgSave = 'Save ...';
lisSaveAs = 'Save As';
@ -294,6 +295,7 @@ resourcestring
lisMenuNewForm = 'New Form';
lisMenuNewOther = 'New ...';
lisMenuOpen = '&Open ...';
lisMenuOpenUnit = 'Open Unit...';
lisMenuRevert = 'Revert';
lisPESavePackageAs = 'Save Package As ...';
lisPkgEditPublishPackage = 'Publish Package';

View File

@ -195,6 +195,7 @@ type
procedure mnuNewFormClicked(Sender: TObject);
procedure mnuNewOtherClicked(Sender: TObject);
procedure mnuOpenClicked(Sender: TObject);
procedure mnuOpenUnitClicked(Sender: TObject);
procedure mnuOpenRecentClicked(Sender: TObject); override;
procedure mnuRevertClicked(Sender: TObject);
procedure mnuSaveClicked(Sender: TObject);
@ -898,7 +899,7 @@ type
function DoShowAbstractMethods: TModalResult;
function DoRemoveEmptyMethods: TModalResult;
function DoRemoveUnusedUnits: TModalResult;
function DoUseUnit: TModalResult;
function DoUseUnitDlg(DlgType: TUseUnitDialogType): TModalResult;
function DoFindOverloads: TModalResult;
function DoInitIdentCompletion(JumpToError: boolean): boolean;
function DoShowCodeContext(JumpToError: boolean): boolean;
@ -2570,6 +2571,7 @@ begin
itmFileNewForm.OnClick := @mnuNewFormClicked;
itmFileNewOther.OnClick := @mnuNewOtherClicked;
itmFileOpen.OnClick := @mnuOpenClicked;
itmFileOpenUnit.OnClick := @mnuOpenUnitClicked;
itmFileRevert.OnClick := @mnuRevertClicked;
SetRecentFilesMenu;
itmFileSave.OnClick := @mnuSaveClicked;
@ -2993,6 +2995,11 @@ begin
end;
end;
procedure TMainIDE.mnuOpenUnitClicked(Sender: TObject);
begin
DoSourceEditorCommand(ecOpenUnit);
end;
procedure TMainIDE.mnuRevertClicked(Sender: TObject);
begin
if (SourceEditorManager.ActiveSourceWindowIndex < 0)
@ -3231,6 +3238,7 @@ begin
mnuSaveClicked(Self);
end;
ecOpen: mnuOpenClicked(Self);
ecOpenUnit: DoUseUnitDlg(udOpenUnit);
ecSaveAll: DoSaveAll([sfCheckAmbiguousFiles]);
ecQuit: mnuQuitClicked(Self);
ecCompile:
@ -3277,7 +3285,7 @@ begin
ecShowAbstractMethods: DoShowAbstractMethods;
ecRemoveEmptyMethods: DoRemoveEmptyMethods;
ecRemoveUnusedUnits: DoRemoveUnusedUnits;
ecUseUnit: DoUseUnit;
ecUseUnit: DoUseUnitDlg(udUseUnit);
ecFindOverloads: DoFindOverloads;
ecFindBlockOtherEnd: DoGoToPascalBlockOtherEnd;
ecFindBlockStart: DoGoToPascalBlockStart;
@ -10067,7 +10075,7 @@ begin
Result:=ShowUnusedUnitsDialog;
end;
function TMainIDE.DoUseUnit: TModalResult;
function TMainIDE.DoUseUnitDlg(DlgType: TUseUnitDialogType): TModalResult;
var
TempEditor: TSourceEditorInterface;
DefText: String;
@ -10084,7 +10092,7 @@ begin
end;
end;
Result:=ShowUseUnitDialog(DefText);
Result:=ShowUseUnitDialog(DefText, DlgType);
end;
function TMainIDE.DoFindOverloads: TModalResult;

View File

@ -83,6 +83,7 @@ type
//itmFileOpenSave: TIDEMenuSection;
itmFileOpen: TIDEMenuCommand;
itmFileRevert: TIDEMenuCommand;
itmFileOpenUnit: TIDEMenuCommand;
//itmFileRecentOpen: TIDEMenuSection;
itmFileSave: TIDEMenuCommand;
itmFileSaveAs: TIDEMenuCommand;

View File

@ -987,6 +987,7 @@ begin
ParentMI:=itmFileOpenSave;
CreateMenuItem(ParentMI, itmFileOpen, 'itmFileOpen', lisMenuOpen, 'laz_open');
CreateMenuItem(ParentMI,itmFileRevert,'itmFileRevert',lisMenuRevert, 'menu_file_revert');
CreateMenuItem(ParentMI, itmFileOpenUnit, 'itmFileOpenUnit', lisMenuOpenUnit, 'laz_openunit');
CreateMenuSubSection(ParentMI,itmFileRecentOpen,'itmFileRecentOpen',lisMenuOpenRecent);
CreateMenuItem(ParentMI,itmFileSave,'itmFileSave',lisMenuSave,'laz_save');
CreateMenuItem(ParentMI,itmFileSaveAs,'itmFileSaveAs',lisMenuSaveAs,'menu_saveas');
@ -1499,6 +1500,7 @@ begin
itmFileNewForm.Command:=GetCommand(ecNewForm, TNewFormToolButton);
itmFileNewOther.Command:=GetCommand(ecNew);
itmFileOpen.Command:=GetCommand(ecOpen, TOpenFileToolButton);
itmFileOpenUnit.Command:=GetCommand(ecOpenUnit);
itmFileRevert.Command:=GetCommand(ecRevert);
itmFileSave.Command:=GetCommand(ecSave);
itmFileSaveAs.Command:=GetCommand(ecSaveAs);

View File

@ -34,10 +34,12 @@ uses
Dialogs, LCLProc, FileProcs, Graphics, LCLType, SourceEditor, LazIDEIntf,
IDEImagesIntf, LazarusIDEStrConsts, ProjectIntf, IDEWindowIntf, Project,
CodeCache, CodeToolManager, IdentCompletionTool, CodeTree, ListFilterEdit,
LinkScanner, EnvironmentOpts;
LinkScanner, EnvironmentOpts, MainIntf, LazFileUtils;
type
TUseUnitDialogType = (udUseUnit, udOpenUnit);
{ TUseUnitDialog }
TUseUnitDialog = class(TForm)
@ -62,9 +64,11 @@ type
FMainUsedUnits: TStringList;
FImplUsedUnits: TStringList;
FProjUnits, FOtherUnits: TStringList;
DlgType: TUseUnitDialogType;
procedure AddImplUsedUnits;
function GetProjUnits(SrcEdit: TSourceEditor): Boolean;
procedure CreateOtherUnitsList;
function SelectedUnitFileName: string;
function SelectedUnit: string;
function InterfaceSelected: Boolean;
procedure DetermineUsesSection(ACode: TCodeBuffer);
@ -73,13 +77,13 @@ type
end;
function ShowUseUnitDialog(const DefText: string): TModalResult;
function ShowUseUnitDialog(const DefText: string; const aDlgType: TUseUnitDialogType): TModalResult;
implementation
{$R *.lfm}
function ShowUseUnitDialog(const DefText: string): TModalResult;
function ShowUseUnitDialog(const DefText: string; const aDlgType: TUseUnitDialogType): TModalResult;
var
UseUnitDlg: TUseUnitDialog;
SrcEdit: TSourceEditor;
@ -100,6 +104,12 @@ begin
end;
UseUnitDlg:=TUseUnitDialog.Create(nil);
try
UseUnitDlg.DlgType := aDlgType;
case aDlgType of
udUseUnit: UseUnitDlg.Caption := dlgUseUnitCaption;
udOpenUnit: UseUnitDlg.Caption := lisOpenUnit;
end;
if not UseUnitDlg.GetProjUnits(SrcEdit) then begin
debugln(['ShowUseUnitDialog UseUnitDlg.GetProjUnits(SrcEdit) failed: ',SrcEdit.FileName]);
Exit(mrCancel);
@ -116,7 +126,8 @@ begin
// Read recent properties
EnvOptions := EnvironmentOptions.UseUnitDlgOptions;
UseUnitDlg.AllUnitsCheckBox.Checked := EnvOptions.AllUnits;
UseUnitDlg.SectionRadioGroup.ItemIndex:=Ord(EnvOptions.AddToImplementation);
UseUnitDlg.SectionRadioGroup.ItemIndex := Ord(EnvOptions.AddToImplementation);
UseUnitDlg.SectionRadioGroup.Visible := aDlgType=udUseUnit;
if (UseUnitDlg.FilterEdit.Items.Count = 0)
and UseUnitDlg.AllUnitsCheckBox.Checked then begin
@ -132,18 +143,32 @@ begin
// Write recent properties
EnvOptions.AllUnits := UseUnitDlg.AllUnitsCheckBox.Checked;
EnvOptions.AddToImplementation := Boolean(UseUnitDlg.SectionRadioGroup.ItemIndex);
if aDlgType=udUseUnit then
EnvOptions.AddToImplementation := Boolean(UseUnitDlg.SectionRadioGroup.ItemIndex);
EnvironmentOptions.UseUnitDlgOptions := EnvOptions;
s:=UseUnitDlg.SelectedUnit;
if s <> '' then begin
if UseUnitDlg.InterfaceSelected then
CTRes := CodeToolBoss.AddUnitToMainUsesSection(SrcEdit.CodeBuffer, s, '')
else
CTRes:=CodeToolBoss.AddUnitToImplementationUsesSection(SrcEdit.CodeBuffer, s, '');
if not CTRes then begin
LazarusIDE.DoJumpToCodeToolBossError;
exit(mrCancel);
case aDlgType of
udUseUnit:
begin
s:=UseUnitDlg.SelectedUnit;
if s <> '' then begin
if UseUnitDlg.InterfaceSelected then
CTRes := CodeToolBoss.AddUnitToMainUsesSection(SrcEdit.CodeBuffer, s, '')
else
CTRes:=CodeToolBoss.AddUnitToImplementationUsesSection(SrcEdit.CodeBuffer, s, '');
if not CTRes then begin
LazarusIDE.DoJumpToCodeToolBossError;
exit(mrCancel);
end;
end;
end;
udOpenUnit:
begin
s:=UseUnitDlg.SelectedUnitFileName;
if FileExistsUTF8(s) then
Result := MainIDEInterface.DoOpenEditorFile(s,-1,-1,[ofAddToRecent])
else
exit(mrCancel);
end;
end;
end;
@ -153,14 +178,12 @@ begin
end;
end;
{ TUseUnitDialog }
procedure TUseUnitDialog.FormCreate(Sender: TObject);
begin
// Internationalization
IDEDialogLayoutList.ApplyLayout(Self,500,460);
Caption := dlgUseUnitCaption;
AllUnitsCheckBox.Caption := dlgShowAllUnits;
SectionRadioGroup.Caption := dlgInsertSection;
SectionRadioGroup.Items.Clear;
@ -309,16 +332,24 @@ var
x: Integer;
begin
Result := False;
FMainUsedUnits := nil;
FImplUsedUnits := nil;
FreeAndNil(FMainUsedUnits);
FreeAndNil(FImplUsedUnits);
if SrcEdit = nil then Exit;
Assert(Assigned(SrcEdit.CodeBuffer));
if not CodeToolBoss.FindUsedUnitNames(SrcEdit.CodeBuffer, TStrings(FMainUsedUnits),
TStrings(FImplUsedUnits))
then begin
DebugLn(['ShowUseProjUnitDialog CodeToolBoss.FindUsedUnitNames failed']);
LazarusIDE.DoJumpToCodeToolBossError;
Exit;
if DlgType=udUseUnit then
begin
if not CodeToolBoss.FindUsedUnitNames(SrcEdit.CodeBuffer, TStrings(FMainUsedUnits),
TStrings(FImplUsedUnits))
then begin
DebugLn(['ShowUseProjUnitDialog CodeToolBoss.FindUsedUnitNames failed']);
LazarusIDE.DoJumpToCodeToolBossError;
Exit;
end;
end else
begin
// don't filter units in current uses sections - use empty lists
FMainUsedUnits := TStringList.Create;
FImplUsedUnits := TStringList.Create;
end;
Result := True;
if Assigned(FMainUsedUnits) then begin
@ -406,6 +437,20 @@ begin
Result := '';
end;
function TUseUnitDialog.SelectedUnitFileName: string;
var
CodeBuf: TCodeBuffer;
AUnit: string;
begin
Result := '';
AUnit := SelectedUnit;
if AUnit='' then
Exit;
CodeBuf := CodeToolBoss.FindUnitSource(SourceEditorManager.ActiveEditor.CodeBuffer, AUnit, '');
if Assigned(CodeBuf) then
Result := CodeBuf.Filename;
end;
function TUseUnitDialog.InterfaceSelected: Boolean;
begin
Result:=SectionRadioGroup.ItemIndex=0;

Binary file not shown.

After

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

View File

@ -12,6 +12,7 @@ actions/laz_delete.png
actions/laz_edit.png
actions/laz_highlighter.png
actions/laz_open.png
actions/laz_openunit.png
actions/laz_refresh.png
actions/laz_save.png
actions/laz_set_color_default.png