Ticket #12270: delete-note.patch

File delete-note.patch, 6.3 KB (added by NoteRoamer, 3 years ago)

Adds a delete option to note dialog popup menu.

  • src/org/openstreetmap/josm/data/notes/Note.java

     
    190190    }
    191191
    192192    /**
     193     * Is this note modified? A new note and a note with a new comment is
     194     * considered to be modified. Actions such as Close, ReOpen adds a new
     195     * comment and is therefor considered modified.
     196     * @since xxx
     197     */
     198    public boolean isModified() {
     199        if (this.getId() < 0) { //notes with negative IDs are new
     200            return true;
     201        }
     202        for (NoteComment comment : getComments()) {
     203            if (comment.isNew()) {
     204                return true;
     205            }
     206        }
     207
     208        return false;
     209    }
     210
     211    /**
    193212     * Copies values from a new note into an existing one. Used after a note
    194213     * has been updated on the server and the local copy needs refreshing.
    195214     * @param note New values to copy
  • src/org/openstreetmap/josm/data/notes/NoteComment.java

     
    77import org.openstreetmap.josm.data.osm.User;
    88
    99/**
    10  * Represents a comment made on a note. All notes have at least on comment
     10 * Represents a comment made on a note. All notes have at least one comment
    1111 * which is the comment the note was opened with. Comments are immutable.
    1212 * @since 7451
    1313 */
     
    1717    private final User user;
    1818    private final Instant commentTimestamp;
    1919    private final Action action;
    20 
    21     //not currently used. I'm planning on using this to keep track of new actions that need to be uploaded
    2220    private boolean isNew;
    2321
    2422    /**
  • src/org/openstreetmap/josm/data/osm/NoteData.java

     
    119119     */
    120120    public synchronized boolean isModified() {
    121121        for (Note note : noteList) {
    122             if (note.getId() < 0) { //notes with negative IDs are new
     122            if (note.isModified()) {
    123123                return true;
    124124            }
    125             for (NoteComment comment : note.getComments()) {
    126                 if (comment.isNew()) {
    127                     return true;
    128                 }
    129             }
    130125        }
    131126        return false;
    132127    }
     
    232227    }
    233228
    234229    /**
     230     * Delete a note from the local data layer.
     231     * @param note Note to remove.
     232     * @since xxx
     233     */
     234    public synchronized void deleteNote(Note note) {
     235        if (!noteList.contains(note)) {
     236            throw new IllegalArgumentException("Note to delete must be in layer");
     237        }
     238        noteList.removeElem(note);
     239        dataUpdated();
     240    }
     241
     242    /**
    235243     * Reopen a closed note.
    236244     * @param note Note to reopen. Must already exist in the layer
    237245     * @param text Comment to attach to the reopen action, if desired
  • src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java

     
    4646import org.openstreetmap.josm.data.osm.ChangesetCache;
    4747import org.openstreetmap.josm.data.osm.NoteData;
    4848import org.openstreetmap.josm.data.osm.NoteData.NoteDataUpdateListener;
     49import org.openstreetmap.josm.gui.ExtendedDialog;
    4950import org.openstreetmap.josm.gui.MainApplication;
    5051import org.openstreetmap.josm.gui.MapFrame;
    5152import org.openstreetmap.josm.gui.NoteInputDialog;
     
    8182    private final JosmTextField filter = setupFilter();
    8283    private final AddCommentAction addCommentAction;
    8384    private final CloseAction closeAction;
     85    private final DeleteAction deleteAction;
    8486    private final DownloadNotesInViewAction downloadNotesInViewAction;
    8587    private final NewAction newAction;
    8688    private final ReopenAction reopenAction;
     
    9799                KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), 150);
    98100        addCommentAction = new AddCommentAction();
    99101        closeAction = new CloseAction();
     102        deleteAction = new DeleteAction();
    100103        downloadNotesInViewAction = DownloadNotesInViewAction.newActionWithDownloadIcon();
    101104        newAction = new NewAction();
    102105        reopenAction = new ReopenAction();
     
    148151        notesPopupMenu.add(openInBrowserAction);
    149152        notesPopupMenu.add(closeAction);
    150153        notesPopupMenu.add(reopenAction);
     154        notesPopupMenu.add(deleteAction);
    151155        displayList.addMouseListener(new PopupMenuLauncher(notesPopupMenu));
    152156    }
    153157
     
    474478    }
    475479
    476480    /**
     481     * Delete a note from the local layer.
     482     */
     483    class DeleteAction extends JosmAction {
     484
     485        /**
     486         * Constructs a new {@code DeleteAction}.
     487         */
     488        DeleteAction() {
     489            super(tr("Delete note"), "dialogs/delete", tr("Delete note"),
     490                    Shortcut.registerShortcut("notes:comment:delete", tr("Notes: Delete note"), KeyEvent.VK_UNDEFINED, Shortcut.NONE),
     491                    false, false);
     492        }
     493
     494        @Override
     495        public void actionPerformed(ActionEvent e) {
     496            Note note = displayList.getSelectedValue();
     497
     498            // Can happen when called from a keyboard binding.
     499            if (note == null) {
     500                return;
     501            }
     502
     503            if (note.isModified()) {
     504                ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(), tr("Delete note"), tr("Delete"), tr("Cancel"));
     505                ed.setButtonIcons("dialogs/delete", "cancel");
     506                ed.setContent(tr("Note has been localy modified. Continue with deletion?"));
     507                ed.showDialog();
     508                if (ed.getValue() != 1) {
     509                    return;
     510                }
     511            }
     512
     513            noteData.deleteNote(note);
     514            noteData.setSelectedNote(null);
     515        }
     516    }
     517
     518    /**
    477519     * Create a new note
    478520     */
    479521    class NewAction extends JosmAction {