ide: Fixed problems with package renaming

git-svn-id: svn://ultimatepp.org/upp/trunk@10372 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2016-10-28 09:21:16 +00:00
parent a2fd05305e
commit 66d90187c6
4 changed files with 29 additions and 15 deletions

View file

@ -215,6 +215,8 @@ inline
String PackageDirectory(const String& name) { return GetFileDirectory(PackagePath(name)); }
bool IsNestReadOnly(const String& path);
String GetPackagePathNest(const String& path);
String GetLocalDir();
String LocalPath(const String& filename);

View file

@ -241,6 +241,15 @@ String PackagePath(const String& name)
return MainNest().PackagePath(name);
}
String GetPackagePathNest(const String& path)
{
String h = UnixPath(NormalizePath(path));
for(auto dir : GetUppDirs())
if(h.StartsWith(UnixPath(NormalizePath(dir)) + '/'))
return dir;
return Null;
}
String SourcePath(const String& package, const String& file) {
if(IsFullPath(file)) return NativePath(file);
return NormalizePath(AppendFileName(GetFileFolder(PackagePath(package)), file));

View file

@ -26,12 +26,13 @@ bool RenamePackageFs(const String& upp, const String& newname)
return false;
}
String pf = GetFileFolder(upp);
String npf = GetFileFolder(pf) + "/" + newname;
String npf = GetPackagePathNest(pf) + "/" + newname;
RealizePath(npf);
if(!FileMove(pf, npf)) {
Exclamation("Renaming package folder has failed.");
return false;
}
if(!FileMove(npf + "/" + GetFileName(upp), npf + "/" + newname + ".upp")) {
if(!FileMove(npf + "/" + GetFileName(upp), npf + "/" + GetFileName(newname) + ".upp")) {
FileMove(npf, pf);
Exclamation("Renaming .upp file has failed.");
return false;

View file

@ -977,19 +977,20 @@ void WorkspaceWork::PackageOp(String active, String from_package, String rename)
from_package = UnixPath(from_package);
rename = UnixPath(rename);
for(int i = 0; i < package.GetCount(); i++)
if(IsNull(from_package) || UnixPath(package[i].name) == from_package) {
if(*package[i].name != '<' &&
(IsNull(from_package) || UnixPath(package[i].name) == from_package)) {
String pp = PackagePath(package[i].name);
RealizePath(pp);
Package prj;
prj.Load(pp);
for(int i = prj.uses.GetCount(); --i >= 0;)
if(UnixPath(prj.uses[i].text) == active) {
if(rename.GetCount())
prj.uses[i].text = rename;
else
prj.uses.Remove(i);
}
prj.Save(pp);
if(prj.Load(pp)) {
for(int i = prj.uses.GetCount(); --i >= 0;)
if(UnixPath(prj.uses[i].text) == active) {
if(rename.GetCount())
prj.uses[i].text = rename;
else
prj.uses.Remove(i);
}
prj.Save(pp);
}
}
ScanWorkspace();
SyncWorkspace();
@ -1024,9 +1025,10 @@ again:
if(dlg.Execute() != IDOK)
return;
String pn = ~dlg.name;
if(!RenamePackageFs(GetActivePackage(), pn))
String ap = GetActivePackage();
if(!RenamePackageFs(PackagePath(ap), pn))
goto again;
PackageOp(GetActivePackage(), Null, pn);
PackageOp(ap, Null, pn);
}
void WorkspaceWork::DeletePackage()