Skip to content

Commit

Permalink
[GP-176] todoList와 doneList가 편집기를 껐다 켜도 유지된다 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gon2gon2 authored Apr 13, 2024
1 parent f1c6ca1 commit 15257f7
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 118 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = com.github.gon2gon2.mdtdd
pluginName = mdtdd
pluginRepositoryUrl = https://github.com/gon2gon2/mdtdd
# SemVer format -> https://semver.org
pluginVersion = 0.0.2
pluginVersion = 0.1.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.gon2gon2.mdtdd

import com.github.gon2gon2.mdtdd.toolwindow.UnifiedToolWindow
import com.github.gon2gon2.mdtdd.view.UnifiedToolWindow
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
package com.github.gon2gon2.mdtdd.infra

import com.github.gon2gon2.mdtdd.services.TodoRepository
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.BaseState
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.SimplePersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil

@Service(Service.Level.PROJECT)
@State(
name = "com.github.gon2gon2.mdtdd.TodoListState",
name = "TodoListState",
storages = [Storage("TodoList.xml")]
)
class TodoStateRepository : PersistentStateComponent<TodoStateRepository>, TodoRepository {
private var todoList: MutableList<String> = mutableListOf()

override fun add(todo: String) {
todoList.add(todo)
}

override fun remove(todo: String) {
todoList.remove(todo)
}

override fun remove(todoIndex: Int) {
todoList.removeAt(todoIndex)
class TodoStateRepository : SimplePersistentStateComponent<TodoStateRepository.State>(State()) {
class State : BaseState() {
var todoList: MutableList<String> by list()
var doneList: MutableList<String> by list()
}
}

override fun getAll(): List<String> {
return todoList
}

override fun getState(): TodoStateRepository = this

override fun loadState(state: TodoStateRepository) {
XmlSerializerUtil.copyBean(state, this)
}
}

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/kotlin/com/github/gon2gon2/mdtdd/services/TodoService.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.gon2gon2.mdtdd.view

import com.github.gon2gon2.mdtdd.infra.TodoStateRepository
import com.github.gon2gon2.mdtdd.view.timer.TimerPanel
import com.github.gon2gon2.mdtdd.view.todo.TodoListPanel
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import javax.swing.BoxLayout
import javax.swing.JPanel

class UnifiedToolWindow(project: Project) {
private val mainPanel = JPanel()
private val timerPanel = TimerPanel().panel

private val todoListPanel = TodoListPanel(
project.service<TodoStateRepository>().state.todoList,
project.service<TodoStateRepository>().state.doneList,
).panel

init {
mainPanel.layout = BoxLayout(mainPanel, BoxLayout.Y_AXIS)
mainPanel.add(timerPanel)
mainPanel.add(todoListPanel)
}

val content: JPanel
get() = mainPanel
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.gon2gon2.mdtdd.toolwindow.panel
package com.github.gon2gon2.mdtdd.view.timer

import com.github.gon2gon2.mdtdd.services.TimerService
import javax.swing.JButton
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.gon2gon2.mdtdd.view.todo

import javax.swing.AbstractListModel

class CustomListModel(private val backingList: MutableList<String>) : AbstractListModel<String>() {
override fun getSize(): Int = backingList.size

override fun getElementAt(index: Int): String = backingList[index]

fun addElement(element: String) {
backingList.add(element)
fireIntervalAdded(this, backingList.size - 1, backingList.size - 1)
}

fun removeElementAt(element: String) {

Check warning on line 15 in src/main/kotlin/com/github/gon2gon2/mdtdd/view/todo/CustomListModel.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused symbol

Function "removeElementAt" is never used
val index = backingList.indexOf(element)
if (index != -1) {
backingList.removeAt(index)
fireIntervalRemoved(this, index, index)
}
}

fun removeElementAt(index: Int) {
if (index != -1) {
backingList.removeAt(index)
fireIntervalRemoved(this, index, index)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.github.gon2gon2.mdtdd.toolwindow.panel
package com.github.gon2gon2.mdtdd.view.todo

import com.github.gon2gon2.mdtdd.services.TodoService
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBList
import java.awt.FlowLayout
import javax.swing.BoxLayout
import javax.swing.DefaultListModel
import javax.swing.JButton
import javax.swing.JPanel
import javax.swing.JScrollPane
import javax.swing.JTextField

class TodoListPanel(project: Project) {

class TodoListPanel(
todoList: MutableList<String>,
doneList: MutableList<String>,
) {
val panel = JPanel()
private val shouldBeDoneListModel = DefaultListModel<String>()
private val shouldBeDoneList = JBList(shouldBeDoneListModel)

private val alreadyDoneListModel = DefaultListModel<String>()
private val alreadyDoneList = JBList(alreadyDoneListModel)
private val todoListModel = CustomListModel(todoList)
private val todoJbList = JBList(todoListModel)

private val doneListModel = CustomListModel(doneList)
private val doneJbList = JBList(doneListModel)

private val taskInput = JTextField()

Expand All @@ -27,8 +28,6 @@ class TodoListPanel(project: Project) {
private val doneButton = JButton("Done")
private val removeButton = JButton("Remove")

private val todoService = project.service<TodoService>()

init {
setupUI()
setupActions()
Expand All @@ -37,8 +36,8 @@ class TodoListPanel(project: Project) {
private fun setupUI() {
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
buttonPanel.layout = FlowLayout(FlowLayout.LEFT)
panel.add(JScrollPane(shouldBeDoneList))
panel.add(JScrollPane(alreadyDoneList))
panel.add(JScrollPane(todoJbList))
panel.add(JScrollPane(doneJbList))
panel.add(taskInput)
panel.add(addButton)
panel.add(doneButton)
Expand All @@ -49,23 +48,23 @@ class TodoListPanel(project: Project) {
addButton.addActionListener {
val task = taskInput.text
if (task.isNotBlank()) {
shouldBeDoneListModel.addElement(task)
todoListModel.addElement(task)
taskInput.text = ""
}
}

removeButton.addActionListener {
val selectedIndex = shouldBeDoneList.selectedIndex
val selectedIndex = todoJbList.selectedIndex
if (selectedIndex != -1) {
shouldBeDoneListModel.removeElementAt(selectedIndex)
todoListModel.removeElementAt(selectedIndex)
}
}

doneButton.addActionListener {
val selectedIndex = shouldBeDoneList.selectedIndex
val selectedIndex = todoJbList.selectedIndex
if (selectedIndex != -1) {
alreadyDoneListModel.addElement(shouldBeDoneList.selectedValue)
shouldBeDoneListModel.removeElementAt(selectedIndex)
doneListModel.addElement(todoJbList.selectedValue)
todoListModel.removeElementAt(selectedIndex)
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/test/kotlin/com/github/gon2gon2/mdtdd/MyPluginTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.github.gon2gon2.mdtdd

import com.github.gon2gon2.mdtdd.infra.TodoStateRepository
import com.github.gon2gon2.mdtdd.services.TodoRepository
import com.github.gon2gon2.mdtdd.services.TodoService
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.openapi.components.service
import com.intellij.psi.xml.XmlFile
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.fixtures.BasePlatformTestCase
Expand All @@ -31,15 +27,5 @@ class MyPluginTest : BasePlatformTestCase() {
myFixture.testRename("foo.xml", "foo_after.xml", "a2")
}

fun testProjectService() {
val projectService = project.service<TodoService>()
assertNotNull(projectService)
}

fun testGetRepository() {
val projectService: TodoRepository = project.service<TodoStateRepository>()
assertNotNull(projectService)
}

override fun getTestDataPath() = "src/test/testData/rename"
}

0 comments on commit 15257f7

Please sign in to comment.