use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.
the class Searcher method searchFiles.
private void searchFiles() throws Exception {
Path root = Paths.get(expression.rootDir);
FilterMaster fm = Core.getFilterMaster();
final SearchCallback searchCallback = new SearchCallback(m_project.getProjectProperties());
int depth = expression.recursive ? Integer.MAX_VALUE : 0;
Files.walk(root, depth, FileVisitOption.FOLLOW_LINKS).forEach(path -> {
String filename = path.toString();
FileInfo fi = new FileInfo();
// determine actual file name w/ no root path info
fi.filePath = root.relativize(path).toString();
searchCallback.setCurrentFile(fi);
try {
fm.loadFile(filename, new FilterContext(m_project.getProjectProperties()), searchCallback);
} catch (TranslationException | IOException ex) {
Log.log(ex);
}
searchCallback.fileFinished();
checkStop.checkInterrupted();
});
}
use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.
the class EditorController method removeFilter.
/**
* {@inheritDoc} Document is reloaded if appropriate to immediately remove
* the filter;
*/
public void removeFilter() {
UIThreadsUtil.mustBeSwingThread();
if (entriesFilter == null && entriesFilterControlComponent == null) {
return;
}
entriesFilter = null;
if (entriesFilterControlComponent != null) {
pane.remove(entriesFilterControlComponent);
pane.revalidate();
entriesFilterControlComponent = null;
}
int curEntryNum = getCurrentEntryNumber();
Document3 doc = editor.getOmDocument();
IProject project = Core.getProject();
// Only load if there is a document and the project is loaded.
if (doc != null && project != null && project.isProjectLoaded()) {
List<FileInfo> files = project.getProjectFiles();
if (files != null && !files.isEmpty()) {
loadDocument();
gotoEntry(curEntryNum);
}
}
}
use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.
the class CalcStandardStatistics method buildProjectStats.
/**
* Builds a file with statistic info about the project. The total word &
* character count of the project, the total number of unique segments, plus
* the details for each file.
*/
public static String buildProjectStats(final IProject project, final StatisticsInfo hotStat, final StatisticsPanel callback) {
StatCount total = new StatCount();
StatCount remaining = new StatCount();
StatCount unique = new StatCount();
StatCount remainingUnique = new StatCount();
// find unique segments
Map<String, SourceTextEntry> uniqueSegment = new HashMap<String, SourceTextEntry>();
Set<String> translated = new HashSet<String>();
for (SourceTextEntry ste : project.getAllEntries()) {
String src = ste.getSrcText();
for (ProtectedPart pp : ste.getProtectedParts()) {
src = src.replace(pp.getTextInSourceSegment(), pp.getReplacementUniquenessCalculation());
}
if (!uniqueSegment.containsKey(src)) {
uniqueSegment.put(src, ste);
}
TMXEntry tr = project.getTranslationInfo(ste);
if (tr.isTranslated()) {
translated.add(src);
}
}
Set<String> filesUnique = new HashSet<String>();
Set<String> filesRemainingUnique = new HashSet<String>();
for (Map.Entry<String, SourceTextEntry> en : uniqueSegment.entrySet()) {
/* Number of words and chars calculated without all tags and protected parts. */
StatCount count = new StatCount(en.getValue());
// add to unique
unique.add(count);
filesUnique.add(en.getValue().getKey().file);
// add to unique remaining
if (!translated.contains(en.getKey())) {
remainingUnique.add(count);
filesRemainingUnique.add(en.getValue().getKey().file);
}
}
unique.addFiles(filesUnique.size());
remainingUnique.addFiles(filesRemainingUnique.size());
List<FileData> counts = new ArrayList<FileData>();
Map<String, Boolean> firstSeenUniqueSegment = new HashMap<String, Boolean>();
for (FileInfo file : project.getProjectFiles()) {
FileData numbers = new FileData();
numbers.filename = file.filePath;
counts.add(numbers);
int fileTotal = 0;
int fileRemaining = 0;
for (SourceTextEntry ste : file.entries) {
String src = ste.getSrcText();
for (ProtectedPart pp : ste.getProtectedParts()) {
src = src.replace(pp.getTextInSourceSegment(), pp.getReplacementUniquenessCalculation());
}
/* Number of words and chars calculated without all tags and protected parts. */
StatCount count = new StatCount(ste);
// add to total
total.add(count);
fileTotal = 1;
// add to remaining
TMXEntry tr = project.getTranslationInfo(ste);
if (!tr.isTranslated()) {
remaining.add(count);
fileRemaining = 1;
}
// add to file's info
numbers.total.add(count);
Boolean firstSeen = firstSeenUniqueSegment.get(src);
if (firstSeen == null) {
firstSeenUniqueSegment.put(src, false);
numbers.unique.add(count);
if (!tr.isTranslated()) {
numbers.remainingUnique.add(count);
}
}
if (!tr.isTranslated()) {
numbers.remaining.add(count);
}
}
total.addFiles(fileTotal);
remaining.addFiles(fileRemaining);
}
StringBuilder result = new StringBuilder();
result.append(OStrings.getString("CT_STATS_Project_Statistics"));
result.append("\n\n");
String[][] headerTable = calcHeaderTable(new StatCount[] { total, remaining, unique, remainingUnique });
if (callback != null) {
callback.setProjectTableData(HT_HEADERS, headerTable);
}
result.append(TextUtil.showTextTable(HT_HEADERS, headerTable, HT_ALIGN));
result.append("\n\n");
// STATISTICS BY FILE
result.append(OStrings.getString("CT_STATS_FILE_Statistics"));
result.append("\n\n");
String[][] filesTable = calcFilesTable(project.getProjectProperties(), counts);
if (callback != null) {
callback.setFilesTableData(FT_HEADERS, filesTable);
}
result.append(TextUtil.showTextTable(FT_HEADERS, filesTable, FT_ALIGN));
if (hotStat != null) {
hotStat.numberOfSegmentsTotal = total.segments;
hotStat.numberofTranslatedSegments = translated.size();
hotStat.numberOfUniqueSegments = unique.segments;
hotStat.uniqueCountsByFile.clear();
for (FileData fd : counts) {
hotStat.uniqueCountsByFile.put(fd.filename, fd.unique.segments);
}
}
return result.toString();
}
use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.
the class EditorController method iterateToEntry.
private void iterateToEntry(boolean forward, Predicate<SourceTextEntry> shouldStop) {
UIThreadsUtil.mustBeSwingThread();
if (!Core.getProject().isProjectLoaded()) {
return;
}
Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
Cursor oldCursor = editor.getCursor();
editor.setCursor(hourglassCursor);
commitAndDeactivate();
List<FileInfo> files = Core.getProject().getProjectFiles();
if (files.isEmpty()) {
return;
}
SourceTextEntry ste;
int startFileIndex = displayedFileIndex;
int startEntryIndex = displayedEntryIndex;
boolean looped = false;
while (true) {
if (forward) {
displayedEntryIndex++;
if (displayedEntryIndex >= m_docSegList.length) {
displayedFileIndex++;
displayedEntryIndex = 0;
if (displayedFileIndex >= files.size()) {
displayedFileIndex = 0;
looped = true;
}
loadDocument();
}
} else {
displayedEntryIndex--;
if (displayedEntryIndex < 0) {
displayedFileIndex--;
if (displayedFileIndex < 0) {
displayedFileIndex = files.size() - 1;
looped = true;
}
loadDocument();
displayedEntryIndex = m_docSegList.length - 1;
}
}
ste = getCurrentEntry();
if (ste != null && shouldStop.test(ste)) {
break;
}
if (looped && displayedFileIndex == startFileIndex) {
if (forward && displayedEntryIndex >= startEntryIndex) {
// We have looped forward to our starting point
break;
} else if (!forward && displayedEntryIndex <= startEntryIndex) {
// We have looped backwards to our starting point
break;
}
if (m_docSegList.length == 0) {
// and there were no hits in any files
break;
}
}
}
activateEntry();
editor.setCursor(oldCursor);
}
use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.
the class Searcher method getFileForEntry.
private String getFileForEntry(int i) {
List<FileInfo> fileList = Core.getProject().getProjectFiles();
for (FileInfo fi : fileList) {
int first = fi.entries.get(0).entryNum();
int last = fi.entries.get(fi.entries.size() - 1).entryNum();
if (i >= first && i <= last) {
return fi.filePath;
}
}
return null;
}
Aggregations