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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Memo(
val selectionEnd: Int? = null,

val visibleStart: Int? = null,
val visibleEnd: Int? = null
val visibleEnd: Int? = null,

val fullCodeSnapshot: String? = null
) {
init {
validate()
Expand All @@ -33,7 +35,8 @@ class Memo(
selectionStart: Int?,
selectionEnd: Int?,
visibleStart: Int?,
visibleEnd: Int?
visibleEnd: Int?,
fullCodeSnapshot: String?
) : this(
id = System.currentTimeMillis(),
createdAt = LocalDateTime.now(),
Expand All @@ -45,7 +48,8 @@ class Memo(
selectionStart = selectionStart,
selectionEnd = selectionEnd,
visibleStart = visibleStart,
visibleEnd = visibleEnd
visibleEnd = visibleEnd,
fullCodeSnapshot = fullCodeSnapshot
)

private fun validate() {
Expand All @@ -71,6 +75,7 @@ class Memo(
commitHash = this.commitHash,
filePath = this.filePath,
selectedCodeSnippet = this.selectedCodeSnippet,
fullCodeSnapshot = this.fullCodeSnapshot,
selectionStart = this.selectionStart,
selectionEnd = this.selectionEnd,
visibleStart = this.visibleStart,
Expand All @@ -88,6 +93,7 @@ class Memo(
commitHash = this.commitHash,
filePath = this.filePath,
selectedCodeSnippet = this.selectedCodeSnippet,
fullCodeSnapshot = this.fullCodeSnapshot,
selectionStart = this.selectionStart,
selectionEnd = this.selectionEnd,
visibleStart = this.visibleStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import java.time.LocalDateTime

data class MemoState(
var id: Long = 0L,
var createdAt: String,
var updatedAt: String,
var createdAt: String = LocalDateTime.now().toString(),
var updatedAt: String = LocalDateTime.now().toString(),
var content: String = "",
var commitHash: String? = null,
var filePath: String? = null,
var selectedCodeSnippet: String? = null,
var fullCodeSnapshot: String? = null,
var selectionStart: Int? = null,
var selectionEnd: Int? = null,
var visibleStart: Int? = null,
Expand All @@ -25,6 +26,7 @@ data class MemoState(
commitHash = commitHash,
filePath = filePath,
selectedCodeSnippet = selectedCodeSnippet,
fullCodeSnapshot = fullCodeSnapshot,
selectionStart = selectionStart,
selectionEnd = selectionEnd,
visibleStart = visibleStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class MemoService(private val project: Project) {
val document = editor.document

val selectedCodeSnippet = selectionModel.selectedText
val hasSelection = selectionModel.hasSelection()
val fullCodeSnapshot = if (hasSelection) document.text else null

val selectionStart = selectionModel.selectionStart
val selectionEnd = selectionModel.selectionEnd
Expand Down Expand Up @@ -61,6 +63,7 @@ class MemoService(private val project: Project) {
commitHash = commitHash,
filePath = filePath,
selectedCodeSnippet = selectedCodeSnippet,
fullCodeSnapshot = fullCodeSnapshot,
selectionStart = selectionStart,
selectionEnd = selectionEnd,
visibleStart = visibleStartLine,
Expand Down Expand Up @@ -167,4 +170,8 @@ class MemoService(private val project: Project) {

return file
}
}

fun findMemoById(memoId: Long): Memo? {
return memoRepository.findMemoById(memoId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,27 @@
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import java.time.LocalDateTime

@State(
name = "DevLogNoteStorage",
storages = [Storage("devlog-note.xml")]
)
@Service(Service.Level.PROJECT)
class NoteRepository : PersistentStateComponent<NoteState> {
class NoteRepository : PersistentStateComponent<NoteStorageState> {

private var state: NoteState? = NoteState(
content = "",
updatedAt = LocalDateTime.now().toString()
)
private var state: NoteStorageState = NoteStorageState()

override fun getState(): NoteState? = state
override fun getState(): NoteStorageState? = state

Check warning on line 18 in src/main/kotlin/com/github/yeoli/devlog/domain/note/repository/NoteRepository.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant nullable return type

'getState' always returns non-null type

override fun loadState(state: NoteState) {
override fun loadState(state: NoteStorageState) {
this.state = state
}

fun getNote(): Note {
if (state == null) {
state = Note(
content = ""
).toState()
}
return state!!.toDomain()
return state.noteState.toDomain()
}

fun updateNote(updatedNote: Note) {
this.state = updatedNote.toState()
this.state.noteState = updatedNote.toState()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.github.yeoli.devlog.domain.note.domain.Note
import java.time.LocalDateTime

data class NoteState(
val content: String,
val updatedAt: String
var content: String = "",
var updatedAt: String = LocalDateTime.now().toString()
) {

fun toDomain(): Note {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.yeoli.devlog.domain.note.repository

class NoteStorageState(
var noteState: NoteState = NoteState()
) {

Check notice on line 5 in src/main/kotlin/com/github/yeoli/devlog/domain/note/repository/NoteStorageState.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Replace empty class body

Redundant empty class body
}
12 changes: 12 additions & 0 deletions src/main/kotlin/com/github/yeoli/devlog/event/MemoChangedEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.yeoli.devlog.event

import com.intellij.util.messages.Topic

fun interface MemoListener {
fun onChanged()
}

object MemoChangedEvent {
val TOPIC: Topic<MemoListener> =
Topic.create("MemoChanged", MemoListener::class.java)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,45 +1,96 @@
package com.github.yeoli.devlog.toolWindow

import com.intellij.openapi.components.service

import com.github.yeoli.devlog.ui.DevLogPanel
import com.intellij.icons.AllIcons
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBPanel
import com.intellij.openapi.wm.*
import com.intellij.openapi.wm.ex.ToolWindowManagerListener
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi
import com.intellij.ui.JBColor
import com.intellij.ui.content.ContentFactory
import com.github.yeoli.devlog.MyBundle
import com.github.yeoli.devlog.services.MyProjectService
import javax.swing.JButton

import com.intellij.util.ui.JBUI
import java.awt.Color

/**
* RetrospectPanel을 IntelliJ ToolWindow 영역에 붙여주는 팩토리.
* ToolWindow 생성 시 UI와 경계선 스타일을 세팅한다.
*/
class MyToolWindowFactory : ToolWindowFactory {

init {
thisLogger().warn("Don't forget to remove all non-needed sample code files with their corresponding registration entries in `plugin.xml`.")
thisLogger().info("Yeoli Retrospect ToolWindow ready.")
}

/**
* ToolWindow가 초기화될 때 호출되어 컨텐츠와 테두리 스타일을 구성한다.
*/
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val myToolWindow = MyToolWindow(toolWindow)
val content = ContentFactory.getInstance().createContent(myToolWindow.getContent(), null, false)

toolWindow.setIcon(AllIcons.Actions.Annotate)
val panel = DevLogPanel(project, toolWindow.disposable)
val content = ContentFactory.getInstance().createContent(panel.component, null, false);

Check warning on line 33 in src/main/kotlin/com/github/yeoli/devlog/toolWindow/MyToolWindowFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Redundant semicolon

Redundant semicolon

toolWindow.contentManager.addContent(content)
toolWindow.component.putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "false")
applyDockBorder(toolWindow)
project.messageBus.connect(toolWindow.disposable).subscribe(
ToolWindowManagerListener.TOPIC,
object : ToolWindowManagerListener {
override fun stateChanged(toolWindowManager: ToolWindowManager) {
val updated = toolWindowManager.getToolWindow(toolWindow.id) ?: return
applyDockBorder(updated)
}
}
)
}

override fun shouldBeAvailable(project: Project) = true

class MyToolWindow(toolWindow: ToolWindow) {

private val service = toolWindow.project.service<MyProjectService>()
/**
* 도킹 상태/위치에 맞춰 ToolWindow 테두리를 설정한다.
*/
private fun applyDockBorder(toolWindow: ToolWindow) {
if (toolWindow.type == ToolWindowType.FLOATING ||
toolWindow.type == ToolWindowType.WINDOWED ||
toolWindow.type == ToolWindowType.SLIDING
) {
toolWindow.component.border = JBUI.Borders.empty()
toolWindow.component.repaint()
return
}

fun getContent() = JBPanel<JBPanel<*>>().apply {
val label = JBLabel(MyBundle.message("randomLabel", "?"))
val sides = when (toolWindow.anchor) {
ToolWindowAnchor.LEFT -> BorderSides(0, 0, 0, BORDER_WIDTH)
ToolWindowAnchor.RIGHT -> BorderSides(0, BORDER_WIDTH, 0, 0)
ToolWindowAnchor.TOP -> BorderSides(0, 0, BORDER_WIDTH, 0)
ToolWindowAnchor.BOTTOM -> BorderSides(BORDER_WIDTH, 0, 0, 0)
else -> BorderSides(0, 0, 0, 0)
}

add(label)
add(JButton(MyBundle.message("shuffle")).apply {
addActionListener {
label.text = MyBundle.message("randomLabel", service.getRandomNumber())
}
})
val border = if (sides.isEmpty()) {
JBUI.Borders.empty()
} else {
JBUI.Borders.customLine(
DOCK_BORDER_COLOR,
sides.top,
sides.left,
sides.bottom,
sides.right
)
}
toolWindow.component.border = border
toolWindow.component.revalidate()
toolWindow.component.repaint()
}

companion object {
private val DOCK_BORDER_COLOR = JBColor(Color(0x2b, 0x2d, 0x30), Color(0x2b, 0x2d, 0x30))
private const val BORDER_WIDTH = 1
}

private data class BorderSides(val top: Int, val left: Int, val bottom: Int, val right: Int) {
fun isEmpty() = top + left + bottom + right == 0
}
}
Loading
Loading