Search in sources :

Example 1 with FileFilter

use of com.mucommander.commons.file.filter.FileFilter in project mucommander by mucommander.

the class CombineFilesAction method performAction.

@Override
public void performAction(FileSet files) {
    // Filter out files that are not regular files
    FileFilter filter = new AttributeFileFilter(FileAttribute.FILE);
    filter.filter(files);
    if (files.size() == 0)
        return;
    AbstractFile destFolder = mainFrame.getInactivePanel().getCurrentFolder();
    new CombineFilesDialog(mainFrame, files, destFolder).showDialog();
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) CombineFilesDialog(com.mucommander.ui.dialog.file.CombineFilesDialog) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter)

Example 2 with FileFilter

use of com.mucommander.commons.file.filter.FileFilter in project mucommander by mucommander.

the class CommandManager method buildAssociations.

/**
 * Passes all known file associations to the specified builder.
 * <p>
 * This method guarantees that the builder's {@link AssociationBuilder#startBuilding() startBuilding()} and
 * {@link AssociationBuilder#endBuilding() endBuilding()} methods will both be called even if an error occurs.
 * If that happens however, it is entirely possible that not all associations will be passed to
 * the builder.
 * </p>
 * @param  builder          object that will receive association list building messages.
 * @throws CommandException if anything goes wrong.
 */
public static void buildAssociations(AssociationBuilder builder) throws CommandException {
    // Used to iterate through commands and associations.
    Iterator<CommandAssociation> iterator;
    // Used to iterate through each association's filters.
    Iterator<FileFilter> filters;
    // Buffer for the current file filter.
    FileFilter filter;
    // Current command association.
    CommandAssociation current;
    builder.startBuilding();
    // Goes through all the registered associations.
    iterator = associations();
    try {
        while (iterator.hasNext()) {
            current = iterator.next();
            builder.startAssociation(current.getCommand().getAlias());
            filter = current.getFilter();
            if (filter instanceof ChainedFileFilter) {
                filters = ((ChainedFileFilter) filter).getFileFilterIterator();
                while (filters.hasNext()) buildFilter(filters.next(), builder);
            } else
                buildFilter(filter, builder);
            builder.endAssociation();
        }
    } finally {
        builder.endBuilding();
    }
}
Also used : ChainedFileFilter(com.mucommander.commons.file.filter.ChainedFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) ChainedFileFilter(com.mucommander.commons.file.filter.ChainedFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter)

Example 3 with FileFilter

use of com.mucommander.commons.file.filter.FileFilter in project mucommander by mucommander.

the class ConfigurableFolderFilter method configurationChanged.

// ////////////////////////////////////////
// ConfigurationListener implementation //
// ////////////////////////////////////////
/**
 * Adds or removes filters based on configuration changes.
 */
public void configurationChanged(ConfigurationEvent event) {
    FileFilter fileFilter = null;
    switch(event.getVariable()) {
        // Show or hide hidden files
        case MuPreferences.SHOW_HIDDEN_FILES:
            fileFilter = hiddenFileFilter;
            break;
        // Show or hide .DS_Store files (macOS option)
        case MuPreferences.SHOW_DS_STORE_FILES:
            fileFilter = dsFileFilter;
            break;
        // Show or hide system folders (macOS option)
        case MuPreferences.SHOW_SYSTEM_FOLDERS:
            fileFilter = systemFileFilter;
            break;
    }
    if (fileFilter != null) {
        Consumer<FileFilter> func = event.getBooleanValue() ? this::removeFileFilter : this::addFileFilter;
        func.accept(fileFilter);
    }
}
Also used : AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter)

Example 4 with FileFilter

use of com.mucommander.commons.file.filter.FileFilter in project mucommander by mucommander.

the class FileSelectionDialog method actionPerformed.

// //////////////////////////
// ActionListener methods //
// //////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    FileTable activeTable = mainFrame.getActiveTable();
    // Action coming from the selection dialog
    if ((source == okButton || source == selectionField)) {
        // Save values for next time this dialog is invoked
        caseSensitive = caseSensitiveCheckBox.isSelected();
        includeFolders = includeFoldersCheckBox.isSelected();
        comparison = comparisonComboBox.getSelectedIndex();
        String testString;
        keywordString = selectionField.getText();
        if (comparison != REGEXP) {
            // Remove '*' characters
            testString = keywordString.replace("*", "");
        } else {
            testString = keywordString;
        }
        // Instantiate the main file filter
        FileFilter filter;
        switch(comparison) {
            case CONTAINS:
                filter = new ContainsFilenameFilter(testString, caseSensitive);
                break;
            case STARTS_WITH:
                filter = new StartsWithFilenameFilter(testString, caseSensitive);
                break;
            case ENDS_WIDTH:
                filter = new EndsWithFilenameFilter(testString, caseSensitive);
                break;
            case IS:
                filter = new EqualsFilenameFilter(testString, caseSensitive);
                break;
            case REGEXP:
            default:
                try {
                    filter = new RegexpFilenameFilter(testString, caseSensitive);
                } catch (PatternSyntaxException ex) {
                    // Todo: let the user know the regexp is invalid
                    LOGGER.debug("Invalid regexp", ex);
                    // This filter does match any file
                    filter = new PassThroughFileFilter(false);
                }
                break;
        }
        // If folders are excluded, add a regular file filter and chain it with an AndFileFilter
        if (!includeFolders) {
            filter = new AndFileFilter(new AttributeFileFilter(FileAttribute.FILE), filter);
        }
        // Mark/unmark the files using the filter
        activeTable.getFileTableModel().setFilesMarked(filter, addToSelection);
        // Notify registered listeners that currently marked files have changed on this FileTable
        activeTable.fireMarkedFilesChangedEvent();
        activeTable.repaint();
    }
    dispose();
}
Also used : AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileTable(com.mucommander.ui.main.table.FileTable) EndsWithFilenameFilter(com.mucommander.commons.file.filter.EndsWithFilenameFilter) ContainsFilenameFilter(com.mucommander.commons.file.filter.ContainsFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) EqualsFilenameFilter(com.mucommander.commons.file.filter.EqualsFilenameFilter) StartsWithFilenameFilter(com.mucommander.commons.file.filter.StartsWithFilenameFilter) RegexpFilenameFilter(com.mucommander.commons.file.filter.RegexpFilenameFilter) AndFileFilter(com.mucommander.commons.file.filter.AndFileFilter) PassThroughFileFilter(com.mucommander.commons.file.filter.PassThroughFileFilter) AttributeFileFilter(com.mucommander.commons.file.filter.AttributeFileFilter) FileFilter(com.mucommander.commons.file.filter.FileFilter) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 5 with FileFilter

