mirror of https://github.com/zlatinb/muwire
ability to remove attachments from message
parent
1110f5eb7d
commit
040203cd58
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue