Search in sources :

Example 6 with FileInfo

use of org.omegat.core.data.IProject.FileInfo in project omegat by omegat-org.

the class ProjectFilesListController method createContextMenuForRow.

private JPopupMenu createContextMenuForRow(int row) {
    int[] rows;
    if (IntStream.of(list.tableFiles.getSelectedRows()).anyMatch(r -> r == row)) {
        // If clicked on selection, use selection
        rows = list.tableFiles.getSelectedRows();
    } else {
        // Otherwise use the clicked row
        rows = new int[] { row };
    }
    List<FileInfo> infos = IntStream.of(rows).map(list.tableFiles.getRowSorter()::convertRowIndexToModel).mapToObj(modelFiles::getDataAtRow).collect(Collectors.toList());
    if (infos.isEmpty() || infos.stream().anyMatch(Objects::isNull)) {
        return null;
    }
    String sourceDir = Core.getProject().getProjectProperties().getSourceRoot();
    String targetDir = Core.getProject().getProjectProperties().getTargetRoot();
    JPopupMenu menu = new JPopupMenu();
    addContextMenuItem(menu, true, infos.stream().map(i -> new File(sourceDir, i.filePath)).collect(Collectors.toList()));
    addContextMenuItem(menu, false, infos.stream().map(i -> new File(targetDir, Core.getProject().getTargetPathForSourceFile(i.filePath))).collect(Collectors.toList()));
    return menu;
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo) File(java.io.File) JPopupMenu(javax.swing.JPopupMenu)

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