add a view comment button

pull/24/head
Zlatin Balevsky 2019-10-19 05:35:04 +01:00
parent 47d406d93b
commit dbcb8508b8
3 changed files with 35 additions and 23 deletions

View File

@ -4,6 +4,8 @@ import griffon.core.artifact.GriffonController
import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import net.i2p.data.Base64
import javax.annotation.Nonnull
import com.muwire.core.Core
@ -101,4 +103,22 @@ class SearchTabController {
mvcGroup.createMVCGroup("browse", groupId, params)
}
@ControllerAction
void showComment() {
int[] selectedRows = view.resultsTable.getSelectedRows()
if (selectedRows.length != 1)
return
if (view.lastSortEvent != null)
selectedRows[0] = view.resultsTable.rowSorter.convertRowIndexToModel(selectedRows[0])
UIResultEvent event = model.results[selectedRows[0]]
if (event.comment == null)
return
String groupId = Base64.encode(event.infohash.getRoot())
Map<String,Object> params = new HashMap<>()
params['result'] = event
mvcGroup.createMVCGroup("show-comment", groupId, params)
}
}

View File

@ -22,6 +22,7 @@ class SearchTabModel {
@Observable boolean downloadActionEnabled
@Observable boolean trustButtonsEnabled
@Observable boolean browseActionEnabled
@Observable boolean viewCommentActionEnabled
Core core
UISettings uiSettings

View File

@ -100,6 +100,7 @@ class SearchTabView {
panel()
panel {
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
button(text : "View Comment", enabled : bind {model.viewCommentActionEnabled}, showCommentAction)
}
panel {
gridBagLayout()
@ -190,6 +191,16 @@ class SearchTabView {
}
})
resultsTable.getSelectionModel().addListSelectionListener({
def result = getSelectedResult()
if (result == null) {
model.viewCommentActionEnabled = false
return
} else {
model.viewCommentActionEnabled = result.comment != null
}
})
// senders table
sendersTable.setDefaultRenderer(Integer.class, centerRenderer)
sendersTable.rowSorter.addRowSorterListener({evt -> lastSendersSortEvent = evt})
@ -241,12 +252,9 @@ class SearchTabView {
showMenu = true
// show comment if any
int selectedRow = resultsTable.getSelectedRow()
if (lastSortEvent != null)
selectedRow = resultsTable.rowSorter.convertRowIndexToModel(selectedRow)
if (model.results[selectedRow].comment != null) {
JMenuItem showComment = new JMenuItem("Show Comment")
showComment.addActionListener({mvcGroup.view.showComment()})
if (model.viewCommentActionEnabled) {
JMenuItem showComment = new JMenuItem("View Comment")
showComment.addActionListener({mvcGroup.controller.showComment()})
menu.add(showComment)
}
}
@ -283,23 +291,6 @@ class SearchTabView {
clipboard.setContents(selection, null)
}
def showComment() {
int selectedRow = resultsTable.getSelectedRow()
if (selectedRow < 0)
return
if (lastSortEvent != null)
selectedRow = resultsTable.rowSorter.convertRowIndexToModel(selectedRow)
UIResultEvent event = model.results[selectedRow]
if (event.comment == null)
return
String groupId = Base64.encode(event.infohash.getRoot())
Map<String,Object> params = new HashMap<>()
params['result'] = event
mvcGroup.createMVCGroup("show-comment", groupId, params)
}
int selectedSenderRow() {
int row = sendersTable.getSelectedRow()
if (row < 0)