Project Inspector: A new button for adding files from file system easily. Issue #24337.

git-svn-id: trunk@46311 -
This commit is contained in:
juha 2014-09-24 17:01:50 +00:00
parent 3cc9bd1361
commit e187809d73
8 changed files with 94 additions and 126 deletions

View File

@ -90,7 +90,7 @@ object AddToProjectDialog: TAddToProjectDialog
Anchors = [akTop, akLeft, akRight] Anchors = [akTop, akLeft, akRight]
AutoComplete = True AutoComplete = True
AutoCompleteText = [cbactEnabled, cbactEndOfLineComplete, cbactSearchAscending] AutoCompleteText = [cbactEnabled, cbactEndOfLineComplete, cbactSearchAscending]
ItemHeight = 0 ItemHeight = 15
OnChange = DependPkgNameComboBoxChange OnChange = DependPkgNameComboBoxChange
TabOrder = 0 TabOrder = 0
Text = 'DependPkgNameComboBox' Text = 'DependPkgNameComboBox'
@ -136,12 +136,11 @@ object AddToProjectDialog: TAddToProjectDialog
OnSelectItem = FilesListViewSelectItem OnSelectItem = FilesListViewSelectItem
end end
object FilesDirButton: TBitBtn object FilesDirButton: TBitBtn
AnchorSideLeft.Control = FilesBrowseButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 142 Left = 6
Height = 28 Height = 27
Top = 221 Top = 233
Width = 102 Width = 96
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 6 BorderSpacing.Left = 6
@ -149,44 +148,33 @@ object AddToProjectDialog: TAddToProjectDialog
OnClick = FilesDirButtonClick OnClick = FilesDirButtonClick
TabOrder = 1 TabOrder = 1
end end
object FilesBrowseButton: TBitBtn
Left = 6
Height = 28
Top = 221
Width = 130
Anchors = [akLeft, akBottom]
AutoSize = True
Caption = 'FilesBrowseButton'
OnClick = FilesBrowseButtonClick
TabOrder = 2
end
object FilesShortenButton: TBitBtn object FilesShortenButton: TBitBtn
AnchorSideLeft.Control = FilesDirButton AnchorSideLeft.Control = FilesDirButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 250 Left = 108
Height = 28 Height = 27
Top = 221 Top = 233
Width = 135 Width = 126
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 6 BorderSpacing.Left = 6
Caption = 'FilesShortenButton' Caption = 'FilesShortenButton'
OnClick = FilesShortenButtonClick OnClick = FilesShortenButtonClick
TabOrder = 3 TabOrder = 2
end end
object FilesDeleteButton: TBitBtn object FilesDeleteButton: TBitBtn
AnchorSideLeft.Control = FilesShortenButton AnchorSideLeft.Control = FilesShortenButton
AnchorSideLeft.Side = asrBottom AnchorSideLeft.Side = asrBottom
Left = 391 Left = 240
Height = 28 Height = 27
Top = 221 Top = 233
Width = 126 Width = 118
Anchors = [akLeft, akBottom] Anchors = [akLeft, akBottom]
AutoSize = True AutoSize = True
BorderSpacing.Left = 6 BorderSpacing.Left = 6
Caption = 'FilesDeleteButton' Caption = 'FilesDeleteButton'
OnClick = FilesDeleteButtonClick OnClick = FilesDeleteButtonClick
TabOrder = 4 TabOrder = 3
end end
end end
end end

View File

