Skip to content

Commit a52cac2

Browse files
committed
feat: ask for confirmation when clearing the local message history
Closes: #147
1 parent be815dc commit a52cac2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/main/kotlin/com/github/lppedd/cc/vcs/ClearLocalMessageHistoryAction.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.github.lppedd.cc.vcs
22

33
import com.github.lppedd.cc.CC
4+
import com.github.lppedd.cc.CCBundle
45
import com.intellij.openapi.actionSystem.ActionUpdateThread
56
import com.intellij.openapi.actionSystem.AnActionEvent
7+
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
68
import com.intellij.openapi.project.DumbAwareAction
9+
import com.intellij.openapi.ui.popup.JBPopupFactory
710
import com.intellij.openapi.vcs.CommitMessageI
811
import com.intellij.openapi.vcs.VcsDataKeys
12+
import java.awt.Component
913

1014
/**
1115
* @author Edoardo Luppi
@@ -32,10 +36,21 @@ internal class ClearLocalMessageHistoryAction : DumbAwareAction() {
3236

3337
override fun actionPerformed(event: AnActionEvent) {
3438
val project = event.project ?: return
35-
val recentCommitsService = RecentCommitsService.getInstance(project)
36-
recentCommitsService.clearLocalMessageHistory()
39+
val component = getActionComponent(event) ?: return
40+
val popup = JBPopupFactory.getInstance().createConfirmation(
41+
/* title = */ CCBundle["action.cc.vcs.clearLocalMessageHistory.text"],
42+
/* onYes = */ { RecentCommitsService.getInstance(project).clearLocalMessageHistory() },
43+
/* defaultOptionIndex = */ 1,
44+
)
45+
46+
if (popup.canShow()) {
47+
popup.showUnderneathOf(component)
48+
}
3749
}
3850

3951
private fun getCommitMessagePanel(event: AnActionEvent): CommitMessageI? =
4052
event.getData(VcsDataKeys.COMMIT_MESSAGE_CONTROL)
53+
54+
private fun getActionComponent(event: AnActionEvent): Component? =
55+
event.inputEvent?.component ?: event.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT)
4156
}

0 commit comments

Comments
 (0)