Skip to content

Commit f4afc6c

Browse files
authored
Merge pull request #96 from mallowigi/counter
counter
2 parents 173d888 + 395a109 commit f4afc6c

5 files changed

Lines changed: 70 additions & 96 deletions

File tree

src/main/java/krasa/editorGroups/EditorGroupPanel.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ import com.intellij.util.BitUtil
3737
import com.intellij.util.concurrency.AppExecutorUtil
3838
import com.intellij.util.ui.JBUI
3939
import com.intellij.util.ui.UIUtil
40-
import krasa.editorGroups.actions.PopupMenu
41-
import krasa.editorGroups.actions.RefreshAction
42-
import krasa.editorGroups.actions.RemoveFromCurrentBookmarksAction
43-
import krasa.editorGroups.actions.SwitchGroupAction
40+
import krasa.editorGroups.actions.*
4441
import krasa.editorGroups.events.EditorGroupChangeListener
4542
import krasa.editorGroups.index.IndexNotReady
4643
import krasa.editorGroups.language.EditorGroupsLanguage.isEditorGroupsLanguage
@@ -330,12 +327,14 @@ class EditorGroupPanel(
330327

331328
/** Add the action buttons at the left of the panel. */
332329
private fun createToolbar() {
330+
val actionManager = ActionManager.getInstance()
333331
val actionGroup = DefaultActionGroup().apply {
334-
add(ActionManager.getInstance().getAction(RefreshAction.ID))
335-
add(ActionManager.getInstance().getAction(SwitchGroupAction.ID))
332+
add(actionManager.getAction(RefreshAction.ID))
333+
add(actionManager.getAction(SwitchGroupAction.ID))
334+
add(GroupLinksCountAction())
336335
}
337336

338-
toolbar = ActionManager.getInstance().createActionToolbar(
337+
toolbar = actionManager.createActionToolbar(
339338
TOOLBAR_PLACE,
340339
actionGroup,
341340
true
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package krasa.editorGroups.actions
2+
3+
import com.intellij.openapi.actionSystem.ActionUpdateThread
4+
import com.intellij.openapi.actionSystem.AnActionEvent
5+
import com.intellij.openapi.project.DumbAwareAction
6+
import com.intellij.ui.JBColor
7+
import com.intellij.util.ui.UIUtil
8+
import com.intellij.util.ui.UIUtil.drawCenteredString
9+
import krasa.editorGroups.EditorGroupManager
10+
import java.awt.*
11+
import javax.swing.Icon
12+
13+
class GroupLinksCountAction : DumbAwareAction() {
14+
override fun isDumbAware(): Boolean = false
15+
16+
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
17+
18+
override fun actionPerformed(e: AnActionEvent): Unit = Unit
19+
20+
override fun update(e: AnActionEvent) {
21+
val project = e.project ?: return
22+
val currentGroup = EditorGroupManager.getInstance(project).lastGroup
23+
val count = currentGroup.size(project)
24+
25+
e.presentation.text = count.toString()
26+
e.presentation.icon = CompositeIcon(count)
27+
}
28+
29+
internal class CompositeIcon(private val counter: Int) : Icon {
30+
val backgroundColor: Color
31+
get() = JBColor.namedColor("Counter.background", Color(-0x33655850, true))
32+
33+
override fun paintIcon(c: Component?, g: Graphics, x: Int, y: Int) {
34+
val counterText = counter.toString()
35+
val g2d = g as Graphics2D
36+
val fontSize = if (counter < 100) FONT_SIZE else SMALL_FONT_SIZE
37+
38+
g2d.color = backgroundColor
39+
g2d.fillOval(x, y, ICON_SIZE, ICON_SIZE)
40+
41+
g2d.color = UIUtil.getPanelBackground()
42+
g2d.font = g2d.font.deriveFont(fontSize)
43+
drawCenteredString(
44+
g2d,
45+
Rectangle(x, y, ICON_SIZE, ICON_SIZE),
46+
counterText,
47+
)
48+
}
49+
50+
override fun getIconWidth(): Int = ICON_SIZE
51+
52+
override fun getIconHeight(): Int = ICON_SIZE
53+
}
54+
55+
companion object {
56+
private const val FONT_SIZE = 10.0f
57+
private const val SMALL_FONT_SIZE = 8.0f
58+
private const val ICON_SIZE = 16
59+
}
60+
}

src/main/java/krasa/editorGroups/extensions/CustomFileIconLayerProvider.kt

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/main/java/krasa/editorGroups/toolwindow/EditorGroupsToolWindowFactory.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ internal class EditorGroupsToolWindowFactory : ToolWindowFactory {
4343
panel.add(tabList, BorderLayout.CENTER)
4444

4545
// Add action toolbar with RefreshAction and SwitchGroupAction
46+
val actionManager = ActionManager.getInstance()
4647
val actionGroup = DefaultActionGroup().apply {
47-
add(ActionManager.getInstance().getAction(RefreshAction.ID))
48-
add(ActionManager.getInstance().getAction(SwitchGroupAction.ID))
48+
add(actionManager.getAction(RefreshAction.ID))
49+
add(actionManager.getAction(SwitchGroupAction.ID))
4950
}
50-
val actionToolbar: ActionToolbar = ActionManager.getInstance().createActionToolbar("EditorGroupsToolbar", actionGroup, true)
51+
val actionToolbar: ActionToolbar = actionManager.createActionToolbar("EditorGroupsToolbar", actionGroup, true)
5152
actionToolbar.targetComponent = panel
5253
panel.add(actionToolbar.component, BorderLayout.NORTH)
5354

src/main/resources/META-INF/plugin.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
<editorTabColorProvider implementation="krasa.editorGroups.extensions.CustomEditorGroupsTabColorProvider" order="first"/>
6161
<editorTabColorProvider implementation="krasa.editorGroups.extensions.CurrentEditorGroupColorProvider" order="last"/>
6262

63-
<!-- TODO: Custom size (WIP) -->
64-
<!--<iconLayerProvider implementation="krasa.editorGroups.extensions.CustomFileIconLayerProvider"/>-->
65-
6663
<!-- Indices -->
6764
<fileBasedIndex implementation="krasa.editorGroups.index.EditorGroupIndex"/>
6865
<fileBasedIndex implementation="krasa.editorGroups.index.FilenameWithoutExtensionIndex"/>

0 commit comments

Comments
 (0)