@ -60,7 +60,6 @@ type
TAddToProjectDialog = class(TForm) TAddToProjectDialog = class(TForm)
AddFileListView: TListView; AddFileListView: TListView;
ButtonPanel: TButtonPanel; ButtonPanel: TButtonPanel;
FilesBrowseButton: TBitBtn;
FilesDeleteButton: TBitBtn; FilesDeleteButton: TBitBtn;
FilesDirButton: TBitBtn; FilesDirButton: TBitBtn;
FilesShortenButton: TBitBtn; FilesShortenButton: TBitBtn;
@ -91,14 +90,12 @@ type
Selected: Boolean); Selected: Boolean);
procedure NewDependButtonClick(Sender: TObject); procedure NewDependButtonClick(Sender: TObject);
procedure FilesAddButtonClick(Sender: TObject); procedure FilesAddButtonClick(Sender: TObject);
procedure FilesBrowseButtonClick(Sender: TObject);
procedure FilesDeleteButtonClick(Sender: TObject); procedure FilesDeleteButtonClick(Sender: TObject);
procedure FilesShortenButtonClick(Sender: TObject); procedure FilesShortenButtonClick(Sender: TObject);
procedure NotebookChange(Sender: TObject); procedure NotebookChange(Sender: TObject);
private private
fPackages: TAVLTree;// tree of TLazPackage or TPackageLink fPackages: TAVLTree;// tree of TLazPackage or TPackageLink
function CheckAddingFile(NewFiles: TStringList; var NewFilename: string function CheckAddingFile(NewFiles: TStringList; var NewFilename: string): TModalResult;
): TModalResult;
procedure SetupComponents; procedure SetupComponents;
procedure SetupAddEditorFilePage; procedure SetupAddEditorFilePage;
procedure SetupAddRequirementPage; procedure SetupAddRequirementPage;
@ -359,50 +356,6 @@ begin
ModalResult:=mrOk; ModalResult:=mrOk;
end; end;
procedure TAddToProjectDialog.FilesBrowseButtonClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
AFilename: string;
i: Integer;
NewListItem: TListItem;
NewPgkFileType: TPkgFileType;
ADirectory: String;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
ADirectory:=TheProject.ProjectDirectory;
if not FilenameIsAbsolute(ADirectory) then ADirectory:='';
if ADirectory<>'' then
OpenDialog.InitialDir:=ADirectory;
OpenDialog.Title:=lisOpenFile;
OpenDialog.Options:=OpenDialog.Options
+[ofFileMustExist,ofPathMustExist,ofAllowMultiSelect];
OpenDialog.Filter:=dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask
+'|'+lisLazarusUnit+' (*.pas;*.pp)|*.pas;*.pp'
+'|'+lisLazarusInclude+' (*.inc)|*.inc'
+'|'+lisLazarusForm+' (*.lfm;*.dfm)|*.lfm;*.dfm';
if OpenDialog.Execute then begin
for i:=0 to OpenDialog.Files.Count-1 do begin
AFilename:=CleanAndExpandFilename(OpenDialog.Files[i]);
if FileExistsUTF8(AFilename) then begin
NewPgkFileType:=FileNameToPkgFileType(AFilename);
if ADirectory<>'' then
AFilename:=CreateRelativePath(AFilename,ADirectory);
NewListItem:=FilesListView.Items.Add;
NewListItem.Caption:=AFilename;
NewListItem.SubItems.Add(GetPkgFileTypeLocalizedName(NewPgkFileType));
NewListItem.Selected:=True;
end;
end;
UpdateFilesButtons;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
OpenDialog.Free;
end;
end;
procedure TAddToProjectDialog.FilesDeleteButtonClick(Sender: TObject); procedure TAddToProjectDialog.FilesDeleteButtonClick(Sender: TObject);
var var
i: Integer; i: Integer;
@ -503,11 +456,6 @@ begin
CurColumn:=FilesListView.Columns.Add; CurColumn:=FilesListView.Columns.Add;
CurColumn.Caption:=dlgEnvType; CurColumn.Caption:=dlgEnvType;
with FilesBrowseButton do begin
Caption:=lisA2PAddFiles;
LoadGlyphFromResourceName(HInstance, 'laz_add');
end;
with FilesDirButton do begin with FilesDirButton do begin
Caption:=lisAddFilesInDirectory; Caption:=lisAddFilesInDirectory;
LoadGlyphFromResourceName(HInstance, 'pkg_files'); LoadGlyphFromResourceName(HInstance, 'pkg_files');

View File

