Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main menu Open With now contains apps on macos #966

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -209,7 +209,6 @@ private JScrollPane createCreditsPanel() {
insertDetailedUrl(doc, "jdeb", "Apache Software License", "http://vafer.org/projects/jdeb/");
insertDetailedUrl(doc, "Launch4j", "GPL", "http://launch4j.sourceforge.net");
insertDetailedUrl(doc, "NSIS", "zlib/libpng license", "http://nsis.sourceforge.net");
// insertDetailedUrl(doc, "ProGuard", "GPL", "http://proguard.sourceforge.net");
} catch (Exception e) {
}

Original file line number Diff line number Diff line change
@@ -92,6 +92,8 @@ public class MainMenuBar extends JMenuBar implements ActionListener, MenuListene

/* TODO branch private JCheckBoxMenuItem toggleBranchView; */

// File menu
private JMenu fileMenu;

// Go menu
private JMenu goMenu;
@@ -110,6 +112,8 @@ public class MainMenuBar extends JMenuBar implements ActionListener, MenuListene
/** Maps window menu items onto weakly-referenced frames */
private WeakHashMap<JMenuItem, Frame> windowMenuFrames;

/** A handler for Open With menu */
private OpenWithMenu openWithMenu;

private final static String RECALL_WINDOW_ACTION_IDS[] = {
ActionType.RecallWindow1.toString(),
@@ -140,13 +144,13 @@ public MainMenuBar(MainFrame mainFrame) {
MnemonicHelper menuItemMnemonicHelper2 = new MnemonicHelper();

// File menu
JMenu fileMenu = MenuToolkit.addMenu(Translator.get("file_menu"), menuMnemonicHelper, this);
fileMenu = MenuToolkit.addMenu(Translator.get("file_menu"), menuMnemonicHelper, this);
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.NewWindow, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.NewTab, mainFrame), menuItemMnemonicHelper);
fileMenu.add(new JSeparator());
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.Open, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.OpenNatively, mainFrame), menuItemMnemonicHelper);
fileMenu.add(new OpenWithMenu(mainFrame));
fileMenu.add(openWithMenu = new OpenWithMenu(mainFrame));
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.OpenInNewTab, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.OpenInOtherPanel, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.OpenInBothPanels, mainFrame), menuItemMnemonicHelper);
@@ -169,16 +173,17 @@ public MainMenuBar(MainFrame mainFrame) {
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.ChangeDate, mainFrame), menuItemMnemonicHelper);

// Under Mac OS X, 'Preferences' already appears in the application (muCommander) menu, do not display it again
if(!OsFamily.MAC_OS.isCurrent()) {
if (!OsFamily.MAC_OS.isCurrent()) {
fileMenu.add(new JSeparator());
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.ShowPreferences, mainFrame), menuItemMnemonicHelper);
}

fileMenu.add(new JSeparator());
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.CloseWindow, mainFrame), menuItemMnemonicHelper);
// Under Mac OS X, 'Quit' already appears in the application (muCommander) menu, do not display it again
if(!OsFamily.MAC_OS.isCurrent())
if (!OsFamily.MAC_OS.isCurrent()) {
MenuToolkit.addMenuItem(fileMenu, ActionManager.getActionInstance(ActionType.Quit, mainFrame), menuItemMnemonicHelper);
}

add(fileMenu);

