mirror of https://github.com/zlatinb/muwire
add a view comment button
parent
47d406d93b
commit
dbcb8508b8
|
@ -4,6 +4,8 @@ import griffon.core.artifact.GriffonController
|
||||||
import griffon.core.controller.ControllerAction
|
import griffon.core.controller.ControllerAction
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
import net.i2p.data.Base64
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
|
@ -101,4 +103,22 @@ class SearchTabController {
|
||||||
|
|
||||||
mvcGroup.createMVCGroup("browse", groupId, params)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@ class SearchTabModel {
|
||||||
@Observable boolean downloadActionEnabled
|
@Observable boolean downloadActionEnabled
|
||||||
@Observable boolean trustButtonsEnabled
|
@Observable boolean trustButtonsEnabled
|
||||||
@Observable boolean browseActionEnabled
|
@Observable boolean browseActionEnabled
|
||||||
|
@Observable boolean viewCommentActionEnabled
|
||||||
|
|
||||||
Core core
|
Core core
|
||||||
UISettings uiSettings
|
UISettings uiSettings
|
||||||
|
|
|
@ -100,6 +100,7 @@ class SearchTabView {
|
||||||
panel()
|
panel()
|
||||||
panel {
|
panel {
|
||||||
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
|
button(text : "Download", enabled : bind {model.downloadActionEnabled}, downloadAction)
|
||||||
|
button(text : "View Comment", enabled : bind {model.viewCommentActionEnabled}, showCommentAction)
|
||||||
}
|
}
|
||||||
panel {
|
panel {
|
||||||
gridBagLayout()
|
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
|
// senders table
|
||||||
sendersTable.setDefaultRenderer(Integer.class, centerRenderer)
|
sendersTable.setDefaultRenderer(Integer.class, centerRenderer)
|
||||||
sendersTable.rowSorter.addRowSorterListener({evt -> lastSendersSortEvent = evt})
|
sendersTable.rowSorter.addRowSorterListener({evt -> lastSendersSortEvent = evt})
|
||||||
|
@ -241,12 +252,9 @@ class SearchTabView {
|
||||||
showMenu = true
|
showMenu = true
|
||||||
|
|
||||||
// show comment if any
|
// show comment if any
|
||||||
int selectedRow = resultsTable.getSelectedRow()
|
if (model.viewCommentActionEnabled) {
|
||||||
if (lastSortEvent != null)
|
JMenuItem showComment = new JMenuItem("View Comment")
|
||||||
selectedRow = resultsTable.rowSorter.convertRowIndexToModel(selectedRow)
|
showComment.addActionListener({mvcGroup.controller.showComment()})
|
||||||
if (model.results[selectedRow].comment != null) {
|
|
||||||
JMenuItem showComment = new JMenuItem("Show Comment")
|
|
||||||
showComment.addActionListener({mvcGroup.view.showComment()})
|
|
||||||
menu.add(showComment)
|
menu.add(showComment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,23 +291,6 @@ class SearchTabView {
|
||||||
clipboard.setContents(selection, null)
|
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 selectedSenderRow() {
|
||||||
int row = sendersTable.getSelectedRow()
|
int row = sendersTable.getSelectedRow()
|
||||||
if (row < 0)
|
if (row < 0)
|
||||||
|
|
Loading…
Reference in New Issue