@ -44,6 +44,7 @@ resourcestring
lisLazarus = 'Lazarus'; lisLazarus = 'Lazarus';
lisAdd = 'Add'; lisAdd = 'Add';
lisBtnAdd = '&Add'; lisBtnAdd = '&Add';
lisDlgAdd = 'Add ...';
lisBtnDlgAdd = '&Add ...'; lisBtnDlgAdd = '&Add ...';
lisApply = 'Apply'; lisApply = 'Apply';
lisInsert = 'Insert'; lisInsert = 'Insert';
@ -58,6 +59,7 @@ resourcestring
lisBtnReplace = '&Replace'; lisBtnReplace = '&Replace';
lisBtnDlgReplace = '&Replace ...'; lisBtnDlgReplace = '&Replace ...';
lisEdit = 'Edit'; lisEdit = 'Edit';
lisDlgEdit = 'Edit ...';
lisClear = 'Clear'; lisClear = 'Clear';
lisOpen = 'Open'; lisOpen = 'Open';
lisSave = 'Save'; lisSave = 'Save';
@ -1703,8 +1705,6 @@ resourcestring
lisCompletionLongLineHintTypeRightOnly = 'Extend right only'; lisCompletionLongLineHintTypeRightOnly = 'Extend right only';
lisCompletionLongLineHintTypeLittleLeft = 'Extend some left'; lisCompletionLongLineHintTypeLittleLeft = 'Extend some left';
lisCompletionLongLineHintTypeFullLeft = 'Extend far left'; lisCompletionLongLineHintTypeFullLeft = 'Extend far left';
dlgEdAdd = 'Add ...';
dlgEdEdit = 'Edit ...';
lisAutomaticFeatures = 'Completion and Hints'; lisAutomaticFeatures = 'Completion and Hints';
lisAutoMarkup = 'Markup and Matches'; lisAutoMarkup = 'Markup and Matches';
@ -4191,7 +4191,8 @@ resourcestring
lisPckEditCompilerOptionsForPackage = 'Compiler Options for Package %s'; lisPckEditCompilerOptionsForPackage = 'Compiler Options for Package %s';
lisPckEditSavePackage = 'Save Package'; lisPckEditSavePackage = 'Save Package';
lisPckEditCompilePackage = 'Compile package'; lisPckEditCompilePackage = 'Compile package';
lisPckEditAddAnItem = 'Add an item'; lisPckEditAddFiles = 'Add files from the file system';
lisPckEditAddOtherItems = 'Add other items';
lisPckEditRemoveSelectedItem = 'Remove selected item'; lisPckEditRemoveSelectedItem = 'Remove selected item';
lisPckEditInstallPackageInTheIDE = 'Install package in the IDE'; lisPckEditInstallPackageInTheIDE = 'Install package in the IDE';
lisUseSub = 'Use >>'; lisUseSub = 'Use >>';

View File