@@ -220,8 +225,9 @@ public MainMenuBar(MainFrame mainFrame) {

viewMenu.add(new JSeparator());
ButtonGroup buttonGroup = new ButtonGroup();
for(Column c : Column.values())
for(Column c : Column.values()) {
buttonGroup.add(sortByItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(viewMenu, ActionManager.getActionInstance(c.getSortByColumnActionId(), mainFrame), menuItemMnemonicHelper));
}

MenuToolkit.addMenuItem(viewMenu, ActionManager.getActionInstance(ActionType.ReverseSortOrder, mainFrame), menuItemMnemonicHelper);

@@ -230,9 +236,10 @@ public MainMenuBar(MainFrame mainFrame) {
// Toggle columns submenu
columnsMenu = MenuToolkit.addMenu(Translator.get("view_menu.show_hide_columns"), null, this);
menuItemMnemonicHelper2.clear();
for(Column c : Column.values()) {
if(c==Column.NAME)
for (Column c : Column.values()) {
if (c == Column.NAME) {
continue;
}

toggleColumnItems[c.ordinal()] = MenuToolkit.addCheckBoxMenuItem(columnsMenu, ActionManager.getActionInstance(c.getToggleColumnActionId(), mainFrame), menuItemMnemonicHelper2);
}
@@ -284,8 +291,9 @@ public MainMenuBar(MainFrame mainFrame) {
BrowsableItemsMenuServiceTracker.getMenuServices().forEach(service -> {
JMenu menu = service.getMenu(mainFrame, null);
char mnemonic = menuItemMnemonicHelper.getMnemonic(menu.getName());
if (mnemonic != 0)
if (mnemonic != 0) {
menu.setMnemonic(mnemonic);
}
menu.setIcon(null);
goMenu.add(menu);
});
@@ -317,7 +325,7 @@ public MainMenuBar(MainFrame mainFrame) {
windowMenu = MenuToolkit.addMenu(Translator.get("window_menu"), menuMnemonicHelper, this);

// If running Mac OS X, add 'Minimize' and 'Zoom' items
if(OsFamily.MAC_OS.isCurrent()) {
if (OsFamily.MAC_OS.isCurrent()) {
MenuToolkit.addMenuItem(windowMenu, ActionManager.getActionInstance(ActionType.MinimizeWindow, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(windowMenu, ActionManager.getActionInstance(ActionType.MaximizeWindow, mainFrame), menuItemMnemonicHelper);
windowMenu.add(new JSeparator());
@@ -354,35 +362,36 @@ public MainMenuBar(MainFrame mainFrame) {
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.ShowDebugConsole, mainFrame), menuItemMnemonicHelper);

// Links to website, only shows for OS/Window manager that can launch the default browser to open URLs
if(DesktopManager.canBrowse()) {
if (DesktopManager.canBrowse()) {
helpMenu.add(new JSeparator());
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.GoToWebsite, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.GoToForums, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.GoToForums, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.ReportBug, mainFrame), menuItemMnemonicHelper);
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.Donate, mainFrame), menuItemMnemonicHelper);

helpMenu.add(new JSeparator());
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.CheckForUpdates, mainFrame), menuItemMnemonicHelper);
}

// Under Mac OS X, 'About' already appears in the application (muCommander) menu, do not display it again
if(!OsFamily.MAC_OS.isCurrent()) {
if (!OsFamily.MAC_OS.isCurrent()) {
helpMenu.add(new JSeparator());
MenuToolkit.addMenuItem(helpMenu, ActionManager.getActionInstance(ActionType.ShowAbout, mainFrame), menuItemMnemonicHelper);
}

add(helpMenu);
}


///////////////////////////
// ActionListener method //
///////////////////////////

public void actionPerformed(ActionEvent e) {
// Discard action events while in 'no events mode'
if(mainFrame.getNoEventsMode())
if (mainFrame.getNoEventsMode()) {
return;
}

// Bring the frame corresponding to the clicked menu item to the front
windowMenuFrames.get(e.getSource()).toFront();
@@ -396,7 +405,11 @@ public void actionPerformed(ActionEvent e) {
public void menuSelected(MenuEvent e) {
Object source = e.getSource();

if(source==viewMenu) {
if (source == fileMenu) {
if (openWithMenu != null) {
openWithMenu.refresh(mainFrame.getActiveTable().getSelectedFile());
}
} else if (source == viewMenu) {
FileTable activeTable = mainFrame.getActiveTable();

// Select the 'sort by' criterion currently in use in the active table
@@ -409,62 +422,63 @@ public void menuSelected(MenuEvent e) {
toggleUseSinglePanel.setSelected(mainFrame.isSinglePanel());

/* TODO branch toggleBranchView.setSelected(activeTable.getFolderPanel().isBranchView()); */
}
else if(source==columnsMenu) {
} 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
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());
}
}
else if(source==goMenu) {
} 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--)
for (int i = goMenu.getItemCount(); i> volumeOffset; i--) {
goMenu.remove(volumeOffset);
}

AbstractFile volumes[] = LocalFile.getVolumes();
int nbFolders = volumes.length;

for(int i=0; i<nbFolders; i++)
for (int i = 0; i < nbFolders; i++) {
goMenu.add(new OpenLocationAction(mainFrame, new Hashtable<>(), volumes[i]));
}
else if(source==bookmarksMenu) {
}
} 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--)
for (int i = bookmarksMenu.getItemCount(); i > bookmarksOffset; i--) {
bookmarksMenu.remove(bookmarksOffset);
}

// Add bookmarks menu items
var bookmarks = BookmarkManager.getBookmarks();
if (bookmarks.isEmpty()) {
// 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);
}
else {
} else {
bookmarks.forEach(bookmark -> MenuToolkit.addMenuItem(bookmarksMenu, new OpenLocationAction(mainFrame, new Hashtable<>(), bookmark), null));
}
}
else if(source==windowMenu) {
} else if (source == windowMenu) {
// Select the split orientation currently in use
if(mainFrame.getSplitPaneOrientation())
if (mainFrame.getSplitPaneOrientation()) {
splitVerticallyItem.setSelected(true);
else
} else {
splitHorizontallyItem.setSelected(true);
}

// 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--)
for (int i = windowMenu.getItemCount(); i > windowOffset; i--) {
windowMenu.remove(windowOffset);
}

// 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
@@ -477,13 +491,13 @@ else if(source==windowMenu) {
MainFrame mainFrame;
JCheckBoxMenuItem checkBoxMenuItem;
int nbFrames = mainFrames.size();
for(int i=0; i<nbFrames; i++) {
for (int i = 0; i < nbFrames; i++) {
mainFrame = mainFrames.get(i);
checkBoxMenuItem = new JCheckBoxMenuItem();

// 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) {
if (i < 10) {
recallWindowAction = ActionManager.getActionInstance(RECALL_WINDOW_ACTION_IDS[i], this.mainFrame);
}
// Else use the generic RecallWindowAction
@@ -514,13 +528,13 @@ else if(source==windowMenu) {
Frame frame;
JMenuItem menuItem;
boolean firstFrame = true;
for(int i=0; i<nbFrames; i++) {
for (int i = 0; i < nbFrames; i++) {
frame = frames[i];
// Test if Frame is not hidden (disposed), Frame.getFrames() returns both active and disposed frames
if(frame.isShowing() && (frame instanceof FileFrame)) {
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) {
if (firstFrame) {
windowMenu.add(new JSeparator());
firstFrame = false;
}
@@ -531,8 +545,7 @@ else if(source==windowMenu) {
windowMenuFrames.put(menuItem, frame);
}
}
}
else if(source==themesMenu) {
} 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();
@@ -541,7 +554,7 @@ else if(source==themesMenu) {
JCheckBoxMenuItem item;
themesMenu.add(new JMenuItem(new EditCurrentThemeAction()));
themesMenu.add(new JSeparator());
while(themes.hasNext()) {
while (themes.hasNext()) {
theme = themes.next();
item = new JCheckBoxMenuItem(new ChangeCurrentThemeAction(theme));
buttonGroup.add(item);
@@ -552,10 +565,10 @@ else if(source==themesMenu) {
}
}
}

public void menuDeselected(MenuEvent e) {
}

public void menuCanceled(MenuEvent e) {
}

@@ -575,8 +588,7 @@ public ChangeCurrentThemeAction(Theme theme) {
public void actionPerformed(ActionEvent actionEvent) {
try {
ThemeManager.setCurrentTheme(theme);
}
catch(IllegalArgumentException e) {
} catch(IllegalArgumentException e) {
InformationDialog.showErrorDialog(mainFrame, Translator.get("theme_could_not_be_loaded"));
}
}
Loading
Oops, something went wrong.