Changeset 16596 in josm


Ignore:
Timestamp:
2020-06-11T08:40:14+02:00 (4 years ago)
Author:
simon04
Message:

fix #19320 - Add links to taghistory.raifer.tech

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r16549 r16596  
    195195            tagTable, editHelper::getDataKey, editHelper::getDataValues,
    196196            membershipTable, x -> (IRelation<?>) membershipData.getValueAt(x, 0), null);
     197    private final TaginfoAction tagHistoryAction = taginfoAction.toTagHistoryAction();
    197198    private final Collection<TaginfoAction> taginfoNationalActions = new ArrayList<>();
    198199    private final PasteValueAction pasteValueAction = new PasteValueAction();
     
    457458        tagMenu.addSeparator();
    458459        tagMenu.add(helpTagAction);
     460        tagMenu.add(tagHistoryAction);
    459461        tagMenu.add(taginfoAction);
    460462        tagMenu.addPopupMenuListener(new AbstractTag2LinkPopupListener() {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TaginfoAction.java

    r16275 r16596  
    2727
    2828    private static final StringProperty TAGINFO_URL_PROP = new StringProperty("taginfo.url", "https://taginfo.openstreetmap.org/");
     29    private static final StringProperty TAG_HISTORY_URL_PROP = new StringProperty("taghistory.url", "https://taghistory.raifer.tech/#***");
    2930
    3031    private final Supplier<Tag> tagSupplier;
    3132    private final Supplier<String> relationTypeSupplier;
    32     private final String taginfoUrl;
     33    protected final String taginfoUrl;
     34
     35    private TaginfoAction(String name, Supplier<Tag> tagSupplier, Supplier<String> relationTypeSupplier, String taginfoUrl) {
     36        super(name);
     37        this.tagSupplier = tagSupplier;
     38        this.relationTypeSupplier = relationTypeSupplier;
     39        this.taginfoUrl = taginfoUrl;
     40    }
    3341
    3442    /**
     
    8593        Tag tag = tagSupplier.get();
    8694        if (tag != null) {
    87             openTaginfoForTag(tag, taginfoUrl);
     95            OpenBrowser.displayUrl(getTaginfoUrlForTag(tag));
    8896            return;
    8997        }
    9098        String type = relationTypeSupplier.get();
    9199        if (type != null) {
    92             openTaginfoForRelationType(type, taginfoUrl);
     100            OpenBrowser.displayUrl(getTaginfoUrlForRelationType(type));
    93101        }
    94102    }
     
    98106            taginfoUrl = TAGINFO_URL_PROP.get();
    99107        }
    100         return taginfoUrl.endsWith("/") ? taginfoUrl : taginfoUrl + '/';
     108        return withoutTrailingSlash(taginfoUrl);
     109    }
     110
     111    private static String withoutTrailingSlash(String url) {
     112        return Utils.strip(url, "/");
    101113    }
    102114
     
    104116     * Opens Taginfo for the given tag or key (if the tag value is null)
    105117     * @param tag the tag
    106      * @param taginfoUrl Taginfo URL (may be null)
    107      * @since 16275
     118     * @since 16596
    108119     */
    109     public static void openTaginfoForTag(Tag tag, String taginfoUrl) {
    110         taginfoUrl = getTaginfoUrl(taginfoUrl);
     120    public String getTaginfoUrlForTag(Tag tag) {
    111121        if (tag.getValue().isEmpty()) {
    112             OpenBrowser.displayUrl(taginfoUrl + "keys/" + tag.getKey());
     122            return taginfoUrl + "/keys/" + tag.getKey();
    113123        } else {
    114             OpenBrowser.displayUrl(taginfoUrl + "tags/" + tag.getKey() + '=' + Utils.encodeUrl(tag.getValue()).replaceAll("\\+", "%20"));
     124            return taginfoUrl + "/tags/" + tag.getKey() + '=' + Utils.encodeUrl(tag.getValue()).replaceAll("\\+", "%20");
    115125        }
    116126    }
     
    119129     * Opens Taginfo for the given relation type
    120130     * @param type the relation type
    121      * @param taginfoUrl Taginfo URL (may be null)
    122      * @since 16275
     131     * @since 16596
    123132     */
    124     public static void openTaginfoForRelationType(String type, String taginfoUrl) {
    125         taginfoUrl = getTaginfoUrl(taginfoUrl);
    126         OpenBrowser.displayUrl(taginfoUrl + "relations/" + type);
     133    public String getTaginfoUrlForRelationType(String type) {
     134        return taginfoUrl + "/relations/" + type;
     135    }
     136
     137    /**
     138     * Returns a new action which launches https://taghistory.raifer.tech/ for the given tag
     139     * @return a new action
     140     * @since 16596
     141     */
     142    public TaginfoAction toTagHistoryAction() {
     143        String url = withoutTrailingSlash(TAG_HISTORY_URL_PROP.get());
     144        return new TaginfoAction(tr("Go to OSM Tag History"), tagSupplier, relationTypeSupplier, url) {
     145            @Override
     146            public String getTaginfoUrlForTag(Tag tag) {
     147                return String.join("/", taginfoUrl, tag.getKey(), tag.getValue());
     148            }
     149
     150            @Override
     151            public String getTaginfoUrlForRelationType(String type) {
     152                return null;
     153            }
     154        };
    127155    }
    128156}
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r16593 r16596  
    100100        tagMenu.addSeparator();
    101101        tagMenu.add(trackJosmAction(new HelpTagAction(table, tagKeyFn, tagValuesFn)));
    102         tagMenu.add(trackJosmAction(new TaginfoAction(tr("Go to Taginfo"), table, tagKeyFn, tagValuesFn, null, null, null)));
     102        TaginfoAction taginfoAction = new TaginfoAction(tr("Go to Taginfo"), table, tagKeyFn, tagValuesFn, null, null, null);
     103        tagMenu.add(trackJosmAction(taginfoAction.toTagHistoryAction()));
     104        tagMenu.add(trackJosmAction(taginfoAction));
    103105
    104106        table.addMouseListener(new PopupMenuLauncher(tagMenu));
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/KeyedItem.java

    r16417 r16596  
    214214        popupMenu.add(tr("Key: {0}", key)).setEnabled(false);
    215215        popupMenu.add(new HelpTagAction(() -> tag));
    216         popupMenu.add(new TaginfoAction(() -> tag, () -> null));
     216        TaginfoAction taginfoAction = new TaginfoAction(() -> tag, () -> null);
     217        popupMenu.add(taginfoAction.toTagHistoryAction());
     218        popupMenu.add(taginfoAction);
    217219        return popupMenu;
    218220    }
Note: See TracChangeset for help on using the changeset viewer.