From 281b156f591d1cc346bb5f66d47100529e194f8d Mon Sep 17 00:00:00 2001 From: micio Date: Fri, 6 Jul 2012 17:21:20 +0000 Subject: [PATCH] uppsrc/Ide : allow to have a single translation file in the main package git-svn-id: svn://ultimatepp.org/upp/trunk@5143 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/t.cpp | 55 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/uppsrc/ide/t.cpp b/uppsrc/ide/t.cpp index a58bc2c7b..9da5ffb9d 100644 --- a/uppsrc/ide/t.cpp +++ b/uppsrc/ide/t.cpp @@ -510,22 +510,24 @@ void Ide::SyncT(int kind) } Vector tfile; + VectormainsT; Progress pi; const Workspace& wspc = IdeWorkspace(); pi.SetTotal(wspc.GetCount()); - for(int i = 0; i < wspc.GetCount(); i++) { - const Package& pk = wspc.GetPackage(i); - String n = wspc[i]; + for(int iPackage = 0; iPackage < wspc.GetCount(); iPackage++) { + const Package& pk = wspc.GetPackage(iPackage); + String n = wspc[iPackage]; pi.SetText("Scanning " + n); if(pi.StepCanceled()) return; VectorMap pmap; - for(int i = 0; i < pk.file.GetCount(); i++) { - String file = SourcePath(n, pk.file[i]); + for(int iFile = 0; iFile < pk.file.GetCount(); iFile++) { + String file = SourcePath(n, pk.file[iFile]); LngParseCFile(SourcePath(GetActivePackage(), file), pmap); } - for(int i = 0; i < pk.file.GetCount(); i++) { - String file = SourcePath(n, pk.file[i]); + bool localT = false; + for(int iFile = 0; iFile < pk.file.GetCount(); iFile++) { + String file = SourcePath(n, pk.file[iFile]); String ext = GetFileExt(file); if(ext == ".t" || ext == ".jt") { VectorMap tmap(pmap, 0); @@ -533,10 +535,47 @@ void Ide::SyncT(int kind) TFile& tf = tfile.Add(); tf.java = (ext == ".jt"); tf.package = n; - tf.file = pk.file[i]; + tf.file = pk.file[iFile]; tf.map = tmap; tf.MakeLS(); } + // mark that we've found a local translation file + localT = true; + + // store index of main package translation(s) file(s) + if(iPackage == 0) + mainsT.Add(tfile.GetCount() - 1); + } + } + // if no local translation file(s), we append translation to + // main package one(s), if any + if(!localT && iPackage > 0) + { + for(int i = 0; i < mainsT.GetCount(); i++) + { + VectorMap &map = tfile[mainsT[i]].map; + for(int iEntry = 0; iEntry < pmap.GetCount(); iEntry++) + { + int idx = map.Find(pmap.GetKey(iEntry)); + if(idx < 0) + { + map.Add(pmap.GetKey(iEntry), pmap[iEntry]); + idx = map.GetCount() - 1; + } + LngEntry &entry = map[idx]; + if(!entry.fileline.GetCount()) + { + LngEntry &pEntry = pmap[iEntry]; + for(int iLc = 0; iLc < pEntry.fileline.GetCount(); iLc++) + { + FileLine &fl = entry.fileline.Add(); + String file = GetFileName(pEntry.fileline[iLc].file); + file = "PACKAGE '" + n + "' FILE '" + file + "'"; + fl.file = file; + fl.line = pEntry.fileline[iLc].line; + } + } + } } } }