diff --git a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy index 1e6ca88e..6c70edbf 100644 --- a/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy +++ b/gui/griffon-app/controllers/com/muwire/gui/SearchTabController.groovy @@ -8,73 +8,81 @@ import javax.annotation.Nonnull import com.muwire.core.Core import com.muwire.core.download.UIDownloadEvent +import com.muwire.core.search.UIResultEvent import com.muwire.core.trust.TrustEvent import com.muwire.core.trust.TrustLevel @ArtifactProviderFor(GriffonController) class SearchTabController { - + @MVCMember @Nonnull SearchTabModel model @MVCMember @Nonnull SearchTabView view - + Core core - - private def selectedResult() { - int row = view.resultsTable.getSelectedRow() - if (row == -1) + + private def selectedResults() { + int[] rows = view.resultsTable.getSelectedRows() + if (rows.length == 0) return null def sortEvt = view.lastSortEvent if (sortEvt != null) { - row = view.resultsTable.rowSorter.convertRowIndexToModel(row) + for (int i = 0; i < rows.length; i++) { + rows[i] = view.resultsTable.rowSorter.convertRowIndexToModel(rows[i]) + } + } + List results = new ArrayList<>() + rows.each { results.add(model.results[it]) } + results } - model.results[row] - } - - @ControllerAction - void download() { - def result = selectedResult() - if (result == null) - return - if (!mvcGroup.parentGroup.model.canDownload(result.infohash)) - return + @ControllerAction + void download() { + def results = selectedResults() + if (results == null) + return - def file = new File(application.context.get("muwire-settings").downloadLocation, result.name) + results.removeAll { + !mvcGroup.parentGroup.model.canDownload(it.infohash) + } - def resultsBucket = model.hashBucket[result.infohash] - def sources = model.sourcesBucket[result.infohash] + results.each { result -> + def file = new File(application.context.get("muwire-settings").downloadLocation, result.name) - core.eventBus.publish(new UIDownloadEvent(result : resultsBucket, sources: sources, - target : file, sequential : view.sequentialDownloadCheckbox.model.isSelected())) - mvcGroup.parentGroup.view.showDownloadsWindow.call() - } + def resultsBucket = model.hashBucket[result.infohash] + def sources = model.sourcesBucket[result.infohash] - @ControllerAction - void trust() { - int row = view.selectedSenderRow() - if (row < 0) - return - def sender = model.senders[row] - core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.TRUSTED)) - } + core.eventBus.publish(new UIDownloadEvent(result : resultsBucket, sources: sources, + target : file, sequential : view.sequentialDownloadCheckbox.model.isSelected())) + } + mvcGroup.parentGroup.view.showDownloadsWindow.call() + } - @ControllerAction - void distrust() { - int row = view.selectedSenderRow() - if (row < 0) - return - def sender = model.senders[row] - core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.DISTRUSTED)) - } - - @ControllerAction - void neutral() { - int row = view.selectedSenderRow() - if (row < 0) - return - def sender = model.senders[row] - core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.NEUTRAL)) - } -} \ No newline at end of file + @ControllerAction + void trust() { + int row = view.selectedSenderRow() + if (row < 0) + return + def sender = model.senders[row] + core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.TRUSTED)) + } + + @ControllerAction + void distrust() { + int row = view.selectedSenderRow() + if (row < 0) + return + def sender = model.senders[row] + core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.DISTRUSTED)) + } + + @ControllerAction + void neutral() { + int row = view.selectedSenderRow() + if (row < 0) + return + def sender = model.senders[row] + core.eventBus.publish( new TrustEvent(persona : sender, level : TrustLevel.NEUTRAL)) + } + } \ No newline at end of file diff --git a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy index 631d00f1..91bd26c3 100644 --- a/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy +++ b/gui/griffon-app/views/com/muwire/gui/SearchTabView.groovy @@ -112,16 +112,23 @@ class SearchTabView { this.sequentialDownloadCheckbox = sequentialDownloadCheckbox def selectionModel = resultsTable.getSelectionModel() - selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) + selectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) selectionModel.addListSelectionListener( { - int row = resultsTable.getSelectedRow() - if (row < 0) { + int[] rows = resultsTable.getSelectedRows() + if (rows.length == 0) { model.downloadActionEnabled = false return } - if (lastSortEvent != null) - row = resultsTable.rowSorter.convertRowIndexToModel(row) - model.downloadActionEnabled = mvcGroup.parentGroup.model.canDownload(model.results[row].infohash) + if (lastSortEvent != null) { + for (int i = 0; i < rows.length; i ++) { + rows[i] = resultsTable.rowSorter.convertRowIndexToModel(rows[i]) + } + } + boolean downloadActionEnabled = true + rows.each { + downloadActionEnabled &= mvcGroup.parentGroup.model.canDownload(model.results[it].infohash) + } + model.downloadActionEnabled = downloadActionEnabled }) } } @@ -206,21 +213,28 @@ class SearchTabView { def showPopupMenu(MouseEvent e) { JPopupMenu menu = new JPopupMenu() + boolean showMenu = false if (model.downloadActionEnabled) { JMenuItem download = new JMenuItem("Download") download.addActionListener({mvcGroup.controller.download()}) menu.add(download) + showMenu = true } - JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard") - copyHashToClipboard.addActionListener({mvcGroup.view.copyHashToClipboard()}) - menu.add(copyHashToClipboard) - menu.show(e.getComponent(), e.getX(), e.getY()) + if (resultsTable.getSelectedRows().length == 1) { + JMenuItem copyHashToClipboard = new JMenuItem("Copy hash to clipboard") + copyHashToClipboard.addActionListener({mvcGroup.view.copyHashToClipboard()}) + menu.add(copyHashToClipboard) + showMenu = true + } + if (showMenu) + menu.show(e.getComponent(), e.getX(), e.getY()) } def copyHashToClipboard() { - int selected = resultsTable.getSelectedRow() - if (selected < 0) + int[] selectedRows = resultsTable.getSelectedRows() + if (selectedRows.length != 1) return + int selected = selectedRows[0] if (lastSortEvent != null) selected = resultsTable.rowSorter.convertRowIndexToModel(selected) String hash = Base64.encode(model.results[selected].infohash.getRoot())