Skip to content

Commit 89ae1f0

Browse files
authored
Match IntelliJ's new UI style (#8)
1 parent 6031116 commit 89ae1f0

File tree

12 files changed

+231
-342
lines changed

12 files changed

+231
-342
lines changed

.editorconfig

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,89 @@ root = true
33
[*]
44
indent_size = 2
55
indent_style = space
6+
insert_final_newline = true
7+
8+
# https://github.com/facebook/ktfmt/blob/main/docs/editorconfig/.editorconfig-google
9+
10+
[{*.kt,*.kts}]
11+
max_line_length = 100
12+
ij_continuation_indent_size = 2
13+
ij_java_names_count_to_use_import_on_demand = 9999
14+
ij_kotlin_align_in_columns_case_branch = false
15+
ij_kotlin_align_multiline_binary_operation = false
16+
ij_kotlin_align_multiline_extends_list = false
17+
ij_kotlin_align_multiline_method_parentheses = false
18+
ij_kotlin_align_multiline_parameters = true
19+
ij_kotlin_align_multiline_parameters_in_calls = false
20+
ij_kotlin_allow_trailing_comma = true
21+
ij_kotlin_allow_trailing_comma_on_call_site = true
22+
ij_kotlin_assignment_wrap = normal
23+
ij_kotlin_blank_lines_after_class_header = 0
24+
ij_kotlin_blank_lines_around_block_when_branches = 0
25+
ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
26+
ij_kotlin_block_comment_at_first_column = true
27+
ij_kotlin_call_parameters_new_line_after_left_paren = true
28+
ij_kotlin_call_parameters_right_paren_on_new_line = false
29+
ij_kotlin_call_parameters_wrap = on_every_item
30+
ij_kotlin_catch_on_new_line = false
31+
ij_kotlin_class_annotation_wrap = split_into_lines
32+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
33+
ij_kotlin_continuation_indent_for_chained_calls = true
34+
ij_kotlin_continuation_indent_for_expression_bodies = true
35+
ij_kotlin_continuation_indent_in_argument_lists = true
36+
ij_kotlin_continuation_indent_in_elvis = false
37+
ij_kotlin_continuation_indent_in_if_conditions = false
38+
ij_kotlin_continuation_indent_in_parameter_lists = false
39+
ij_kotlin_continuation_indent_in_supertype_lists = false
40+
ij_kotlin_else_on_new_line = false
41+
ij_kotlin_enum_constants_wrap = off
42+
ij_kotlin_extends_list_wrap = normal
43+
ij_kotlin_field_annotation_wrap = split_into_lines
44+
ij_kotlin_finally_on_new_line = false
45+
ij_kotlin_if_rparen_on_new_line = false
46+
ij_kotlin_import_nested_classes = false
47+
ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
48+
ij_kotlin_keep_blank_lines_before_right_brace = 2
49+
ij_kotlin_keep_blank_lines_in_code = 2
50+
ij_kotlin_keep_blank_lines_in_declarations = 2
51+
ij_kotlin_keep_first_column_comment = true
52+
ij_kotlin_keep_indents_on_empty_lines = false
53+
ij_kotlin_keep_line_breaks = true
54+
ij_kotlin_lbrace_on_next_line = false
55+
ij_kotlin_line_comment_add_space = false
56+
ij_kotlin_line_comment_at_first_column = true
57+
ij_kotlin_method_annotation_wrap = split_into_lines
58+
ij_kotlin_method_call_chain_wrap = normal
59+
ij_kotlin_method_parameters_new_line_after_left_paren = true
60+
ij_kotlin_method_parameters_right_paren_on_new_line = true
61+
ij_kotlin_method_parameters_wrap = on_every_item
62+
ij_kotlin_name_count_to_use_star_import = 9999
63+
ij_kotlin_name_count_to_use_star_import_for_members = 9999
64+
ij_kotlin_parameter_annotation_wrap = off
65+
ij_kotlin_space_after_comma = true
66+
ij_kotlin_space_after_extend_colon = true
67+
ij_kotlin_space_after_type_colon = true
68+
ij_kotlin_space_before_catch_parentheses = true
69+
ij_kotlin_space_before_comma = false
70+
ij_kotlin_space_before_extend_colon = true
71+
ij_kotlin_space_before_for_parentheses = true
72+
ij_kotlin_space_before_if_parentheses = true
73+
ij_kotlin_space_before_lambda_arrow = true
74+
ij_kotlin_space_before_type_colon = false
75+
ij_kotlin_space_before_when_parentheses = true
76+
ij_kotlin_space_before_while_parentheses = true
77+
ij_kotlin_spaces_around_additive_operators = true
78+
ij_kotlin_spaces_around_assignment_operators = true
79+
ij_kotlin_spaces_around_equality_operators = true
80+
ij_kotlin_spaces_around_function_type_arrow = true
81+
ij_kotlin_spaces_around_logical_operators = true
82+
ij_kotlin_spaces_around_multiplicative_operators = true
83+
ij_kotlin_spaces_around_range = false
84+
ij_kotlin_spaces_around_relational_operators = true
85+
ij_kotlin_spaces_around_unary_operator = false
86+
ij_kotlin_spaces_around_when_arrow = true
87+
ij_kotlin_variable_annotation_wrap = off
88+
ij_kotlin_while_on_new_line = false
89+
ij_kotlin_wrap_elvis_expressions = 1
90+
ij_kotlin_wrap_expression_body_functions = 1
91+
ij_kotlin_wrap_first_method_in_call_chain = false

