Search in sources :

Example 1 with FileInfo

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();
    });
}
Also used : Path(java.nio.file.Path) FileInfo(org.omegat.core.data.IProject.FileInfo) FilterMaster(org.omegat.filters2.master.FilterMaster) TranslationException(org.omegat.filters2.TranslationException) IOException(java.io.IOException) FilterContext(org.omegat.filters2.FilterContext)

Example 2 with FileInfo

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);
        }
    }
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo) Point(java.awt.Point) IProject(org.omegat.core.data.IProject)

Example 3 with FileInfo

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();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileInfo(org.omegat.core.data.IProject.FileInfo) SourceTextEntry(org.omegat.core.data.SourceTextEntry) HashMap(java.util.HashMap) Map(java.util.Map) TMXEntry(org.omegat.core.data.TMXEntry) HashSet(java.util.HashSet)

Example 4 with FileInfo

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);
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Cursor(java.awt.Cursor) Point(java.awt.Point)

Example 5 with FileInfo

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;
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo)

Aggregations

FileInfo (org.omegat.core.data.IProject.FileInfo)6 Point (java.awt.Point)2 SourceTextEntry (org.omegat.core.data.SourceTextEntry)2 Cursor (java.awt.Cursor)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 JPopupMenu (javax.swing.JPopupMenu)1 IProject (org.omegat.core.data.IProject)1 ProtectedPart (org.omegat.core.data.ProtectedPart)1 TMXEntry (org.omegat.core.data.TMXEntry)1 FilterContext (org.omegat.filters2.FilterContext)1 TranslationException (org.omegat.filters2.TranslationException)1 FilterMaster (org.omegat.filters2.master.FilterMaster)1