@ -63,7 +63,7 @@ uses
PackageIntf, PackageIntf,
// IDE // IDE
LazarusIDEStrConsts, IDEProcs, DialogProcs, IDEOptionDefs, EnvironmentOpts, LazarusIDEStrConsts, IDEProcs, DialogProcs, IDEOptionDefs, EnvironmentOpts,
PackageDefs, Project, MainIntf, PackageEditor, AddToProjectDlg; PackageDefs, Project, MainIntf, PackageEditor, AddToProjectDlg, InputHistory;
type type
TOnAddUnitToProject = TOnAddUnitToProject =
@ -97,10 +97,12 @@ type
ToolBar: TToolBar; ToolBar: TToolBar;
// toolbuttons // toolbuttons
AddBitBtn: TToolButton; AddBitBtn: TToolButton;
AddMoreBitBtn: TToolButton;
RemoveBitBtn: TToolButton; RemoveBitBtn: TToolButton;
OptionsBitBtn: TToolButton; OptionsBitBtn: TToolButton;
HelpBitBtn: TToolButton; HelpBitBtn: TToolButton;
procedure AddBitBtnClick(Sender: TObject); procedure AddBitBtnClick(Sender: TObject);
procedure AddMoreBitBtnClick(Sender: TObject);
procedure CopyMoveToDirMenuItemClick(Sender: TObject); procedure CopyMoveToDirMenuItemClick(Sender: TObject);
procedure DirectoryHierarchyButtonClick(Sender: TObject); procedure DirectoryHierarchyButtonClick(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String); procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
@ -159,6 +161,7 @@ type
ImageIndexDirectory: integer; ImageIndexDirectory: integer;
FFlags: TProjectInspectorFlags; FFlags: TProjectInspectorFlags;
FProjectNodeDataList : array [TPENodeType] of TPENodeData; FProjectNodeDataList : array [TPENodeType] of TPENodeData;
function AddOneFile(aFilename: string): TModalResult;
procedure FreeNodeData(Typ: TPENodeType); procedure FreeNodeData(Typ: TPENodeType);
function CreateNodeData(Typ: TPENodeType; aName: string; aRemoved: boolean): TPENodeData; function CreateNodeData(Typ: TPENodeType; aName: string; aRemoved: boolean): TPENodeData;
procedure SetDependencyDefaultFilename(AsPreferred: boolean); procedure SetDependencyDefaultFilename(AsPreferred: boolean);
@ -373,7 +376,62 @@ begin
end; end;
end; end;
function TProjectInspectorForm.AddOneFile(aFilename: string): TModalResult;
var
NewFile: TUnitInfo;
begin
Result := mrOK;
aFilename:=CleanAndExpandFilename(aFilename);
NewFile:=LazProject.UnitInfoWithFilename(aFilename);
if NewFile<>nil then begin
if NewFile.IsPartOfProject then Exit(mrIgnore);
end else begin
NewFile:=TUnitInfo.Create(nil);
NewFile.Filename:=aFilename;
LazProject.AddFile(NewFile,false);
end;
NewFile.IsPartOfProject:=true;
if Assigned(OnAddUnitToProject) then begin
Result:=OnAddUnitToProject(Self,NewFile);
if Result<>mrOK then Exit;
end;
FNextSelectedPart:=NewFile;
end;
procedure TProjectInspectorForm.AddBitBtnClick(Sender: TObject); procedure TProjectInspectorForm.AddBitBtnClick(Sender: TObject);
var
OpenDialog: TOpenDialog;
AFilename: string;
i: Integer;
NewListItem: TListItem;
NewPgkFileType: TPkgFileType;
ADirectory: String;
begin
OpenDialog:=TOpenDialog.Create(nil);
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
ADirectory:=LazProject.ProjectDirectory;
if not FilenameIsAbsolute(ADirectory) then ADirectory:='';
if ADirectory<>'' then
OpenDialog.InitialDir:=ADirectory;
OpenDialog.Title:=lisOpenFile;
OpenDialog.Options:=OpenDialog.Options
+[ofFileMustExist,ofPathMustExist,ofAllowMultiSelect];
OpenDialog.Filter:=dlgAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask
+'|'+lisLazarusUnit+' (*.pas;*.pp)|*.pas;*.pp'
+'|'+lisLazarusInclude+' (*.inc)|*.inc'
+'|'+lisLazarusForm+' (*.lfm;*.dfm)|*.lfm;*.dfm';
if OpenDialog.Execute then begin
for i:=0 to OpenDialog.Files.Count-1 do
if not (AddOneFile(OpenDialog.Files[i]) in [mrOk, mrIgnore]) then break;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
OpenDialog.Free;
end;
end;
procedure TProjectInspectorForm.AddMoreBitBtnClick(Sender: TObject);
var var
AddResult: TAddToProjectResult; AddResult: TAddToProjectResult;
i: Integer; i: Integer;
@ -386,22 +444,8 @@ begin
a2pFiles: a2pFiles:
begin begin
BeginUpdate; BeginUpdate;
for i:=0 to AddResult.FileNames.Count-1 do begin for i:=0 to AddResult.FileNames.Count-1 do
NewFilename:=AddResult.FileNames[i]; if not (AddOneFile(AddResult.FileNames[i]) in [mrOk, mrIgnore]) then break;
NewFile:=LazProject.UnitInfoWithFilename(NewFilename);
if NewFile<>nil then begin
if NewFile.IsPartOfProject then continue;
end else begin
NewFile:=TUnitInfo.Create(nil);
NewFile.Filename:=NewFilename;
LazProject.AddFile(NewFile,false);
end;
NewFile.IsPartOfProject:=true;
if Assigned(OnAddUnitToProject) then begin
if OnAddUnitToProject(Self,NewFile)<>mrOk then break;
end;
FNextSelectedPart:=NewFile;
end;
UpdateAll; UpdateAll;
EndUpdate; EndUpdate;
end; end;
@ -444,24 +488,9 @@ begin
if length(FileNames)=0 then exit; if length(FileNames)=0 then exit;
BeginUpdate; BeginUpdate;
try try
for i:=0 to high(Filenames) do begin for i:=0 to high(Filenames) do
NewFilename:=CleanAndExpandFilename(FileNames[i]); if not (AddOneFile(FileNames[i]) in [mrOk, mrIgnore]) then break;
if not FileExistsUTF8(NewFilename) then continue;
if DirPathExists(NewFilename) then continue;
NewFile:=LazProject.UnitInfoWithFilename(NewFilename);
if (NewFile<>nil) and (NewFile.IsPartOfProject) then continue;
{$IFDEF VerboseProjInspDrag}
debugln(['TProjectInspectorForm.FormDropFiles Adding files: ',NewFilename]);
{$ENDIF}
if NewFile=nil then begin
NewFile:=TUnitInfo.Create(nil);
NewFile.Filename:=NewFilename;
LazProject.AddFile(NewFile,false);
end;
if OnAddUnitToProject(Self,NewFile)<>mrOk then
break;
UpdateAll; UpdateAll;
end;
finally finally
EndUpdate; EndUpdate;
end; end;
@ -914,7 +943,8 @@ begin
ToolBar.Images := IDEImages.Images_16; ToolBar.Images := IDEImages.Images_16;
FilterEdit.OnGetImageIndex:=@OnTreeViewGetImageIndex; FilterEdit.OnGetImageIndex:=@OnTreeViewGetImageIndex;
AddBitBtn := CreateToolButton('AddBitBtn', lisAdd, lisPckEditAddAnItem, 'laz_add', @AddBitBtnClick); AddBitBtn := CreateToolButton('AddBitBtn', lisAdd, lisPckEditAddFiles, 'laz_add', @AddBitBtnClick);
AddMoreBitBtn := CreateToolButton('AddMoreBitBtn', lisDlgAdd, lisPckEditAddOtherItems, 'laz_addmore', @AddMoreBitBtnClick);
RemoveBitBtn := CreateToolButton('RemoveBitBtn', lisRemove, lisPckEditRemoveSelectedItem, 'laz_delete', @RemoveBitBtnClick); RemoveBitBtn := CreateToolButton('RemoveBitBtn', lisRemove, lisPckEditRemoveSelectedItem, 'laz_delete', @RemoveBitBtnClick);
CreateDivider; CreateDivider;
OptionsBitBtn := CreateToolButton('OptionsBitBtn', dlgFROpts, lisPckEditEditGeneralOptions, 'menu_environment_options', @OptionsBitBtnClick); OptionsBitBtn := CreateToolButton('OptionsBitBtn', dlgFROpts, lisPckEditEditGeneralOptions, 'menu_environment_options', @OptionsBitBtnClick);

