Search in sources :

Example 1 with MuPreferencesAPI

use of com.mucommander.conf.MuPreferencesAPI in project mucommander by mucommander.

the class MainFrameBuilder method getInitialPath.

/**
 * Retrieves the user's initial path for the specified frame.
 * <p>
 * If the path found in preferences is either illegal or does not exist, this method will
 * return the user's home directory - we assume this will always exist, which might be a bit
 * of a leap of faith.
 * </p>
 * @param  folderPanelType panel for which the initial path should be returned (either {@link com.mucommander.ui.main.FolderPanel.FolderPanelType.LEFT} or
 *               {@link #@link com.mucommander.ui.main.FolderPanel.FolderPanelType.RIGHT}).
 * @return       the user's initial path for the specified frame.
 */
protected FileURL getInitialPath(FolderPanelType folderPanelType) {
    // Preferences configuration
    MuPreferencesAPI preferences = MuConfigurations.getPreferences();
    // Checks which kind of initial path we're dealing with.
    boolean isCustom = preferences.getVariable(MuPreference.STARTUP_FOLDERS, MuPreferences.DEFAULT_STARTUP_FOLDERS).equals(MuPreferences.STARTUP_FOLDERS_CUSTOM);
    String customPath = null;
    // Handles custom initial paths.
    if (isCustom) {
        customPath = (folderPanelType == FolderPanelType.LEFT ? preferences.getVariable(MuPreference.LEFT_CUSTOM_FOLDER) : preferences.getVariable(MuPreference.RIGHT_CUSTOM_FOLDER));
    }
    AbstractFile result = null;
    if (customPath == null || (result = FileFactory.getFile(customPath)) == null || !result.exists())
        result = getHomeFolder();
    LOGGER.debug("initial folder: " + result);
    return result.getURL();
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) MuPreferencesAPI(com.mucommander.conf.MuPreferencesAPI)

Example 2 with MuPreferencesAPI

use of com.mucommander.conf.MuPreferencesAPI in project mucommander by mucommander.

the class MainFrameBuilder method getInitialPaths.

/**
 * Retrieves the user's initial path for the specified frame.
 * <p>
 * If the path found in preferences is either illegal or does not exist, this method will
 * return the user's home directory - we assume this will always exist, which might be a bit
 * of a leap of faith.
 * </p>
 * @param  folderPanelType panel for which the initial path should be returned (either {@link com.mucommander.ui.main.FolderPanel.FolderPanelType.LEFT} or
 *               {@link #@link com.mucommander.ui.main.FolderPanel.FolderPanelType.RIGHT}).
 * @return       the user's initial path for the specified frame.
 */
protected AbstractFile[] getInitialPaths(FolderPanelType folderPanelType, int window) {
    // Whether the initial path is a custom one or the last used folder.
    boolean isCustom;
    // Paths to the initial folders.
    String[] folderPaths;
    // Snapshot configuration
    Configuration snapshot = MuSnapshot.getSnapshot();
    // Preferences configuration
    MuPreferencesAPI preferences = MuConfigurations.getPreferences();
    // Checks which kind of initial path we're dealing with.
    isCustom = preferences.getVariable(MuPreference.STARTUP_FOLDERS, MuPreferences.DEFAULT_STARTUP_FOLDERS).equals(MuPreferences.STARTUP_FOLDERS_CUSTOM);
    // Handles custom initial paths.
    if (isCustom) {
        folderPaths = new String[] { (folderPanelType == FolderPanelType.LEFT ? preferences.getVariable(MuPreference.LEFT_CUSTOM_FOLDER) : preferences.getVariable(MuPreference.RIGHT_CUSTOM_FOLDER)) };
    } else // Handles "last folder" initial paths.
    {
        // Set initial path to each tab
        int nbFolderPaths = snapshot.getIntegerVariable(MuSnapshot.getTabsCountVariable(window, folderPanelType == FolderPanelType.LEFT));
        folderPaths = new String[nbFolderPaths];
        for (int i = 0; i < nbFolderPaths; ++i) folderPaths[i] = snapshot.getVariable(MuSnapshot.getTabLocationVariable(window, folderPanelType == FolderPanelType.LEFT, i));
    }
    // Initial folders
    List<AbstractFile> initialFolders = new LinkedList<AbstractFile>();
    AbstractFile folder;
    for (String folderPath : folderPaths) {
        // TODO: consider whether to search for workable path in case the folder doesn't exist
        if (folderPath != null && (folder = FileFactory.getFile(folderPath)) != null && folder.exists())
            initialFolders.add(folder);
    }
    // If the initial path is not legal or does not exist, defaults to the user's home.
    AbstractFile[] results = initialFolders.size() == 0 ? new AbstractFile[] { FileFactory.getFile(System.getProperty("user.home")) } : initialFolders.toArray(new AbstractFile[0]);
    LOGGER.debug("initial folders:");
    for (AbstractFile result : results) LOGGER.debug("\t" + result);
    return results;
}
Also used : AbstractFile(com.mucommander.commons.file.AbstractFile) FileTableConfiguration(com.mucommander.ui.main.table.FileTableConfiguration) Configuration(com.mucommander.commons.conf.Configuration) MuPreferencesAPI(com.mucommander.conf.MuPreferencesAPI) LinkedList(java.util.LinkedList)

Aggregations

AbstractFile (com.mucommander.commons.file.AbstractFile)2 MuPreferencesAPI (com.mucommander.conf.MuPreferencesAPI)2 Configuration (com.mucommander.commons.conf.Configuration)1 FileTableConfiguration (com.mucommander.ui.main.table.FileTableConfiguration)1 LinkedList (java.util.LinkedList)1