.idea/ktfmt.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99

1010
group = "com.gitlab.lae.intellij.actions.tree"
1111

12-
version = "0.6.4-SNAPSHOT"
12+
version = "0.7.0-SNAPSHOT"
1313

1414
repositories { mavenCentral() }
1515

src/main/kotlin/com/gitlab/lae/intellij/actions/tree/ActionNode.kt

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.gitlab.lae.intellij.actions.tree
22

33
import com.gitlab.lae.intellij.actions.tree.ui.ActionPresentation
44
import com.intellij.openapi.actionSystem.ActionManager
5-
import com.intellij.openapi.actionSystem.ActionPlaces
65
import com.intellij.openapi.actionSystem.AnAction
76
import com.intellij.openapi.actionSystem.DataContext
87
import javax.swing.KeyStroke
@@ -24,13 +23,7 @@ data class ActionNode(
2423
): ActionPresentation {
2524

2625
val action = toAction(actionManager)
27-
val presentation =
28-
ActionPresentation.create(
29-
action,
30-
keysOverride,
31-
separatorAbove,
32-
isSticky,
33-
)
26+
val presentation = ActionPresentation.create(action, keysOverride, separatorAbove, isSticky)
3427
presentation.update(actionManager, dataContext)
3528
return presentation
3629
}
@@ -58,16 +51,4 @@ data class ActionNode(
5851
.toList()
5952
.reversed()
6053
}
61-
62-
companion object {
63-
64-
/* Use ACTION_SEARCH as the action place seems to work the best.
65-
*
66-
* 'Run | Stop' menu action works correctly this way by
67-
* showing a list of processes to stop
68-
*
69-
* 'Exit' actions works (doesn't work if place is MAIN_MENU)
70-
*/
71-
const val ACTION_PLACE = ActionPlaces.ACTION_SEARCH
72-
}
7354
}

src/main/kotlin/com/gitlab/lae/intellij/actions/tree/Popup.kt

Lines changed: 20 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
package com.gitlab.lae.intellij.actions.tree
22

