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

View File

@ -1519,6 +1519,7 @@ resourcestring
// file checks // file checks
lisUnableToCreateFile = 'Unable to create file'; lisUnableToCreateFile = 'Unable to create file';
lisCanNotCreateFile = 'Can not create file %s%s%s';
lisUnableToCreateFilename = 'Unable to create file %s%s%s.'; lisUnableToCreateFilename = 'Unable to create file %s%s%s.';
lisUnableToWriteFile = 'Unable to write file'; lisUnableToWriteFile = 'Unable to write file';
lisUnableToWriteFilename = 'Unable to write file %s%s%s.'; lisUnableToWriteFilename = 'Unable to write file %s%s%s.';
@ -2034,6 +2035,10 @@ resourcestring
lisPckEditpackageNotSaved = 'package %s not saved'; lisPckEditpackageNotSaved = 'package %s not saved';
lisPckEditReadOnly = 'Read Only: %s'; lisPckEditReadOnly = 'Read Only: %s';
lisPckEditModified = 'Modified: %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 // package options dialog
lisPckOptsUsage = 'Usage'; lisPckOptsUsage = 'Usage';

View File

@ -39,9 +39,10 @@ interface
uses uses
Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls, Buttons, Classes, SysUtils, Forms, Controls, StdCtrls, ExtCtrls, ComCtrls, Buttons,
LResources, Graphics, LCLType, Menus, Dialogs, Laz_XMLCfg, AVL_Tree, IDEProcs, LResources, Graphics, LCLType, Menus, Dialogs, FileCtrl, Laz_XMLCfg, AVL_Tree,
LazConf, LazarusIDEStrConsts, IDEOptionDefs, IDEDefs, CompilerOptions, IDEProcs, LazConf, LazarusIDEStrConsts, IDEOptionDefs, IDEDefs,
ComponentReg, PackageDefs, PkgOptionsDlg, AddToPackageDlg, PackageSystem; CompilerOptions, ComponentReg, PackageDefs, PkgOptionsDlg, AddToPackageDlg,
PackageSystem;
type type
TOnOpenFile = TOnOpenFile =
@ -162,6 +163,7 @@ type
function GetCurrentFile(var Removed: boolean): TPkgFile; function GetCurrentFile(var Removed: boolean): TPkgFile;
function StoreCurrentTreeSelection: TStringList; function StoreCurrentTreeSelection: TStringList;
procedure ApplyTreeSelection(ASelection: TStringList; FreeList: boolean); procedure ApplyTreeSelection(ASelection: TStringList; FreeList: boolean);
procedure ExtendUnitPathForNewUnit(const AFilename: string);
public public
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
@ -769,6 +771,7 @@ begin
d2ptUnit: d2ptUnit:
begin begin
ExtendUnitPathForNewUnit(AddParams.UnitFilename);
// add unit file // add unit file
with AddParams do with AddParams do
LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal); LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal);
@ -791,6 +794,7 @@ begin
d2ptNewComponent: d2ptNewComponent:
begin begin
ExtendUnitPathForNewUnit(AddParams.UnitFilename);
// add file // add file
with AddParams do with AddParams do
LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal); LazPackage.AddFile(UnitFilename,UnitName,FileType,PkgFileFlags,cpNormal);
@ -1579,6 +1583,33 @@ begin
if FreeList then ASelection.Free; if FreeList then ASelection.Free;
end; 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); procedure TPackageEditorForm.DoSave(SaveAs: boolean);
begin begin
PackageEditors.SavePackage(LazPackage,SaveAs); PackageEditors.SavePackage(LazPackage,SaveAs);