From 9712a9b51735f6023f4081e1d6753ccab701d28f Mon Sep 17 00:00:00 2001 From: Trol Date: Mon, 9 Jul 2018 23:23:54 +0400 Subject: [PATCH] added OpenAs command code refactor --- res/runtime/dictionary.properties | 1 + res/runtime/dictionary_ru_RU.properties | 1 + src/main/com/mucommander/TrolCommander.java | 6 +- src/main/com/mucommander/adb/AdbUtils.java | 8 +- .../com/mucommander/cache/WindowsStorage.java | 103 +++-- .../commons/DummyDecoratedFile.java | 2 +- .../mucommander/commons/file/FileFactory.java | 12 +- .../com/mucommander/commons/file/FileURL.java | 5 +- .../file/filter/MountedDriveFilter.java | 2 +- .../commons/file/impl/avrdude/Avrdude.java | 2 +- .../commons/runtime/OsVersion.java | 10 +- .../desktop/DefaultDesktopAdapter.java | 4 +- .../desktop/osx/OSXDesktopAdapter.java | 2 +- .../windows/WindowsDesktopAdapter.java | 2 +- src/main/com/mucommander/job/FindFileJob.java | 3 +- .../mucommander/job/MakeDirectoryFileJob.java | 4 +- .../com/mucommander/tools/FileMergeTool.java | 2 +- .../ui/action/AbstractActionDescriptor.java | 4 + .../mucommander/ui/action/ActionManager.java | 1 + .../ui/action/impl/AddBookmarkAction.java | 16 +- .../ui/action/impl/AddTabAction.java | 6 +- .../ui/action/impl/ChangeLocationAction.java | 6 +- .../ui/action/impl/CloseOtherTabsAction.java | 6 +- .../ui/action/impl/CloseTabAction.java | 6 +- .../ui/action/impl/CompareFilesAction.java | 2 +- .../ui/action/impl/ConnectToServerAction.java | 6 +- .../action/impl/CopyFileBaseNamesAction.java | 6 +- .../ui/action/impl/CopyFileNamesAction.java | 1 + .../impl/CopyFilesToClipboardAction.java | 14 +- .../ui/action/impl/EjectDriveAction.java | 14 +- .../ui/action/impl/EmailAction.java | 6 +- .../action/impl/ExploreBookmarksAction.java | 6 +- .../ui/action/impl/FindFileAction.java | 8 +- .../ui/action/impl/FocusNextAction.java | 6 +- .../ui/action/impl/FocusPreviousAction.java | 6 +- .../impl/GoToParentInBothPanelsAction.java | 6 +- .../impl/GoToParentInOtherPanelAction.java | 6 +- .../ui/action/impl/MarkAllAction.java | 6 +- .../ui/action/impl/MarkNextBlockAction.java | 6 +- .../action/impl/MarkPreviousBlockAction.java | 6 +- .../ui/action/impl/NewWindowAction.java | 6 +- .../ui/action/impl/NextTabAction.java | 12 +- .../ui/action/impl/OpenAction.java | 116 ++--- .../ui/action/impl/OpenAsAction.java | 91 ++++ .../action/impl/OpenInBothPanelsAction.java | 6 +- .../ui/action/impl/OpenInNewTabAction.java | 6 +- .../action/impl/OpenInOtherPanelAction.java | 6 +- .../ui/action/impl/PackAction.java | 6 +- .../impl/PasteClipboardFilesAction.java | 6 +- .../ui/action/impl/PreviousTabAction.java | 12 +- .../ui/action/impl/QuitAction.java | 6 +- .../action/impl/RecallNextWindowAction.java | 6 +- .../impl/RecallPreviousWindowAction.java | 6 +- .../ui/action/impl/RevealInDesktopAction.java | 10 +- .../ui/action/impl/RunCommandAction.java | 6 +- .../ui/action/impl/SelectNextBlockAction.java | 6 +- .../impl/SelectPreviousBlockAction.java | 6 +- .../ui/action/impl/SetSameFolderAction.java | 6 +- .../impl/ShowServerConnectionsAction.java | 6 +- .../ui/action/impl/SwapFoldersAction.java | 6 +- .../ui/action/impl/TextEditorsListAction.java | 6 +- .../action/impl/ToggleHiddenFilesAction.java | 6 +- .../ui/action/impl/ToggleTreeAction.java | 6 +- .../ui/action/impl/UnmarkAllAction.java | 6 +- .../ui/action/impl/UnpackAction.java | 6 +- .../ui/button/RolloverButtonAdapter.java | 14 +- .../mucommander/ui/dialog/FocusDialog.java | 5 +- .../dialog/symlink/CreateSymLinkDialog.java | 15 +- .../com/mucommander/ui/icon/FileIcons.java | 2 +- .../com/mucommander/ui/layout/AsyncPanel.java | 2 +- .../mucommander/ui/macosx/IMacOsWindow.java | 21 + .../mucommander/ui/macosx/OSXIntegration.java | 2 +- .../com/mucommander/ui/main/MainFrame.java | 7 +- .../mucommander/ui/main/menu/MainMenuBar.java | 396 ++++++++++-------- .../mucommander/ui/main/menu/OpenAsMenu.java | 54 +++ .../ui/main/menu/OpenWithMenu.java | 4 +- .../ui/main/menu/TablePopupMenu.java | 8 +- .../quicklist/ViewedAndEditedFilesQL.java | 2 +- .../ui/main/statusbar/HeapIndicator.java | 18 +- .../ui/main/statusbar/StatusBar.java | 124 +++--- .../ui/main/statusbar/TrashPopupButton.java | 6 +- .../ui/main/statusbar/VolumeSpaceLabel.java | 35 +- .../mucommander/ui/main/toolbar/ToolBar.java | 16 +- .../ui/terminal/JediTerminalPanelEx.java | 2 +- .../com/mucommander/ui/theme/ThemeData.java | 2 +- .../com/mucommander/ui/viewer/FileEditor.java | 4 +- .../com/mucommander/ui/viewer/FileFrame.java | 5 +- .../com/mucommander/ui/viewer/FileViewer.java | 2 +- .../mucommander/ui/viewer/hex/HexViewer.java | 6 +- .../ui/viewer/image/ImageViewer.java | 12 +- .../ui/viewer/text/TextEditorImpl.java | 2 +- .../ui/viewer/text/TextMenuHelper.java | 6 +- .../ru/trolsoft/macosx/FileLabelCache.java | 2 +- .../ru/trolsoft/ui/TCheckBoxMenuItem.java | 2 +- src/main/ru/trolsoft/ui/TMenuSeparator.java | 2 +- 95 files changed, 789 insertions(+), 669 deletions(-) create mode 100644 src/main/com/mucommander/ui/action/impl/OpenAsAction.java create mode 100644 src/main/com/mucommander/ui/macosx/IMacOsWindow.java create mode 100644 src/main/com/mucommander/ui/main/menu/OpenAsMenu.java diff --git a/res/runtime/dictionary.properties b/res/runtime/dictionary.properties index 6376b8063..960188094 100644 --- a/res/runtime/dictionary.properties +++ b/res/runtime/dictionary.properties @@ -387,6 +387,7 @@ EjectDrive.label = Eject drive EjectDrive.tooltip = Safely remove drive file_menu = File file_menu.open_with = Open with +file_menu.open_as = Open as mark_menu = Mark view_menu = View view_menu.show_hide_columns = Show/Hide columns diff --git a/res/runtime/dictionary_ru_RU.properties b/res/runtime/dictionary_ru_RU.properties index 2c4f0e849..11bfcc8b6 100644 --- a/res/runtime/dictionary_ru_RU.properties +++ b/res/runtime/dictionary_ru_RU.properties @@ -372,6 +372,7 @@ FocusPrevious.label = Перейти к предыдущему компонен FocusNext.label = Перейти к следующему компоненту file_menu = Файл file_menu.open_with = Открыть с помощью +file_menu.open_as = Open как mark_menu = Выделение view_menu = Вид view_menu.show_hide_columns = Показать/скрыть столбцы diff --git a/src/main/com/mucommander/TrolCommander.java b/src/main/com/mucommander/TrolCommander.java index 44d8489ba..bbc08136a 100644 --- a/src/main/com/mucommander/TrolCommander.java +++ b/src/main/com/mucommander/TrolCommander.java @@ -767,7 +767,7 @@ public boolean execute(LauncherTask task, boolean force) { */ @SuppressWarnings({"unchecked"}) public static void main(String args[]) throws IOException { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { System.setProperty("com.apple.mrj.application.apple.menu.about.name", "trolCommander"); // disable openGL in javaFX (used for HtmlViewer) as it cashes JVM under vmWare System.setProperty("prism.order", "sw"); @@ -821,7 +821,7 @@ public static void main(String args[]) throws IOException { LauncherTask taskRegisterArchives = new RegisterArchiveProtocolsTask(helper); LauncherTask taskRegisterNetwork = new RegisterNetworkProtocolsTask(helper); LauncherTask taskRegisterOtherProtocols = new RegisterOtherProtocolsTask(helper); - LauncherTask taskLoadEnviroment = new LoadEnvironmentTask(helper); + LauncherTask taskLoadEnvironment = new LoadEnvironmentTask(helper); List tasks = new LinkedList<>(); // tasks.add(taskPrepareLogger); @@ -853,7 +853,7 @@ public static void main(String args[]) throws IOException { tasks.add(taskRegisterArchives); tasks.add(taskRegisterNetwork); tasks.add(taskRegisterOtherProtocols); - tasks.add(taskLoadEnviroment); + tasks.add(taskLoadEnvironment); //System.out.println("Execute tasks"); if (processors <= 1 ) { diff --git a/src/main/com/mucommander/adb/AdbUtils.java b/src/main/com/mucommander/adb/AdbUtils.java index 72a35ed46..9db77d473 100644 --- a/src/main/com/mucommander/adb/AdbUtils.java +++ b/src/main/com/mucommander/adb/AdbUtils.java @@ -93,7 +93,8 @@ private static AbstractFile getAdbPath() { path = null; } if (path != null) { - AbstractFile result = FileFactory.getFile(path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\platform-tools\\adb.exe" : "/platform-tools/adb")); + String adb = path + (OsFamily.WINDOWS .isCurrent() ? "\\platform-tools\\adb.exe" : "/platform-tools/adb"); + AbstractFile result = FileFactory.getFile(adb); if (result != null && result.exists() && !result.isDirectory()) { return result.getParent(); } @@ -104,12 +105,13 @@ private static AbstractFile getAdbPath() { path = null; } if (path != null) { - AbstractFile result = FileFactory.getFile(path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\adb.exe" : "/adb")); + String adb = path + (OsFamily.getCurrent() == OsFamily.WINDOWS ? "\\adb.exe" : "/adb"); + AbstractFile result = FileFactory.getFile(adb); if (result != null && result.exists() && !result.isDirectory()) { return result.getParent(); } } - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { String defaultPath = System.getProperty("user.home") + "/Library/Android/sdk/platform-tools/adb"; AbstractFile result = FileFactory.getFile(defaultPath); if (result != null && result.exists() && !result.isDirectory()) { diff --git a/src/main/com/mucommander/cache/WindowsStorage.java b/src/main/com/mucommander/cache/WindowsStorage.java index a33c3a49d..ec61f134d 100644 --- a/src/main/com/mucommander/cache/WindowsStorage.java +++ b/src/main/com/mucommander/cache/WindowsStorage.java @@ -40,7 +40,7 @@ public class WindowsStorage { public static class Record { public final int left, top, width, height; - public Record(String s) { + Record(String s) { String[] val = s.split(","); this.left = Integer.parseInt(val[0].trim()); this.top = Integer.parseInt(val[1].trim()); @@ -60,7 +60,7 @@ public boolean equals(Object obj) { if (obj == this) { return true; } - if (obj == null || !(obj instanceof Record)) { + if (!(obj instanceof Record)) { return false; } Record rec = (Record)obj; @@ -77,7 +77,7 @@ public void apply(Window window) { window.setSize(width, height); } - public void applyPos(Window window) { + void applyPos(Window window) { window.setLocation(left, top); } } @@ -171,56 +171,77 @@ private Map getRecords() { private void load(AbstractFile file) throws IOException { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(file.getInputStream())); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getInputStream()))) { String line; - while ( (line = reader.readLine() ) != null) { - line = line.trim(); - if (line.isEmpty() || line.startsWith("#")) { - continue; - } - int index = line.indexOf('='); - if (index < 0) { - continue; - } - String key = line.substring(0, index); - String val = line.substring(index + 1); - try { - records.put(key, new Record(val)); - } catch (Exception e) { - e.printStackTrace(); - } + while ((line = reader.readLine()) != null) { + loadRecord(line.trim()); } + } +// BufferedReader reader = null; +// try { +// reader = new BufferedReader(new InputStreamReader(file.getInputStream())); +// String line; +// while ( (line = reader.readLine() ) != null) { +// line = line.trim(); +// if (line.isEmpty() || line.startsWith("#")) { +// continue; +// } +// int index = line.indexOf('='); +// if (index < 0) { +// continue; +// } +// String key = line.substring(0, index); +// String val = line.substring(index + 1); +// try { +// records.put(key, new Record(val)); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } finally { +// if (reader != null) { +// reader.close(); +// } +// } + } + + private void loadRecord(String line) { + if (line.isEmpty() || line.startsWith("#")) { + return; + } + int index = line.indexOf('='); + if (index < 0) { + return; + } + String key = line.substring(0, index); + String val = line.substring(index + 1); + try { + records.put(key, new Record(val)); } catch (Exception e) { e.printStackTrace(); - } finally { - if (reader != null) { - reader.close(); - } } } - private void save(AbstractFile file) throws IOException { - BufferedWriter writer = null; - try { - writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream())); - for (String key : records.keySet()) { - if (key == null) { - continue; + + private void save(AbstractFile file) throws IOException { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(file.getOutputStream()))) { + for (String key : getRecords().keySet()) { + if (key != null) { + saveRecord(writer, key, records.get(key)); } - writer.write(key); - writer.write('='); - writer.write(records.get(key).toString()); - writer.write('\n'); - } - } finally { - if (writer != null) { - writer.close(); } } } + private void saveRecord(Writer writer, String key, Record record) throws IOException { + writer.write(key); + writer.write('='); + writer.write(record.toString()); + writer.write('\n'); + } + /** * Returns the path to the history file. *

diff --git a/src/main/com/mucommander/commons/DummyDecoratedFile.java b/src/main/com/mucommander/commons/DummyDecoratedFile.java index 56821e3b8..713c9616b 100644 --- a/src/main/com/mucommander/commons/DummyDecoratedFile.java +++ b/src/main/com/mucommander/commons/DummyDecoratedFile.java @@ -17,7 +17,7 @@ public class DummyDecoratedFile extends DummyFile { static { String prefix = "file://" + FileURL.LOCALHOST; - LOCAL_FILE_PREFIX = OsFamily.getCurrent().equals(OsFamily.WINDOWS) ? prefix + '/' : prefix; + LOCAL_FILE_PREFIX = OsFamily.WINDOWS.isCurrent() ? prefix + '/' : prefix; } public DummyDecoratedFile(FileURL url) { diff --git a/src/main/com/mucommander/commons/file/FileFactory.java b/src/main/com/mucommander/commons/file/FileFactory.java index 94abc4b21..8e7b8954d 100644 --- a/src/main/com/mucommander/commons/file/FileFactory.java +++ b/src/main/com/mucommander/commons/file/FileFactory.java @@ -712,8 +712,8 @@ public static AbstractFile wrapArchive(AbstractFile file) throws IOException { // the filename contains a dot '.' character, since most of the time this method is called with a filename that // doesn't match any of the filters. if (filename.indexOf('.') >= 0) { - ArchiveFormatProvider provider; - if ((provider = getArchiveFormatProvider(filename)) != null) { + ArchiveFormatProvider provider = getArchiveFormatProvider(filename); + if (provider != null) { return provider.getFile(file); } } @@ -721,6 +721,14 @@ public static AbstractFile wrapArchive(AbstractFile file) throws IOException { return file; } + /** + * Same as wrapArchive(AbstractFile) but using the given extension rather than the file's extension. + */ + public static AbstractFile wrapArchive(AbstractFile file, String extension) throws IOException { + ArchiveFormatProvider provider = getArchiveFormatProvider(file.getBaseName() + extension); + return provider != null ? provider.getFile(file) : file; + } + /** * Returns the default {@link com.mucommander.commons.file.icon.FileIconProvider} instance. The default provider class diff --git a/src/main/com/mucommander/commons/file/FileURL.java b/src/main/com/mucommander/commons/file/FileURL.java index 479178d77..ed54b9865 100644 --- a/src/main/com/mucommander/commons/file/FileURL.java +++ b/src/main/com/mucommander/commons/file/FileURL.java @@ -866,7 +866,7 @@ public boolean portEquals(FileURL url) { * @return true if the path of this URL and the given URL are equal */ public boolean pathEquals(FileURL url) { - boolean isCaseSensitiveOS = !(OsFamily.getCurrent().equals(OsFamily.WINDOWS) || OsFamily.getCurrent().equals(OsFamily.OS_2)); + boolean isCaseSensitiveOS = !(OsFamily.WINDOWS.isCurrent() || OsFamily.OS_2.isCurrent()); String path1 = isCaseSensitiveOS ? this.getPath() : this.getPath().toLowerCase(); String path2 = isCaseSensitiveOS ? url.getPath() : url.getPath().toLowerCase(); @@ -1014,8 +1014,9 @@ public boolean equals(Object o) { * @return true if both FileURL instances are equal */ public boolean equals(Object o, boolean compareCredentials, boolean compareProperties) { - if (o == null || !(o instanceof FileURL)) + if (!(o instanceof FileURL)) { return false; + } FileURL url = (FileURL)o; diff --git a/src/main/com/mucommander/commons/file/filter/MountedDriveFilter.java b/src/main/com/mucommander/commons/file/filter/MountedDriveFilter.java index ab4d0915d..72414b46d 100644 --- a/src/main/com/mucommander/commons/file/filter/MountedDriveFilter.java +++ b/src/main/com/mucommander/commons/file/filter/MountedDriveFilter.java @@ -28,7 +28,7 @@ public class MountedDriveFilter extends AbstractFileFilter { @Override public boolean accept(AbstractFile file) { - if (file == null || OsFamily.getCurrent() != OsFamily.MAC_OS_X) { + if (file == null || !OsFamily.MAC_OS_X.isCurrent()) { return false; } for (AbstractFile f : LocalFile.getVolumes() ) { diff --git a/src/main/com/mucommander/commons/file/impl/avrdude/Avrdude.java b/src/main/com/mucommander/commons/file/impl/avrdude/Avrdude.java index 8b75a4251..712c615d3 100644 --- a/src/main/com/mucommander/commons/file/impl/avrdude/Avrdude.java +++ b/src/main/com/mucommander/commons/file/impl/avrdude/Avrdude.java @@ -80,7 +80,7 @@ private static String buildCommandLine(AvrdudeConfiguration config, Operation op if (config.avrdudeLocation != null) { cmd = config.avrdudeLocation; } else { - cmd = OsFamily.getCurrent() == OsFamily.WINDOWS ? "avrdude.exe" : "avrdude"; + cmd = OsFamily.WINDOWS.isCurrent() ? "avrdude.exe" : "avrdude"; } cmd += " -p " + config.deviceName; if (config.baudrate != null) { diff --git a/src/main/com/mucommander/commons/runtime/OsVersion.java b/src/main/com/mucommander/commons/runtime/OsVersion.java index c116a4fed..cca3cf1f7 100644 --- a/src/main/com/mucommander/commons/runtime/OsVersion.java +++ b/src/main/com/mucommander/commons/runtime/OsVersion.java @@ -111,7 +111,10 @@ public enum OsVersion implements ComparableRuntimeProperty { MAC_OS_X_10_11("10.11"), /** Mac OS X 10.12 (Sierra) */ - MAC_OS_X_10_12("10.12"); + MAC_OS_X_10_12("10.12"), + + /** Mac OS X 10.13 (High Sierra) */ + MAC_OS_X_10_13("10.13"); @@ -208,6 +211,9 @@ static OsVersion parseSystemProperty(String osVersionProp, String osNameProp, Os } // Mac OS X versions if (osFamily == OsFamily.MAC_OS_X) { + if (osVersionProp.startsWith("10.13")) + return MAC_OS_X_10_13; + if (osVersionProp.startsWith("10.12")) return MAC_OS_X_10_12; @@ -248,7 +254,7 @@ static OsVersion parseSystemProperty(String osVersionProp, String osNameProp, Os return MAC_OS_X_10_0; // Newer version we don't know of yet, assume latest supported OS version - return MAC_OS_X_10_12; + return MAC_OS_X_10_13; } return OsVersion.UNKNOWN_VERSION; diff --git a/src/main/com/mucommander/desktop/DefaultDesktopAdapter.java b/src/main/com/mucommander/desktop/DefaultDesktopAdapter.java index a7c0c66de..b37be34d8 100644 --- a/src/main/com/mucommander/desktop/DefaultDesktopAdapter.java +++ b/src/main/com/mucommander/desktop/DefaultDesktopAdapter.java @@ -146,7 +146,7 @@ public String getDefaultShell() { private String getDefaultShellPath() { - if (OsFamily.getCurrent() == OsFamily.WINDOWS) { + if (OsFamily.WINDOWS.isCurrent()) { return "cmd.exe"; } if (defaultShell == null) { @@ -165,7 +165,7 @@ private String getDefaultShellPath() { public String getDefaultTerminalShellCommand() { String path = getDefaultShellPath(); - if (OsFamily.getCurrent() != OsFamily.WINDOWS) { + if (!OsFamily.WINDOWS.isCurrent()) { return path + " --login"; } return path; diff --git a/src/main/com/mucommander/desktop/osx/OSXDesktopAdapter.java b/src/main/com/mucommander/desktop/osx/OSXDesktopAdapter.java index a5a5c4dba..5b3e692ab 100644 --- a/src/main/com/mucommander/desktop/osx/OSXDesktopAdapter.java +++ b/src/main/com/mucommander/desktop/osx/OSXDesktopAdapter.java @@ -44,7 +44,7 @@ public String toString() { @Override public boolean isAvailable() { - return OsFamily.getCurrent().equals(OsFamily.MAC_OS_X); + return OsFamily.MAC_OS_X.isCurrent(); } @Override diff --git a/src/main/com/mucommander/desktop/windows/WindowsDesktopAdapter.java b/src/main/com/mucommander/desktop/windows/WindowsDesktopAdapter.java index 13f9a9c73..105f2f1b4 100644 --- a/src/main/com/mucommander/desktop/windows/WindowsDesktopAdapter.java +++ b/src/main/com/mucommander/desktop/windows/WindowsDesktopAdapter.java @@ -42,7 +42,7 @@ public void init(boolean install) throws DesktopInitialisationException { @Override public boolean isAvailable() { - return OsFamily.getCurrent().equals(OsFamily.WINDOWS); + return OsFamily.WINDOWS.isCurrent(); } /** diff --git a/src/main/com/mucommander/job/FindFileJob.java b/src/main/com/mucommander/job/FindFileJob.java index 6b372577e..e53748dd6 100644 --- a/src/main/com/mucommander/job/FindFileJob.java +++ b/src/main/com/mucommander/job/FindFileJob.java @@ -161,8 +161,7 @@ public void setup(String fileMask, String fileContent, boolean searchSubdirs, bo this.searchSubdirectories = searchSubdirs; this.searchArchives = searchArchives; this.ignoreHidden = ignoreHidden; - IOCase filterCase = OsFamily.getCurrent() == OsFamily.MAC_OS_X || OsFamily.getCurrent() == OsFamily.WINDOWS ? - IOCase.INSENSITIVE : IOCase.SENSITIVE; + IOCase filterCase = OsFamily.MAC_OS_X.isCurrent() || OsFamily.WINDOWS.isCurrent() ? IOCase.INSENSITIVE : IOCase.SENSITIVE; if (fileMask.contains(",")) { String masks[] = fileMask.split(","); diff --git a/src/main/com/mucommander/job/MakeDirectoryFileJob.java b/src/main/com/mucommander/job/MakeDirectoryFileJob.java index dd9da7698..24d0f41a0 100644 --- a/src/main/com/mucommander/job/MakeDirectoryFileJob.java +++ b/src/main/com/mucommander/job/MakeDirectoryFileJob.java @@ -156,7 +156,7 @@ protected boolean processFile(AbstractFile file, Object recurseParams) { boolean needAdminPermissions = e instanceof FileAccessDeniedException; int action; if (needAdminPermissions && !mkfileMode) { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { if (!mkfileMode) { tryMkDirAsAdministrator(file.getAbsolutePath(), null); } @@ -196,7 +196,7 @@ protected boolean processFile(AbstractFile file, Object recurseParams) { } private void tryMkDirAsAdministrator(String path, String password) { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { AppleScript.execute("do shell script \"mkdir -p + '" + path + "' \" with administrator privileges", new StringBuilder()); } } diff --git a/src/main/com/mucommander/tools/FileMergeTool.java b/src/main/com/mucommander/tools/FileMergeTool.java index 261282e23..2e4825115 100644 --- a/src/main/com/mucommander/tools/FileMergeTool.java +++ b/src/main/com/mucommander/tools/FileMergeTool.java @@ -27,7 +27,7 @@ public class FileMergeTool extends ExternalTool { @Override public boolean isActive() { - return OsFamily.getCurrent() == OsFamily.MAC_OS_X; + return OsFamily.MAC_OS_X.isCurrent(); } @Override diff --git a/src/main/com/mucommander/ui/action/AbstractActionDescriptor.java b/src/main/com/mucommander/ui/action/AbstractActionDescriptor.java index abf43acfd..e36ad089d 100644 --- a/src/main/com/mucommander/ui/action/AbstractActionDescriptor.java +++ b/src/main/com/mucommander/ui/action/AbstractActionDescriptor.java @@ -19,10 +19,12 @@ package com.mucommander.ui.action; import com.mucommander.commons.file.util.ResourceLoader; +import com.mucommander.commons.runtime.OsFamily; import com.mucommander.utils.text.Translator; import com.mucommander.ui.icon.IconManager; import javax.swing.*; +import java.awt.event.KeyEvent; /** * AbstractActionDescriptor is an abstract class which implements ActionDescriptor interface. @@ -34,6 +36,8 @@ * @author Arik Hadas */ public abstract class AbstractActionDescriptor implements ActionDescriptor { + protected static final int CTRL_OR_META_DOWN_MASK = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK; + // static int count; // public AbstractActionDescriptor() { // count++; diff --git a/src/main/com/mucommander/ui/action/ActionManager.java b/src/main/com/mucommander/ui/action/ActionManager.java index 70272cfb4..0ec372992 100644 --- a/src/main/com/mucommander/ui/action/ActionManager.java +++ b/src/main/com/mucommander/ui/action/ActionManager.java @@ -132,6 +132,7 @@ public static void registerActions() { registerAction(new NewWindowAction.Descriptor()); registerAction(new NextTabAction.Descriptor()); registerAction(new OpenAction.Descriptor()); + registerAction(new OpenAsAction.Descriptor()); registerAction(new OpenInBothPanelsAction.Descriptor()); registerAction(new OpenInNewTabAction.Descriptor()); registerAction(new OpenInOtherPanelAction.Descriptor()); diff --git a/src/main/com/mucommander/ui/action/impl/AddBookmarkAction.java b/src/main/com/mucommander/ui/action/impl/AddBookmarkAction.java index 342f655a4..407d0b90c 100644 --- a/src/main/com/mucommander/ui/action/impl/AddBookmarkAction.java +++ b/src/main/com/mucommander/ui/action/impl/AddBookmarkAction.java @@ -18,16 +18,14 @@ package com.mucommander.ui.action.impl; -import java.awt.event.KeyEvent; -import java.util.Map; - -import javax.swing.KeyStroke; - -import com.mucommander.commons.runtime.OsFamily; import com.mucommander.ui.action.*; import com.mucommander.ui.dialog.bookmark.AddBookmarkDialog; import com.mucommander.ui.main.MainFrame; +import javax.swing.*; +import java.awt.event.KeyEvent; +import java.util.Map; + /** * This action brings up the 'Add bookmark' dialog that allows to bookmark the current folder. * @@ -62,11 +60,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_B, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/AddTabAction.java b/src/main/com/mucommander/ui/action/impl/AddTabAction.java index bafb6560c..fce5c3523 100644 --- a/src/main/com/mucommander/ui/action/impl/AddTabAction.java +++ b/src/main/com/mucommander/ui/action/impl/AddTabAction.java @@ -60,11 +60,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_T, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/ChangeLocationAction.java b/src/main/com/mucommander/ui/action/impl/ChangeLocationAction.java index 186d5cd66..621db3d8a 100644 --- a/src/main/com/mucommander/ui/action/impl/ChangeLocationAction.java +++ b/src/main/com/mucommander/ui/action/impl/ChangeLocationAction.java @@ -72,11 +72,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_G, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_G, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/CloseOtherTabsAction.java b/src/main/com/mucommander/ui/action/impl/CloseOtherTabsAction.java index 90b09a761..c663c7cb4 100644 --- a/src/main/com/mucommander/ui/action/impl/CloseOtherTabsAction.java +++ b/src/main/com/mucommander/ui/action/impl/CloseOtherTabsAction.java @@ -61,11 +61,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.META_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/CloseTabAction.java b/src/main/com/mucommander/ui/action/impl/CloseTabAction.java index 2fe49875c..cc7334f68 100644 --- a/src/main/com/mucommander/ui/action/impl/CloseTabAction.java +++ b/src/main/com/mucommander/ui/action/impl/CloseTabAction.java @@ -73,11 +73,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_W, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/CompareFilesAction.java b/src/main/com/mucommander/ui/action/impl/CompareFilesAction.java index 97a4a2d4d..c22554815 100644 --- a/src/main/com/mucommander/ui/action/impl/CompareFilesAction.java +++ b/src/main/com/mucommander/ui/action/impl/CompareFilesAction.java @@ -76,7 +76,7 @@ public void performAction(FileSet files) { } private static boolean supported() { - return OsFamily.getCurrent() == OsFamily.MAC_OS_X && new File("/usr/bin/opendiff").exists(); + return OsFamily.MAC_OS_X.isCurrent() && new File("/usr/bin/opendiff").exists(); } @Override diff --git a/src/main/com/mucommander/ui/action/impl/ConnectToServerAction.java b/src/main/com/mucommander/ui/action/impl/ConnectToServerAction.java index 2ab43c873..883f8bbd1 100644 --- a/src/main/com/mucommander/ui/action/impl/ConnectToServerAction.java +++ b/src/main/com/mucommander/ui/action/impl/ConnectToServerAction.java @@ -69,11 +69,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_K, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/CopyFileBaseNamesAction.java b/src/main/com/mucommander/ui/action/impl/CopyFileBaseNamesAction.java index 2f37feb29..1c19e075e 100644 --- a/src/main/com/mucommander/ui/action/impl/CopyFileBaseNamesAction.java +++ b/src/main/com/mucommander/ui/action/impl/CopyFileBaseNamesAction.java @@ -80,11 +80,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.ALT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.ALT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.ALT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/CopyFileNamesAction.java b/src/main/com/mucommander/ui/action/impl/CopyFileNamesAction.java index d5f33f8e2..2d91883a6 100644 --- a/src/main/com/mucommander/ui/action/impl/CopyFileNamesAction.java +++ b/src/main/com/mucommander/ui/action/impl/CopyFileNamesAction.java @@ -77,6 +77,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { + if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); } else { diff --git a/src/main/com/mucommander/ui/action/impl/CopyFilesToClipboardAction.java b/src/main/com/mucommander/ui/action/impl/CopyFilesToClipboardAction.java index 3a5a3fe17..844c00785 100644 --- a/src/main/com/mucommander/ui/action/impl/CopyFilesToClipboardAction.java +++ b/src/main/com/mucommander/ui/action/impl/CopyFilesToClipboardAction.java @@ -59,16 +59,16 @@ public static final class Descriptor extends AbstractActionDescriptor { public String getId() { return ACTION_ID; } - public ActionCategory getCategory() { return ActionCategory.SELECTION; } + public ActionCategory getCategory() { + return ActionCategory.SELECTION; + } - public KeyStroke getDefaultAltKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK); } + public KeyStroke getDefaultAltKeyStroke() { + return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK); + } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_C, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/EjectDriveAction.java b/src/main/com/mucommander/ui/action/impl/EjectDriveAction.java index 737565119..06d456c73 100644 --- a/src/main/com/mucommander/ui/action/impl/EjectDriveAction.java +++ b/src/main/com/mucommander/ui/action/impl/EjectDriveAction.java @@ -55,7 +55,7 @@ public void performAction(FileSet files) { } public static void eject(MainFrame mainFrame, AbstractFile file) { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { new EjectWorker(mainFrame, file.getName()).execute(); } } @@ -71,11 +71,17 @@ public static final class Descriptor extends AbstractActionDescriptor { public String getId() { return ACTION_ID; } - public ActionCategory getCategory() { return ActionCategory.FILES; } + public ActionCategory getCategory() { + return ActionCategory.FILES; + } - public KeyStroke getDefaultAltKeyStroke() { return null; } + public KeyStroke getDefaultAltKeyStroke() { + return null; + } - public KeyStroke getDefaultKeyStroke() { return null; } + public KeyStroke getDefaultKeyStroke() { + return null; + } public MuAction createAction(MainFrame mainFrame, Map properties) { return new EjectDriveAction(mainFrame, properties); diff --git a/src/main/com/mucommander/ui/action/impl/EmailAction.java b/src/main/com/mucommander/ui/action/impl/EmailAction.java index f6922aadb..24f45a178 100644 --- a/src/main/com/mucommander/ui/action/impl/EmailAction.java +++ b/src/main/com/mucommander/ui/action/impl/EmailAction.java @@ -79,11 +79,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_S, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/ExploreBookmarksAction.java b/src/main/com/mucommander/ui/action/impl/ExploreBookmarksAction.java index 7dfa303d8..118735eba 100644 --- a/src/main/com/mucommander/ui/action/impl/ExploreBookmarksAction.java +++ b/src/main/com/mucommander/ui/action/impl/ExploreBookmarksAction.java @@ -72,11 +72,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/FindFileAction.java b/src/main/com/mucommander/ui/action/impl/FindFileAction.java index 18edf9cb7..ab0c609de 100644 --- a/src/main/com/mucommander/ui/action/impl/FindFileAction.java +++ b/src/main/com/mucommander/ui/action/impl/FindFileAction.java @@ -65,14 +65,10 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_F, CTRL_OR_META_DOWN_MASK); } - public MuAction createAction(MainFrame mainFrame, Map properties) { + public MuAction createAction(MainFrame mainFrame, Map properties) { return new FindFileAction(mainFrame, properties); } } diff --git a/src/main/com/mucommander/ui/action/impl/FocusNextAction.java b/src/main/com/mucommander/ui/action/impl/FocusNextAction.java index eaf7e6c36..8d0e45937 100644 --- a/src/main/com/mucommander/ui/action/impl/FocusNextAction.java +++ b/src/main/com/mucommander/ui/action/impl/FocusNextAction.java @@ -95,11 +95,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/FocusPreviousAction.java b/src/main/com/mucommander/ui/action/impl/FocusPreviousAction.java index 7856756ed..91f859e94 100644 --- a/src/main/com/mucommander/ui/action/impl/FocusPreviousAction.java +++ b/src/main/com/mucommander/ui/action/impl/FocusPreviousAction.java @@ -96,11 +96,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK| CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/GoToParentInBothPanelsAction.java b/src/main/com/mucommander/ui/action/impl/GoToParentInBothPanelsAction.java index 2feff3729..37b0c74fc 100644 --- a/src/main/com/mucommander/ui/action/impl/GoToParentInBothPanelsAction.java +++ b/src/main/com/mucommander/ui/action/impl/GoToParentInBothPanelsAction.java @@ -115,11 +115,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.SHIFT_DOWN_MASK| CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/GoToParentInOtherPanelAction.java b/src/main/com/mucommander/ui/action/impl/GoToParentInOtherPanelAction.java index 5b2cf29e5..3e0e2f626 100644 --- a/src/main/com/mucommander/ui/action/impl/GoToParentInOtherPanelAction.java +++ b/src/main/com/mucommander/ui/action/impl/GoToParentInOtherPanelAction.java @@ -103,11 +103,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/MarkAllAction.java b/src/main/com/mucommander/ui/action/impl/MarkAllAction.java index 8121e0226..6fbb4d7c3 100644 --- a/src/main/com/mucommander/ui/action/impl/MarkAllAction.java +++ b/src/main/com/mucommander/ui/action/impl/MarkAllAction.java @@ -79,11 +79,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_A, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/MarkNextBlockAction.java b/src/main/com/mucommander/ui/action/impl/MarkNextBlockAction.java index a4b5661dd..5c6f24712 100644 --- a/src/main/com/mucommander/ui/action/impl/MarkNextBlockAction.java +++ b/src/main/com/mucommander/ui/action/impl/MarkNextBlockAction.java @@ -66,11 +66,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/MarkPreviousBlockAction.java b/src/main/com/mucommander/ui/action/impl/MarkPreviousBlockAction.java index 20ab9e213..e4f4e31cb 100644 --- a/src/main/com/mucommander/ui/action/impl/MarkPreviousBlockAction.java +++ b/src/main/com/mucommander/ui/action/impl/MarkPreviousBlockAction.java @@ -67,11 +67,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/NewWindowAction.java b/src/main/com/mucommander/ui/action/impl/NewWindowAction.java index 1026078cc..efbe2192e 100644 --- a/src/main/com/mucommander/ui/action/impl/NewWindowAction.java +++ b/src/main/com/mucommander/ui/action/impl/NewWindowAction.java @@ -63,11 +63,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_N, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/NextTabAction.java b/src/main/com/mucommander/ui/action/impl/NextTabAction.java index b2d18939b..29d8e2130 100644 --- a/src/main/com/mucommander/ui/action/impl/NextTabAction.java +++ b/src/main/com/mucommander/ui/action/impl/NextTabAction.java @@ -75,19 +75,11 @@ public static final class Descriptor extends AbstractActionDescriptor { public ActionCategory getCategory() { return ActionCategory.TAB; } public KeyStroke getDefaultAltKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, CTRL_OR_META_DOWN_MASK); } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/OpenAction.java b/src/main/com/mucommander/ui/action/impl/OpenAction.java index d2f902930..c56c43b38 100644 --- a/src/main/com/mucommander/ui/action/impl/OpenAction.java +++ b/src/main/com/mucommander/ui/action/impl/OpenAction.java @@ -18,6 +18,7 @@ package com.mucommander.ui.action.impl; +import com.mucommander.bookmark.Bookmark; import com.mucommander.bookmark.BookmarkManager; import com.mucommander.commons.file.AbstractFile; import com.mucommander.commons.file.FileProtocols; @@ -88,54 +89,26 @@ public class OpenAction extends MuAction { * @param destination if file is browsable, folder panel in which to open the file. */ protected void open(final AbstractFile file, FolderPanel destination) { - AbstractFile resolvedFile; - if (file.isSymlink()) { - resolvedFile = resolveSymlink(file); - - if (resolvedFile == null) { - InformationDialog.showErrorDialog(mainFrame, Translator.get("cannot_open_cyclic_symlink")); - return; - } - } else { - resolvedFile = file; - } + AbstractFile resolvedFile = resolveIfSymlink(file); + if (resolvedFile == null) { + return; + } // Opens browsable files in the destination FolderPanel. if (resolvedFile.isBrowsable()) { - resolvedFile = MuConfigurations.getPreferences().getVariable(MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS) ? resolvedFile : file; - - FileTableTabs tabs = destination.getTabs(); - - if (BookmarkManager.isBookmark(resolvedFile)) { - String bookmarkLocation = BookmarkManager.getBookmark(resolvedFile.getName()).getLocation(); - try { - FileURL bookmarkURL = FileURL.getFileURL(bookmarkLocation); - if (tabs.getCurrentTab().isLocked()) { - tabs.add(bookmarkURL); - } else { - destination.tryChangeCurrentFolder(bookmarkURL); - } - } catch (MalformedURLException ignore) {} - } else { - if (tabs.getCurrentTab().isLocked()) { - tabs.add(resolvedFile); - } else { - destination.tryChangeCurrentFolder(resolvedFile); - } - } - } - - // Opens local files using their native associations. - else if (resolvedFile.getURL().getScheme().equals(FileProtocols.FILE) && resolvedFile.hasAncestor(LocalFile.class)) { - try { - DesktopManager.open(resolvedFile); - RecentExecutedFilesQL.addFile(resolvedFile); - } catch (IOException e) { - InformationDialog.showErrorDialog(mainFrame); - } + resolvedFile = cdFollowsSymlinks() ? resolvedFile : file; + openBrowsable(resolvedFile, destination); } - - // Copies non-local file in a temporary local file and opens them using their native association. + // Opens local files using their native associations. + else if (isLocalFile(resolvedFile)) { + try { + DesktopManager.open(resolvedFile); + RecentExecutedFilesQL.addFile(resolvedFile); + } catch (IOException e) { + InformationDialog.showErrorDialog(mainFrame); + } + } + // Copies non-local file in a temporary local file and opens them using their native association. else { ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying")); TempExecJob job = new TempExecJob(progressDialog, mainFrame, resolvedFile); @@ -143,6 +116,54 @@ else if (resolvedFile.getURL().getScheme().equals(FileProtocols.FILE) && resolve } } + AbstractFile resolveIfSymlink(AbstractFile file) { + if (!file.isSymlink()) { + return file; + } + AbstractFile resolvedFile = resolveSymlink(file); + + if (resolvedFile == null) { + InformationDialog.showErrorDialog(mainFrame, Translator.get("cannot_open_cyclic_symlink")); + return null; + } + return resolvedFile; + } + + private void openBrowsable(AbstractFile file, FolderPanel destination) { + FileTableTabs tabs = destination.getTabs(); + + if (BookmarkManager.isBookmark(file)) { + Bookmark bookmark = BookmarkManager.getBookmark(file.getName()); + if (bookmark == null) { + return; + } + String bookmarkLocation = bookmark.getLocation(); + try { + FileURL bookmarkURL = FileURL.getFileURL(bookmarkLocation); + if (tabs.getCurrentTab().isLocked()) { + tabs.add(bookmarkURL); + } else { + destination.tryChangeCurrentFolder(bookmarkURL); + } + } catch (MalformedURLException ignore) {} + } else { + if (tabs.getCurrentTab().isLocked()) { + tabs.add(file); + } else { + destination.tryChangeCurrentFolder(file); + } + } + } + + private static boolean isLocalFile(AbstractFile file) { + return file.getURL().getScheme().equals(FileProtocols.FILE) && file.hasAncestor(LocalFile.class); + } + + + private static boolean cdFollowsSymlinks() { + return MuConfigurations.getPreferences().getVariable(MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS); + } + private AbstractFile resolveSymlink(AbstractFile symlink) { return resolveSymlink(symlink, new HashSet<>()); } @@ -163,12 +184,9 @@ public void performAction() { // Retrieves the currently selected file, aborts if none. // Note: a CachedFile instance is retrieved to avoid blocking the event thread. AbstractFile file = mainFrame.getActiveTable().getSelectedFile(true, true); - if (file == null) { - return; + if (file != null) { + open(file, mainFrame.getActivePanel()); } - - // Opens the currently selected file. - open(file, mainFrame.getActivePanel()); } @Override diff --git a/src/main/com/mucommander/ui/action/impl/OpenAsAction.java b/src/main/com/mucommander/ui/action/impl/OpenAsAction.java new file mode 100644 index 000000000..45ec91a71 --- /dev/null +++ b/src/main/com/mucommander/ui/action/impl/OpenAsAction.java @@ -0,0 +1,91 @@ +/* + * This file is part of trolCommander, http://www.trolsoft.ru/en/soft/trolcommander + * Copyright (C) 2014-2018 Oleg Trifonov + * + * trolCommander is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * trolCommander is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.mucommander.ui.action.impl; + +import com.mucommander.commons.file.AbstractFile; +import com.mucommander.commons.file.FileFactory; +import com.mucommander.ui.action.AbstractActionDescriptor; +import com.mucommander.ui.action.ActionCategory; +import com.mucommander.ui.action.ActionDescriptor; +import com.mucommander.ui.action.MuAction; +import com.mucommander.ui.main.MainFrame; + +import javax.swing.*; +import java.io.IOException; +import java.util.Map; + +/** + * Open a file as if it has the specified file extension. + */ +public class OpenAsAction extends OpenAction { + + private String extension; + + public OpenAsAction(MainFrame mainFrame, Map properties) { + super(mainFrame, properties); + extension = (String) properties.get("extension"); + } + + /** + * Opens the currently selected file in the active folder panel. + */ + @Override + public void performAction() { + // Retrieves the currently selected file, + // Note: a CachedFile instance is retrieved to avoid blocking the event thread. + AbstractFile file = mainFrame.getActiveTable().getSelectedFile(true, true); + if (file == null) { + return; + } + AbstractFile resolvedFile = resolveIfSymlink(file); + try { + resolvedFile = FileFactory.wrapArchive(resolvedFile, extension); + open(resolvedFile, mainFrame.getActivePanel()); + } catch (IOException ignore) {} + } + + @Override + public ActionDescriptor getDescriptor() { + return new Descriptor(); + } + + public static final class Descriptor extends AbstractActionDescriptor { + public static final String ACTION_ID = "OpenAs"; + + public String getId() { + return ACTION_ID; + } + + public ActionCategory getCategory() { + return ActionCategory.NAVIGATION; + } + + public KeyStroke getDefaultAltKeyStroke() { + return null; + } + + public KeyStroke getDefaultKeyStroke() { + return null; + } + + public MuAction createAction(MainFrame mainFrame, Map properties) { + return new OpenAsAction(mainFrame, properties); + } + } + +} diff --git a/src/main/com/mucommander/ui/action/impl/OpenInBothPanelsAction.java b/src/main/com/mucommander/ui/action/impl/OpenInBothPanelsAction.java index b045859b3..60cca797c 100644 --- a/src/main/com/mucommander/ui/action/impl/OpenInBothPanelsAction.java +++ b/src/main/com/mucommander/ui/action/impl/OpenInBothPanelsAction.java @@ -164,11 +164,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/OpenInNewTabAction.java b/src/main/com/mucommander/ui/action/impl/OpenInNewTabAction.java index 77fe426cb..570bd3494 100644 --- a/src/main/com/mucommander/ui/action/impl/OpenInNewTabAction.java +++ b/src/main/com/mucommander/ui/action/impl/OpenInNewTabAction.java @@ -95,11 +95,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/OpenInOtherPanelAction.java b/src/main/com/mucommander/ui/action/impl/OpenInOtherPanelAction.java index 81fa04d95..1274983e8 100644 --- a/src/main/com/mucommander/ui/action/impl/OpenInOtherPanelAction.java +++ b/src/main/com/mucommander/ui/action/impl/OpenInOtherPanelAction.java @@ -96,11 +96,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_O, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/PackAction.java b/src/main/com/mucommander/ui/action/impl/PackAction.java index 574251199..9e725855b 100644 --- a/src/main/com/mucommander/ui/action/impl/PackAction.java +++ b/src/main/com/mucommander/ui/action/impl/PackAction.java @@ -65,11 +65,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_I, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/PasteClipboardFilesAction.java b/src/main/com/mucommander/ui/action/impl/PasteClipboardFilesAction.java index 23742557e..c8dea3768 100644 --- a/src/main/com/mucommander/ui/action/impl/PasteClipboardFilesAction.java +++ b/src/main/com/mucommander/ui/action/impl/PasteClipboardFilesAction.java @@ -84,11 +84,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_V, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/PreviousTabAction.java b/src/main/com/mucommander/ui/action/impl/PreviousTabAction.java index 2bda34209..d7e40d45b 100644 --- a/src/main/com/mucommander/ui/action/impl/PreviousTabAction.java +++ b/src/main/com/mucommander/ui/action/impl/PreviousTabAction.java @@ -75,19 +75,11 @@ public static final class Descriptor extends AbstractActionDescriptor { public ActionCategory getCategory() { return ActionCategory.TAB; } public KeyStroke getDefaultAltKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, CTRL_OR_META_DOWN_MASK); } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/QuitAction.java b/src/main/com/mucommander/ui/action/impl/QuitAction.java index 1ab263f83..1b2636167 100644 --- a/src/main/com/mucommander/ui/action/impl/QuitAction.java +++ b/src/main/com/mucommander/ui/action/impl/QuitAction.java @@ -63,11 +63,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_O, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/RecallNextWindowAction.java b/src/main/com/mucommander/ui/action/impl/RecallNextWindowAction.java index 202726d8a..0902b2891 100644 --- a/src/main/com/mucommander/ui/action/impl/RecallNextWindowAction.java +++ b/src/main/com/mucommander/ui/action/impl/RecallNextWindowAction.java @@ -59,11 +59,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/RecallPreviousWindowAction.java b/src/main/com/mucommander/ui/action/impl/RecallPreviousWindowAction.java index 4148e0439..0f9ba2ae9 100644 --- a/src/main/com/mucommander/ui/action/impl/RecallPreviousWindowAction.java +++ b/src/main/com/mucommander/ui/action/impl/RecallPreviousWindowAction.java @@ -59,11 +59,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/RevealInDesktopAction.java b/src/main/com/mucommander/ui/action/impl/RevealInDesktopAction.java index 510d38b5f..8311e7374 100644 --- a/src/main/com/mucommander/ui/action/impl/RevealInDesktopAction.java +++ b/src/main/com/mucommander/ui/action/impl/RevealInDesktopAction.java @@ -60,7 +60,7 @@ protected void toggleEnabledState() { @Override public void performAction() { try { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { AbstractFile currentFile = mainFrame.getActiveTable().getSelectedFile(); if (currentFile == null) { currentFile = mainFrame.getActivePanel().getCurrentFolder(); @@ -90,11 +90,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_L, CTRL_OR_META_DOWN_MASK); } @Override @@ -105,7 +101,7 @@ public String getLabel() { @Override public ImageIcon getIcon() { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { return getStandardIcon("Finder"); } return super.getIcon(); diff --git a/src/main/com/mucommander/ui/action/impl/RunCommandAction.java b/src/main/com/mucommander/ui/action/impl/RunCommandAction.java index e5961f3df..196fe7308 100644 --- a/src/main/com/mucommander/ui/action/impl/RunCommandAction.java +++ b/src/main/com/mucommander/ui/action/impl/RunCommandAction.java @@ -59,11 +59,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_R, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/SelectNextBlockAction.java b/src/main/com/mucommander/ui/action/impl/SelectNextBlockAction.java index 4ddd478ac..3fcb2523e 100644 --- a/src/main/com/mucommander/ui/action/impl/SelectNextBlockAction.java +++ b/src/main/com/mucommander/ui/action/impl/SelectNextBlockAction.java @@ -65,11 +65,7 @@ public ActionCategory getCategory() { } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, CTRL_OR_META_DOWN_MASK); } public KeyStroke getDefaultAltKeyStroke() { diff --git a/src/main/com/mucommander/ui/action/impl/SelectPreviousBlockAction.java b/src/main/com/mucommander/ui/action/impl/SelectPreviousBlockAction.java index 4a542eb8a..451a5ba73 100644 --- a/src/main/com/mucommander/ui/action/impl/SelectPreviousBlockAction.java +++ b/src/main/com/mucommander/ui/action/impl/SelectPreviousBlockAction.java @@ -65,11 +65,7 @@ public ActionCategory getCategory() { } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_UP, CTRL_OR_META_DOWN_MASK); } public KeyStroke getDefaultAltKeyStroke() { diff --git a/src/main/com/mucommander/ui/action/impl/SetSameFolderAction.java b/src/main/com/mucommander/ui/action/impl/SetSameFolderAction.java index 964a43f36..c07cbbb3a 100644 --- a/src/main/com/mucommander/ui/action/impl/SetSameFolderAction.java +++ b/src/main/com/mucommander/ui/action/impl/SetSameFolderAction.java @@ -77,11 +77,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_E, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/ShowServerConnectionsAction.java b/src/main/com/mucommander/ui/action/impl/ShowServerConnectionsAction.java index ddbc5cedf..1288614f6 100644 --- a/src/main/com/mucommander/ui/action/impl/ShowServerConnectionsAction.java +++ b/src/main/com/mucommander/ui/action/impl/ShowServerConnectionsAction.java @@ -60,11 +60,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.SHIFT_DOWN_MASK | CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/SwapFoldersAction.java b/src/main/com/mucommander/ui/action/impl/SwapFoldersAction.java index 95344cc8c..2de2e4863 100644 --- a/src/main/com/mucommander/ui/action/impl/SwapFoldersAction.java +++ b/src/main/com/mucommander/ui/action/impl/SwapFoldersAction.java @@ -59,11 +59,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_U, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/TextEditorsListAction.java b/src/main/com/mucommander/ui/action/impl/TextEditorsListAction.java index 3cdc15299..7423a61b3 100644 --- a/src/main/com/mucommander/ui/action/impl/TextEditorsListAction.java +++ b/src/main/com/mucommander/ui/action/impl/TextEditorsListAction.java @@ -58,11 +58,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.ALT_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_TAB, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/ToggleHiddenFilesAction.java b/src/main/com/mucommander/ui/action/impl/ToggleHiddenFilesAction.java index 9ff1c4be4..1359bc9f9 100644 --- a/src/main/com/mucommander/ui/action/impl/ToggleHiddenFilesAction.java +++ b/src/main/com/mucommander/ui/action/impl/ToggleHiddenFilesAction.java @@ -76,11 +76,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/ToggleTreeAction.java b/src/main/com/mucommander/ui/action/impl/ToggleTreeAction.java index 7e80af2fe..8b53d1f64 100644 --- a/src/main/com/mucommander/ui/action/impl/ToggleTreeAction.java +++ b/src/main/com/mucommander/ui/action/impl/ToggleTreeAction.java @@ -65,11 +65,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_J, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_J, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_J, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/UnmarkAllAction.java b/src/main/com/mucommander/ui/action/impl/UnmarkAllAction.java index 21f33b19b..be9ecbf98 100644 --- a/src/main/com/mucommander/ui/action/impl/UnmarkAllAction.java +++ b/src/main/com/mucommander/ui/action/impl/UnmarkAllAction.java @@ -56,11 +56,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_D, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/action/impl/UnpackAction.java b/src/main/com/mucommander/ui/action/impl/UnpackAction.java index 1ef1a6a3f..af93bb3da 100644 --- a/src/main/com/mucommander/ui/action/impl/UnpackAction.java +++ b/src/main/com/mucommander/ui/action/impl/UnpackAction.java @@ -70,11 +70,7 @@ public static final class Descriptor extends AbstractActionDescriptor { public KeyStroke getDefaultAltKeyStroke() { return null; } public KeyStroke getDefaultKeyStroke() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK); - } else { - return KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.META_DOWN_MASK); - } + return KeyStroke.getKeyStroke(KeyEvent.VK_P, CTRL_OR_META_DOWN_MASK); } public MuAction createAction(MainFrame mainFrame, Map properties) { diff --git a/src/main/com/mucommander/ui/button/RolloverButtonAdapter.java b/src/main/com/mucommander/ui/button/RolloverButtonAdapter.java index f816cff5f..ebf0f85c4 100644 --- a/src/main/com/mucommander/ui/button/RolloverButtonAdapter.java +++ b/src/main/com/mucommander/ui/button/RolloverButtonAdapter.java @@ -18,6 +18,8 @@ package com.mucommander.ui.button; +import com.mucommander.commons.runtime.OsVersion; + import javax.swing.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -30,7 +32,7 @@ * Such buttons are particularly effective for toolbars, where a large number of buttons are usually present. * *

- * To 'rollover-enable' a button, the {@link #setButtonDecoration(javax.swing.JButton)} method must first be called to + * To 'rollover-enable' a button, the {@link #decorateButton(javax.swing.JButton)} method must first be called to * set decoration properties. Then, the button must register an instance of RolloverButtonAdapter as a * mouse listener. Note that a single RolloverButtonAdapter instance can be registered with several buttons. * @@ -38,6 +40,8 @@ */ public class RolloverButtonAdapter implements MouseListener { + private static final RolloverButtonAdapter INSTANCE = new RolloverButtonAdapter(); + /** * Creates a new RolloverButtonAdapter. */ @@ -49,11 +53,17 @@ public RolloverButtonAdapter() { * * @param button the button to 'rollover-enable' */ - public static void setButtonDecoration(JButton button) { + public static void decorateButton(JButton button) { // Set button decorations and rollover behavior button.setRolloverEnabled(true); button.setFocusPainted(false); button.setBorderPainted(false); + button.setContentAreaFilled(false); +// if (OsVersion.MAC_OS_X_10_5.isCurrentOrHigher()) { +// button.putClientProperty("JButton.buttonType", "textured"); +// } + button.setRolloverEnabled(true); + button.addMouseListener(INSTANCE); } diff --git a/src/main/com/mucommander/ui/dialog/FocusDialog.java b/src/main/com/mucommander/ui/dialog/FocusDialog.java index 976556a37..fbcdd0b58 100644 --- a/src/main/com/mucommander/ui/dialog/FocusDialog.java +++ b/src/main/com/mucommander/ui/dialog/FocusDialog.java @@ -29,6 +29,7 @@ import javax.swing.border.EmptyBorder; import com.mucommander.cache.WindowsStorage; +import com.mucommander.ui.macosx.IMacOsWindow; import com.mucommander.ui.main.MainFrame; import com.mucommander.utils.text.Translator; import org.slf4j.Logger; @@ -48,7 +49,7 @@ * * @author Maxence Bernard */ -public class FocusDialog extends JDialog implements WindowListener { +public class FocusDialog extends JDialog implements WindowListener, IMacOsWindow { private static final Logger LOGGER = LoggerFactory.getLogger(FocusDialog.class); private static final EmptyBorder BORDER = new EmptyBorder(6, 8, 6, 8); @@ -137,6 +138,8 @@ private void init(Component locationRelativeComp) { this.locationRelativeComp = locationRelativeComp; setLocationRelativeTo(locationRelativeComp); + initLookAndFeel(); + JPanel contentPane = (JPanel)getContentPane(); contentPane.setBorder(BORDER); setResizable(true); diff --git a/src/main/com/mucommander/ui/dialog/symlink/CreateSymLinkDialog.java b/src/main/com/mucommander/ui/dialog/symlink/CreateSymLinkDialog.java index a023cf16d..e7adfed9d 100644 --- a/src/main/com/mucommander/ui/dialog/symlink/CreateSymLinkDialog.java +++ b/src/main/com/mucommander/ui/dialog/symlink/CreateSymLinkDialog.java @@ -54,15 +54,16 @@ public class CreateSymLinkDialog extends FocusDialog implements ActionListener { */ private static final Dimension MAXIMUM_DIALOG_DIMENSION = new Dimension(1024, 320); + private static final int RETRY_ACTION = 1; + private static final int CANCEL_ACTION = 0; + private final Frame mainFrame; private final FilePathField edtTarget; private final JTextField edtName; private final JButton btnOk; + private final JButton btnCancel; - private static final int RETRY_ACTION = 1; - private static final int CANCEL_ACTION = 0; - /** @@ -74,8 +75,6 @@ public class CreateSymLinkDialog extends FocusDialog implements ActionListener { public CreateSymLinkDialog(Frame mainFrame, AbstractFile linkPath, AbstractFile targetFile) { super(mainFrame, i18n("symboliclinkeditor.create"), null); this.mainFrame = mainFrame; - AbstractFile linkPath1 = linkPath; - AbstractFile targetFile1 = targetFile; Container contentPane = getContentPane(); @@ -93,7 +92,7 @@ public CreateSymLinkDialog(Frame mainFrame, AbstractFile linkPath, AbstractFile contentPane.add(yPanel, BorderLayout.NORTH); btnOk = new JButton(i18n("ok")); - JButton btnCancel = new JButton(i18n("cancel")); + btnCancel = new JButton(i18n("cancel")); contentPane.add(DialogToolkit.createOKCancelPanel(btnOk, btnCancel, getRootPane(), this), BorderLayout.SOUTH); // Path field will receive initial focus @@ -110,7 +109,9 @@ public CreateSymLinkDialog(Frame mainFrame, AbstractFile linkPath, AbstractFile public void actionPerformed(ActionEvent e) { if (e.getSource() == btnOk) { new Thread(this::execute).start(); - } // btnOk + } else if (e.getSource() == btnCancel) { + dispose(); + } } diff --git a/src/main/com/mucommander/ui/icon/FileIcons.java b/src/main/com/mucommander/ui/icon/FileIcons.java index e19983436..83ecdd419 100644 --- a/src/main/com/mucommander/ui/icon/FileIcons.java +++ b/src/main/com/mucommander/ui/icon/FileIcons.java @@ -64,7 +64,7 @@ public class FileIcons { public final static String USE_SYSTEM_ICONS_ALWAYS = "always"; /** Default policy for system icons */ - private final static String DEFAULT_SYSTEM_ICONS_POLICY = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? USE_SYSTEM_ICONS_ALWAYS : USE_SYSTEM_ICONS_APPLICATIONS; + private final static String DEFAULT_SYSTEM_ICONS_POLICY = OsFamily.MAC_OS_X.isCurrent() ? USE_SYSTEM_ICONS_ALWAYS : USE_SYSTEM_ICONS_APPLICATIONS; /** Default icon scale factor (no rescaling) */ private final static float DEFAULT_SCALE_FACTOR = 1.0f; diff --git a/src/main/com/mucommander/ui/layout/AsyncPanel.java b/src/main/com/mucommander/ui/layout/AsyncPanel.java index 03153891e..c76e28f47 100644 --- a/src/main/com/mucommander/ui/layout/AsyncPanel.java +++ b/src/main/com/mucommander/ui/layout/AsyncPanel.java @@ -71,7 +71,7 @@ protected void done() { add(targetComponent, BorderLayout.CENTER); updateLayout(); // Force update viewer/editor window on Windows 8.1 - if (OsFamily.getCurrent() == OsFamily.WINDOWS) { + if (OsFamily.WINDOWS.isCurrent()) { setSize(getSize()); } } diff --git a/src/main/com/mucommander/ui/macosx/IMacOsWindow.java b/src/main/com/mucommander/ui/macosx/IMacOsWindow.java new file mode 100644 index 000000000..49b3b314e --- /dev/null +++ b/src/main/com/mucommander/ui/macosx/IMacOsWindow.java @@ -0,0 +1,21 @@ +package com.mucommander.ui.macosx; + +import com.mucommander.commons.runtime.OsVersion; +import com.mucommander.conf.MuConfigurations; +import com.mucommander.conf.MuPreference; +import com.mucommander.conf.MuPreferences; + + +import javax.swing.*; + + +public interface IMacOsWindow extends RootPaneContainer { + + default void initLookAndFeel() { + if (OsVersion.MAC_OS_X_10_4.isCurrentOrLower() || OsVersion.MAC_OS_X_10_13.isCurrentOrHigher()) { + getRootPane().putClientProperty("apple.awt.brushMetalLook", + MuConfigurations.getPreferences().getVariable(MuPreference.USE_BRUSHED_METAL, MuPreferences.DEFAULT_USE_BRUSHED_METAL)); + } + + } +} diff --git a/src/main/com/mucommander/ui/macosx/OSXIntegration.java b/src/main/com/mucommander/ui/macosx/OSXIntegration.java index 470824f2d..74bf21a51 100644 --- a/src/main/com/mucommander/ui/macosx/OSXIntegration.java +++ b/src/main/com/mucommander/ui/macosx/OSXIntegration.java @@ -54,7 +54,7 @@ public OSXIntegration() { // At the time of writing, the 'brushed metal' look causes the JVM to crash randomly under Leopard (10.5) // so we disable brushed metal on that OS version but leave it for earlier versions where it works fine. // See http://www.mucommander.com/forums/viewtopic.php?f=4&t=746 for more info about this issue. - if (OsVersion.MAC_OS_X_10_4.isCurrentOrLower()) { + if (OsVersion.MAC_OS_X_10_4.isCurrentOrLower() || OsVersion.MAC_OS_X_10_13.isCurrentOrHigher()) { // Turn on/off brush metal look (default is off because still buggy when scrolling and panning dialog windows) : // "Allows you to display your main windows with the 'textured' Aqua window appearance. // This property should be applied only to the primary application window, diff --git a/src/main/com/mucommander/ui/main/MainFrame.java b/src/main/com/mucommander/ui/main/MainFrame.java index ec6a8e757..7d9f256f2 100644 --- a/src/main/com/mucommander/ui/main/MainFrame.java +++ b/src/main/com/mucommander/ui/main/MainFrame.java @@ -40,6 +40,7 @@ import com.mucommander.ui.icon.IconManager; import com.mucommander.ui.layout.ProportionalSplitPane; import com.mucommander.ui.layout.YBoxPanel; +import com.mucommander.ui.macosx.IMacOsWindow; import com.mucommander.ui.main.commandbar.CommandBar; import com.mucommander.ui.main.menu.MainMenuBar; import com.mucommander.ui.main.statusbar.StatusBar; @@ -65,7 +66,7 @@ * * @author Maxence Bernard */ -public class MainFrame extends JFrame implements LocationListener { +public class MainFrame extends JFrame implements LocationListener, IMacOsWindow { private ProportionalSplitPane splitPane; @@ -115,8 +116,9 @@ private void setWindowIcon() { // TODO: this code should probably be moved to the desktop API // - Mac OS X completely ignores calls to #setIconImage/setIconImages, no need to waste time - if (OsFamily.MAC_OS_X.isCurrent()) + if (OsFamily.MAC_OS_X.isCurrent()) { return; + } // Use Java 1.6 's new Window#setIconImages(List) when available if (JavaVersion.JAVA_1_6.isCurrentOrHigher()) { @@ -154,6 +156,7 @@ private void setWindowIcon() { private void init(FolderPanel leftFolderPanel, FolderPanel rightFolderPanel) { // Set the window icon setWindowIcon(); + //initLookAndFeel(); if (OsFamily.MAC_OS_X.isCurrent()) { // Lion Fullscreen support diff --git a/src/main/com/mucommander/ui/main/menu/MainMenuBar.java b/src/main/com/mucommander/ui/main/menu/MainMenuBar.java index d451a2b4e..0c8e1680c 100644 --- a/src/main/com/mucommander/ui/main/menu/MainMenuBar.java +++ b/src/main/com/mucommander/ui/main/menu/MainMenuBar.java @@ -80,17 +80,19 @@ public class MainMenuBar extends JMenuBar implements ActionListener, MenuListene // View menu private JMenu viewMenu; private JMenu themesMenu; - private JCheckBoxMenuItem[] sortByItems = new TCheckBoxMenuItem[Column.values().length]; + private JCheckBoxMenuItem[] cbSortByItems = new TCheckBoxMenuItem[Column.values().length]; private JMenu tableModeMenu; - private JCheckBoxMenuItem[] tableModeItems = new TCheckBoxMenuItem[3]; + private JCheckBoxMenuItem[] cbTableModeItems = new TCheckBoxMenuItem[3]; private JMenu columnsMenu; - private JCheckBoxMenuItem[] toggleColumnItems = new TCheckBoxMenuItem[Column.values().length]; - private JCheckBoxMenuItem toggleToggleAutoSizeItem; - private JCheckBoxMenuItem toggleShowFoldersFirstItem; - private JCheckBoxMenuItem toggleFoldersAlwaysAlphabeticalItem; - private JCheckBoxMenuItem toggleShowHiddenFilesItem; - private JCheckBoxMenuItem toggleTreeItem; - private JCheckBoxMenuItem toggleSinglePanel; + private JCheckBoxMenuItem[] cbToggleColumnItems = new TCheckBoxMenuItem[Column.values().length]; + private JCheckBoxMenuItem cbToggleToggleAutoSizeItem; + private JCheckBoxMenuItem cbToggleShowFoldersFirstItem; + private JCheckBoxMenuItem cbToggleFoldersAlwaysAlphabeticalItem; + private JCheckBoxMenuItem cbToggleShowHiddenFilesItem; + private JCheckBoxMenuItem cbToggleTreeItem; + private JCheckBoxMenuItem cbToggleSinglePanel; + private OpenWithMenu openWithMenu; + private OpenAsMenu openAsMenu; /* TODO branch private JCheckBoxMenuItem toggleBranchView; */ @@ -150,7 +152,10 @@ public MainMenuBar(MainFrame mainFrame) { fileMenu.add(new TMenuSeparator()); MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(OpenAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(OpenNativelyAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - fileMenu.add(new OpenWithMenu(mainFrame, null)); + openWithMenu = new OpenWithMenu(mainFrame, null); + fileMenu.add(openWithMenu); + openAsMenu = new OpenAsMenu(mainFrame); + fileMenu.add(openAsMenu); MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(OpenInNewTabAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(OpenInOtherPanelAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(OpenInBothPanelsAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); @@ -220,18 +225,18 @@ public MainMenuBar(MainFrame mainFrame) { tableModeMenu = MenuToolkit.addMenu(Translator.get("view_menu.table_mode"), null, this); - tableModeItems[0] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeFullAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); - tableModeItems[1] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeCompactAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); - tableModeItems[2] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeShortAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); + cbTableModeItems[0] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeFullAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); + cbTableModeItems[1] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeCompactAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); + cbTableModeItems[2] = MenuToolkit.addCheckBoxMenuItem(tableModeMenu, ActionManager.getActionInstance(ToggleTableViewModeShortAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper2); ButtonGroup groupViewMode = new ButtonGroup(); - for (JCheckBoxMenuItem checkBoxMenuItem : tableModeItems) { + for (JCheckBoxMenuItem checkBoxMenuItem : cbTableModeItems) { groupViewMode.add(checkBoxMenuItem); } // tableModeMenu.addMenuListener(new MenuListener() { // @Override // public void menuSelected(MenuEvent e) { // int mode = mainFrame.getActiveTable().getViewMode().ordinal(); -// tableModeItems[mode].setSelected(true); +// cbTableModeItems[mode].setSelected(true); // } // // @Override @@ -245,11 +250,11 @@ public MainMenuBar(MainFrame mainFrame) { viewMenu.add(tableModeMenu); viewMenu.add(new TMenuSeparator()); - toggleShowFoldersFirstItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleShowFoldersFirstAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - toggleFoldersAlwaysAlphabeticalItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleFoldersAlwaysAlphabeticalAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - toggleShowHiddenFilesItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleHiddenFilesAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - toggleTreeItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleTreeAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - toggleSinglePanel = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleSinglePanelAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleShowFoldersFirstItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleShowFoldersFirstAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleFoldersAlwaysAlphabeticalItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleFoldersAlwaysAlphabeticalAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleShowHiddenFilesItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleHiddenFilesAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleTreeItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleTreeAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleSinglePanel = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleSinglePanelAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); /* TODO branch toggleBranchView = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleBranchViewAction.class, mainFrame), menuItemMnemonicHelper); */ @@ -258,7 +263,7 @@ public MainMenuBar(MainFrame mainFrame) { viewMenu.add(new TMenuSeparator()); ButtonGroup buttonGroup = new ButtonGroup(); for (Column c : Column.values()) { - buttonGroup.add(sortByItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(c.getSortByColumnActionId(), mainFrame), menuItemMnemonicHelper)); + buttonGroup.add(cbSortByItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(c.getSortByColumnActionId(), mainFrame), menuItemMnemonicHelper)); } MenuToolkit.addMenuItem(viewMenu, ActionManager.getActionInstance(ReverseSortOrderAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); @@ -273,11 +278,11 @@ public MainMenuBar(MainFrame mainFrame) { continue; } - toggleColumnItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(columnsMenu, ActionManager.getActionInstance(c.getToggleColumnActionId(), mainFrame), menuItemMnemonicHelper2); + cbToggleColumnItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(columnsMenu, ActionManager.getActionInstance(c.getToggleColumnActionId(), mainFrame), menuItemMnemonicHelper2); } viewMenu.add(columnsMenu); - toggleToggleAutoSizeItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleAutoSizeAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); + cbToggleToggleAutoSizeItem = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(ToggleAutoSizeAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); viewMenu.add(new TMenuSeparator()); MenuToolkit.addMenuItem(viewMenu, ActionManager.getActionInstance(ToggleToolBarAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); @@ -348,7 +353,7 @@ public MuAction getMenuItemAction(BonjourService bs) { MenuToolkit.addMenuItem(toolsMenu, ActionManager.getActionInstance(FindFileAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); MenuToolkit.addMenuItem(toolsMenu, ActionManager.getActionInstance(CalculatorAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); MenuToolkit.addMenuItem(toolsMenu, ActionManager.getActionInstance(RunCommandAction.Descriptor.ACTION_ID, mainFrame), menuItemMnemonicHelper); - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { ejectDrivesMenu = MenuToolkit.addMenu(Translator.get("eject_menu"), menuMnemonicHelper, this); toolsMenu.add(ejectDrivesMenu); @@ -450,7 +455,8 @@ public void actionPerformed(ActionEvent e) { } // Bring the frame corresponding to the clicked menu item to the front - windowMenuFrames.get(e.getSource()).toFront(); + JMenuItem source = (JMenuItem) e.getSource(); + windowMenuFrames.get(source).toFront(); } @@ -462,180 +468,216 @@ public void menuSelected(MenuEvent e) { Object source = e.getSource(); if (source == viewMenu) { - FileTable activeTable = mainFrame.getActiveTable(); - - // Select the 'sort by' criterion currently in use in the active table - sortByItems[activeTable.getSortInfo().getCriterion().ordinal()].setSelected(true); - - Boolean foldersFirst = activeTable.getSortInfo().getFoldersFirst(); - toggleShowFoldersFirstItem.setSelected(foldersFirst); - toggleFoldersAlwaysAlphabeticalItem.setEnabled(foldersFirst); - toggleFoldersAlwaysAlphabeticalItem.setSelected(foldersFirst && activeTable.getSortInfo().getFoldersAlwaysAlphabetical()); - toggleShowHiddenFilesItem.setSelected(MuConfigurations.getPreferences().getVariable(MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES)); - toggleTreeItem.setSelected(activeTable.getFolderPanel().isTreeVisible()); - toggleToggleAutoSizeItem.setSelected(mainFrame.isAutoSizeColumnsEnabled()); - toggleSinglePanel.setSelected(mainFrame.isSinglePanel()); - /* TODO branch toggleBranchView.setSelected(activeTable.getFolderPanel().isBranchView()); */ + updateViewMenu(); } else if (source == columnsMenu) { - // Update the selected and enabled state of each column menu item. - FileTable activeTable = mainFrame.getActiveTable(); - for (Column c : Column.values()) { - if (c == Column.NAME) // Name column doesn't have a menu item as it cannot be disabled - continue; - - JCheckBoxMenuItem item = toggleColumnItems[c.ordinal()]; - item.setSelected(activeTable.isColumnEnabled(c)); - item.setEnabled(activeTable.isColumnDisplayable(c)); - // Override the action's label to a shorter one - item.setText(c.getLabel()); - } + updateShowHideColumnsMenu(); } else if (source == goMenu) { - // Remove any previous volumes from the Go menu - // as they might have changed since menu was last selected - for (int i = goMenu.getItemCount(); i > volumeOffset; i--) { - goMenu.remove(volumeOffset); - } - - AbstractFile volumes[] = LocalFile.getVolumes(); - for (AbstractFile volume : volumes) { - goMenu.add(new OpenLocationAction(mainFrame, new Hashtable<>(), volume)); - } + updateGoMenu(); } else if (source == ejectDrivesMenu) { - // Remove any previous drives menu items from menu - // as there might have changed since menu was last selected - ejectDrivesMenu.removeAll(); - - AbstractFile[] volumes = LocalFile.getVolumes(); - boolean empty = true; - for (AbstractFile volume : volumes) { - if (volume != null && !volume.isSymlink() && !volume.getPath().toLowerCase().startsWith("/users/")) { - MenuToolkit.addMenuItem(ejectDrivesMenu, volume.getName(), null, null, event -> { - EjectDriveAction.eject(mainFrame, volume); - mainFrame.tryRefreshCurrentFolders(); - }); - empty = false; - } - } - if (empty) { - JMenuItem menuItem = new JMenuItem(Translator.get("eject.no_mounted_devices")); - menuItem.setEnabled(false); - ejectDrivesMenu.add(menuItem); - } + updateEjectDriveMenu(); } else if (source == bookmarksMenu) { - // Remove any previous bookmarks menu items from menu - // as bookmarks might have changed since menu was last selected - for (int i=bookmarksMenu.getItemCount(); i>bookmarksOffset; i--) { - bookmarksMenu.remove(bookmarksOffset); - } - - // Add bookmarks menu items - List bookmarks = BookmarkManager.getBookmarks(); - if (!bookmarks.isEmpty()) { - for (Bookmark bookmark : bookmarks) { - MenuToolkit.addMenuItem(bookmarksMenu, new OpenLocationAction(mainFrame, new HashMap<>(), bookmark), null); - } - } else { - // Show 'No bookmark' as a disabled menu item instead showing nothing - JMenuItem noBookmarkItem = MenuToolkit.addMenuItem(bookmarksMenu, Translator.get("bookmarks_menu.no_bookmark"), null, null, null); - noBookmarkItem.setEnabled(false); - } + updateBookmarksMenu(); } else if (source == windowMenu) { - // Select the split orientation currently in use - if (mainFrame.getSplitPaneOrientation()) { - splitVerticallyItem.setSelected(true); - } else { - splitHorizontallyItem.setSelected(true); + updateWindowsMenu(); + } else if (source == themesMenu) { + updateThemesMenu(); + } else if (source == tableModeMenu) { + int mode = mainFrame.getActiveTable().getViewMode().ordinal(); + cbTableModeItems[mode].setSelected(true); + } else if (source == openWithMenu) { + openWithMenu.populate(mainFrame.getActiveTable().getSelectedFile()); + } else if (source == openAsMenu) { + final AbstractFile selectedFile = mainFrame.getActiveTable().getSelectedFile(); + openAsMenu.setEnabled(selectedFile != null && !selectedFile.isDirectory()); + } + } + + private void updateViewMenu() { + FileTable activeTable = mainFrame.getActiveTable(); + + // Select the 'sort by' criterion currently in use in the active table + cbSortByItems[activeTable.getSortInfo().getCriterion().ordinal()].setSelected(true); + + Boolean foldersFirst = activeTable.getSortInfo().getFoldersFirst(); + cbToggleShowFoldersFirstItem.setSelected(foldersFirst); + cbToggleFoldersAlwaysAlphabeticalItem.setEnabled(foldersFirst); + cbToggleFoldersAlwaysAlphabeticalItem.setSelected(foldersFirst && activeTable.getSortInfo().getFoldersAlwaysAlphabetical()); + cbToggleShowHiddenFilesItem.setSelected(MuConfigurations.getPreferences().getVariable(MuPreference.SHOW_HIDDEN_FILES, MuPreferences.DEFAULT_SHOW_HIDDEN_FILES)); + cbToggleTreeItem.setSelected(activeTable.getFolderPanel().isTreeVisible()); + cbToggleToggleAutoSizeItem.setSelected(mainFrame.isAutoSizeColumnsEnabled()); + cbToggleSinglePanel.setSelected(mainFrame.isSinglePanel()); + // TODO branch toggleBranchView.setSelected(activeTable.getFolderPanel().isBranchView()); + } + + private void updateShowHideColumnsMenu() { + // Update the selected and enabled state of each column menu item. + FileTable activeTable = mainFrame.getActiveTable(); + for (Column c : Column.values()) { + if (c == Column.NAME) { // Name column doesn't have a menu item as it cannot be disabled + continue; } - // Removing any window menu item previously added - // Note: menu item cannot be removed by menuDeselected() as actionPerformed() will be called after - // menu has been deselected. - for (int i = windowMenu.getItemCount(); i > windowOffset; i--) { - windowMenu.remove(windowOffset); + JCheckBoxMenuItem item = cbToggleColumnItems[c.ordinal()]; + item.setSelected(activeTable.isColumnEnabled(c)); + item.setEnabled(activeTable.isColumnDisplayable(c)); + // Override the action's label to a shorter one + item.setText(c.getLabel()); + } + } + + private void updateGoMenu() { + // Remove any previous volumes from the Go menu + // as they might have changed since menu was last selected + for (int i = goMenu.getItemCount(); i > volumeOffset; i--) { + goMenu.remove(volumeOffset); + } + + AbstractFile volumes[] = LocalFile.getVolumes(); + for (AbstractFile volume : volumes) { + goMenu.add(new OpenLocationAction(mainFrame, new Hashtable<>(), volume)); + } + } + + private void updateEjectDriveMenu() { + // Remove any previous drives menu items from menu + // as there might have changed since menu was last selected + ejectDrivesMenu.removeAll(); + + AbstractFile[] volumes = LocalFile.getVolumes(); + boolean empty = true; + for (AbstractFile volume : volumes) { + if (volume != null && !volume.isSymlink() && !volume.getPath().toLowerCase().startsWith("/users/")) { + MenuToolkit.addMenuItem(ejectDrivesMenu, volume.getName(), null, null, event -> { + EjectDriveAction.eject(mainFrame, volume); + mainFrame.tryRefreshCurrentFolders(); + }); + empty = false; } + } + if (empty) { + JMenuItem menuItem = new JMenuItem(Translator.get("eject.no_mounted_devices")); + menuItem.setEnabled(false); + ejectDrivesMenu.add(menuItem); + } + } - // This WeakHashMap maps menu items to frame instances. It has to be a weakly referenced hash map - // and not a regular hash map, since it will not (and cannot) be emptied when the menu has been deselected - // and we really do not want this hash map to prevent the frames to be GCed - windowMenuFrames = new WeakHashMap<>(); - - // create a menu item for each of the MainFrame instances, that displays the MainFrame's path - // and a keyboard accelerator to recall the frame (for the first 10 frames only). - List mainFrames = WindowManager.getMainFrames(); - int nbFrames = mainFrames.size(); - for (int i = 0; i < nbFrames; i++) { - MainFrame mainFrame = mainFrames.get(i); - JCheckBoxMenuItem checkBoxMenuItem = new TCheckBoxMenuItem(); - - // If frame number is less than 10, use the corresponding action class (accelerator will be displayed in the menu item) - MuAction recallWindowAction; - if (i < 10) { - recallWindowAction = ActionManager.getActionInstance(RECALL_WINDOW_ACTION_IDS[i], this.mainFrame); - } else { // Else use the generic RecallWindowAction - Map actionProps = new HashMap<>(); - // Specify the window number using the dedicated property - actionProps.put(RecallWindowAction.WINDOW_NUMBER_PROPERTY_KEY, ""+(i+1)); - recallWindowAction = ActionManager.getActionInstance(new ActionParameters(RecallWindowAction.Descriptor.ACTION_ID, actionProps), this.mainFrame); - } + private void updateBookmarksMenu() { + // Remove any previous bookmarks menu items from menu + // as bookmarks might have changed since menu was last selected + for (int i = bookmarksMenu.getItemCount(); i > bookmarksOffset; i--) { + bookmarksMenu.remove(bookmarksOffset); + } - checkBoxMenuItem.setAction(recallWindowAction); + // Add bookmarks menu items + List bookmarks = BookmarkManager.getBookmarks(); + if (!bookmarks.isEmpty()) { + for (Bookmark bookmark : bookmarks) { + MenuToolkit.addMenuItem(bookmarksMenu, new OpenLocationAction(mainFrame, new HashMap<>(), bookmark), null); + } + } else { + // Show 'No bookmark' as a disabled menu item instead showing nothing + JMenuItem noBookmarkItem = MenuToolkit.addMenuItem(bookmarksMenu, Translator.get("bookmarks_menu.no_bookmark"), null, null, null); + noBookmarkItem.setEnabled(false); + } + } - // Replace the action's label and use the MainFrame's current folder path instead - checkBoxMenuItem.setText((i+1)+" "+mainFrame.getActiveTable().getFolderPanel().getCurrentFolder().getAbsolutePath()); - // Use the action's label as a tooltip - checkBoxMenuItem.setToolTipText(recallWindowAction.getLabel()); + private void updateWindowsMenu() { + // Select the split orientation currently in use + if (mainFrame.getSplitPaneOrientation()) { + splitVerticallyItem.setSelected(true); + } else { + splitHorizontallyItem.setSelected(true); + } - // Check current MainFrame (the one this menu bar belongs to) - checkBoxMenuItem.setSelected(mainFrame == this.mainFrame); + // Removing any window menu item previously added + // Note: menu item cannot be removed by menuDeselected() as actionPerformed() will be called after + // menu has been deselected. + for (int i = windowMenu.getItemCount(); i > windowOffset; i--) { + windowMenu.remove(windowOffset); + } - windowMenu.add(checkBoxMenuItem); + // This WeakHashMap maps menu items to frame instances. It has to be a weakly referenced hash map + // and not a regular hash map, since it will not (and cannot) be emptied when the menu has been deselected + // and we really do not want this hash map to prevent the frames to be GCed + windowMenuFrames = new WeakHashMap<>(); + + // create a menu item for each of the MainFrame instances, that displays the MainFrame's path + // and a keyboard accelerator to recall the frame (for the first 10 frames only). + List mainFrames = WindowManager.getMainFrames(); + int nbFrames = mainFrames.size(); + for (int i = 0; i < nbFrames; i++) { + MainFrame mainFrame = mainFrames.get(i); + JCheckBoxMenuItem checkBoxMenuItem = new TCheckBoxMenuItem(); + + // If frame number is less than 10, use the corresponding action class (accelerator will be displayed in the menu item) + MuAction recallWindowAction; + if (i < 10) { + recallWindowAction = ActionManager.getActionInstance(RECALL_WINDOW_ACTION_IDS[i], this.mainFrame); + } else { // Else use the generic RecallWindowAction + Map actionProps = new HashMap<>(); + // Specify the window number using the dedicated property + actionProps.put(RecallWindowAction.WINDOW_NUMBER_PROPERTY_KEY, ""+(i+1)); + recallWindowAction = ActionManager.getActionInstance(new ActionParameters(RecallWindowAction.Descriptor.ACTION_ID, actionProps), this.mainFrame); } - // Add 'other' (non-MainFrame) windows : viewer and editor frames, no associated accelerator - Frame frames[] = Frame.getFrames(); - nbFrames = frames.length; - boolean firstFrame = true; - for (int i = 0; i < nbFrames; i++) { - Frame frame = frames[i]; - // Test if Frame is not hidden (disposed), Frame.getFrames() returns both active and disposed frames - if (frame.isShowing() && (frame instanceof FileFrame)) { - // Add a separator before the first non-MainFrame frame to mark a separation between MainFrames - // and other frames - if (firstFrame) { - windowMenu.add(new TMenuSeparator()); - firstFrame = false; - } - // Use frame's window title - JMenuItem menuItem = new JMenuItem(frame.getTitle()); - menuItem.addActionListener(this); - windowMenu.add(menuItem); - windowMenuFrames.put(menuItem, frame); + checkBoxMenuItem.setAction(recallWindowAction); + + // Replace the action's label and use the MainFrame's current folder path instead + checkBoxMenuItem.setText((i+1)+" "+mainFrame.getActiveTable().getFolderPanel().getCurrentFolder().getAbsolutePath()); + + // Use the action's label as a tooltip + checkBoxMenuItem.setToolTipText(recallWindowAction.getLabel()); + + // Check current MainFrame (the one this menu bar belongs to) + checkBoxMenuItem.setSelected(mainFrame == this.mainFrame); + + windowMenu.add(checkBoxMenuItem); + } + + // Add 'other' (non-MainFrame) windows : viewer and editor frames, no associated accelerator + Frame frames[] = Frame.getFrames(); + nbFrames = frames.length; + boolean firstFrame = true; + for (int i = 0; i < nbFrames; i++) { + Frame frame = frames[i]; + // Test if Frame is not hidden (disposed), Frame.getFrames() returns both active and disposed frames + if (frame.isShowing() && (frame instanceof FileFrame)) { + // Add a separator before the first non-MainFrame frame to mark a separation between MainFrames + // and other frames + if (firstFrame) { + windowMenu.add(new TMenuSeparator()); + firstFrame = false; } + // Use frame's window title + JMenuItem menuItem = new JMenuItem(frame.getTitle()); + menuItem.addActionListener(this); + windowMenu.add(menuItem); + windowMenuFrames.put(menuItem, frame); } - } else if (source == themesMenu) { - // Remove all previous theme items, create new ones for each available theme and select the current theme - themesMenu.removeAll(); - ButtonGroup buttonGroup = new ButtonGroup(); - Iterator themes = ThemeManager.availableThemes(); - themesMenu.add(new JMenuItem(new EditCurrentThemeAction())); - themesMenu.add(new TMenuSeparator()); - while (themes.hasNext()) { - Theme theme = themes.next(); - JCheckBoxMenuItem item = new TCheckBoxMenuItem(new ChangeCurrentThemeAction(theme)); - buttonGroup.add(item); - if (ThemeManager.isCurrentTheme(theme)) { - item.setSelected(true); - } + } + } - themesMenu.add(item); + private void updateThemesMenu() { + // Remove all previous theme items, create new ones for each available theme and select the current theme + themesMenu.removeAll(); + ButtonGroup buttonGroup = new ButtonGroup(); + Iterator themes = ThemeManager.availableThemes(); + themesMenu.add(new JMenuItem(new EditCurrentThemeAction())); + themesMenu.add(new TMenuSeparator()); + while (themes.hasNext()) { + Theme theme = themes.next(); + JCheckBoxMenuItem item = new TCheckBoxMenuItem(new ChangeCurrentThemeAction(theme)); + buttonGroup.add(item); + if (ThemeManager.isCurrentTheme(theme)) { + item.setSelected(true); } - } else if (source == tableModeMenu) { - int mode = mainFrame.getActiveTable().getViewMode().ordinal(); - tableModeItems[mode].setSelected(true); + + themesMenu.add(item); } } - + + public void menuDeselected(MenuEvent e) { } diff --git a/src/main/com/mucommander/ui/main/menu/OpenAsMenu.java b/src/main/com/mucommander/ui/main/menu/OpenAsMenu.java new file mode 100644 index 000000000..ae732feb2 --- /dev/null +++ b/src/main/com/mucommander/ui/main/menu/OpenAsMenu.java @@ -0,0 +1,54 @@ +package com.mucommander.ui.main.menu; + +import com.mucommander.commons.file.ArchiveFormatProvider; +import com.mucommander.commons.file.FileFactory; +import com.mucommander.ui.action.ActionManager; +import com.mucommander.ui.action.ActionParameters; +import com.mucommander.ui.action.impl.OpenAsAction; +import com.mucommander.ui.helper.MenuToolkit; +import com.mucommander.ui.main.MainFrame; +import com.mucommander.utils.text.Translator; + +import javax.swing.*; +import java.util.*; + +public class OpenAsMenu extends JMenu { + + private final static List EXTENSIONS = new ArrayList<>(); + private MainFrame mainFrame; + + static { + for (Iterator it = FileFactory.archiveFormats(); it.hasNext(); ) { + ArchiveFormatProvider provider = it.next(); + EXTENSIONS.addAll(Arrays.asList(provider.getFileExtensions())); + } + Collections.sort(EXTENSIONS); + } + + + OpenAsMenu(MainFrame mainFrame) { + super(Translator.get("file_menu.open_as") + "..."); + this.mainFrame = mainFrame; + populate(); + } + + /** + * Refreshes the content of the menu. + */ + private void populate() { + for (String extension : EXTENSIONS) { + Map params = Collections.singletonMap("extension", extension); + Action action = ActionManager.getActionInstance(new ActionParameters(OpenAsAction.Descriptor.ACTION_ID, params), mainFrame); + action.putValue(Action.NAME, extension.substring(1)); + add(action); + } + } + + @Override + public final JMenuItem add(Action a) { + JMenuItem item = super.add(a); + MenuToolkit.configureActionMenuItem(item); + return item; + } + +} diff --git a/src/main/com/mucommander/ui/main/menu/OpenWithMenu.java b/src/main/com/mucommander/ui/main/menu/OpenWithMenu.java index 77b8a7478..74f52d7c5 100644 --- a/src/main/com/mucommander/ui/main/menu/OpenWithMenu.java +++ b/src/main/com/mucommander/ui/main/menu/OpenWithMenu.java @@ -45,7 +45,7 @@ public class OpenWithMenu extends JMenu { /** * Creates a new Open With menu. */ - public OpenWithMenu(MainFrame frame, AbstractFile clickedFile) { + OpenWithMenu(MainFrame frame, AbstractFile clickedFile) { super(Translator.get("file_menu.open_with") + "..."); this.mainFrame = frame; populate(clickedFile); @@ -54,7 +54,7 @@ public OpenWithMenu(MainFrame frame, AbstractFile clickedFile) { /** * Refreshes the content of the menu. */ - private synchronized void populate(AbstractFile clickedFile) { + public void populate(AbstractFile clickedFile) { for (Command command : CommandManager.commands()) { if (command.getType() != CommandType.NORMAL_COMMAND) { continue; diff --git a/src/main/com/mucommander/ui/main/menu/TablePopupMenu.java b/src/main/com/mucommander/ui/main/menu/TablePopupMenu.java index b2d11059a..054dc15c1 100644 --- a/src/main/com/mucommander/ui/main/menu/TablePopupMenu.java +++ b/src/main/com/mucommander/ui/main/menu/TablePopupMenu.java @@ -29,13 +29,14 @@ /** * Contextual popup menu invoked by FileTable when right-clicking on a file or a group of files. - * + *

* The following items are displayed (see constructor code for conditions) : - * + *

* Open * Open in new tab * Open natively * Open with... + * Open as... * Rename * Reveal in Finder * ---- @@ -75,6 +76,9 @@ public TablePopupMenu(MainFrame mainFrame, AbstractFile currentFolder, AbstractF addAction(com.mucommander.ui.action.impl.OpenAction.Descriptor.ACTION_ID); addAction(com.mucommander.ui.action.impl.OpenNativelyAction.Descriptor.ACTION_ID); add(new OpenWithMenu(mainFrame, clickedFile)); + if (clickedFile != null && !clickedFile.isDirectory()) { + add(new OpenAsMenu(mainFrame)); + } addAction(com.mucommander.ui.action.impl.OpenInNewTabAction.Descriptor.ACTION_ID); } diff --git a/src/main/com/mucommander/ui/main/quicklist/ViewedAndEditedFilesQL.java b/src/main/com/mucommander/ui/main/quicklist/ViewedAndEditedFilesQL.java index 5e666a1ac..03d769d4c 100644 --- a/src/main/com/mucommander/ui/main/quicklist/ViewedAndEditedFilesQL.java +++ b/src/main/com/mucommander/ui/main/quicklist/ViewedAndEditedFilesQL.java @@ -56,7 +56,7 @@ public void keyPressed(KeyEvent e) { @Override public void keyReleased(KeyEvent e) { - int mask = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL; + int mask = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL; if (e.getKeyCode() == mask) { setVisible(false); acceptListItem(dataList.getSelectedValue()); diff --git a/src/main/com/mucommander/ui/main/statusbar/HeapIndicator.java b/src/main/com/mucommander/ui/main/statusbar/HeapIndicator.java index ded00eb3a..5195b0250 100644 --- a/src/main/com/mucommander/ui/main/statusbar/HeapIndicator.java +++ b/src/main/com/mucommander/ui/main/statusbar/HeapIndicator.java @@ -20,9 +20,8 @@ import com.mucommander.cache.TextHistory; import com.mucommander.cache.WindowsStorage; -import com.mucommander.ui.theme.ColorChangedEvent; -import com.mucommander.ui.theme.FontChangedEvent; -import com.mucommander.ui.theme.ThemeListener; +import com.mucommander.ui.border.MutableLineBorder; +import com.mucommander.ui.theme.*; import com.mucommander.utils.FileIconsCache; import javax.swing.JLabel; @@ -46,17 +45,18 @@ public class HeapIndicator extends JLabel implements ActionListener, ThemeListen private long usedMem; private long totalMem; - private final Color colorBorder = new Color(0x555555); - private final Color colorForeground = new Color(0x8888ff); + private static final Color COLOR_BORDER = new Color(0x555555); + private static final Color COLOR_FOREGROUND = new Color(0x8888ff); HeapIndicator() { super(""); setHorizontalAlignment(CENTER); setRefreshInterval(1000*10); update(); - setMinimumSize(new Dimension(80, 0)); - setMaximumSize(new Dimension(80, 100)); +// setMinimumSize(new Dimension(80, 0)); +// setMaximumSize(new Dimension(80, 100)); addMouseListener(this); + setBorder(new MutableLineBorder(ThemeManager.getCurrentColor(Theme.STATUS_BAR_BORDER_COLOR))); } @Override @@ -70,9 +70,9 @@ public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); - g.setColor(colorBorder); + g.setColor(COLOR_BORDER); g.drawRect(0, 0, width-1, height-1); - g.setColor(colorForeground); + g.setColor(COLOR_FOREGROUND); int x2 = (int)(width*((float)usedMem/(float)totalMem)); g.fillRect(1, 1, x2-1, height-2); diff --git a/src/main/com/mucommander/ui/main/statusbar/StatusBar.java b/src/main/com/mucommander/ui/main/statusbar/StatusBar.java index 520f02591..4faa1b047 100644 --- a/src/main/com/mucommander/ui/main/statusbar/StatusBar.java +++ b/src/main/com/mucommander/ui/main/statusbar/StatusBar.java @@ -216,7 +216,7 @@ public StatusBar(MainFrame mainFrame) { // Show/hide this status bar based on user preferences // Note: setVisible has to be called even with true for the auto-update thread to be initialized - setVisible(MuConfigurations.getPreferences().getVariable(MuPreference.STATUS_BAR_VISIBLE, MuPreferences.DEFAULT_STATUS_BAR_VISIBLE)); + setVisible(shouldBeVisible()); // Catch location events to update status bar info when folder is changed FolderPanel leftPanel = mainFrame.getLeftPanel(); @@ -250,6 +250,10 @@ public StatusBar(MainFrame mainFrame) { ThemeManager.addCurrentThemeListener(this); } + private static boolean shouldBeVisible() { + return MuConfigurations.getPreferences().getVariable(MuPreference.STATUS_BAR_VISIBLE, MuPreferences.DEFAULT_STATUS_BAR_VISIBLE); + } + /** * Updates info displayed on the status bar: currently selected files and volume info. @@ -304,69 +308,73 @@ public void updateSelectedFilesInfo() { } if (selectedFile != null) { - filesInfo.append(" - "); - filesInfo.append(""); - filesInfo.append(selectedFile.getName()); - filesInfo.append(""); - if (selectedFile.isSymlink()) { - String target = getFileLink(selectedFile); - if (target != null) { - filesInfo.append(" -> "); - filesInfo.append(target); + appendSelectedFileInfo(filesInfo, selectedFile); + } + } + + // Update label + setStatusInfo("" + filesInfo.toString()); + } + + private void appendSelectedFileInfo(StringBuilder filesInfo, AbstractFile selectedFile) { + filesInfo.append(" - "); + filesInfo.append(""); + filesInfo.append(selectedFile.getName()); + filesInfo.append(""); + if (selectedFile.isSymlink()) { + String target = getFileLink(selectedFile); + if (target != null) { + filesInfo.append(" -> "); + filesInfo.append(target); + } + } + boolean local = selectedFile.getAncestor() instanceof LocalFile; + if (selectedFile.isDirectory()) { + if (local) { + filesInfo.append(" ("); + try { + filesInfo.append(selectedFile.ls().length); + } catch (IOException ignored) {} + filesInfo.append(' '); + filesInfo.append(Translator.get("files")); + filesInfo.append(')'); + } + } else { + filesInfo.append(" ("); + filesInfo.append(SizeFormat.format(selectedFile.getSize(), SizeFormat.DIGITS_FULL | SizeFormat.UNIT_LONG | SizeFormat.INCLUDE_SPACE)); + + if (local && SUPPORTED_IMAGE_FILTER.accept(selectedFile)) { + // Show image size + try (InputStream is = selectedFile.getInputStream()) { + ImageSizeDetector detector = new ImageSizeDetector(is); + if (detector.getType() != null) { + filesInfo.append(", "); + filesInfo.append(detector.getWidth()); + filesInfo.append(" x "); + filesInfo.append(detector.getHeight()); } + } catch (FileNotFoundException ignore) { + // etc. if file was moved + } catch (IOException e) { + e.printStackTrace(); } - boolean local = selectedFile.getAncestor() instanceof LocalFile; - if (selectedFile.isDirectory()) { - if (local) { - filesInfo.append(" ("); - try { - filesInfo.append(selectedFile.ls().length); - } catch (IOException ignored) {} - filesInfo.append(' '); - filesInfo.append(Translator.get("files")); - filesInfo.append(')'); + } else if (JAVA_CLASS_FILTER.accept(selectedFile)) { + try (InputStream is = selectedFile.getPushBackInputStream(16)) { + JavaClassVersionDetector detector = new JavaClassVersionDetector(is); + + if (detector.getVersion() != JavaClassVersionDetector.Version.UNKNOWN) { + filesInfo.append(", Java v").append(detector.getVersion().name); + } else if (detector.getVersion() != JavaClassVersionDetector.Version.WRONG_FORMAT) { + filesInfo.append(", Java major = ").append(detector.getMajor()).append(", minor = ").append(detector.getMinor()); } - } else { - filesInfo.append(" ("); - filesInfo.append(SizeFormat.format(selectedFile.getSize(), SizeFormat.DIGITS_FULL | SizeFormat.UNIT_LONG | SizeFormat.INCLUDE_SPACE)); - - if (local && SUPPORTED_IMAGE_FILTER.accept(selectedFile)) { - // Show image size - try (InputStream is = selectedFile.getInputStream()) { - ImageSizeDetector detector = new ImageSizeDetector(is); - if (detector.getType() != null) { - filesInfo.append(", "); - filesInfo.append(detector.getWidth()); - filesInfo.append(" x "); - filesInfo.append(detector.getHeight()); - } - } catch (FileNotFoundException ignore) { - // etc. if file was moved - } catch (IOException e) { - e.printStackTrace(); - } - } else if (JAVA_CLASS_FILTER.accept(selectedFile)) { - try (InputStream is = selectedFile.getPushBackInputStream(16)) { - JavaClassVersionDetector detector = new JavaClassVersionDetector(is); - - if (detector.getVersion() != JavaClassVersionDetector.Version.UNKNOWN) { - filesInfo.append(", Java v").append(detector.getVersion().name); - } else if (detector.getVersion() != JavaClassVersionDetector.Version.WRONG_FORMAT) { - filesInfo.append(", Java major = ").append(detector.getMajor()).append(", minor = ").append(detector.getMinor()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - filesInfo.append(")"); - + } catch (IOException e) { + e.printStackTrace(); } } - } - // Update label - setStatusInfo("" + filesInfo.toString()); + filesInfo.append(")"); + + } } diff --git a/src/main/com/mucommander/ui/main/statusbar/TrashPopupButton.java b/src/main/com/mucommander/ui/main/statusbar/TrashPopupButton.java index fe25f546b..a27ee47a0 100644 --- a/src/main/com/mucommander/ui/main/statusbar/TrashPopupButton.java +++ b/src/main/com/mucommander/ui/main/statusbar/TrashPopupButton.java @@ -50,11 +50,7 @@ public class TrashPopupButton extends PopupButton { setContentAreaFilled(false); setIcon(IconManager.getIcon(IconManager.IconSet.STATUS_BAR, "trash.png")); - // Rollover-enable the button and hold a reference to the RolloverButtonAdapter instance so that it doesn't - // get garbage-collected - RolloverButtonAdapter rolloverButtonAdapter = new RolloverButtonAdapter(); - RolloverButtonAdapter.setButtonDecoration(this); - addMouseListener(rolloverButtonAdapter); + RolloverButtonAdapter.decorateButton(this); } @Override diff --git a/src/main/com/mucommander/ui/main/statusbar/VolumeSpaceLabel.java b/src/main/com/mucommander/ui/main/statusbar/VolumeSpaceLabel.java index 6d6615543..27ea911e7 100644 --- a/src/main/com/mucommander/ui/main/statusbar/VolumeSpaceLabel.java +++ b/src/main/com/mucommander/ui/main/statusbar/VolumeSpaceLabel.java @@ -27,6 +27,7 @@ import java.awt.Dimension; import java.awt.Graphics; +import static com.mucommander.ui.theme.ThemeManager.*; /** * This label displays the amount of free and/or total space on a volume. */ @@ -50,12 +51,12 @@ class VolumeSpaceLabel extends JLabel implements ThemeListener { VolumeSpaceLabel() { super(""); setHorizontalAlignment(CENTER); - backgroundColor = ThemeManager.getCurrentColor(Theme.STATUS_BAR_BACKGROUND_COLOR); - // borderColor = ThemeManager.getCurrentColor(Theme.STATUS_BAR_BORDER_COLOR); - okColor = ThemeManager.getCurrentColor(Theme.STATUS_BAR_OK_COLOR); - warningColor = ThemeManager.getCurrentColor(Theme.STATUS_BAR_WARNING_COLOR); - criticalColor = ThemeManager.getCurrentColor(Theme.STATUS_BAR_CRITICAL_COLOR); - setBorder(new MutableLineBorder(ThemeManager.getCurrentColor(Theme.STATUS_BAR_BORDER_COLOR))); + backgroundColor = getCurrentColor(Theme.STATUS_BAR_BACKGROUND_COLOR); + //borderColor = getCurrentColor(Theme.STATUS_BAR_BORDER_COLOR); + okColor = getCurrentColor(Theme.STATUS_BAR_OK_COLOR); + warningColor = getCurrentColor(Theme.STATUS_BAR_WARNING_COLOR); + criticalColor = getCurrentColor(Theme.STATUS_BAR_CRITICAL_COLOR); + setBorder(new MutableLineBorder(getCurrentColor(Theme.STATUS_BAR_BORDER_COLOR))); ThemeManager.addCurrentThemeListener(this); } @@ -72,6 +73,18 @@ void setVolumeSpace(long totalSpace, long freeSpace) { this.totalSpace = totalSpace; // Set new label's text + setText(getVolumeInfo()); + + // Set tooltip + if (freeSpace < 0 || totalSpace < 0) { + setToolTipText(null); // Removes any previous tooltip + } else { + setToolTipText((int) (100 * freeSpace / (float) totalSpace) + "%"); + } + repaint(); + } + + private String getVolumeInfo() { String volumeInfo; if (freeSpace >= 0) { volumeInfo = SizeFormat.format(freeSpace, VOLUME_INFO_SIZE_FORMAT); @@ -85,15 +98,7 @@ void setVolumeSpace(long totalSpace, long freeSpace) { } else { volumeInfo = ""; } - setText(volumeInfo); - - // Set tooltip - if (freeSpace < 0 || totalSpace < 0) { - setToolTipText(null); // Removes any previous tooltip - } else { - setToolTipText((int) (100 * freeSpace / (float) totalSpace) + "%"); - } - repaint(); + return volumeInfo; } diff --git a/src/main/com/mucommander/ui/main/toolbar/ToolBar.java b/src/main/com/mucommander/ui/main/toolbar/ToolBar.java index 94445eed6..3759d4231 100644 --- a/src/main/com/mucommander/ui/main/toolbar/ToolBar.java +++ b/src/main/com/mucommander/ui/main/toolbar/ToolBar.java @@ -63,9 +63,6 @@ public class ToolBar extends JToolBar implements ConfigurationListener, MouseLis private final MainFrame mainFrame; - /** Holds a reference to the RolloverButtonAdapter instance so that it doesn't get garbage-collected */ - private final RolloverButtonAdapter rolloverButtonAdapter; - /** Dimension of button separators */ private final static Dimension SEPARATOR_DIMENSION = new Dimension(10, 16); @@ -97,10 +94,6 @@ public ToolBar(MainFrame mainFrame) { // Listen to configuration changes to reload toolbar buttons when icon size has changed MuConfigurations.addPreferencesListener(this); - // Rollover-enable the button and hold a reference to the RolloverButtonAdapter instance so that it doesn't - // get garbage-collected - rolloverButtonAdapter = new RolloverButtonAdapter(); - // create buttons for each actions and add them to the toolbar addButtons(ToolBarAttributes.getActions()); @@ -181,14 +174,9 @@ private void addButton(MuAction action) { button.putClientProperty("JButton.buttonType", "segmentedTextured"); } button.setRolloverEnabled(true); + } else { + RolloverButtonAdapter.decorateButton(button); } - // On other platforms, use a custom rollover effect - else { - // Init rollover - RolloverButtonAdapter.setButtonDecoration(button); - button.addMouseListener(rolloverButtonAdapter); - } - add(button); } diff --git a/src/main/com/mucommander/ui/terminal/JediTerminalPanelEx.java b/src/main/com/mucommander/ui/terminal/JediTerminalPanelEx.java index a016d3c19..01970d8fb 100644 --- a/src/main/com/mucommander/ui/terminal/JediTerminalPanelEx.java +++ b/src/main/com/mucommander/ui/terminal/JediTerminalPanelEx.java @@ -45,7 +45,7 @@ public class JediTerminalPanelEx extends com.jediterm.terminal.ui.TerminalPanel @NotNull StyleState styleState, MainFrame mainFrame) { super(settingsProvider, terminalTextBuffer, styleState); this.mainFrame = mainFrame; - this.keyModifier = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK; + this.keyModifier = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK; } diff --git a/src/main/com/mucommander/ui/theme/ThemeData.java b/src/main/com/mucommander/ui/theme/ThemeData.java index 32cc1e15a..2e401d699 100644 --- a/src/main/com/mucommander/ui/theme/ThemeData.java +++ b/src/main/com/mucommander/ui/theme/ThemeData.java @@ -191,7 +191,7 @@ public JComponent getComponent() { @Override public Font getFont(ThemeData data) { Font font = super.getFont(data); - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { return new Font("Menlo", font.getStyle(), font.getSize()); } return font; diff --git a/src/main/com/mucommander/ui/viewer/FileEditor.java b/src/main/com/mucommander/ui/viewer/FileEditor.java index 94d1a0a0e..69ee881bf 100644 --- a/src/main/com/mucommander/ui/viewer/FileEditor.java +++ b/src/main/com/mucommander/ui/viewer/FileEditor.java @@ -222,14 +222,14 @@ public JMenuBar getMenuBar() { // File menu JMenu fileMenu = MenuToolkit.addMenu(Translator.get("file_editor.file_menu"), mnemonicHelper, null); - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { miSave = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.save"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.META_DOWN_MASK), this); } else { miSave = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.save"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK), this); } miSaveAs = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.save_as"), mnemonicHelper, null, this); fileMenu.add(new TMenuSeparator()); - int mask = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; + int mask = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; miFiles = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.files"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_TAB, mask), this); miMainFrame = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.show_file_manager"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_1, KeyEvent.CTRL_MASK), this); fileMenu.add(miMainFrame); diff --git a/src/main/com/mucommander/ui/viewer/FileFrame.java b/src/main/com/mucommander/ui/viewer/FileFrame.java index 8788e5f02..0545bb6ef 100644 --- a/src/main/com/mucommander/ui/viewer/FileFrame.java +++ b/src/main/com/mucommander/ui/viewer/FileFrame.java @@ -7,6 +7,7 @@ import javax.swing.*; import com.mucommander.cache.WindowsStorage; +import com.mucommander.ui.macosx.IMacOsWindow; import com.mucommander.ui.quicklist.QuickListContainer; import org.fife.ui.StatusBar; import org.slf4j.Logger; @@ -24,7 +25,7 @@ * * @author Arik Hadas */ -public abstract class FileFrame extends JFrame implements QuickListContainer { +public abstract class FileFrame extends JFrame implements QuickListContainer, IMacOsWindow { private static final Logger LOGGER = LoggerFactory.getLogger(FileFrame.class); // private final static Dimension WAIT_DIALOG_SIZE = new Dimension(400, 350); @@ -47,6 +48,8 @@ public abstract class FileFrame extends JFrame implements QuickListContainer { this.mainFrame = mainFrame; setIconImage(icon); + + initLookAndFeel(); // Call #dispose() on close (default is hide) setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); diff --git a/src/main/com/mucommander/ui/viewer/FileViewer.java b/src/main/com/mucommander/ui/viewer/FileViewer.java index ad5b0d11d..7d92f7280 100644 --- a/src/main/com/mucommander/ui/viewer/FileViewer.java +++ b/src/main/com/mucommander/ui/viewer/FileViewer.java @@ -70,7 +70,7 @@ public JMenuBar getMenuBar() { // File menu JMenu fileMenu = MenuToolkit.addMenu(Translator.get("file_viewer.file_menu"), mnemonicHelper, null); - int mask = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; + int mask = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; miFiles = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.files"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_TAB, mask), this); miMainFrame = MenuToolkit.addMenuItem(fileMenu, Translator.get("file_editor.show_file_manager"), mnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_1, KeyEvent.CTRL_MASK), this); fileMenu.add(miMainFrame); diff --git a/src/main/com/mucommander/ui/viewer/hex/HexViewer.java b/src/main/com/mucommander/ui/viewer/hex/HexViewer.java index 633a68357..e0ca6ab75 100644 --- a/src/main/com/mucommander/ui/viewer/hex/HexViewer.java +++ b/src/main/com/mucommander/ui/viewer/hex/HexViewer.java @@ -82,11 +82,7 @@ public class HexViewer extends FileViewer implements ThemeId { } private int getCtrlOrMetaMask() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyEvent.CTRL_MASK; - } else { - return KeyEvent.META_MASK; - } + return OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK; } private OnOffsetChangeListener onOffsetChangeListener = new OnOffsetChangeListener() { diff --git a/src/main/com/mucommander/ui/viewer/image/ImageViewer.java b/src/main/com/mucommander/ui/viewer/image/ImageViewer.java index d06266f81..baea260b6 100644 --- a/src/main/com/mucommander/ui/viewer/image/ImageViewer.java +++ b/src/main/com/mucommander/ui/viewer/image/ImageViewer.java @@ -111,7 +111,7 @@ class ImageViewer extends FileViewer implements ActionListener { } - public ImageViewer() { + ImageViewer() { imageViewerImpl = new ImageViewerImpl(); setComponentToPresent(imageViewerImpl); @@ -123,12 +123,12 @@ public ImageViewer() { nextImageItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.next_image"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), this); prevImageItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.previous_image"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), this); controlsMenu.add(new TMenuSeparator()); - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - zoomInItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_in"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), this); - zoomOutItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_out"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), this); - } else { + if (OsFamily.MAC_OS_X.isCurrent()) { zoomInItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_in"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), this); zoomOutItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_out"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), this); + } else { + zoomInItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_in"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0), this); + zoomOutItem = MenuToolkit.addMenuItem(controlsMenu, Translator.get("image_viewer.zoom_out"), menuMnemonicHelper, KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0), this); } } @@ -145,7 +145,7 @@ public JMenuBar getMenuBar() { @Override protected StatusBar getStatusBar() { if (statusBar == null) { - statusBar = new StatusBar(); + statusBar = new StatusBar(); } return statusBar; } diff --git a/src/main/com/mucommander/ui/viewer/text/TextEditorImpl.java b/src/main/com/mucommander/ui/viewer/text/TextEditorImpl.java index 7dbb35a36..7026e6bcd 100644 --- a/src/main/com/mucommander/ui/viewer/text/TextEditorImpl.java +++ b/src/main/com/mucommander/ui/viewer/text/TextEditorImpl.java @@ -108,7 +108,7 @@ public void keyPressed(KeyEvent e) { return; } - int mask = OsFamily.getCurrent() == OsFamily.MAC_OS_X ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; + int mask = OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.ALT_MASK : KeyEvent.CTRL_MASK; if (textArea.isEditable() && e.getKeyChar() == KeyEvent.VK_TAB && e.getModifiers() == mask) { ViewedAndEditedFilesQL viewedAndEditedFilesQL = new ViewedAndEditedFilesQL(frame, frame.getFilePresenter().getCurrentFile()); viewedAndEditedFilesQL.show(); diff --git a/src/main/com/mucommander/ui/viewer/text/TextMenuHelper.java b/src/main/com/mucommander/ui/viewer/text/TextMenuHelper.java index 61f5dd345..d8d7e61e2 100644 --- a/src/main/com/mucommander/ui/viewer/text/TextMenuHelper.java +++ b/src/main/com/mucommander/ui/viewer/text/TextMenuHelper.java @@ -133,11 +133,7 @@ void initMenu(ActionListener actionListener, boolean lineNumbers) { } private int getCtrlOrMetaMask() { - if (OsFamily.getCurrent() != OsFamily.MAC_OS_X) { - return KeyEvent.CTRL_MASK; - } else { - return KeyEvent.META_MASK; - } + return OsFamily.MAC_OS_X.isCurrent() ? KeyEvent.META_MASK : KeyEvent.CTRL_MASK; } diff --git a/src/main/ru/trolsoft/macosx/FileLabelCache.java b/src/main/ru/trolsoft/macosx/FileLabelCache.java index 95fd3fe32..62f9d2801 100644 --- a/src/main/ru/trolsoft/macosx/FileLabelCache.java +++ b/src/main/ru/trolsoft/macosx/FileLabelCache.java @@ -47,7 +47,7 @@ public static FileLabelCache getInstance() { if (instance == null) { synchronized (FileIconsCache.class) { if (instance == null) { - if (OsFamily.getCurrent() == OsFamily.MAC_OS_X) { + if (OsFamily.MAC_OS_X.isCurrent()) { instance = new FileLabelCache(); } else { instance = new FileLabelCache() { diff --git a/src/main/ru/trolsoft/ui/TCheckBoxMenuItem.java b/src/main/ru/trolsoft/ui/TCheckBoxMenuItem.java index 502a6d25e..afdf2e859 100644 --- a/src/main/ru/trolsoft/ui/TCheckBoxMenuItem.java +++ b/src/main/ru/trolsoft/ui/TCheckBoxMenuItem.java @@ -68,7 +68,7 @@ public TCheckBoxMenuItem(String text, Icon icon, boolean b) { private void init() { - if (OsFamily.getCurrent() == OsFamily.LINUX) { + if (OsFamily.LINUX.isCurrent()) { setOpaque(true); setForeground(Color.BLACK); } diff --git a/src/main/ru/trolsoft/ui/TMenuSeparator.java b/src/main/ru/trolsoft/ui/TMenuSeparator.java index 3a0bcd98c..205f482c2 100644 --- a/src/main/ru/trolsoft/ui/TMenuSeparator.java +++ b/src/main/ru/trolsoft/ui/TMenuSeparator.java @@ -32,7 +32,7 @@ public class TMenuSeparator extends JSeparator { public TMenuSeparator() { super(); - if (OsFamily.getCurrent() == OsFamily.LINUX && getPreferredSize().height <= 0) { + if (OsFamily.LINUX.isCurrent() && getPreferredSize().height <= 0) { Dimension d = getPreferredSize(); d.height = 1; setPreferredSize(d);