3-
import com.gitlab.lae.intellij.actions.tree.ui.ActionList
4-
import com.gitlab.lae.intellij.actions.tree.ui.ActionPopupEventDispatcher
53
import com.gitlab.lae.intellij.actions.tree.ui.ActionPresentation
4+
import com.gitlab.lae.intellij.actions.tree.ui.ActionPresentationStep
65
import com.gitlab.lae.intellij.actions.tree.util.setBestLocation
76
import com.intellij.ide.DataManager
8-
import com.intellij.ide.IdeEventQueue
97
import com.intellij.openapi.actionSystem.ActionGroup
108
import com.intellij.openapi.actionSystem.ActionManager
9+
import com.intellij.openapi.actionSystem.ActionPlaces.ACTION_PLACE_QUICK_LIST_POPUP_ACTION
1110
import com.intellij.openapi.actionSystem.AnAction
1211
import com.intellij.openapi.actionSystem.AnActionEvent
1312
import com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR
1413
import com.intellij.openapi.actionSystem.DataContext
15-
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_ESCAPE
1614
import com.intellij.openapi.actionSystem.PlatformDataKeys.CONTEXT_COMPONENT
1715
import com.intellij.openapi.actionSystem.ex.ActionUtil
1816
import com.intellij.openapi.application.ApplicationManager.getApplication
19-
import com.intellij.openapi.ui.popup.JBPopup
2017
import com.intellij.openapi.ui.popup.JBPopupFactory
2118
import com.intellij.openapi.ui.popup.JBPopupFactory.ActionSelectionAid
22-
import com.intellij.openapi.ui.popup.PopupChooserBuilder
2319
import com.intellij.openapi.wm.IdeFocusManager
20+
import com.intellij.ui.popup.list.ListPopupImpl
2421
import java.awt.event.ActionEvent
2522
import javax.swing.JComponent
2623
import javax.swing.KeyStroke
@@ -31,29 +28,23 @@ internal class Popup(action: ActionNode, e: AnActionEvent) {
3128
private val actionManager = e.actionManager
3229
private val sourceComponent = e.getData(CONTEXT_COMPONENT)
3330
private val sourceEditor = e.getData(EDITOR)
34-
private val list: ActionList
35-
private val popup: JBPopup
31+
private val popup: ListPopupImpl
32+
private val items: List<ActionPresentation>
3633

3734
init {
38-
val items =
35+
items =
3936
action.prepare(e.dataContext).map { (keys, item) ->
4037
createPresentation(item, e.actionManager, e.dataContext, keys)
4138
}
42-
list = ActionList(items)
43-
44-
// Register our action first before IntelliJ registers the default
45-
// actions (e.g. com.intellij.ui.ScrollingUtil) so that in case of
46-
// conflict our action will be executed
47-
items.forEach { it.registerShortcuts(list) { item, e -> this.onActionChosen(item, e) } }
48-
popup = createPopup()
49-
popup.addListener(
50-
ActionPopupEventDispatcher(
51-
popup,
52-
list,
53-
IdeEventQueue.getInstance().popupManager,
54-
),
55-
)
56-
registerIdeAction(ACTION_EDITOR_ESCAPE, popup::cancel)
39+
40+
popup =
41+
ListPopupImpl(
42+
e.project,
43+
ActionPresentationStep(items) { value, modifiers -> onActionChosen(value, modifiers) },
44+
)
45+
items.forEach { item ->
46+
item.registerShortcuts(popup.list) { event -> onActionChosen(item, event) }
47+
}
5748
}
5849

5950
fun show(dataContext: DataContext) {
@@ -65,41 +56,7 @@ internal class Popup(action: ActionNode, e: AnActionEvent) {
6556
actionManager: ActionManager,
6657
dataContext: DataContext,
6758
keysOverride: List<KeyStroke>,
68-
): ActionPresentation =
69-
action.createPresentation(
70-
actionManager,
71-
dataContext,
72-
keysOverride,
73-
)
74-
75-
private fun createPopup(): JBPopup =
76-
PopupChooserBuilder(list)
77-
.setModalContext(true)
78-
.setCloseOnEnter(false)
79-
.setItemChosenCallback(
80-
Runnable {
81-
val item = list.selectedValue
82-
if (item != null) {
83-
onActionChosen(item, 0)
84-
}
85-
}
86-
)
87-
.createPopup()
88-
89-
private fun registerIdeAction(actionId: String, runnable: () -> Unit) {
90-
val action = actionManager.getAction(actionId) ?: return
91-
val shortcutSet = action.shortcutSet
92-
if (shortcutSet.shortcuts.isEmpty()) {
93-
return
94-
}
95-
96-
object : AnAction() {
97-
override fun actionPerformed(e: AnActionEvent) {
98-
runnable()
99-
}
100-
}
101-
.registerCustomShortcutSet(shortcutSet, list)
102-
}
59+
): ActionPresentation = action.createPresentation(actionManager, dataContext, keysOverride)
10360

10461
private fun onActionChosen(item: ActionPresentation, e: ActionEvent) {
10562
onActionChosen(item, e.modifiers)
@@ -110,8 +67,7 @@ internal class Popup(action: ActionNode, e: AnActionEvent) {
11067
return
11168
}
11269

113-
list.setSelectedValue(item, false)
114-
val invocation = { performAction(item.action, modifiers) }
70+
val invocation = { performAction(item.value, modifiers) }
11571
if (item.sticky) {
11672
invocation()
11773
getApplication().invokeLater {
@@ -138,11 +94,7 @@ internal class Popup(action: ActionNode, e: AnActionEvent) {
13894
* action should be enabled/disabled for current cursor position.
13995
*/
14096
private fun updatePresentations() {
141-
getDataContextAsync { context ->
142-
generateSequence(0, Int::inc).take(list.model.size).map(list.model::getElementAt).forEach {
143-
it.update(actionManager, context)
144-
}
145-
}
97+
getDataContextAsync { context -> items.forEach { it.update(actionManager, context) } }
14698
}
14799

148100
private fun getDataContextAsync(consumer: (DataContext) -> Unit) {
@@ -174,16 +126,12 @@ internal class Popup(action: ActionNode, e: AnActionEvent) {
174126
}
175127
}
176128

177-
private fun performAction(
178-
action: AnAction,
179-
modifiers: Int,
180-
dataContext: DataContext,
181-
) {
129+
private fun performAction(action: AnAction, modifiers: Int, dataContext: DataContext) {
182130
val event =
183131
AnActionEvent(
184132
null,
185133
dataContext,
186-
ActionNode.ACTION_PLACE,
134+
ACTION_PLACE_QUICK_LIST_POPUP_ACTION,
187135
action.templatePresentation.clone(),
188136
actionManager,
189137
modifiers,

src/main/kotlin/com/gitlab/lae/intellij/actions/tree/ui/ActionList.kt

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

src/main/kotlin/com/gitlab/lae/intellij/actions/tree/ui/ActionPopupEventDispatcher.kt

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

0 commit comments

Comments
 (0)