add right-click and show-in-library option for uploads

This commit is contained in:
Zlatin Balevsky
2019-11-07 05:02:53 +00:00
parent 5802ba7734
commit c998011873
3 changed files with 84 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import javax.swing.JOptionPane
import javax.swing.JTable
import com.muwire.core.Core
import com.muwire.core.InfoHash
import com.muwire.core.Persona
import com.muwire.core.SharedFile
import com.muwire.core.SplitPattern
@@ -39,6 +40,8 @@ import com.muwire.core.trust.RemoteTrustList
import com.muwire.core.trust.TrustEvent
import com.muwire.core.trust.TrustLevel
import com.muwire.core.trust.TrustSubscriptionEvent
import com.muwire.core.upload.HashListUploader
import com.muwire.core.upload.Uploader
@ArtifactProviderFor(GriffonController)
class MainFrameController {
@@ -329,6 +332,28 @@ class MainFrameController {
model.uploads.removeAll { it.finished }
}
@ControllerAction
void showInLibrary() {
Uploader uploader = view.selectedUploader()
if (uploader == null)
return
SharedFile sf = null
if (uploader instanceof HashListUploader) {
InfoHash infoHash = uploader.infoHash
Set<SharedFile> sfs = core.fileManager.rootToFiles.get(infoHash)
if (sfs != null && !sfs.isEmpty())
sf = sfs.first()
} else {
File f = uploader.file
sf = core.fileManager.fileToSharedFile.get(f)
}
if (sf == null)
return // can happen if user un-shared
view.focusOnSharedFile(sf)
}
@ControllerAction
void restoreSession() {
model.sessionRestored = true

View File

@@ -176,8 +176,7 @@ class MainFrameModel {
}
}
builder.getVariable("uploads-table")?.model.fireTableDataChanged()
updateTablePreservingSelection("uploads-table")
updateTablePreservingSelection("downloads-table")
updateTablePreservingSelection("trusted-table")
updateTablePreservingSelection("distrusted-table")
@@ -409,8 +408,7 @@ class MainFrameModel {
wrapper.finished = false
} else
uploads << new UploaderWrapper(uploader : e.uploader)
JTable table = builder.getVariable("uploads-table")
table.model.fireTableDataChanged()
updateTablePreservingSelection("uploads-table")
view.refreshSharedFiles()
}
}
@@ -429,8 +427,7 @@ class MainFrameModel {
} else {
wrapper.finished = true
}
JTable table = builder.getVariable("uploads-table")
table.model.fireTableDataChanged()
updateTablePreservingSelection("uploads-table")
}
}

View File

@@ -46,6 +46,7 @@ import java.awt.FlowLayout
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import java.awt.Insets
import java.awt.Rectangle
import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
import java.awt.datatransfer.StringSelection
@@ -70,6 +71,7 @@ class MainFrameView {
def downloadsTable
def lastDownloadSortEvent
def lastUploadsSortEvent
def lastSharedSortEvent
def trustTablesSortEvents = [:]
def expansionListener = new TreeExpansions()
@@ -320,7 +322,7 @@ class MainFrameView {
label("Uploads")
}
scrollPane (constraints : BorderLayout.CENTER) {
table(id : "uploads-table", rowHeight : rowHeight) {
table(id : "uploads-table", autoCreateRowSorter: true, rowHeight : rowHeight) {
tableModel(list : model.uploads) {
closureColumn(header : "Name", type : String, read : {row -> row.uploader.getName() })
closureColumn(header : "Progress", type : String, read : { row ->
@@ -650,6 +652,29 @@ class MainFrameView {
sharedFilesTree.addTreeExpansionListener(expansionListener)
// uploadsTable
def uploadsTable = builder.getVariable("uploads-table")
uploadsTable.rowSorter.addRowSorterListener({evt -> lastUploadsSortEvent = evt})
uploadsTable.rowSorter.setSortsOnUpdates(true)
selectionModel = uploadsTable.getSelectionModel()
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
JPopupMenu uploadsTableMenu = new JPopupMenu()
JMenuItem showInLibrary = new JMenuItem("Show in library")
showInLibrary.addActionListener({mvcGroup.controller.showInLibrary()})
uploadsTableMenu.add(showInLibrary)
uploadsTable.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger())
showPopupMenu(uploadsTableMenu, e)
}
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger())
showPopupMenu(uploadsTableMenu, e)
}
})
// searches table
def searchesTable = builder.getVariable("searches-table")
JPopupMenu searchTableMenu = new JPopupMenu()
@@ -902,6 +927,36 @@ class MainFrameView {
showPopupMenu(menu, e)
}
def selectedUploader() {
def uploadsTable = builder.getVariable("uploads-table")
int selectedRow = uploadsTable.getSelectedRow()
if (selectedRow < 0)
return null
if (lastUploadsSortEvent != null)
selectedRow = uploadsTable.rowSorter.convertRowIndexToModel(selectedRow)
model.uploads[selectedRow].uploader
}
void focusOnSharedFile(SharedFile sf) {
if(model.treeVisible) {
def tree = builder.getVariable("shared-files-tree")
def node = model.fileToNode.get(sf)
if (node == null)
return
def path = new TreePath(node.getPath())
tree.setSelectionPath(path)
tree.scrollPathToVisible(path)
} else {
def table = builder.getVariable("shared-files-table")
int row = model.shared.indexOf(sf)
if (row < 0)
return
table.setRowSelectionInterval(row, row)
table.scrollRectToVisible(new Rectangle(table.getCellRect(row, 0, true)))
}
}
void showRestoreOrEmpty() {
def searchWindow = builder.getVariable("search window")
String id