Ticket #12270: delete-note.patch
| File delete-note.patch, 6.3 KB (added by , 3 years ago) |
|---|
-
src/org/openstreetmap/josm/data/notes/Note.java
190 190 } 191 191 192 192 /** 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 /** 193 212 * Copies values from a new note into an existing one. Used after a note 194 213 * has been updated on the server and the local copy needs refreshing. 195 214 * @param note New values to copy -
src/org/openstreetmap/josm/data/notes/NoteComment.java
7 7 import org.openstreetmap.josm.data.osm.User; 8 8 9 9 /** 10 * Represents a comment made on a note. All notes have at least on comment10 * Represents a comment made on a note. All notes have at least one comment 11 11 * which is the comment the note was opened with. Comments are immutable. 12 12 * @since 7451 13 13 */ … … 17 17 private final User user; 18 18 private final Instant commentTimestamp; 19 19 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 uploaded22 20 private boolean isNew; 23 21 24 22 /** -
src/org/openstreetmap/josm/data/osm/NoteData.java
119 119 */ 120 120 public synchronized boolean isModified() { 121 121 for (Note note : noteList) { 122 if (note. getId() < 0) { //notes with negative IDs are new122 if (note.isModified()) { 123 123 return true; 124 124 } 125 for (NoteComment comment : note.getComments()) {126 if (comment.isNew()) {127 return true;128 }129 }130 125 } 131 126 return false; 132 127 } … … 232 227 } 233 228 234 229 /** 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 /** 235 243 * Reopen a closed note. 236 244 * @param note Note to reopen. Must already exist in the layer 237 245 * @param text Comment to attach to the reopen action, if desired -
src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
46 46 import org.openstreetmap.josm.data.osm.ChangesetCache; 47 47 import org.openstreetmap.josm.data.osm.NoteData; 48 48 import org.openstreetmap.josm.data.osm.NoteData.NoteDataUpdateListener; 49 import org.openstreetmap.josm.gui.ExtendedDialog; 49 50 import org.openstreetmap.josm.gui.MainApplication; 50 51 import org.openstreetmap.josm.gui.MapFrame; 51 52 import org.openstreetmap.josm.gui.NoteInputDialog; … … 81 82 private final JosmTextField filter = setupFilter(); 82 83 private final AddCommentAction addCommentAction; 83 84 private final CloseAction closeAction; 85 private final DeleteAction deleteAction; 84 86 private final DownloadNotesInViewAction downloadNotesInViewAction; 85 87 private final NewAction newAction; 86 88 private final ReopenAction reopenAction; … … 97 99 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), 150); 98 100 addCommentAction = new AddCommentAction(); 99 101 closeAction = new CloseAction(); 102 deleteAction = new DeleteAction(); 100 103 downloadNotesInViewAction = DownloadNotesInViewAction.newActionWithDownloadIcon(); 101 104 newAction = new NewAction(); 102 105 reopenAction = new ReopenAction(); … … 148 151 notesPopupMenu.add(openInBrowserAction); 149 152 notesPopupMenu.add(closeAction); 150 153 notesPopupMenu.add(reopenAction); 154 notesPopupMenu.add(deleteAction); 151 155 displayList.addMouseListener(new PopupMenuLauncher(notesPopupMenu)); 152 156 } 153 157 … … 474 478 } 475 479 476 480 /** 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 /** 477 519 * Create a new note 478 520 */ 479 521 class NewAction extends JosmAction {