use of com.mucommander.commons.file.filter.FileFilter in project mucommander by mucommander.

the class GnomeDesktopAdapter method init.

@Override
public void init(boolean install) throws DesktopInitialisationException {
    String fileOpener = String.format("%s $f", getFileOpenerCommand());
    try {
        CommandManager.registerDefaultCommand(new Command(CommandManager.FILE_OPENER_ALIAS, fileOpener, CommandType.SYSTEM_COMMAND, null));
        CommandManager.registerDefaultCommand(new Command(CommandManager.URL_OPENER_ALIAS, fileOpener, CommandType.SYSTEM_COMMAND, null));
        CommandManager.registerDefaultCommand(new Command(CommandManager.EXE_OPENER_ALIAS, EXE_OPENER, CommandType.SYSTEM_COMMAND, null));
        CommandManager.registerDefaultCommand(new Command(CommandManager.FILE_MANAGER_ALIAS, fileOpener, CommandType.SYSTEM_COMMAND, FILE_MANAGER_NAME));
        CommandManager.registerDefaultCommand(new Command(CommandManager.CMD_OPENER_ALIAS, CMD_OPENER_COMMAND, CommandType.SYSTEM_COMMAND, null));
        // Disabled actual permissions checking as this will break normal +x files.
        // With this, a +x PDF file will not be opened.
        /*
            // Identifies which kind of filter should be used to match executable files.
            if(JavaVersion.JAVA_6.isCurrentOrHigher())
                filter = new PermissionsFileFilter(PermissionTypes.EXECUTE_PERMISSION, true);
            else
            */
        FileFilter filter = new RegexpFilenameFilter("[^.]+", true);
        CommandManager.registerDefaultAssociation(CommandManager.EXE_OPENER_ALIAS, filter);
        // Multi-click interval retrieval
        try {
            String value = GnomeConfig.getValue(DOUBLE_CLICK_CONFIG_KEY);
            if (value == null)
                multiClickInterval = super.getMultiClickInterval();
            multiClickInterval = Integer.parseInt(value);
        } catch (Exception e) {
            LOGGER.debug("Error while retrieving double-click interval from gconftool", e);
            multiClickInterval = super.getMultiClickInterval();
        }
    } catch (CommandException e) {
        throw new DesktopInitialisationException(e);
    }
}
Also used : Command(com.mucommander.command.Command) RegexpFilenameFilter(com.mucommander.commons.file.filter.RegexpFilenameFilter) CommandException(com.mucommander.command.CommandException) DesktopInitialisationException(com.mucommander.desktop.DesktopInitialisationException) FileFilter(com.mucommander.commons.file.filter.FileFilter) DesktopInitialisationException(com.mucommander.desktop.DesktopInitialisationException) CommandException(com.mucommander.command.CommandException)

Aggregations

FileFilter (com.mucommander.commons.file.filter.FileFilter)5 AttributeFileFilter (com.mucommander.commons.file.filter.AttributeFileFilter)4 AndFileFilter (com.mucommander.commons.file.filter.AndFileFilter)2 RegexpFilenameFilter (com.mucommander.commons.file.filter.RegexpFilenameFilter)2 Command (com.mucommander.command.Command)1 CommandException (com.mucommander.command.CommandException)1 AbstractFile (com.mucommander.commons.file.AbstractFile)1 ChainedFileFilter (com.mucommander.commons.file.filter.ChainedFileFilter)1 ContainsFilenameFilter (com.mucommander.commons.file.filter.ContainsFilenameFilter)1 EndsWithFilenameFilter (com.mucommander.commons.file.filter.EndsWithFilenameFilter)1 EqualsFilenameFilter (com.mucommander.commons.file.filter.EqualsFilenameFilter)1 PassThroughFileFilter (com.mucommander.commons.file.filter.PassThroughFileFilter)1 StartsWithFilenameFilter (com.mucommander.commons.file.filter.StartsWithFilenameFilter)1 DesktopInitialisationException (com.mucommander.desktop.DesktopInitialisationException)1 CombineFilesDialog (com.mucommander.ui.dialog.file.CombineFilesDialog)1 FileTable (com.mucommander.ui.main.table.FileTable)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1