ability to remove attachments from message

pull/53/head
Zlatin Balevsky 2020-11-11 15:28:33 +00:00
parent 1110f5eb7d
commit 040203cd58
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 37 additions and 2 deletions

View File

@ -53,6 +53,7 @@ class NewMessageView {
JTextField subjectField
JTextArea bodyArea
JTable attachmentsTable
def lastAttachmentsTableSortEvent
void initUI() {
int rowHeight = application.context.get("row-height")
@ -115,14 +116,33 @@ class NewMessageView {
}
void mvcGroupInit(Map<String, String> args) {
subjectField.setText(model.replySubject)
bodyArea.setText(model.replyBody)
// attachments table
def transferHandler = new AttachmentTransferHandler()
attachmentsTable.setTransferHandler(transferHandler)
attachmentsTable.setFillsViewportHeight(true)
attachmentsTable.setDefaultRenderer(Long.class, new SizeRenderer())
attachmentsTable.rowSorter.setSortsOnUpdates(true)
attachmentsTable.rowSorter.addRowSorterListener({evt -> lastAttachmentsTableSortEvent = evt})
attachmentsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)
JPopupMenu attachmentsMenu = new JPopupMenu()
JMenuItem removeAttachmentItem = new JMenuItem(trans("REMOVE"))
removeAttachmentItem.addActionListener({removeSelectedAttachments()})
attachmentsMenu.add(removeAttachmentItem)
attachmentsTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3)
attachmentsMenu.show(e.getComponent(), e.getX(), e.getY())
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger() || e.getButton() == MouseEvent.BUTTON3)
attachmentsMenu.show(e.getComponent(), e.getX(), e.getY())
}
})
subjectField.setText(model.replySubject)
bodyArea.setText(model.replyBody)
// recipients list
transferHandler = new PersonaTransferHandler()
@ -167,6 +187,21 @@ class NewMessageView {
}
}
void removeSelectedAttachments() {
int [] selected = attachmentsTable.getSelectedRows()
if (selected.length == 0)
return
if (lastAttachmentsTableSortEvent != null) {
for (int i = 0; i < selected.length; i++)
selected[i] = attachmentsTable.rowSorter.convertRowIndexToModel(selected[i])
}
Arrays.sort(selected)
for (int i = selected.length - 1; i >= 0; i--)
model.attachments.remove(selected[i])
attachmentsTable.model.fireTableDataChanged()
}
class AttachmentTransferHandler extends TransferHandler {
@Override