fixed renaming unit

git-svn-id: trunk@4141 -
This commit is contained in:
mattias 2003-05-09 13:24:32 +00:00
parent ac301233b5
commit fd99e419e3
3 changed files with 43 additions and 7 deletions

View File

@ -304,7 +304,7 @@ end;
function TCodeCache.SaveBufferAs(OldBuffer: TCodeBuffer;
const AFilename: string; var NewBuffer: TCodeBuffer): boolean;
begin
//writeln('[TCodeCache.SaveBufferAs] ',OldBuffer.Filename,' ',AFilename);
//writeln('[TCodeCache.SaveBufferAs] ',OldBuffer.Filename,' ',AFilename);
if (OldBuffer=nil) then begin
NewBuffer:=nil;
Result:=false;
@ -316,14 +316,14 @@ begin
exit;
end;
NewBuffer:=FindFile(AFilename);
//writeln('[TCodeCache.SaveBufferAs] B ',NewBuffer=nil);
//WriteAllFileNames;
//writeln('[TCodeCache.SaveBufferAs] B ',NewBuffer=nil);
//WriteAllFileNames;
if NewBuffer=nil then begin
NewBuffer:=TCodeBuffer.Create;
NewBuffer.FileName:=AFilename;
NewBuffer.Source:=OldBuffer.Source;
Result:=NewBuffer.Save;
//writeln('[TCodeCache.SaveBufferAs] C ',Result,' ',NewBuffer.IsVirtual);
//writeln('[TCodeCache.SaveBufferAs] C ',Result,' ',NewBuffer.IsVirtual);
if not Result then begin
NewBuffer.Free;
NewBuffer:=nil;

View File

@ -1519,6 +1519,7 @@ resourcestring
// file checks
lisUnableToCreateFile = 'Unable to create file';
lisCanNotCreateFile = 'Can not create file %s%s%s';
lisUnableToCreateFilename = 'Unable to create file %s%s%s.';
lisUnableToWriteFile = 'Unable to write file';
lisUnableToWriteFilename = 'Unable to write file %s%s%s.';
@ -2034,6 +2035,10 @@ resourcestring
lisPckEditpackageNotSaved = 'package %s not saved';
lisPckEditReadOnly = 'Read Only: %s';
lisPckEditModified = 'Modified: %s';
lisPkgEditNewUnitNotInUnitpath = 'New unit not in unitpath';
lisPkgEditTheFileIsCurrentlyNotInTheUnitpathOfThePackage = 'The file %s%s%s%'
+'sis currently not in the unitpath of the package.%s%sAdd %s%s%s to '
+'UnitPath?';
// package options dialog
lisPckOptsUsage = 'Usage';

View File

@ -39,9 +39,10 @@ interface
uses
Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls, Buttons,
LResources, Graphics, LCLType, Menus, Dialogs, Laz_XMLCfg, AVL_Tree, IDEProcs,
LazConf, LazarusIDEStrConsts, IDEOptionDefs, IDEDefs, CompilerOptions,
ComponentReg, PackageDefs, PkgOptionsDlg, AddToPackageDlg, PackageSystem;
LResources, Graphics, LCLType, Menus, Dialogs, FileCtrl, Laz_XMLCfg, AVL_Tree,
IDEProcs, LazConf, LazarusIDEStrConsts, IDEOptionDefs, IDEDefs,
CompilerOptions, ComponentReg, PackageDefs, PkgOptionsDlg, AddToPackageDlg,
PackageSystem;
type
TOnOpenFile =
@ -162,6 +163,7 @@ type
function GetCurrentFile(var Removed: boolean): TPkgFile;
function StoreCurrentTreeSelection: TStringList;
procedure ApplyTreeSelection(ASelection: TStringList; FreeList: boolean);
procedure ExtendUnitPathForNewUnit(const AFilename: string);
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -769,6 +771,7 @@ begin
d2ptUnit:
begin
ExtendUnitPathForNewUnit(AddParams.UnitFilename);
// add unit file
with AddParams do
LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal);
@ -791,6 +794,7 @@ begin
d2ptNewComponent:
begin
ExtendUnitPathForNewUnit(AddParams.UnitFilename);
// add file
with AddParams do
LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal);
@ -1579,6 +1583,33 @@ begin
if FreeList then ASelection.Free;
end;
procedure TPackageEditorForm.ExtendUnitPathForNewUnit(const AFilename: string);
var
NewDirectory: String;
UnitPath: String;
i: Integer;
begin
if LazPackage=nil then exit;
// check if directory is already in the unit path of the package
NewDirectory:=ExtractFilePath(AFilename);
UnitPath:=LazPackage.GetUnitPath(false);
i:=SearchDirectoryInSearchPath(UnitPath,NewDirectory,1);
if i>=1 then begin
// directory is there
exit;
end;
// ask user to add the unit path
LazPackage.ShortenFilename(NewDirectory);
if MessageDlg(lisPkgEditNewUnitNotInUnitpath,
Format(lisPkgEditTheFileIsCurrentlyNotInTheUnitpathOfThePackage, ['"',
AFilename, '"', #13, #13, #13, '"', NewDirectory, '"']),
mtConfirmation,[mbYes,mbNo],0)<>mrYes
then exit;
// add path
with LazPackage.CompilerOptions do
OtherUnitFiles:=MergeSearchPaths(OtherUnitFiles,NewDirectory);
end;
procedure TPackageEditorForm.DoSave(SaveAs: boolean);
begin
PackageEditors.SavePackage(LazPackage,SaveAs);