Ticket #23179: v4-0001-Include-changeset-in-note-comment-if-feasible.patch

File v4-0001-Include-changeset-in-note-comment-if-feasible.patch, 4.5 KB (added by qeef, 14 months ago)
  • src/org/openstreetmap/josm/gui/NoteInputDialog.java

    From 530b5d2dec2c00d334925d09f7a77bad63f148df Mon Sep 17 00:00:00 2001
    From: Jiri Vlasak <jiri.hubacek@gmail.com>
    Date: Tue, 19 Sep 2023 01:02:05 +0200
    Subject: [PATCH v4] Include changeset in note comment if feasible
    
    When closing a note, check for the changeset in the changeset cache. If
    there is a changeset with the comment that contains a link to the note
    being closed, put the link to the changeset as the default text of the
    closing note comment.
    ---
     .../josm/gui/NoteInputDialog.java              | 12 ++++++++++++
     .../josm/gui/dialogs/NotesDialog.java          | 18 ++++++++++++++++--
     2 files changed, 28 insertions(+), 2 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/gui/NoteInputDialog.java b/src/org/openstreetmap/josm/gui/NoteInputDialog.java
    index 779959b856..c2881d5d13 100644
    a b public class NoteInputDialog extends ExtendedDialog {  
    4444     * @param icon Icon to display in the action button
    4545     */
    4646    public void showNoteDialog(String message, Icon icon) {
     47        showNoteDialog(message, icon, "");
     48    }
     49
     50    /**
     51     * Displays the dialog to the user
     52     * @param message Translated message to display to the user as input prompt
     53     * @param icon Icon to display in the action button
     54     * @param text Default text of the note's comment
     55     * @param since xxx
     56     */
     57    public void showNoteDialog(String message, Icon icon, String text) {
     58        textArea.setText(text);
    4759        textArea.setRows(6);
    4860        textArea.setColumns(30);
    4961        textArea.setLineWrap(true);
  • src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java b/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
    index 6e0fc7e8ff..8282a6444a 100644
    a b import org.openstreetmap.josm.actions.mapmode.AddNoteAction;  
    4040import org.openstreetmap.josm.data.notes.Note;
    4141import org.openstreetmap.josm.data.notes.Note.State;
    4242import org.openstreetmap.josm.data.notes.NoteComment;
     43import org.openstreetmap.josm.data.osm.Changeset;
     44import org.openstreetmap.josm.data.osm.ChangesetCache;
    4345import org.openstreetmap.josm.data.osm.NoteData;
    4446import org.openstreetmap.josm.data.osm.NoteData.NoteDataUpdateListener;
    4547import org.openstreetmap.josm.gui.MainApplication;
    import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField  
    5759import org.openstreetmap.josm.gui.widgets.FilterField;
    5860import org.openstreetmap.josm.gui.widgets.JosmTextField;
    5961import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     62import org.openstreetmap.josm.io.OsmApi;
    6063import org.openstreetmap.josm.spi.preferences.Config;
    6164import org.openstreetmap.josm.tools.ImageProvider;
    6265import org.openstreetmap.josm.tools.OpenBrowser;
    public class NotesDialog extends ToggleDialog implements LayerChangeListener, No  
    422425
    423426        @Override
    424427        public void actionPerformed(ActionEvent e) {
     428            Note note = displayList.getSelectedValue();
     429            String changesetUrl = "";
     430            if (note != null) {
     431                Boolean isDefaultOsmInstance = Config.getUrls().getDefaultOsmApiUrl().equals(OsmApi.getOsmApi().getServerUrl());
     432                String noteUrlShort = "osm.org/note/" + note.getId();
     433                String noteUrlLong = "openstreetmap.org/note/" + note.getId();
     434                for (Changeset cs: ChangesetCache.getInstance().getChangesets()) {
     435                    if (isDefaultOsmInstance && (cs.getComment().indexOf(noteUrlShort) > -1 || cs.getComment().indexOf(noteUrlLong) > -1)) {
     436                        changesetUrl = "https://www.osm.org/changeset/" + cs.getId();
     437                    }
     438                }
     439            }
    425440            NoteInputDialog dialog = new NoteInputDialog(MainApplication.getMainFrame(), tr("Close note"), tr("Close note"));
    426             dialog.showNoteDialog(tr("Close note with message:"), ImageProvider.get("dialogs/notes", "note_closed"));
     441            dialog.showNoteDialog(tr("Close note with message:"), ImageProvider.get("dialogs/notes", "note_closed"), changesetUrl);
    427442            if (dialog.getValue() != 1) {
    428443                return;
    429444            }
    430             Note note = displayList.getSelectedValue();
    431445            if (note != null) {
    432446                int selectedIndex = displayList.getSelectedIndex();
    433447                noteData.closeNote(note, dialog.getInputText());