From: Svjatoslav Agejenko Date: Mon, 12 Jan 2015 20:10:42 +0000 (+0200) Subject: use emacs client instead of emacs X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=9c0eb0495baba596bda20490790b17fb71929390;p=instantlauncher.git use emacs client instead of emacs --- diff --git a/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java b/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java index 4d1ec06..b4ca9ab 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/FileAssociationManager.java @@ -8,112 +8,134 @@ import eu.svjatoslav.commons.gui.dialog.ExceptionDialog; public class FileAssociationManager { - private static final String TEXT_EDITOR = "emacs"; - - private static final String DOCUMENT_EDITOR = "lowriter"; - - private static final String SPREADSHEET_EDITOR = "localc"; - - private static final String FILE_INDICATOR = ""; + private static boolean isLogFile(final String fileName) { + if (fileName.endsWith(".out")) + return true; + if (fileName.endsWith(".log")) + return true; + if (fileName.contains(".log.")) + return true; - private static final String MUSIC_PLAYER = "clementine"; + return false; + } - public static HashMap extensionToApplication = new HashMap(); + /** + * @return true if file was opened. false if + * unknown file type. + */ + public static boolean openFile(final File file) { - /** - * @return true if file was opened. false if unknown file type. - */ - public static boolean openFile(final File file) { + if (isLogFile(file.getName())) { + runOpeningApplication(file, + new String[] { "glogg", FILE_INDICATOR }); + return true; + } - if (isLogFile(file.getName())){ - runOpeningApplication(file, new String[] { "glogg", FILE_INDICATOR }); - return true; - } - - final String fileExtension = Utils.getFileExtension(file); + final String fileExtension = Utils.getFileExtension(file); - if (extensionToApplication.containsKey(fileExtension)) { - final String[] commands = extensionToApplication.get(fileExtension); - runOpeningApplication(file, commands); - return true; - } else { + if (extensionToApplication.containsKey(fileExtension)) { + final String[] commands = extensionToApplication.get(fileExtension); + runOpeningApplication(file, commands); + return true; + } else return false; - } - } + } - private static void runOpeningApplication(final File file, final String[] commands) { - for (int i = 0; i < commands.length; i++) { - if (commands[i].equals(FILE_INDICATOR)) { + private static void runOpeningApplication(final File file, + final String[] commands) { + for (int i = 0; i < commands.length; i++) + if (commands[i].equals(FILE_INDICATOR)) commands[i] = file.getAbsolutePath(); - } - } try { - Runtime.getRuntime().exec(commands); - InstantLauncher.exitProgram(); + Runtime.getRuntime().exec(commands); + InstantLauncher.exitProgram(); } catch (final IOException e) { - new ExceptionDialog(e); - } - } - - private static boolean isLogFile(String fileName) { - if (fileName.endsWith(".out")) { - return true; - } - if (fileName.endsWith(".log")) { - return true; - } - if (fileName.contains(".log.")) { - return true; + new ExceptionDialog(e); } - - return false; } - public FileAssociationManager() { - - extensionToApplication.put("txt", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("xml", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("org", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("properties", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("ini", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("", new String[] { TEXT_EDITOR, FILE_INDICATOR }); - - extensionToApplication.put("jpg", new String[] { "eog", FILE_INDICATOR }); - extensionToApplication.put("jpeg", new String[] { "eog", FILE_INDICATOR }); - extensionToApplication.put("png", new String[] { "eog", FILE_INDICATOR }); - - extensionToApplication.put("pdf", new String[] { "evince", FILE_INDICATOR }); + private static final String FILE_INDICATOR = ""; + + private static final String[] TEXT_EDITOR_PATTERN = new String[] { + "emacsclient", "-a", "\"\"", "-c", FILE_INDICATOR }; + + private static final String DOCUMENT_EDITOR = "lowriter"; + + private static final String SPREADSHEET_EDITOR = "localc"; + + private static final String MUSIC_PLAYER = "clementine"; + + public static HashMap extensionToApplication = new HashMap(); + + public FileAssociationManager() { + + extensionToApplication.put("txt", TEXT_EDITOR_PATTERN); + extensionToApplication.put("xml", TEXT_EDITOR_PATTERN); + extensionToApplication.put("org", TEXT_EDITOR_PATTERN); + extensionToApplication.put("properties", TEXT_EDITOR_PATTERN); + extensionToApplication.put("ini", TEXT_EDITOR_PATTERN); + extensionToApplication.put("", TEXT_EDITOR_PATTERN); + + extensionToApplication.put("jpg", + new String[] { "eog", FILE_INDICATOR }); + extensionToApplication.put("jpeg", + new String[] { "eog", FILE_INDICATOR }); + extensionToApplication.put("png", + new String[] { "eog", FILE_INDICATOR }); + + extensionToApplication.put("pdf", new String[] { "evince", + FILE_INDICATOR }); + + extensionToApplication.put("mp3", new String[] { "banshee", + FILE_INDICATOR }); + extensionToApplication.put("ogg", new String[] { "banshee", + FILE_INDICATOR }); + + extensionToApplication.put("avi", + new String[] { "vlc", FILE_INDICATOR }); + extensionToApplication.put("mkv", + new String[] { "vlc", FILE_INDICATOR }); + extensionToApplication.put("ogv", + new String[] { "vlc", FILE_INDICATOR }); + extensionToApplication.put("mp4", + new String[] { "vlc", FILE_INDICATOR }); + extensionToApplication.put("flv", + new String[] { "vlc", FILE_INDICATOR }); + extensionToApplication.put("wmv", + new String[] { "vlc", FILE_INDICATOR }); + + extensionToApplication.put("flac", new String[] { MUSIC_PLAYER, + FILE_INDICATOR }); + extensionToApplication.put("mp3", new String[] { MUSIC_PLAYER, + FILE_INDICATOR }); + extensionToApplication.put("ogg", new String[] { MUSIC_PLAYER, + FILE_INDICATOR }); + extensionToApplication.put("wav", new String[] { MUSIC_PLAYER, + FILE_INDICATOR }); + + extensionToApplication.put("ods", new String[] { SPREADSHEET_EDITOR, + FILE_INDICATOR }); + extensionToApplication.put("xls", new String[] { SPREADSHEET_EDITOR, + FILE_INDICATOR }); + extensionToApplication.put("xlsx", new String[] { SPREADSHEET_EDITOR, + FILE_INDICATOR }); + + extensionToApplication.put("docx", new String[] { DOCUMENT_EDITOR, + FILE_INDICATOR }); + extensionToApplication.put("doc", new String[] { DOCUMENT_EDITOR, + FILE_INDICATOR }); + + extensionToApplication.put("desktop", new String[] { "run-desktop", + FILE_INDICATOR }); + + extensionToApplication.put("log", new String[] { "glogg", + FILE_INDICATOR }); + extensionToApplication.put("out", new String[] { "glogg", + FILE_INDICATOR }); - extensionToApplication.put("mp3", new String[] { "banshee", FILE_INDICATOR }); - extensionToApplication.put("ogg", new String[] { "banshee", FILE_INDICATOR }); - - extensionToApplication.put("avi", new String[] { "vlc", FILE_INDICATOR }); - extensionToApplication.put("mkv", new String[] { "vlc", FILE_INDICATOR }); - extensionToApplication.put("ogv", new String[] { "vlc", FILE_INDICATOR }); - extensionToApplication.put("mp4", new String[] { "vlc", FILE_INDICATOR }); - extensionToApplication.put("flv", new String[] { "vlc", FILE_INDICATOR }); - extensionToApplication.put("wmv", new String[] { "vlc", FILE_INDICATOR }); - - extensionToApplication.put("flac", new String[] { MUSIC_PLAYER, FILE_INDICATOR }); - extensionToApplication.put("mp3", new String[] { MUSIC_PLAYER, FILE_INDICATOR }); - extensionToApplication.put("ogg", new String[] { MUSIC_PLAYER, FILE_INDICATOR }); - extensionToApplication.put("wav", new String[] { MUSIC_PLAYER, FILE_INDICATOR }); - - extensionToApplication.put("ods", new String[] { SPREADSHEET_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("xls", new String[] { SPREADSHEET_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("xlsx", new String[] { SPREADSHEET_EDITOR, FILE_INDICATOR }); - - extensionToApplication.put("docx", new String[] { DOCUMENT_EDITOR, FILE_INDICATOR }); - extensionToApplication.put("doc", new String[] { DOCUMENT_EDITOR, FILE_INDICATOR }); - - extensionToApplication.put("desktop", new String[] { "run-desktop", FILE_INDICATOR }); - - extensionToApplication.put("log", new String[] { "glogg", FILE_INDICATOR }); - extensionToApplication.put("out", new String[] { "glogg", FILE_INDICATOR }); - - } + } }