View File

@ -423,8 +423,8 @@ begin
Columns.EndUpdate; Columns.EndUpdate;
end; end;
UserOverridesAddButton.Caption := dlgEdAdd; UserOverridesAddButton.Caption := lisDlgAdd;
UserOverridesEditButton.Caption := dlgEdEdit; UserOverridesEditButton.Caption := lisDlgEdit;
UserOverridesDeleteButton.Caption := lisDelete; UserOverridesDeleteButton.Caption := lisDelete;
IncludeSystemVariablesCheckBox.Caption := dlgIncludeSystemVariables; IncludeSystemVariablesCheckBox.Caption := dlgIncludeSystemVariables;
end; end;

Binary file not shown.

View File

@ -3,6 +3,7 @@ folder.png
template.png template.png
mainiconproject.ico mainiconproject.ico
actions/laz_add.png actions/laz_add.png
actions/laz_addmore.png
actions/arrow_down.png actions/arrow_down.png
actions/arrow_left.png actions/arrow_left.png
actions/arrow_right.png actions/arrow_right.png

View File

@ -1825,7 +1825,7 @@ begin
CompileBitBtn := CreateToolButton('CompileBitBtn', lisCompile, lisPckEditCompilePackage, 'pkg_compile', @CompileBitBtnClick); CompileBitBtn := CreateToolButton('CompileBitBtn', lisCompile, lisPckEditCompilePackage, 'pkg_compile', @CompileBitBtnClick);
UseBitBtn := CreateToolButton('UseBitBtn', lisPckEditInstall, lisPckEditInstallPackageInTheIDE, 'pkg_install', nil); UseBitBtn := CreateToolButton('UseBitBtn', lisPckEditInstall, lisPckEditInstallPackageInTheIDE, 'pkg_install', nil);
CreateDivider; CreateDivider;
AddBitBtn := CreateToolButton('AddBitBtn', lisAdd, lisPckEditAddAnItem, 'laz_add', @AddBitBtnClick); AddBitBtn := CreateToolButton('AddBitBtn', lisAdd, lisPckEditAddOtherItems, 'laz_add', @AddBitBtnClick);
RemoveBitBtn := CreateToolButton('RemoveBitBtn', lisRemove, lisPckEditRemoveSelectedItem, 'laz_delete', @RemoveBitBtnClick); RemoveBitBtn := CreateToolButton('RemoveBitBtn', lisRemove, lisPckEditRemoveSelectedItem, 'laz_delete', @RemoveBitBtnClick);
CreateDivider; CreateDivider;
OptionsBitBtn := CreateToolButton('OptionsBitBtn', dlgFROpts, lisPckEditEditGeneralOptions, 'pkg_properties', @OptionsBitBtnClick); OptionsBitBtn := CreateToolButton('OptionsBitBtn', dlgFROpts, lisPckEditEditGeneralOptions, 'pkg_properties', @OptionsBitBtnClick);