Skip to content

Commit

Permalink
fix Library/Tool reference links in help menu (resolves processing/pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Aug 4, 2022
1 parent bb5b46b commit 752cc6b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 81 deletions.
124 changes: 44 additions & 80 deletions java/src/processing/mode/java/JavaEditor.java
Expand Up @@ -31,7 +31,6 @@
import java.util.Map;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
Expand Down Expand Up @@ -316,96 +315,61 @@ public JMenu buildHelpMenu() {
menu.addSeparator();

final JMenu libRefSubmenu = new JMenu(Language.text("menu.help.libraries_reference"));
// Populate only when sub-menu is opened, to avoid having spurious menu
// options if a library is deleted, or a missing menu option if a library is added
libRefSubmenu.addMenuListener(new MenuListener() {

@Override
public void menuSelected(MenuEvent e) {
// Adding this in case references are included in a core library,
// or other core libraries are included in the future
boolean isCoreLibMenuItemAdded =
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);

if (isCoreLibMenuItemAdded && !mode.contribLibraries.isEmpty()) {
libRefSubmenu.addSeparator();
}

boolean isContribLibMenuItemAdded =
addLibReferencesToSubMenu(mode.contribLibraries, libRefSubmenu);
// Adding this in case references are included in a core library,
// or other core libraries are included in the future
boolean isCoreLibMenuItemAdded =
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);

if (!isContribLibMenuItemAdded && !isCoreLibMenuItemAdded) {
JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
emptyMenuItem.setEnabled(false);
emptyMenuItem.setFocusable(false);
emptyMenuItem.setFocusPainted(false);
libRefSubmenu.add(emptyMenuItem);
if (isCoreLibMenuItemAdded && !mode.contribLibraries.isEmpty()) {
libRefSubmenu.addSeparator();
}

} else if (!isContribLibMenuItemAdded && !mode.coreLibraries.isEmpty()) {
//re-populate the menu to get rid of terminal separator
libRefSubmenu.removeAll();
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
}
}
boolean isContribLibMenuItemAdded =
addLibReferencesToSubMenu(mode.contribLibraries, libRefSubmenu);

@Override
public void menuDeselected(MenuEvent e) {
libRefSubmenu.removeAll();
}
if (!isContribLibMenuItemAdded && !isCoreLibMenuItemAdded) {
JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
emptyMenuItem.setEnabled(false);
emptyMenuItem.setFocusable(false);
emptyMenuItem.setFocusPainted(false);
libRefSubmenu.add(emptyMenuItem);

@Override
public void menuCanceled(MenuEvent e) {
menuDeselected(e);
}
});
} else if (!isContribLibMenuItemAdded && !mode.coreLibraries.isEmpty()) {
//re-populate the menu to get rid of terminal separator
libRefSubmenu.removeAll();
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
}
menu.add(libRefSubmenu);

final JMenu toolRefSubmenu = new JMenu(Language.text("menu.help.tools_reference"));
// Populate only when sub-menu is opened, to avoid having spurious menu
// options if a tool is deleted, or a missing menu option if a library is added
toolRefSubmenu.addMenuListener(new MenuListener() {
boolean coreToolMenuItemAdded;
boolean contribToolMenuItemAdded;

@Override
public void menuSelected(MenuEvent e) {
boolean coreToolMenuItemAdded;
boolean contribToolMenuItemAdded;

List<ToolContribution> contribTools = base.getToolContribs();
// Adding this in in case a reference folder is added for MovieMaker, or in case
// other core tools are introduced later
coreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);

if (coreToolMenuItemAdded && !contribTools.isEmpty())
toolRefSubmenu.addSeparator();

contribToolMenuItemAdded = addToolReferencesToSubMenu(contribTools, toolRefSubmenu);

if (!contribToolMenuItemAdded && !coreToolMenuItemAdded) {
toolRefSubmenu.removeAll(); // in case a separator was added
final JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
emptyMenuItem.setEnabled(false);
emptyMenuItem.setBorderPainted(false);
emptyMenuItem.setFocusable(false);
emptyMenuItem.setFocusPainted(false);
toolRefSubmenu.add(emptyMenuItem);
}
else if (!contribToolMenuItemAdded && !contribTools.isEmpty()) {
// re-populate the menu to get rid of terminal separator
toolRefSubmenu.removeAll();
addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
}
}
List<ToolContribution> contribTools = base.getToolContribs();
// Adding this in in case a reference folder is added for MovieMaker, or in case
// other core tools are introduced later
coreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);

@Override
public void menuDeselected(MenuEvent e) {
toolRefSubmenu.removeAll();
}
if (coreToolMenuItemAdded && !contribTools.isEmpty())
toolRefSubmenu.addSeparator();

@Override
public void menuCanceled(MenuEvent e) {
menuDeselected(e);
}
});
contribToolMenuItemAdded = addToolReferencesToSubMenu(contribTools, toolRefSubmenu);

if (!contribToolMenuItemAdded && !coreToolMenuItemAdded) {
toolRefSubmenu.removeAll(); // in case a separator was added
final JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
emptyMenuItem.setEnabled(false);
emptyMenuItem.setBorderPainted(false);
emptyMenuItem.setFocusable(false);
emptyMenuItem.setFocusPainted(false);
toolRefSubmenu.add(emptyMenuItem);
}
else if (!contribToolMenuItemAdded && !contribTools.isEmpty()) {
// re-populate the menu to get rid of terminal separator
toolRefSubmenu.removeAll();
addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
}
menu.add(toolRefSubmenu);

menu.addSeparator();
Expand Down
4 changes: 3 additions & 1 deletion todo.txt
Expand Up @@ -33,6 +33,9 @@ X disable behavior with sketch.name.replace_underscore = false
X add clean-libs target to build.xml files that need it
X check all Help menu entries and their destinations
X Help > Environment not going to the right place
X Help > Libraries Reference > submenu items don't work
X same for Tools reference
X https://github.com/processing/processing/issues/5839

naming
X Friendly Names for new Sketches (includes UI for switching it back)
Expand Down Expand Up @@ -561,7 +564,6 @@ _ versions for aarch64 as well
_ https://github.com/eugeneware/ffmpeg-static/releases
_ but need to figure out a good way to highlight it/encourage installation
_ ...as well as the other libraries? separate window?
_ Help > Library/Tools reference links don't work
_ Export to Application not working with the current video library
_ https://github.com/processing/processing-video/issues/188
_ loadShape(), show a warning when using style instead of presentation attributes
Expand Down

0 comments on commit 752cc6b

Please sign in to comment.