use of com.mucommander.commons.conf.Configuration in project mucommander by mucommander.
the class MuPreferences method write.
/**
* Saves the muCommander CONFIGURATION.
* @throws IOException if an I/O error occurs.
* @throws ConfigurationException if a CONFIGURATION related error occurs.
*/
void write() throws IOException, ConfigurationException {
// Clear the configuration before saving to drop preferences which are unused anymore
Configuration conf = new Configuration(MuPreferencesFile.getPreferencesFile(), () -> new XmlConfigurationReader(), out -> new XmlConfigurationWriter(out, ROOT_ELEMENT));
for (MuPreference preference : MuPreference.values()) conf.setVariable(preference.toString(), configuration.getVariable(preference.toString()));
// Remove preferences which are not relevant if we're not using MAC
if (!OsFamily.MAC_OS.isCurrent()) {
conf.removeVariable(USE_SCREEN_MENU_BAR);
}
configuration = conf;
configuration.write();
}
use of com.mucommander.commons.conf.Configuration 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;
}
Aggregations