From b99ab40ba29cdc45d0ff239295b351ebd990b65c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 22 Mar 2016 14:15:22 +0100 Subject: [PATCH] Enable links to directly open Lib/Board manager If a sketch contains a link to http://librarymanager/${dropdown}#${filter} or http://boardmanager/${dropdown}#${filter} (for example http://librarymanager/All#OneWire) Library or Board manager will be opened applying the secified filters --- .../arduino/UpdatableBoardsLibsFakeURLsHandler.java | 10 ++++++++-- .../contributions/ContributionsSelfCheck.java | 4 ++-- app/src/processing/app/Base.java | 7 +++++-- app/src/processing/app/Editor.java | 13 ++++++++++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java b/app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java index 112296b43..4cc377ea9 100644 --- a/app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java +++ b/app/src/cc/arduino/UpdatableBoardsLibsFakeURLsHandler.java @@ -53,22 +53,28 @@ public class UpdatableBoardsLibsFakeURLsHandler implements HyperlinkListener { } URL url = event.getURL(); + openBoardLibManager(url); + } + public void openBoardLibManager(URL url) { if (BOARDSMANAGER.equals(url.getHost())) { try { - base.openBoardsManager("", "DropdownUpdatableCoresItem"); + base.openBoardsManager(url.getRef() == null ? "": url.getRef() , url.getPath() == null ? "" : url.getPath().replace("/", "")); } catch (Exception e) { e.printStackTrace(); } return; } + System.out.println(url.getRef() + " " + url.getHost() + " " + url.getPath()); + if (LIBRARYMANAGER.equals(url.getHost())) { - base.openLibraryManager("DropdownUpdatableLibrariesItem"); + base.openLibraryManager(url.getRef() == null ? "": url.getRef() , url.getPath() == null ? "" : url.getPath().replace("/", "")); return; } throw new IllegalArgumentException(url.getHost() + " is invalid"); + } } diff --git a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java index 1031effc3..636319d29 100644 --- a/app/src/cc/arduino/contributions/ContributionsSelfCheck.java +++ b/app/src/cc/arduino/contributions/ContributionsSelfCheck.java @@ -83,9 +83,9 @@ public class ContributionsSelfCheck extends TimerTask { String text; if (updatableLibraries > 0 && updatablePlatforms <= 0) { - text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "", ""); + text = I18n.format(tr("Updates available for some of your {0}libraries{1}"), "", ""); } else if (updatableLibraries <= 0 && updatablePlatforms > 0) { - text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "", ""); + text = I18n.format(tr("Updates available for some of your {0}boards{1}"), "", ""); } else { text = I18n.format(tr("Updates available for some of your {0}boards{1} and {2}libraries{3}"), "", "", "", ""); } diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 832973fe1..7f9906dad 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1135,7 +1135,7 @@ public class Base { importMenu.removeAll(); JMenuItem menu = new JMenuItem(tr("Manage Libraries...")); - menu.addActionListener(e -> openLibraryManager("")); + menu.addActionListener(e -> openLibraryManager("", "")); importMenu.add(menu); importMenu.addSeparator(); @@ -1264,7 +1264,7 @@ public class Base { } } - public void openLibraryManager(String dropdownItem) { + public void openLibraryManager(final String filterText, String dropdownItem) { if (contributionsSelfCheck != null) { contributionsSelfCheck.cancel(); } @@ -1280,6 +1280,9 @@ public class Base { if (StringUtils.isNotEmpty(dropdownItem)) { selectDropdownItemByClassName(dropdownItem); } + if (StringUtils.isNotEmpty(filterText)) { + setFilterText(filterText); + } } }; managerUI.setLocationRelativeTo(activeEditor); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index c41c82b3b..8da903bcb 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -29,6 +29,7 @@ import cc.arduino.packages.uploaders.SerialUploader; import cc.arduino.view.GoToLineNumber; import cc.arduino.view.StubMenuListener; import cc.arduino.view.findreplace.FindReplace; +import cc.arduino.UpdatableBoardsLibsFakeURLsHandler; import com.jcraft.jsch.JSchException; import jssc.SerialPortException; import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; @@ -1015,9 +1016,15 @@ public class Editor extends JFrame implements RunnerListener { textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size")); textArea.addHyperlinkListener(evt -> { try { - platform.openURL(sketch.getFolder(), evt.getURL().toExternalForm()); - } catch (Exception e) { - Base.showWarning(e.getMessage(), e.getMessage(), e); + UpdatableBoardsLibsFakeURLsHandler boardLibHandler = new UpdatableBoardsLibsFakeURLsHandler(base); + boardLibHandler.openBoardLibManager(evt.getURL()); + } + catch (Exception e) { + try { + platform.openURL(sketch.getFolder(), evt.getURL().toExternalForm()); + } catch (Exception f) { + Base.showWarning(f.getMessage(), f.getMessage(), f); + } } }); textArea.addCaretListener(e -> {