Skip to content

Commit 752cc6b

Browse files
committed
fix Library/Tool reference links in help menu (resolves processing/processing#5839)
1 parent bb5b46b commit 752cc6b

File tree

2 files changed

+47
-81
lines changed

2 files changed

+47
-81
lines changed

java/src/processing/mode/java/JavaEditor.java

Lines changed: 44 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Map;
3232

3333
import javax.swing.*;
34-
import javax.swing.border.*;
3534
import javax.swing.event.*;
3635
import javax.swing.text.BadLocationException;
3736
import javax.swing.text.Document;
@@ -316,96 +315,61 @@ public JMenu buildHelpMenu() {
316315
menu.addSeparator();
317316

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

323-
@Override
324-
public void menuSelected(MenuEvent e) {
325-
// Adding this in case references are included in a core library,
326-
// or other core libraries are included in the future
327-
boolean isCoreLibMenuItemAdded =
328-
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
329-
330-
if (isCoreLibMenuItemAdded && !mode.contribLibraries.isEmpty()) {
331-
libRefSubmenu.addSeparator();
332-
}
333-
334-
boolean isContribLibMenuItemAdded =
335-
addLibReferencesToSubMenu(mode.contribLibraries, libRefSubmenu);
319+
// Adding this in case references are included in a core library,
320+
// or other core libraries are included in the future
321+
boolean isCoreLibMenuItemAdded =
322+
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
336323

337-
if (!isContribLibMenuItemAdded && !isCoreLibMenuItemAdded) {
338-
JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
339-
emptyMenuItem.setEnabled(false);
340-
emptyMenuItem.setFocusable(false);
341-
emptyMenuItem.setFocusPainted(false);
342-
libRefSubmenu.add(emptyMenuItem);
324+
if (isCoreLibMenuItemAdded && !mode.contribLibraries.isEmpty()) {
325+
libRefSubmenu.addSeparator();
326+
}
343327

344-
} else if (!isContribLibMenuItemAdded && !mode.coreLibraries.isEmpty()) {
345-
//re-populate the menu to get rid of terminal separator
346-
libRefSubmenu.removeAll();
347-
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
348-
}
349-
}
328+
boolean isContribLibMenuItemAdded =
329+
addLibReferencesToSubMenu(mode.contribLibraries, libRefSubmenu);
350330

351-
@Override
352-
public void menuDeselected(MenuEvent e) {
353-
libRefSubmenu.removeAll();
354-
}
331+
if (!isContribLibMenuItemAdded && !isCoreLibMenuItemAdded) {
332+
JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
333+
emptyMenuItem.setEnabled(false);
334+
emptyMenuItem.setFocusable(false);
335+
emptyMenuItem.setFocusPainted(false);
336+
libRefSubmenu.add(emptyMenuItem);
355337

356-
@Override
357-
public void menuCanceled(MenuEvent e) {
358-
menuDeselected(e);
359-
}
360-
});
338+
} else if (!isContribLibMenuItemAdded && !mode.coreLibraries.isEmpty()) {
339+
//re-populate the menu to get rid of terminal separator
340+
libRefSubmenu.removeAll();
341+
addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu);
342+
}
361343
menu.add(libRefSubmenu);
362344

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

368-
@Override
369-
public void menuSelected(MenuEvent e) {
370-
boolean coreToolMenuItemAdded;
371-
boolean contribToolMenuItemAdded;
372-
373-
List<ToolContribution> contribTools = base.getToolContribs();
374-
// Adding this in in case a reference folder is added for MovieMaker, or in case
375-
// other core tools are introduced later
376-
coreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
377-
378-
if (coreToolMenuItemAdded && !contribTools.isEmpty())
379-
toolRefSubmenu.addSeparator();
380-
381-
contribToolMenuItemAdded = addToolReferencesToSubMenu(contribTools, toolRefSubmenu);
382-
383-
if (!contribToolMenuItemAdded && !coreToolMenuItemAdded) {
384-
toolRefSubmenu.removeAll(); // in case a separator was added
385-
final JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
386-
emptyMenuItem.setEnabled(false);
387-
emptyMenuItem.setBorderPainted(false);
388-
emptyMenuItem.setFocusable(false);
389-
emptyMenuItem.setFocusPainted(false);
390-
toolRefSubmenu.add(emptyMenuItem);
391-
}
392-
else if (!contribToolMenuItemAdded && !contribTools.isEmpty()) {
393-
// re-populate the menu to get rid of terminal separator
394-
toolRefSubmenu.removeAll();
395-
addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
396-
}
397-
}
349+
List<ToolContribution> contribTools = base.getToolContribs();
350+
// Adding this in in case a reference folder is added for MovieMaker, or in case
351+
// other core tools are introduced later
352+
coreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
398353

399-
@Override
400-
public void menuDeselected(MenuEvent e) {
401-
toolRefSubmenu.removeAll();
402-
}
354+
if (coreToolMenuItemAdded && !contribTools.isEmpty())
355+
toolRefSubmenu.addSeparator();
403356

404-
@Override
405-
public void menuCanceled(MenuEvent e) {
406-
menuDeselected(e);
407-
}
408-
});
357+
contribToolMenuItemAdded = addToolReferencesToSubMenu(contribTools, toolRefSubmenu);
358+
359+
if (!contribToolMenuItemAdded && !coreToolMenuItemAdded) {
360+
toolRefSubmenu.removeAll(); // in case a separator was added
361+
final JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty"));
362+
emptyMenuItem.setEnabled(false);
363+
emptyMenuItem.setBorderPainted(false);
364+
emptyMenuItem.setFocusable(false);
365+
emptyMenuItem.setFocusPainted(false);
366+
toolRefSubmenu.add(emptyMenuItem);
367+
}
368+
else if (!contribToolMenuItemAdded && !contribTools.isEmpty()) {
369+
// re-populate the menu to get rid of terminal separator
370+
toolRefSubmenu.removeAll();
371+
addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu);
372+
}
409373
menu.add(toolRefSubmenu);
410374

411375
menu.addSeparator();

todo.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ X disable behavior with sketch.name.replace_underscore = false
3333
X add clean-libs target to build.xml files that need it
3434
X check all Help menu entries and their destinations
3535
X Help > Environment not going to the right place
36+
X Help > Libraries Reference > submenu items don't work
37+
X same for Tools reference
38+
X https://github.com/processing/processing/issues/5839
3639

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

0 commit comments

Comments
 (0)