Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.io.ByteArrayOutputStream
plugins {
id("java")
alias(libs.plugins.kotlinJvm)
id("org.jetbrains.intellij.platform") version "2.0.0-beta5" // See https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
id("org.jetbrains.intellij.platform") version "2.2.0" // See https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
id("me.filippov.gradle.jvm.wrapper") version "0.14.0"
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PublishToken="_PLACEHOLDER_"
# Release: 2020.2
# Nightly: 2020.3-SNAPSHOT
# EAP: 2020.3-EAP2-SNAPSHOT
ProductVersion=2024.3-EAP2-SNAPSHOT
ProductVersion=2024.3
# 2021.3.3

# Kotlin 1.4 will bundle the stdlib dependency by default, causing problems with the version bundled with the IDE
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.9.24" # https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
rdGen = "2024.3.0" # https://github.com/JetBrains/rd/releases
rdGen = "2024.3.1" # https://github.com/JetBrains/rd/releases

[libraries]
kotlinStdLib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion protocol/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ val RiderPluginId: String by rootProject

rdgen {
val csOutput = File(rootDir, "src/dotnet/${DotnetPluginId}")
val ktOutput = File(rootDir, "src/rider/main/kotlin/com/jetbrains/rider/plugins/${RiderPluginId.replace('.','/').toLowerCase()}")
val ktOutput = File(rootDir, "src/rider/main/kotlin/com/jetbrains/rider/plugins/${RiderPluginId.replace('.','/').lowercase()}")

verbose = true
packages = "model.rider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

<ItemGroup>
<PackageReference Include="JetBrains.Rider.SDK" Version="$(SdkVersion)" />
<!-- https://www.nuget.org/packages/JetBrains.Rider.Rider.Backend -->
<PackageReference Include="JetBrains.Rider.Rider.Backend" Version="243.0.20241010.72915-eap04" />
</ItemGroup>

<!-- TODO: uncomment for xaml icons -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.components.service
import com.intellij.platform.backend.workspace.WorkspaceModel
import com.jetbrains.rider.projectView.hasSolution
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
import com.jetbrains.rider.projectView.workspace.findProjects
import kotlinx.coroutines.launch
Expand All @@ -27,7 +28,8 @@ abstract class BeatSaberProjectAction : AnAction() {
return
}

e.presentation.isEnabledAndVisible = project.hasSolution == true
e.presentation.isVisible = project.hasSolution == true
e.presentation.isEnabled = project.solution.solutionLifecycle.fullStartupFinished.valueOrNull?.fullStartupTime != null

findProjects = WorkspaceModel.getInstance(project).findProjects()
val beatSaberProjectManager = project.service<BeatSaberProjectManager>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.fernthedev.bsmt_rider.actions

import com.github.fernthedev.bsmt_rider.helpers.BeatSaberReferenceManager
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.components.service
import com.intellij.platform.ide.progress.withBackgroundProgress
import kotlinx.coroutines.launch
Expand All @@ -14,14 +16,15 @@ class BeatSaberReferenceGeneratorAction : BeatSaberProjectAction() {

override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT)
val selectedItem = e.getData(PlatformCoreDataKeys.SELECTED_ITEM) as? AbstractTreeNode<*>

if (project == null || !e.presentation.isEnabledAndVisible || findProjects == null) return
if (project == null || selectedItem == null || !e.presentation.isEnabledAndVisible || findProjects == null) return

val referenceManager = project.service<BeatSaberReferenceManager>()

referenceManager.scope.launch {
withBackgroundProgress(project, "Adding to Beat Saber References", cancellable = true) {
referenceManager.askToAddReferences()
referenceManager.askToAddReferences(selectedItem.parent.name!!)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class BeatSaberChooseDialogue(val project: Project?) : DialogWrapper(project) {
beatSaberInput.componentPopupMenu?.isVisible = AppSettingsState.instance.beatSaberFolders.isNotEmpty()
beatSaberInput.isEditable = true

setAsDefault = CheckBox("Set this beat saber folder as default")
addToConfigCheckbox = CheckBox("Store this beat saber folder in config")
setAsDefault = CheckBox("Set as default")
addToConfigCheckbox = CheckBox("Store in config")

// logic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package com.github.fernthedev.bsmt_rider.dialogue
import com.github.fernthedev.bsmt_rider.xml.ReferenceXML
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.CheckBoxList
import com.intellij.ui.SearchTextField
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.table.JBTable
import com.intellij.util.PathUtil
import com.intellij.util.ui.FormBuilder
import com.intellij.util.ui.UI
import com.intellij.util.ui.JBUI
import java.awt.Dimension
import java.io.File
import java.util.*
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.table.AbstractTableModel


/// $(Beat_Saber_Path)\Beat Saber_Data\Managed
Expand All @@ -29,8 +28,7 @@ class BeatSaberReferencesDialogue(
val references = ArrayList<File>()

private val _searchBox = SearchTextField(false)
private val _parentDirectoryCheckbox = JBCheckBox("Show parent directory", true)
private val _beatSaberReferences: JBTable
private val _beatSaberReferences: CheckBoxList<BeatSaberReferencePair>
private val _beatSaberReferencesScrollPane: JBScrollPane

init {
Expand All @@ -40,7 +38,7 @@ class BeatSaberReferencesDialogue(
throw IllegalArgumentException("Beat saber folders are empty or not found!")

val existingReferencesMatch = existingReferences.map { ref ->
PathUtil.getFileName(ref.stringHintPath)
ref.stringHintPath?.let { PathUtil.getFileName(it) }
}


Expand All @@ -55,72 +53,77 @@ class BeatSaberReferencesDialogue(
// Merge list
}.reduce { acc, arrayOfFiles ->
acc + arrayOfFiles
// Remove duplicates
}.distinct().map {
}.map {
BeatSaberReferencePair(false, it)
}


title = "Beat Saber Reference Manager"
title = "Add Beat Saber Reference"

_beatSaberReferences =
JBTable(BeatSaberReferenceTable(_foundBeatSaberReferences, _parentDirectoryCheckbox.isSelected))
_beatSaberReferences.setShowColumns(true)
_beatSaberReferences = CheckBoxList<BeatSaberReferencePair>()
_beatSaberReferences.setItems(_foundBeatSaberReferences) { pair ->
pair.file.nameWithoutExtension
}
_beatSaberReferences.setCheckBoxListListener { index, value ->
_beatSaberReferences.getItemAt(index)!!.included = value
}

_beatSaberReferencesScrollPane = JBScrollPane(_beatSaberReferences)

_searchBox.textEditor.addCaretListener {
val beatSaberReferenceTable = _beatSaberReferences.model as BeatSaberReferenceTable
beatSaberReferenceTable.rows =
_foundBeatSaberReferences.filter { it.file.path.lowercase().contains(_searchBox.text.lowercase()) }
beatSaberReferenceTable.fireTableDataChanged()
}
val searchText = _searchBox.text.lowercase()
val filteredReferences = _foundBeatSaberReferences.filter { pair ->
pair.file.nameWithoutExtension.lowercase().contains(searchText)
}

_beatSaberReferences.setItems(filteredReferences) { pair ->
pair.file.nameWithoutExtension
}

_parentDirectoryCheckbox.addChangeListener {
val beatSaberReferenceTable = _beatSaberReferences.model as BeatSaberReferenceTable
beatSaberReferenceTable.showParentFolder = _parentDirectoryCheckbox.isSelected
beatSaberReferenceTable.fireTableDataChanged()
refreshCheckboxes()
}

setOKButtonText("Add")
refreshCheckboxes()
init()
}

private fun refreshCheckboxes() {
val model = _beatSaberReferences.model
for (i in 0 until model.size) {
val checkbox = model.getElementAt(i) as JCheckBox
val pair = _beatSaberReferences.getItemAt(i)!!
checkbox.isSelected = pair.included
checkbox.toolTipText = pair.file.absolutePath
}
}

override fun createCenterPanel(): JComponent {
// This is not a self assignment, they are different methods!
// _beatSaberReferencesScrollPane.preferredSize = _beatSaberReferences.preferredSize
_beatSaberReferences.autoResizeMode = JBTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS

_beatSaberReferences.columnModel.getColumn(0).maxWidth = UI.scale(100)
_beatSaberReferences.fillsViewportHeight = true


// _beatSaberReferences.preferredScrollableViewportSize = _beatSaberReferences.preferredScrollableViewportSize

val panel = FormBuilder.createFormBuilder()
.addComponent(_searchBox)
.addComponent(_parentDirectoryCheckbox)
.addLabeledComponentFillVertically("BeatSaber references", _beatSaberReferencesScrollPane)
.addComponentFillVertically(_beatSaberReferencesScrollPane, 8)
// .addComponentFillVertically(JPanel(GridLayout()), 0)
.panel


panel.preferredSize = Dimension(UI.scale(340), UI.scale(350))
panel.minimumSize = Dimension(JBUI.scale(400), JBUI.scale(400))
panel.preferredSize = Dimension(JBUI.scale(400), JBUI.scale(400))

return panel
}

override fun getPreferredFocusedComponent(): JComponent? {
override fun getPreferredFocusedComponent(): JComponent {
return _searchBox
}

override fun doOKAction() {
val model = _beatSaberReferences.model

for (i in 0 until model.rowCount) {

val pair = model.getValueAt(i, -1) as BeatSaberReferencePair

_foundBeatSaberReferences.forEach { pair ->
if (pair.included) {
references.add(pair.file)
}
Expand All @@ -130,127 +133,7 @@ class BeatSaberReferencesDialogue(
}
}

private enum class ColumnEnum(
val strName: String,
val clazz: Class<*>,
val editable: Boolean = false,
) {
INCLUDE("Include", Boolean::class.javaObjectType, true),
REFERENCE("Reference", String::class.java)
}

data class BeatSaberReferencePair(
var included: Boolean = false,
var file: File,
)


class BeatSaberReferenceTable(files: List<BeatSaberReferencePair>, var showParentFolder: Boolean) :
AbstractTableModel() {
private val columns: Array<ColumnEnum> = arrayOf(ColumnEnum.INCLUDE, ColumnEnum.REFERENCE)

var rows: List<BeatSaberReferencePair> = ArrayList(files)
set(value) {
field = ArrayList(value)
}

/**
* Returns a default name for the column using spreadsheet conventions:
* A, B, C, ... Z, AA, AB, etc. If `column` cannot be found,
* returns an empty string.
*
* @param column the column being queried
* @return a string containing the default name of `column`
*/
override fun getColumnName(column: Int): String {
return columns[column].strName
}

/**
* Returns `Object.class` regardless of `columnIndex`.
*
* @param columnIndex the column being queried
* @return the Object.class
*/
override fun getColumnClass(columnIndex: Int): Class<*> {
return columns[columnIndex].clazz
}

/**
* Returns false. This is the default implementation for all cells.
*
* @param rowIndex the row being queried
* @param columnIndex the column being queried
* @return false
*/
override fun isCellEditable(rowIndex: Int, columnIndex: Int): Boolean {
return columns[columnIndex].editable
}

/**
* Returns the number of rows in the model. A
* `JTable` uses this method to determine how many rows it
* should display. This method should be quick, as it
* is called frequently during rendering.
*
* @return the number of rows in the model
* @see .getColumnCount
*/
override fun getRowCount(): Int {
return rows.size
}

/**
* Returns the number of columns in the model. A
* `JTable` uses this method to determine how many columns it
* should create and display by default.
*
* @return the number of columns in the model
* @see .getRowCount
*/
override fun getColumnCount(): Int {
return columns.size
}

/**
* Returns the value for the cell at `columnIndex` and
* `rowIndex`.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
override fun getValueAt(rowIndex: Int, columnIndex: Int): Any? {
val pair = rows[rowIndex]

return when (columnIndex) {
// We use this ourselves
-1 -> pair
0 -> pair.included
1 ->
if (showParentFolder) "${pair.file.parentFile.name}/${pair.file.nameWithoutExtension}"
else pair.file.nameWithoutExtension

else -> null
}
}

/**
* This empty implementation is provided so users don't have to implement
* this method if their data model is not editable.
*
* @param aValue value to assign to cell
* @param rowIndex row of cell
* @param columnIndex column of cell
*/
override fun setValueAt(aValue: Any?, rowIndex: Int, columnIndex: Int) {

val pair = rows[rowIndex]

when (columnIndex) {
0 -> pair.included = aValue as Boolean
}
}


}
Loading
Loading